shithub: scc

Download patch

ref: 904d47a869c5d7051c6b56ffefa504db3d2c8351
parent: 13bb65b0a913612763d1066aa60d5513d451f296
parent: 681c75d4db6045572033f07cad7c365ec011f3a3
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Dec 12 02:56:17 EST 2017

Merge branch 'master' of ssh://simple-cc.org:/var/gitrepos/scc

--- a/as/as.h
+++ b/as/as.h
@@ -2,30 +2,23 @@
  * First 3 bits of flags in segments and symbols are for the
  * type of segment
  */
-enum symtype {
-	TUNDEF  = 0,
-	TABS    = 1,
-	TTEXT   = 2,
-	TBSS    = 3,
-	TDATA   = 4,
-	TREG    = 5,
-	TMASK   = 7,
+enum symflags {
+	FREG    = 1 << 0,
+	FCOMMON = 1 << 1,
+	FLOCAL  = 1 << 2,
+	FEXTERN = 1 << 3,
+	FUNDEF  = 1 << 4,
 };
 
 enum secflags {
-	SRELOC  = 1 << 4,
-	SREAD   = 1 << 5,
-	SWRITE  = 1 << 6,
-	SFILE   = 1 << 7,
+	SREAD  = 1 << 0,
+	SWRITE = 1 << 1,
+	SEXEC  = 1 << 2,
+	SLOAD  = 1 << 3,
+	SFILE  = 1 << 4,
+	SABS   = 1 << 5,
 };
 
-enum symflags {
-	FCOMMON = 1 << 4,
-	FLOCAL  = 1 << 5,
-	FEXTERN = 1 << 6,
-	FUNDEF  = 1 << 7,
-};
-
 enum endianess {
 	BIG_ENDIAN    = -1,
 	LITTLE_ENDIAN = 1
@@ -110,6 +103,7 @@
 	unsigned char pass;
 	unsigned char argtype;
 	TUINT value;
+	Section *section;
 	struct symbol *next;
 	struct symbol *hash;
 };
@@ -175,4 +169,4 @@
 extern TUINT maxaddr;
 extern int endian;
 extern Symbol *linesym, *symlist;
-extern char *filename;
+extern char *infile;
--- a/as/expr.c
+++ b/as/expr.c
@@ -200,7 +200,7 @@
 	while (isalnum(c = *endp) || c == '_' || c == '.')
 		++endp;
 	tok2str();
-	yylval.sym = lookup(yytext, TUNDEF);
+	yylval.sym = lookup(yytext, FUNDEF);
 
 	return IDEN;
 }
@@ -267,7 +267,7 @@
 	while (isalnum(c = *endp))
 		++endp;
 	tok2str();
-	yylval.sym = lookup(yytext, TREG);
+	yylval.sym = lookup(yytext, FREG);
 	if (!yylval.sym->argtype)
 		error("incorrect register name");
 	return REG;
--- a/as/main.c
+++ b/as/main.c
@@ -7,8 +7,20 @@
 #include <string.h>
 
 #include "../inc/scc.h"
+#include "../inc/arg.h"
 #include "as.h"
 
