scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

pass5.c (824B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 
      4 #include <scc/mach.h>
      5 
      6 #include "ld.h"
      7 
      8 extern int bintype;
      9 extern Symbol defhead;
     10 
     11 /*
     12         char *name;
     13         int type;
     14         int sect;
     15         unsigned long long size;
     16         unsigned long long value;
     17 */
     18 
     19 void
     20 pass5(int argc, char *argv[])
     21 {
     22 	Obj *obj;
     23 	Symbol *sym;
     24 	Segment **segp;
     25 	Objsym *osym;
     26 	FILE *fp;
     27 	static Segment *segv[] = {
     28 		&text,
     29 		&data,
     30 		&bss,
     31 		/* TODO: debug, */
     32 		NULL,
     33 	};
     34 
     35 	obj = objnew(bintype);
     36 
     37 	for (segp = segv; *segp; segp++)
     38 		/* objaddseg(obj, *segp) */ ;
     39 
     40 	for (sym = defhead.next; sym != &defhead; sym = sym->next) {
     41 		osym = objlookup(obj, sym->name, 1);
     42 		osym->size = sym->size;
     43 		osym->value = sym->value;
     44 	}
     45 
     46 	/* TODO: write relocations */
     47 	/* TODO: write line information */
     48 
     49 	fp = fopen(output, "wb");
     50 	(obj->ops->write)(obj, fp);
     51 }