comparison src/output.c @ 88:6460a1fb5f1f

Checkpoint: object format output
author lost
date Sat, 17 Jan 2009 04:37:40 +0000
parents 41ff4686b46b
children 718998b673ee
comparison
equal deleted inserted replaced
87:41ff4686b46b 88:6460a1fb5f1f
200 200
201 void write_code_obj(asmstate_t *as, FILE *of) 201 void write_code_obj(asmstate_t *as, FILE *of)
202 { 202 {
203 lwasm_line_t *l; 203 lwasm_line_t *l;
204 sectiontab_t *s; 204 sectiontab_t *s;
205 lwasm_symbol_ent_t *se;
206
205 int i; 207 int i;
206 unsigned char buf[16]; 208 unsigned char buf[16];
207 209
208 // output the magic number and file header 210 // output the magic number and file header
209 // the 8 is NOT an error 211 // the 8 is NOT an error
269 271
270 // indicate end of flags - the "" is NOT an error 272 // indicate end of flags - the "" is NOT an error
271 writebytes("", 1, 1, of); 273 writebytes("", 1, 1, of);
272 274
273 275
276 // now the local symbols
277 for (se = as -> symhead; se; se = se -> next)
278 {
279 // ignore symbols not in this section
280 if (se -> sect != s)
281 continue;
282
283 if (se -> flags & SYMBOL_SET)
284 continue;
285
286 if (se -> flags & SYMBOL_EXTERN)
287 continue;
288
289 writebytes(se -> sym, strlen(se -> sym), 1, of);
290 if (se -> context >= 0)
291 {
292 writebytes("\x01", 1, 1, of);
293 sprintf(buf, "%d", se -> context);
294 writebytes(buf, strlen(buf), 1, of);
295 }
296 // the "" is NOT an error
297 writebytes("", 1, 1, of);
298
299 // write the address
300 buf[0] = (se -> value >> 8) & 0xff;
301 buf[1] = se -> value & 0xff;
302 writebytes(buf, 2, 1, of);
303 }
304 // flag end of local symbol table - "" is NOT an error
305 writebytes("", 1, 1, of);
306
274 // now blast out the code 307 // now blast out the code
275 308
276 // length 309 // length
277 buf[0] = s -> oblen >> 8 & 0xff; 310 buf[0] = s -> oblen >> 8 & 0xff;
278 buf[1] = s -> oblen & 0xff; 311 buf[1] = s -> oblen & 0xff;