scc

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

commit 8beaaef5c3c15d1ca09f114e4ff62057a319571a
parent 83da01ff8ebc220738bc8844a72d7e57cf6d02ed
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 16 Nov 2017 10:56:46 +0000

[as] Move writeout() to myro.c

This new file will contain the code to generate
the myro objects files.

Diffstat:
Mas/Makefile | 2+-
Mas/as.h | 2+-
Aas/myro.c | 25+++++++++++++++++++++++++
Mas/symbol.c | 27++++-----------------------
4 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/as/Makefile b/as/Makefile @@ -4,7 +4,7 @@ LIBDIR = ../lib/scc include ../config.mk include $(LIBDIR)/libdep.mk -OBJ = main.o symbol.o ins.o parser.o expr.o +OBJ = main.o symbol.o ins.o parser.o expr.o myro.o HDR = ../inc/scc.h as.h MOREFLAGS = -I../inc/$(STD) $(AS_CFLAGS) diff --git a/as/as.h b/as/as.h @@ -138,7 +138,7 @@ extern int match(Op *op, Node **args); /* * Definition of global variables */ -extern Section *cursec; +extern Section *cursec, *seclist; extern int nr_ins; extern Ins instab[]; extern Op optab[]; diff --git a/as/myro.c b/as/myro.c @@ -0,0 +1,25 @@ +static char sccsid[] = "@(#) ./as/myro.c"; + +#include <stdio.h> + +#include "../inc/scc.h" +#include "as.h" + +void +writeout(char *name) +{ + FILE *fp; + Section *sp; + + if ((fp = fopen(name, "wb")) == NULL) + die("error opening output file '%s'\n", name); + + for (sp = seclist; sp; sp = sp->next) { + if (!sp->mem) + continue; + fwrite(sp->mem, sp->max - sp->base, 1, fp); + } + + if (fclose(fp)) + die("error writing the output file"); +} diff --git a/as/symbol.c b/as/symbol.c @@ -34,7 +34,7 @@ static Section text = { .next = &data, }; -Section *cursec = &text, *headp = &text; +Section *cursec = &text, *seclist = &text; int pass; @@ -207,7 +207,7 @@ section(char *name) { Section *sec; - for (sec = headp; sec; sec = sec->next) { + for (sec = seclist; sec; sec = sec->next) { if (!strcmp(sec->name, name)) break; } @@ -215,7 +215,7 @@ section(char *name) sec = xmalloc(sizeof(*sec)); sec->name = xstrdup(name); sec->base = sec->max = sec->pc = sec->curpc = 0; - sec->next = headp; + sec->next = seclist; sec->flags = SRELOC|SREAD|SWRITE|SFILE; } return cursec = sec; @@ -226,7 +226,7 @@ isections(void) { Section *sec; - for (sec = headp; sec; sec = sec->next) + for (sec = seclist; sec; sec = sec->next) isect(sec); } @@ -260,22 +260,3 @@ killtmp(void) dealloc(tmpalloc); tmpalloc = NULL; } - -void -writeout(char *name) -{ - FILE *fp; - Section *secp; - - if ((fp = fopen(name, "wb")) == NULL) - die("error opening output file '%s'\n", name); - - for (secp = headp; secp; secp = secp->next) { - if (!secp->mem) - continue; - fwrite(secp->mem, secp->max - secp->base, 1, fp); - } - - if (fclose(fp)) - die("error writing the output file"); -}