]> git.sur5r.net Git - cc65/blob - src/ca65/dbginfo.c
Complete redesign of line info generation. Uses spans instead of a fragment
[cc65] / src / ca65 / dbginfo.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 dbginfo.c                                 */
4 /*                                                                           */
5 /*                         Handle the .dbg commands                          */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2011, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <string.h>
37
38 /* common */
39 #include "strbuf.h"
40
41 /* ca65 */
42 #include "error.h"
43 #include "expr.h"
44 #include "filetab.h"
45 #include "lineinfo.h"
46 #include "nexttok.h"
47 #include "dbginfo.h"
48
49
50
51 /*****************************************************************************/
52 /*                                   Data                                    */
53 /*****************************************************************************/
54
55
56
57 /* The current line info */
58 static LineInfo* CurLineInfo = 0;
59
60
61
62 /*****************************************************************************/
63 /*                                   Code                                    */
64 /*****************************************************************************/
65
66
67
68 void DbgInfoFile (void)
69 /* Parse and handle FILE subcommand of the .dbg pseudo instruction */
70 {
71     StrBuf Name = STATIC_STRBUF_INITIALIZER;
72     unsigned long Size;
73     unsigned long MTime;
74
75     /* Parameters are separated by a comma */
76     ConsumeComma ();
77
78     /* Name */
79     if (CurTok.Tok != TOK_STRCON) {
80         ErrorSkip ("String constant expected");
81         return;
82     }
83     SB_Copy (&Name, &CurTok.SVal);
84     NextTok ();
85
86     /* Comma expected */
87     ConsumeComma ();
88
89     /* Size */
90     Size = ConstExpression ();
91
92     /* Comma expected */
93     ConsumeComma ();
94
95     /* MTime */
96     MTime = ConstExpression ();
97
98     /* Insert the file into the table */
99     AddFile (&Name, FT_DBGINFO, Size, MTime);
100
101     /* Free memory used for Name */
102     SB_Done (&Name);
103 }
104
105
106
107 void DbgInfoLine (void)
108 /* Parse and handle LINE subcommand of the .dbg pseudo instruction */
109 {
110     long Line;
111     FilePos Pos = STATIC_FILEPOS_INITIALIZER;
112
113     /* Any new line info terminates the last one */
114     if (CurLineInfo) {
115         EndLine (CurLineInfo);
116         CurLineInfo = 0;
117     }
118
119     /* If a parameters follow, this is actual line info. If no parameters
120      * follow, the last line info is terminated.
121      */
122     if (CurTok.Tok == TOK_SEP) {
123         return;
124     }
125
126     /* Parameters are separated by a comma */
127     ConsumeComma ();
128
129     /* The name of the file follows */
130     if (CurTok.Tok != TOK_STRCON) {
131         ErrorSkip ("String constant expected");
132         return;
133     }
134
135     /* Get the index in the file table for the name */
136     Pos.Name = GetFileIndex (&CurTok.SVal);
137
138     /* Skip the name */
139     NextTok ();
140
141     /* Comma expected */
142     ConsumeComma ();
143
144     /* Line number */
145     Line = ConstExpression ();
146     if (Line < 0) {
147         ErrorSkip ("Line number is out of valid range");
148         return;
149     }
150     Pos.Line = Line;
151
152     /* Generate a new external line info */
153     CurLineInfo = StartLine (&Pos, LI_TYPE_EXT, 0);
154 }
155
156
157
158 void DbgInfoSym (void)
159 /* Parse and handle SYM subcommand of the .dbg pseudo instruction */
160 {
161     ErrorSkip ("Not implemented");
162 }
163
164
165