+char *argv0;
+char *outfile, *infile;
+
+
+static void
+cleanup(void)
+{
+	if (outfile)
+		remove(outfile);
+}
+
 static int
 cmp(const void *f1, const void *f2)
 {
@@ -81,7 +93,7 @@
 	if (fclose(fp))
 		die("as: error reading from input file '%s'", fname);
 	if (pass == 2)
-		writeout("a.out");
+		writeout(outfile);
 	/*
 	 * kill tmp symbols because they are not needed anymore
 	 */
@@ -100,15 +112,27 @@
 int
 main(int argc, char *argv[])
 {
-	if (argc != 2)
+	outfile = "a.out";
+
+	ARGBEGIN {
+	case 'o':
+		outfile = EARGF(usage());
+		break;
+	default:
 		usage();
+	} ARGEND
 
+	if (argc != 1)
+		usage();
+	infile = *argv;
+
+	atexit(cleanup);
 	iarch();
-	filename = argv[1];
 	for (pass = 1; pass <= 2; pass++) {
-		if (!dopass(filename))
+		if (!dopass(infile))
 			return 1;
 	}
+	outfile = NULL;
 
 	return 0;
 }
--- a/as/myro.c
+++ b/as/myro.c
@@ -26,7 +26,7 @@
 	off = sizeof(FORMAT);
 
 	for (sym = symlist; sym; sym = sym->next) {
-		if ((sym->flags & TMASK) == TREG)
+		if (sym->flags & FREG)
 			continue;
 		str = &sym->name;
 		len = strlen(str->buf) + 1;
@@ -57,6 +57,12 @@
 		flags |= MYROSEC_WRITE;
 	if (sp->flags & SFILE)
 		flags |= MYROSEC_FILE;
+	if (sp->flags & SEXEC)
+		flags |= MYROSEC_EXEC;
+	if (sp->flags & SLOAD)
+		flags |= MYROSEC_LOAD;
+	if (sp->flags & SABS)
+		flags |= MYROSEC_ABS;
 	return flags;
 }
 
@@ -88,7 +94,7 @@
 	struct myrosym symbol;
 
 	for (sym = symlist; sym; sym = sym->next) {
-		if ((sym->flags & TMASK) == TREG)
+		if (sym->flags & FREG)
 			continue;
 		symbol.name = sym->name.offset;
 		symbol.type = -1;
--- a/as/parser.c
+++ b/as/parser.c
@@ -12,7 +12,6 @@
 #define NARGS 20
 #define MAXLINE 100
 
-char *filename;
 int nerrors;
 jmp_buf recover;
 
@@ -24,7 +23,7 @@
 	va_list va;
 
 	va_start(va, msg);
-	fprintf(stderr, "as:%s:%u: ", filename, lineno);
+	fprintf(stderr, "as:%s:%u: ", infile, lineno);
 	vfprintf(stderr, msg, va);
 	putc('\n', stderr);
 	nerrors++;
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -13,24 +13,24 @@
 
 static Section abss = {
 	.name  = (String) {"abs"},
-	.flags = TABS|SREAD|SWRITE,
+	.flags = SABS|SREAD|SWRITE|SFILE|SLOAD,
 };
 
 static Section bss = {
 	.name  = (String) {"bss"},
-	.flags = TBSS|SRELOC|SREAD|SWRITE,
+	.flags = SREAD|SWRITE|SLOAD,
 	.next  = &abss,
 };
 
 static Section data = {
 	.name  = (String) {"data"},
-	.flags = TDATA|SRELOC|SREAD|SWRITE|SFILE,
+	.flags = SREAD|SWRITE|SFILE|SLOAD,
 	.next  = &bss,
 };
 
 static Section text = {
 	.name  = (String) {"text"},
-	.flags = TTEXT|SRELOC|SFILE,
+	.flags = SREAD|SEXEC|SLOAD|SFILE,
 	.next  = &data,
 };
 
@@ -83,8 +83,8 @@
 		t = sym->name.buf;
 		if (c != toupper(*t) || casecmp(t, name))
 			continue;
-		symtype = sym->flags & TMASK;
-		if (symtype != TUNDEF && symtype != type)
+		symtype = sym->flags;
+		if (((symtype | type) & FUNDEF) == 0 && symtype != type)
 			continue;
 		return sym;
 	}
@@ -93,6 +93,7 @@
 	sym->name = newstring(name);
 	sym->flags = FLOCAL | FUNDEF | type;
 	sym->value = 0;
+	sym->section = cursec;
 	sym->hash = *list;
 	sym->next = symlist;
 
@@ -124,7 +125,7 @@
 		name = label;
 	}
 
-	sym = lookup(name, TUNDEF);
+	sym = lookup(name, FUNDEF);
 	if (pass == 1 && (sym->flags & FUNDEF) == 0)
 		error("redefinition of label '%s'", name);
 	sym->flags &= ~FUNDEF;
@@ -197,7 +198,7 @@
 		sec->name = newstring(name);
 		sec->base = sec->max = sec->pc = sec->curpc = 0;
 		sec->next = seclist;
-		sec->flags = SRELOC|SREAD|SWRITE|SFILE;
+		sec->flags = 0;
 		sec->fill = 0;
 		sec->aligment = 0;
 	}
@@ -230,7 +231,7 @@
 		tmpalloc = alloc(sizeof(*sym), NALLOC);
 	sym = new(tmpalloc);
 	sym->value = val;
-	sym->flags = TABS;
+	sym->section = NULL;
 
 	return sym;
 }
--- a/as/target/i386/proc.c
+++ b/as/target/i386/proc.c
@@ -92,7 +92,7 @@
 	}, *bp;
 
 	for (bp = regs; bp->name; ++bp) {
-		Symbol *sym = lookup(bp->name, TREG);
+		Symbol *sym = lookup(bp->name, FREG);
 		sym->argtype = bp->type;
 	}
 }
--- a/as/target/z80/proc.c
+++ b/as/target/z80/proc.c
@@ -45,7 +45,7 @@
 	}, *bp;
 
 	for (bp = regs; bp->name; ++bp) {
-		Symbol *sym = lookup(bp->name, TREG);
+		Symbol *sym = lookup(bp->name, FREG);
 		sym->argtype = bp->type;
 	}
 }