6 static const char *_findMapping(const char *szKey)
8 return shash_find(_h, szKey);
11 static va_list _iprintf(char *pInto, const char *szFormat, va_list ap)
14 char *sz = gc_strdup(szFormat);
20 /* See if it's a special emitter */
24 /* Name of the code segment */
26 strcpy(pInto, CODE_NAME);
27 pInto = pStart + strlen(pStart);
31 strcpy(pInto, srcFileName);
32 pInto = pStart + strlen(pStart);
36 sprintf(pInto, "%u", ++count);
37 pInto = pStart + strlen(pStart);
42 /* Scan out the arg and pass it on to sprintf */
49 vsprintf(pInto, p, ap);
50 /* PENDING: Assume that the arg length was an int */
55 pInto = pStart + strlen(pStart);
66 void tvsprintf(char *buffer, const char *szFormat, va_list ap)
68 char *sz = gc_strdup(szFormat);
69 char *pInto = buffer, *p;
75 /* Start of a token. Search until the first
76 [non alplha, *] and call it a token. */
80 while (isalpha(*sz) || *sz == '*') {
85 /* Now find the token in the token list */
86 if ((t = _findMapping(p))) {
87 ap = _iprintf(pInto, t, ap);
88 pInto = buffer + strlen(buffer);
91 fprintf(stderr, "Cant find token \"%s\"\n", p);
96 else if (*sz == '%') {
100 while (!isalpha(*sz))
105 vsprintf(pInto, pFormat, ap);
106 pInto = buffer + strlen(buffer);
117 void tfprintf(FILE *fp, const char *szFormat, ...)
120 char buffer[MAX_INLINEASM];
122 va_start(ap, szFormat);
123 tvsprintf(buffer, szFormat, ap);
127 void tsprintf(char *buffer, const char *szFormat, ...)
130 va_start(ap, szFormat);
131 tvsprintf(buffer, szFormat, ap);
134 void asm_addTree(const ASM_MAPPINGS *pMappings)
136 const ASM_MAPPING *pMap;
137 /* Traverse down first */
138 if (pMappings->pParent)
139 asm_addTree(pMappings->pParent);
140 pMap = pMappings->pMappings;
141 while (pMap->szKey && pMap->szValue) {
142 shash_add(&_h, pMap->szKey, pMap->szValue);
147 static const ASM_MAPPING _asxxxx_mapping[] = {
148 { "labeldef", "%s::" },
149 { "slabeldef", "%s:" },
150 { "tlabeldef", "%05d$:" },
151 { "tlabel", "%05d$" },
155 { "area", ".area %s" },
156 { "areacode", ".area %s" },
157 { "areadata", ".area %s" },
158 { "ascii", ".ascii \"%s\"" },
164 { "constbyte", "0x%02X" },
165 { "constword", "0x%04X" },
166 { "immedword", "#0x%04X" },
167 { "immedbyte", "#0x%02X" },
168 { "hashedstr", "#%s" },
169 { "lsbimmeds", "#<%s" },
170 { "msbimmeds", "#>%s" },
171 { "module", ".module %s" },
172 { "global", ".globl %s" },
173 { "fileprelude", "" },
175 "; ---------------------------------\n"
177 "; ---------------------------------"
179 { "functionlabeldef", "%s:" },
180 { "bankimmeds", "0 ; PENDING: bank support" },
184 const ASM_MAPPINGS asm_asxxxx_mapping = {