2 Provides output functions that modify the output string
3 based on the input tokens and the assembler token mapping
6 Note that the functions below only handle digit format modifiers.
7 eg %02X is ok, but %lu and %.4u will fail.
12 /* A 'token' is like !blah or %24f and is under the programmers
14 #define MAX_TOKEN_LEN 64
19 FileBaseName (char *fileFullName)
21 char *p = fileFullName;
29 if ((*fileFullName == '/') || (*fileFullName == '\\') || (*fileFullName == ':'))
40 _findMapping (const char *szKey)
42 return shash_find (_h, szKey);
45 // Append a string onto another, and update the pointer to the end of
48 _appendAt (char *at, char *onto, const char *sz)
50 wassert (at && onto && sz);
52 return at + strlen (sz);
56 tvsprintf (char *buffer, const char *format, va_list ap)
58 // Under Linux PPC va_list is a structure instead of a primitive type,
59 // and doesnt like being passed around. This version turns everything
64 // %[CIFN] - special formats with no argument (ie list isnt touched)
65 // All of the system formats
67 // This is acheived by expanding the tokens and zero arg formats into
68 // one big format string, which is passed to the native printf.
70 char noTokens[INITIAL_INLINEASM];
71 char newFormat[INITIAL_INLINEASM];
72 char *pInto = noTokens;
74 char token[MAX_TOKEN_LEN];
75 const char *sz = format;
77 // NULL terminate it to let strlen work.
80 /* First pass: expand all of the macros */
85 /* Start of a token. Search until the first
86 [non alpha, *] and call it a token. */
90 while (isalpha (*sz) || *sz == '*')
95 /* Now find the token in the token list */
96 if ((t = _findMapping (token)))
98 pInto = _appendAt (pInto, noTokens, t);
102 fprintf (stderr, "Cant find token \"%s\"\n", token);
114 /* Second pass: Expand any macros that we own */
122 // See if its one that we handle.
127 // Code segment name.
128 pInto = _appendAt (pInto, newFormat, CODE_NAME);
133 pInto = _appendAt (pInto, newFormat, srcFileName);
137 // Current function name.
138 pInto = _appendAt (pInto, newFormat, currFunc->rname);
145 sprintf (id, "%u", ++count);
146 pInto = _appendAt (pInto, newFormat, id);
151 // Not one of ours. Copy until the end.
153 while (!isalpha (*sz))
168 // Now do the actual printing
169 vsprintf (buffer, newFormat, ap);
173 tfprintf (FILE * fp, const char *szFormat,...)
176 char buffer[INITIAL_INLINEASM];
178 va_start (ap, szFormat);
179 tvsprintf (buffer, szFormat, ap);
184 tsprintf (char *buffer, const char *szFormat,...)
187 va_start (ap, szFormat);
188 tvsprintf (buffer, szFormat, ap);
192 asm_addTree (const ASM_MAPPINGS * pMappings)
194 const ASM_MAPPING *pMap;
196 /* Traverse down first */
197 if (pMappings->pParent)
198 asm_addTree (pMappings->pParent);
199 pMap = pMappings->pMappings;
200 while (pMap->szKey && pMap->szValue) {
201 shash_add (&_h, pMap->szKey, pMap->szValue);
206 static const ASM_MAPPING _asxxxx_mapping[] =
208 {"labeldef", "%s::"},
209 {"slabeldef", "%s:"},
210 {"tlabeldef", "%05d$:"},
215 {"area", ".area %s"},
216 {"areacode", ".area %s"},
217 {"areadata", ".area %s"},
218 {"areahome", ".area %s"},
219 {"ascii", ".ascii \"%s\""},
225 {"constbyte", "0x%02X"},
226 {"constword", "0x%04X"},
227 {"immedword", "#0x%04X"},
228 {"immedbyte", "#0x%02X"},
229 {"hashedstr", "#%s"},
230 {"lsbimmeds", "#<%s"},
231 {"msbimmeds", "#>%s"},
232 {"module", ".module %s"},
233 {"global", ".globl %s"},
236 "; ---------------------------------\n"
238 "; ---------------------------------"
240 {"functionlabeldef", "%s:"},
241 {"bankimmeds", "0 ; PENDING: bank support"},
242 {"los","(%s & 0xFF)"},
244 {"hihis","(%s >> 16)"},
245 {"hihihis","(%s >> 24)"},
246 {"lod","(%d & 0xFF)"},
248 {"hihid","(%d >> 16)"},
249 {"hihihid","(%d >> 24)"},
250 {"lol","(%05d$ & 0xFF)"},
251 {"hil","(%05d$ >> 8)"},
252 {"hihil","(%05d$ >> 16)"},
253 {"hihihil","(%05d$ >> 24)"},
258 static const ASM_MAPPING _gas_mapping[] =
260 {"labeldef", "%s::"},
261 {"slabeldef", "%s:"},
262 {"tlabeldef", "%05d$:"},
267 {"area", ".section %s"},
268 {"areacode", ".section %s"},
269 {"areadata", ".section %s"},
270 {"areahome", ".section %s"},
271 {"ascii", ".ascii \"%s\""},
277 {"constbyte", "0x%02X"},
278 {"constword", "0x%04X"},
279 {"immedword", "#0x%04X"},
280 {"immedbyte", "#0x%02X"},
281 {"hashedstr", "#%s"},
282 {"lsbimmeds", "#<%s"},
283 {"msbimmeds", "#>%s"},
284 {"module", ".file \"%s.c\""},
285 {"global", ".globl %s"},
286 {"extern", ".globl %s"},
289 "; ---------------------------------\n"
291 "; ---------------------------------"
293 {"functionlabeldef", "%s:"},
294 {"bankimmeds", "0 ; PENDING: bank support"},
298 static const ASM_MAPPING _a390_mapping[] =
301 {"slabeldef", "%s:"},
302 {"tlabeldef", "L%05d:"},
307 {"area", "; SECTION NOT SUPPORTED"},
308 {"areacode", "; SECTION NOT SUPPORTED"},
309 {"areadata", "; SECTION NOT SUPPORTED"},
310 {"areahome", "; SECTION NOT SUPPORTED"},
311 {"ascii", "db \"%s\""},
312 {"ds", "; STORAGE NOT SUPPORTED"},
314 {"dbs", "db \"%s\""},
317 {"constbyte", "0%02xh"},
318 {"constword", "0%04xh"},
319 {"immedword", "#0%04Xh"},
320 {"immedbyte", "#0%02Xh"},
321 {"hashedstr", "#%s"},
322 {"lsbimmeds", "#<%s"},
323 {"msbimmeds", "#>%s"},
324 {"module", "; .file \"%s.c\""},
325 {"global", "; .globl %s"},
328 "; ---------------------------------\n"
330 "; ---------------------------------"
332 {"functionlabeldef", "%s:"},
333 {"bankimmeds", "0 ; PENDING: bank support"},
334 {"los","(%s & 0FFh)"},
335 {"his","((%s / 256) & 0FFh)"},
336 {"hihis","((%s / 65536) & 0FFh)"},
337 {"hihihis","((%s / 16777216) & 0FFh)"},
338 {"lod","(%d & 0FFh)"},
339 {"hid","((%d / 256) & 0FFh)"},
340 {"hihid","((%d / 65536) & 0FFh)"},
341 {"hihihid","((%d / 16777216) & 0FFh)"},
342 {"lol","(L%05d & 0FFh)"},
343 {"hil","((L%05d / 256) & 0FFh)"},
344 {"hihil","((L%05d / 65536) & 0FFh)"},
345 {"hihihil","((L%09d / 16777216) & 0FFh)"},
350 const ASM_MAPPINGS asm_asxxxx_mapping =
356 const ASM_MAPPINGS asm_gas_mapping =
362 const ASM_MAPPINGS asm_a390_mapping =