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);
19 /* See if it's a special emitter */
23 /* Name of the code segment */
25 strcpy(pInto, CODE_NAME);
26 pInto = pStart + strlen(pStart);
31 /* Scan out the arg and pass it on to sprintf */
38 vsprintf(pInto, p, ap);
39 /* PENDING: Assume that the arg length was an int */
44 pInto = pStart + strlen(pStart);
55 void tvsprintf(char *buffer, const char *szFormat, va_list ap)
57 char *sz = gc_strdup(szFormat);
58 char *pInto = buffer, *p;
64 /* Start of a token. Search until the first
65 [non alplha, *] and call it a token. */
69 while (isalpha(*sz) || *sz == '*') {
74 /* Now find the token in the token list */
75 if ((t = _findMapping(p))) {
76 ap = _iprintf(pInto, t, ap);
77 pInto = buffer + strlen(buffer);
80 fprintf(stderr, "Cant find token \"%s\"\n", p);
85 else if (*sz == '%') {
94 vsprintf(pInto, pFormat, ap);
95 pInto = buffer + strlen(buffer);
106 void tfprintf(FILE *fp, const char *szFormat, ...)
109 char buffer[MAX_INLINEASM];
111 va_start(ap, szFormat);
112 tvsprintf(buffer, szFormat, ap);
116 void tsprintf(char *buffer, const char *szFormat, ...)
119 va_start(ap, szFormat);
120 tvsprintf(buffer, szFormat, ap);
123 void asm_addTree(const ASM_MAPPINGS *pMappings)
125 const ASM_MAPPING *pMap;
126 /* Traverse down first */
127 if (pMappings->pParent)
128 asm_addTree(pMappings->pParent);
129 pMap = pMappings->pMappings;
130 while (pMap->szKey && pMap->szValue) {
131 shash_add(&_h, pMap->szKey, pMap->szValue);
136 static const ASM_MAPPING _asxxxx_mapping[] = {
137 { "labeldef", "%s::" },
138 { "slabeldef", "%s:" },
139 { "tlabeldef", "%05d$:" },
140 { "tlabel", "%05d$" },
144 { "area", ".area %s" },
145 { "areacode", ".area %s" },
146 { "areadata", ".area %s" },
147 { "ascii", ".ascii \"%s\"" },
153 { "constbyte", "0x%02X" },
154 { "constword", "0x%04X" },
155 { "immedword", "#0x%04X" },
156 { "immedbyte", "#0x%02X" },
157 { "hashedstr", "#%s" },
158 { "lsbimmeds", "#>%s" },
159 { "msbimmeds", "#<%s" },
160 { "module", ".module %s" },
161 { "global", ".globl %s" },
162 { "fileprelude", "" },
164 "; ---------------------------------\n"
166 "; ---------------------------------"
168 { "functionlabeldef", "%s:" },
172 const ASM_MAPPINGS asm_asxxxx_mapping = {