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/>.
25 * Code extracted from asnoice.c
27 * John L. Hartman (JLH)
32 #include "dbuf_string.h"
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
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:
52 * char baseName[FILSPC]
54 * used by the BaseFileName function.
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.
69 * struct dbuf_s dbuf a temporary to build the symbol
70 * struct sym * pSym pointer to the created symbol structure
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
79 * char * BaseFileName() asdbg.c
80 * sym * lookup() assym.c
81 * int sprintf() c_library
84 * A new symbol of the form A$FILE$nnn is created.
89 DefineSDCC_Line (void)
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
;
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.
119 * struct dbuf_s dbuf a temporary to build the symbol
120 * struct sym * pSym pointer to the created symbol structure
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
129 * char * BaseFileName() asdbg.c
130 * sym * lookup() assym.c
131 * int sprintf() c_library
134 * A new symbol of the form FILE.nnn is created.
139 DefineNoICE_Line (void)
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
;
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
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
179 * FILE * ofp output file handle
182 * int fprintf() c_library
183 * char * strcpy() c_library
184 * char * strrchr() c_library
185 * char * isspace() c_library
188 * A FILE command of the form ';!FILE string'
189 * is written to the output file.
193 static struct asmf
* prevFile
= NULL
;
194 static char baseName
[FILSPC
];
197 BaseFileName (struct asmf
* currFile
, int spacesToUnderscores
)
201 if (currFile
!= prevFile
) {
204 strcpy(baseName
, afn
);
208 * Dump a FILE command with full path and extension
211 fprintf(ofp
, ";!FILE %s\n", p1
);
214 * The name starts after the last
218 * and ends at the last
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
)