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
18 static const char *_findMapping(const char *szKey)
20 return shash_find(_h, szKey);
23 static va_list _iprintf(char *pInto, const char *sz, va_list ap)
25 char format[MAX_TOKEN_LEN];
32 /* See if it's a special emitter */
36 /* Name of the code segment */
38 strcpy(pInto, CODE_NAME);
39 pInto = pStart + strlen(pStart);
43 strcpy(pInto, srcFileName);
44 pInto = pStart + strlen(pStart);
48 sprintf(pInto, "%u", ++count);
49 pInto = pStart + strlen(pStart);
54 /* Scan out the arg and pass it on to sprintf */
61 vsprintf(pInto, format, ap);
62 /* PENDING: Assume that the arg length was an int */
66 pInto = pStart + strlen(pStart);
77 void tvsprintf(char *buffer, const char *sz, va_list ap)
81 char token[MAX_TOKEN_LEN];
87 /* Start of a token. Search until the first
88 [non alplha, *] and call it a token. */
92 while (isalpha(*sz) || *sz == '*') {
96 /* Now find the token in the token list */
97 if ((t = _findMapping(token))) {
98 ap = _iprintf(pInto, t, ap);
99 pInto = buffer + strlen(buffer);
102 fprintf(stderr, "Cant find token \"%s\"\n", token);
106 else if (*sz == '%') {
109 while (!isalpha(*sz)) {
114 vsprintf(pInto, token, ap);
115 pInto = buffer + strlen(buffer);
125 void tfprintf(FILE *fp, const char *szFormat, ...)
128 char buffer[MAX_INLINEASM];
130 va_start(ap, szFormat);
131 tvsprintf(buffer, szFormat, ap);
135 void tsprintf(char *buffer, const char *szFormat, ...)
138 va_start(ap, szFormat);
139 tvsprintf(buffer, szFormat, ap);
142 void asm_addTree(const ASM_MAPPINGS *pMappings)
144 const ASM_MAPPING *pMap;
145 /* Traverse down first */
146 if (pMappings->pParent)
147 asm_addTree(pMappings->pParent);
148 pMap = pMappings->pMappings;
149 while (pMap->szKey && pMap->szValue) {
150 shash_add(&_h, pMap->szKey, pMap->szValue);
155 static const ASM_MAPPING _asxxxx_mapping[] = {
156 { "labeldef", "%s::" },
157 { "slabeldef", "%s:" },
158 { "tlabeldef", "%05d$:" },
159 { "tlabel", "%05d$" },
163 { "area", ".area %s" },
164 { "areacode", ".area %s" },
165 { "areadata", ".area %s" },
166 { "areahome", ".area %s" },
167 { "ascii", ".ascii \"%s\"" },
173 { "constbyte", "0x%02X" },
174 { "constword", "0x%04X" },
175 { "immedword", "#0x%04X" },
176 { "immedbyte", "#0x%02X" },
177 { "hashedstr", "#%s" },
178 { "lsbimmeds", "#<%s" },
179 { "msbimmeds", "#>%s" },
180 { "module", ".module %s" },
181 { "global", ".globl %s" },
182 { "fileprelude", "" },
184 "; ---------------------------------\n"
186 "; ---------------------------------"
188 { "functionlabeldef", "%s:" },
189 { "bankimmeds", "0 ; PENDING: bank support" },
193 const ASM_MAPPINGS asm_asxxxx_mapping = {