comparison src/output.c @ 87:41ff4686b46b

Checkpoint: object format output
author lost
date Sat, 17 Jan 2009 02:59:24 +0000
parents 033a328a10ae
children 6460a1fb5f1f
comparison
equal deleted inserted replaced
86:033a328a10ae 87:41ff4686b46b
199 } 199 }
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 int i; 205 int i;
206 unsigned char buf[16];
205 207
206 // output the magic number and file header 208 // output the magic number and file header
207 writebytes("LWOBJ16\0", 8, 1, of); 209 // the 8 is NOT an error
210 writebytes("LWOBJ16", 8, 1, of);
208 211
209 // run through the entire system and build the byte streams for each 212 // run through the entire system and build the byte streams for each
210 // section; at the same time, generate a list of "local" symbols to 213 // section; at the same time, generate a list of "local" symbols to
211 // output for each section 214 // output for each section
212 // NOTE: for "local" symbols, we will append \x01 and the ascii string 215 // NOTE: for "local" symbols, we will append \x01 and the ascii string
251 re -> offset = l -> codeaddr + l -> relocoff; 254 re -> offset = l -> codeaddr + l -> relocoff;
252 re -> expr = l -> exprs[0]; 255 re -> expr = l -> exprs[0];
253 } 256 }
254 } 257 }
255 } 258 }
256 } 259
260 // run through the sections
261 for (s = as -> sections; s; s = s -> next)
262 {
263 // write the name
264 writebytes(s -> name, strlen(s -> name) + 1, 1, of);
265
266 // write the flags
267 if (s -> flags & SECTION_BSS)
268 writebytes("\x01", 1, 1, of);
269
270 // indicate end of flags - the "" is NOT an error
271 writebytes("", 1, 1, of);
272
273
274 // now blast out the code
275
276 // length
277 buf[0] = s -> oblen >> 8 & 0xff;
278 buf[1] = s -> oblen & 0xff;
279 writebytes(buf, 2, 1, of);
280
281 if (!(s -> flags & SECTION_BSS))
282 {
283 writebytes(s -> obytes, s -> oblen, 1, of);
284 }
285 }
286
287 // flag no more sections
288 // the "" is NOT an error
289 writebytes("", 1, 1, of);
290 }