comparison leo-obj/tool/richsym.c @ 149:fdf3137c703a

tiobjd richsym handling: prep for handling function locals
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Tue, 29 Apr 2014 07:11:33 +0000
parents 13cc7e19ecec
children df01a4f4c272
comparison
equal deleted inserted replaced
148:13cc7e19ecec 149:fdf3137c703a
134 134
135 char * 135 char *
136 get_base_type_of_syment(sym, is_typedef) 136 get_base_type_of_syment(sym, is_typedef)
137 struct internal_syment *sym; 137 struct internal_syment *sym;
138 { 138 {
139 unsigned idx;
140
139 switch (sym->type & 0xF) { 141 switch (sym->type & 0xF) {
140 case T_VOID: 142 case T_VOID:
141 return("void"); 143 return("void");
142 case T_CHAR: 144 case T_CHAR:
143 if (is_typedef) 145 if (is_typedef)
153 case T_FLOAT: 155 case T_FLOAT:
154 return("float"); 156 return("float");
155 case T_DOUBLE: 157 case T_DOUBLE:
156 return("double"); 158 return("double");
157 case T_STRUCT: 159 case T_STRUCT:
158 return get_struct_type_name(get_u32(sym->aux), C_STRTAG, 160 idx = get_u32(sym->aux);
159 is_typedef); 161 if (idx)
162 return get_struct_type_name(idx, C_STRTAG, is_typedef);
163 else
164 return("struct ?");
160 case T_UNION: 165 case T_UNION:
161 return get_struct_type_name(get_u32(sym->aux), C_UNTAG, 166 idx = get_u32(sym->aux);
162 is_typedef); 167 if (idx)
168 return get_struct_type_name(idx, C_UNTAG, is_typedef);
169 else
170 return("union ?");
163 case T_ENUM: 171 case T_ENUM:
164 return get_struct_type_name(get_u32(sym->aux), C_ENTAG, 172 idx = get_u32(sym->aux);
165 is_typedef); 173 if (idx)
174 return get_struct_type_name(idx, C_ENTAG, is_typedef);
175 else
176 return("enum ?");
166 case T_UCHAR: 177 case T_UCHAR:
167 if (is_typedef) 178 if (is_typedef)
168 return("unsigned char"); 179 return("unsigned char");
169 else 180 else
170 return("u_char"); 181 return("u_char");
183 default: 194 default:
184 return("__unknown_base_type"); 195 return("__unknown_base_type");
185 } 196 }
186 } 197 }
187 198
199 static char *
200 cdecl_obj_name(sym)
201 struct internal_syment *sym;
202 {
203 char *buf;
204 int isund, len;
205
206 isund = (sym->name[0] == '_');
207 len = strlen(sym->name) + 1;
208 if (isund)
209 len--;
210 else
211 len += 2;
212 buf = malloc(len);
213 if (!buf) {
214 perror("malloc");
215 exit(1);
216 }
217 if (isund)
218 strcpy(buf, sym->name + 1);
219 else
220 sprintf(buf, "\"%s\"", sym->name);
221 return(buf);
222 }
223
188 richsym_print_in_c(prefix, sym, is_typedef) 224 richsym_print_in_c(prefix, sym, is_typedef)
189 char *prefix; 225 char *prefix;
190 struct internal_syment *sym; 226 struct internal_syment *sym;
191 { 227 {
192 char *base_type, *s1, *s2; 228 char *base_type, *s1, *s2;
193 int dertype, last_ptr, narray; 229 int dertype, last_ptr, narray;
194 230
195 base_type = get_base_type_of_syment(sym, is_typedef); 231 base_type = get_base_type_of_syment(sym, is_typedef);
196 dertype = sym->type >> 4; 232 dertype = sym->type >> 4;
197 s1 = malloc(strlen(sym->name)); 233 s1 = cdecl_obj_name(sym);
198 if (!s1) {
199 perror("malloc");
200 exit(1);
201 }
202 strcpy(s1, sym->name + 1);
203 last_ptr = 0; 234 last_ptr = 0;
204 narray = 0; 235 narray = 0;
205 for (; dertype; dertype >>= 2) { 236 for (; dertype; dertype >>= 2) {
206 switch (dertype & 3) { 237 switch (dertype & 3) {
207 case DT_NON: 238 case DT_NON: