shithub: scc

Download patch

ref: bcfb495c00ea175223148a037ce64f8cc9504c57
parent: 97bfd21a430fbac3267e12e5d67a92a7f5ced8a9
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Nov 16 05:56:46 EST 2017

[as] Move writeout() to myro.c

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

--- a/as/Makefile
+++ b/as/Makefile
@@ -4,7 +4,7 @@
 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)
 
--- a/as/as.h
+++ b/as/as.h
@@ -138,7 +138,7 @@
 /*
  * Definition of global variables
  */
-extern Section *cursec;
+extern Section *cursec, *seclist;
 extern int nr_ins;
 extern Ins instab[];
 extern Op optab[];
--- /dev/null
+++ b/as/myro.c
@@ -1,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");
+}
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -34,7 +34,7 @@
 	.next  = &data,
 };
 
-Section *cursec = &text, *headp = &text;
+Section *cursec = &text, *seclist = &text;
 
 int pass;
 
@@ -207,7 +207,7 @@
 {
 	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 @@
 		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 @@
 {
 	Section *sec;
 
-	for (sec = headp; sec; sec = sec->next)
+	for (sec = seclist; sec; sec = sec->next)
 		isect(sec);
 }
 
@@ -259,23 +259,4 @@
 		return;
 	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");
 }