struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / asxxsrc / asdbg.c
blobf2dc46f3985c3967c854cc8ce862416b1ff6e031
1 /* asdbg.c */
3 /*
4 * Copyright (C) 2003-2009 Alan R. Baldwin
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * Alan R. Baldwin
21 * 721 Berkeley St.
22 * Kent, Ohio 44240
25 * Code extracted from asnoice.c
26 * written by:
27 * John L. Hartman (JLH)
28 * 3-Nov-1997
31 #include <ctype.h>
32 #include "dbuf_string.h"
33 #include "asxxxx.h"
35 /*)Module asdbg.c
37 * The module asdbg.c contains the functions that
39 * 1) generate debug symbols for assembler code
40 * similiar to those generated by the SDCC compiler
42 * 2) generate debug symbols for the NoICE
43 * remote debugger
45 * asdbg.c contains the following functions:
46 * VOID DefineSDCC_Line()
47 * VOID DefineNoICE_Line()
48 * char * BaseFileName()
50 * asdbg.c contains the static variables:
51 * int prevFile
52 * char baseName[FILSPC]
54 * used by the BaseFileName function.
56 * NOTE:
57 * These functions know nothing about 'include' files
58 * and do not track their inclusion.
61 /*)Function VOID DefineSDCC_Line()
63 * The function DefineSDCC_Line() is called to create
64 * a symbol of the form A$FILE$nnn where FILE is the
65 * Base File Name, the file name without a path or
66 * an extension, and nnn is the line number.
68 * local variables:
69 * struct dbuf_s dbuf a temporary to build the symbol
70 * struct sym * pSym pointer to the created symbol structure
72 * global variables:
73 * asmf * asmc pointer to current assembler file structure
74 * int srcline array of source file line numbers
75 * a_uint laddr current assembler address
76 * area dot.s_area pointer to the current area
78 * functions called:
79 * char * BaseFileName() asdbg.c
80 * sym * lookup() assym.c
81 * int sprintf() c_library
83 * side effects:
84 * A new symbol of the form A$FILE$nnn is created.
87 #if SDCDB
88 VOID
89 DefineSDCC_Line (void)
91 struct dbuf_s dbuf;
92 struct sym *pSym;
95 * Symbol is A$FILE$nnn
97 dbuf_init (&dbuf, NCPS);
98 dbuf_printf (&dbuf, "A$%s$%u", BaseFileName (asmc, 1), srcline);
100 pSym = lookup (dbuf_c_str (&dbuf));
101 dbuf_destroy (&dbuf);
103 pSym->s_type = S_USER;
104 pSym->s_area = dot.s_area;
105 pSym->s_addr = laddr;
106 pSym->s_flag |= S_GBL;
108 #endif
111 /*)Function VOID DefineNoICE_Line()
113 * The function DefineNoICE_Line() is called to create
114 * a symbol of the form FILE.nnn where FILE is the
115 * Base File Name, the file name without a path or
116 * an extension, and nnn is the line number.
118 * local variables:
119 * struct dbuf_s dbuf a temporary to build the symbol
120 * struct sym * pSym pointer to the created symbol structure
122 * global variables:
123 * asmf * asmc pointer to current assembler file structure
124 * int srcline array of source file line numbers
125 * a_uint laddr current assembler address
126 * area dot.s_area pointer to the current area
128 * functions called:
129 * char * BaseFileName() asdbg.c
130 * sym * lookup() assym.c
131 * int sprintf() c_library
133 * side effects:
134 * A new symbol of the form FILE.nnn is created.
137 #if NOICE
138 VOID
139 DefineNoICE_Line (void)
141 struct dbuf_s dbuf;
142 struct sym *pSym;
145 * Symbol is FILE.nnn
147 dbuf_init (&dbuf, NCPS);
148 dbuf_printf (&dbuf, "%s.%u", BaseFileName (asmc, 0), srcline);
150 pSym = lookup (dbuf_c_str (&dbuf));
151 dbuf_destroy (&dbuf);
153 pSym->s_type = S_USER;
154 pSym->s_area = dot.s_area;
155 pSym->s_addr = laddr;
156 pSym->s_flag |= S_GBL;
158 #endif
161 /*)Function char * BaseFileName(currFile, spacesToUnderscores)
163 * The function BaseFileName() is called to extract
164 * the file name from a string containing a path,
165 * filename, and extension. If spacesToUnderscores != 0
166 * then spaces are converted to underscores
168 * currFile is a pointer to the
169 * current assembler object
170 * spacesToUnderscores
172 * local variables:
173 * char baseName[] a place to put the file name
174 * int prevFile previous assembler object
175 * char * p1 temporary string pointer
176 * char * p2 temporary string pointer
178 * global variables:
179 * FILE * ofp output file handle
181 * functions called:
182 * int fprintf() c_library
183 * char * strcpy() c_library
184 * char * strrchr() c_library
185 * char * isspace() c_library
187 * side effects:
188 * A FILE command of the form ';!FILE string'
189 * is written to the output file.
192 #if (NOICE || SDCDB)
193 static struct asmf * prevFile = NULL;
194 static char baseName[FILSPC];
196 char *
197 BaseFileName (struct asmf * currFile, int spacesToUnderscores)
199 char *p1, *p2;
201 if (currFile != prevFile) {
202 prevFile = currFile;
204 strcpy(baseName, afn);
205 p1 = baseName;
208 * Dump a FILE command with full path and extension
210 if (ofp)
211 fprintf(ofp, ";!FILE %s\n", p1);
214 * The name starts after the last
215 * '/' (Unices) or
216 * ':' or '\' (DOS)
218 * and ends at the last
219 * separator 'FSEPX'
221 if ((p2 = strrchr(p1, '\\')) != NULL) p1 = ++p2;
222 if ((p2 = strrchr(p1, '/')) != NULL) p1 = ++p2;
223 if ((p2 = strrchr(p1, ':')) != NULL) p1 = ++p2;
224 if ((p2 = strrchr(p1, FSEPX)) != NULL) *p2 = 0;
225 memmove(baseName, p1, strlen(p1)+1); /* Do not use strcpy(), since baseName and p1 may overlap */
227 if (spacesToUnderscores) {
228 /* Convert spaces to underscores */
229 for (p1 = baseName; *p1; ++p1)
230 if (isspace (*p1))
231 *p1 = '_';
234 return(baseName);
236 #endif