changeset 87:41ff4686b46b

Checkpoint: object format output
author lost
date Sat, 17 Jan 2009 02:59:24 +0000
parents 033a328a10ae
children 6460a1fb5f1f
files src/output.c
diffstat 1 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/output.c	Fri Jan 16 05:33:40 2009 +0000
+++ b/src/output.c	Sat Jan 17 02:59:24 2009 +0000
@@ -201,10 +201,13 @@
 void write_code_obj(asmstate_t *as, FILE *of)
 {
 	lwasm_line_t *l;
+	sectiontab_t *s;
 	int i;
+	unsigned char buf[16];
 
 	// output the magic number and file header
-	writebytes("LWOBJ16\0", 8, 1, of);
+	// the 8 is NOT an error
+	writebytes("LWOBJ16", 8, 1, of);
 	
 	// run through the entire system and build the byte streams for each
 	// section; at the same time, generate a list of "local" symbols to
@@ -253,4 +256,35 @@
 			}
 		}
 	}
+	
+	// run through the sections
+	for (s = as -> sections; s; s = s -> next)
+	{
+		// write the name
+		writebytes(s -> name, strlen(s -> name) + 1, 1, of);
+		
+		// write the flags
+		if (s -> flags & SECTION_BSS)
+			writebytes("\x01", 1, 1, of);
+		
+		// indicate end of flags - the "" is NOT an error
+		writebytes("", 1, 1, of);
+		
+		
+		// now blast out the code
+		
+		// length
+		buf[0] = s -> oblen >> 8 & 0xff;
+		buf[1] = s -> oblen & 0xff;
+		writebytes(buf, 2, 1, of);
+		
+		if (!(s -> flags & SECTION_BSS))
+		{
+			writebytes(s -> obytes, s -> oblen, 1, of);
+		}
+	}
+	
+	// flag no more sections
+	// the "" is NOT an error
+	writebytes("", 1, 1, of);
 }