shithub: scc

Download patch

ref: b96020ecf7d028aca4079de9d484d3fecd0b93e9
parent: 48b3decbbe158d8d164cacfc4a7af81ee4b6e847
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Dec 12 17:50:39 EST 2017

[as] Remove section parameter of emit()

This parameter is going to be always cursec, so it is better to
remove this parameter and use cursec as an internal parameter.

--- a/as/as.h
+++ b/as/as.h
@@ -119,7 +119,7 @@
 
 /* symbol.c */
 extern void isections(void);
-extern void emit(Section *sec, char *bytes, int nbytes);
+extern void emit(char *bytes, int nbytes);
 extern Section *section(char *name);
 extern Symbol *tmpsym(TUINT val);
 extern void killtmp(void);
--- a/as/ins.c
+++ b/as/ins.c
@@ -24,7 +24,7 @@
 void
 noargs(Op *op, Node **args)
 {
-	emit(cursec, op->bytes, op->size);
+	emit(op->bytes, op->size);
 }
 
 void
@@ -37,7 +37,7 @@
 
 		if (sym->flags & FUNDEF)
 			reloc(sym, 0, siz, siz * 8, 0);
-		emit(cursec, tobytes(sym->value, siz, endian), siz);
+		emit(tobytes(sym->value, siz, endian), siz);
 	}
 }
 
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -223,10 +223,12 @@
 }
 
 void
-emit(Section *sec, char *bytes, int n)
+emit(char *bytes, int n)
 {
-	if (sec->mem)
-		memcpy(&sec->mem[sec->pc - sec->base], bytes, n);
+	if (cursec->mem) {
+		size_t len = cursec->pc - cursec->base;
+		memcpy(&cursec->mem[len], bytes, n);
+	}
 	incpc(n);
 }
 
--- a/as/target/x80/ins.c
+++ b/as/target/x80/ins.c
@@ -90,7 +90,7 @@
 	memcpy(buf, op->bytes, n-1);
 	buf[n-1] = par2->sym->value;
 	buf[n-2] |= reg2int(par1->sym->argtype) << 3;
-	emit(cursec, buf, n);
+	emit(buf, n);
 }
 
 void
@@ -104,7 +104,7 @@
 
 	memcpy(buf, op->bytes, n-1);
 	buf[n-1] = par2->sym->value;
-	emit(cursec, buf, n);
+	emit(buf, n);
 }
 
 void
@@ -121,7 +121,7 @@
 	val = par2->sym->value;
 	buf[n-1] = val >> 8;
 	buf[n-2] = val;
-	emit(cursec, buf, n);
+	emit(buf, n);
 }
 
 void
@@ -136,7 +136,7 @@
 	memcpy(buf, op->bytes, n);
 	buf[n-1] |= reg2int(par1->sym->argtype) << 3 | 
 	            reg2int(par2->sym->argtype);
-	emit(cursec, buf, n);
+	emit(buf, n);
 }
 
 void
@@ -151,7 +151,7 @@
 
 	memcpy(buf, op->bytes, n);
 	buf[n-1] |= reg2int(par2->sym->argtype);
-	emit(cursec, buf, n);
+	emit(buf, n);
 }
 
 void
@@ -166,7 +166,7 @@
 
 	memcpy(buf, op->bytes, n);
 	buf[n-1] |= reg2int(par2->sym->argtype) << 3;
-	emit(cursec, buf, n);
+	emit(buf, n);
 }
 
 void
@@ -181,5 +181,5 @@
 
 	memcpy(buf, op->bytes, n);
 	buf[n-1] |= reg2int(par1->sym->argtype) << 3;
-	emit(cursec, buf, n);
+	emit(buf, n);
 }