scc

simple C compiler
git clone git@git.2f30.org/scc.git
Log | Files | Refs | README | LICENSE

wmyro.c (1722B)


      1 static char sccsid[] = "@(#) ./lib/scc/wmyro.c";
      2 
      3 #include <assert.h>
      4 #include <stdio.h>
      5 #include <string.h>
      6 
      7 #include "../../inc/scc.h"
      8 #include "../../inc/myro.h"
      9 
     10 int
     11 wrmyrohdr(FILE *fp, struct myrohdr *hdr)
     12 {
     13 	unsigned char buf[MYROHDR_SIZ];
     14 	int len;
     15 
     16 	len = lpack(buf, "cccclqqqqq",
     17 	            hdr->magic[0], hdr->magic[1],
     18 	            hdr->magic[2], hdr->magic[3],
     19 	            hdr->format,
     20 	            hdr->entry,
     21 	            hdr->strsize,
     22 	            hdr->secsize,
     23 	            hdr->symsize,
     24 	            hdr->relsize);
     25 	assert(MYROHDR_SIZ == len);
     26 	fwrite(buf, len, 1, fp);
     27 
     28 	return (ferror(fp)) ? EOF : len;
     29 }
     30 
     31 int
     32 wrmyrosec(FILE *fp, struct myrosect *sect)
     33 {
     34 	unsigned char buf[MYROSECT_SIZ];
     35 	int len;
     36 
     37 	len = lpack(buf, "lsccqq",
     38 	            sect->name,
     39 	            sect->flags,
     40 	            sect->fill,
     41 	            sect->aligment,
     42 	            sect->offset,
     43 	            sect->len);
     44 	assert(MYROSECT_SIZ == len);
     45 	fwrite(buf, len, 1, fp);
     46 
     47 	return (ferror(fp)) ? EOF : len;
     48 }
     49 
     50 int
     51 wrmyrosym(FILE *fp, struct myrosym *sym)
     52 {
     53 	unsigned char buf[MYROSYM_SIZ];
     54 	int len;
     55 
     56 	len = lpack(buf, "llccqq",
     57 	            sym->name,
     58 	            sym->type,
     59 	            sym->section,
     60 	            sym->flags,
     61 	            sym->offset,
     62 	            sym->len);
     63 	assert(MYROSYM_SIZ == len);
     64 	fwrite(buf, len, 1, fp);
     65 
     66 	return (ferror(fp)) ? EOF : len;
     67 }
     68 
     69 int
     70 wrmyrorel(FILE *fp, struct myrorel *rel)
     71 {
     72 	unsigned char buf[MYROREL_SIZ];
     73 	int len;
     74 
     75 	len = lpack(buf, "lccccq",
     76 	            rel->id,
     77 	            rel->flags,
     78 	            rel->size,
     79 	            rel->nbits,
     80 	            rel->shift,
     81 	            rel->offset);
     82 	assert(MYROREL_SIZ == len);
     83 	fwrite(buf, len, 1, fp);
     84 
     85 	return (ferror(fp)) ? EOF : len;
     86 }