scc

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

rmyro.c (1870B)


      1 static char sccsid[] = "@(#) ./lib/scc/rmyro.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 rdmyrohdr(FILE *fp, struct myrohdr *hdr)
     12 {
     13 	unsigned char buf[MYROHDR_SIZ];
     14 	int len;
     15 
     16 	fread(buf, sizeof(buf), 1, fp);
     17 	if (ferror(fp))
     18 		return EOF;
     19 	len = lunpack(buf, "cccclqqqqq",
     20 	              hdr->magic+0, hdr->magic+1,
     21 	              hdr->magic+2, hdr->magic+3,
     22 	              &hdr->format,
     23 	              &hdr->entry,
     24 	              &hdr->strsize,
     25 	              &hdr->secsize,
     26 	              &hdr->symsize,
     27 	              &hdr->relsize);
     28 	assert(len == MYROHDR_SIZ);
     29 
     30 	return len;
     31 }
     32 
     33 int
     34 rdmyrosec(FILE *fp, struct myrosect *sect)
     35 {
     36 	unsigned char buf[MYROSECT_SIZ];
     37 	int len;
     38 
     39 	fread(buf, sizeof(buf), 1, fp);
     40 	if (ferror(fp))
     41 		return EOF;
     42 	len = lunpack(buf, "lsccqq",
     43 	              &sect->name,
     44 	              &sect->flags,
     45 	              &sect->fill,
     46 	              &sect->aligment,
     47 	              &sect->offset,
     48 	              &sect->len);
     49 	assert(len == MYROSECT_SIZ);
     50 
     51 	return len;
     52 }
     53 
     54 int
     55 rdmyrosym(FILE *fp, struct myrosym *sym)
     56 {
     57 	unsigned char buf[MYROSYM_SIZ];
     58 	int len;
     59 
     60 	fread(buf, sizeof(buf), 1, fp);
     61 	if (ferror(fp))
     62 		return EOF;
     63 	len = lunpack(buf, "llccqq",
     64 	              &sym->name,
     65 	              &sym->type,
     66 	              &sym->section,
     67 	              &sym->flags,
     68 	              &sym->offset,
     69 	              &sym->len);
     70 	assert(len == MYROSYM_SIZ);
     71 
     72 	return len;
     73 }
     74 
     75 int
     76 rdmyrorel(FILE *fp, struct myrorel *rel)
     77 {
     78 	unsigned char buf[MYROREL_SIZ];
     79 	int len;
     80 
     81 	fread(buf, sizeof(buf), 1, fp);
     82 	if (ferror(fp))
     83 		return EOF;
     84 	len = lunpack(buf, "lccccq",
     85 	              &rel->id,
     86 	              &rel->flags,
     87 	              &rel->size,
     88 	              &rel->nbits,
     89 	              &rel->shift,
     90 	              &rel->offset);
     91 	assert(len == MYROREL_SIZ);
     92 
     93 	return len;
     94 }