shithub: scc

Download patch

ref: 90587cbec9a3ffba0aee86c7be5503447f711f6e
parent: 7b11f1552037238aed78c142731722182f6e0ddc
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Feb 2 02:31:45 EST 2018

[as] Allow left to right or right to left parsing

This is a very simple patch that will make happy to everyone.
Uses the style that you prefer.

--- a/as/ins.c
+++ b/as/ins.c
@@ -241,3 +241,14 @@
 {
 	endpass = 1;
 }
+
+void
+att(Op *op, Node **args)
+{
+	Symbol *sym = args[0]->sym;
+	extern int left2right;
+
+	if ((sym->flags & FABS) == 0)
+		error("align expression is not an absolute expression");
+	left2right = sym->value;
+}
--- a/as/main.c
+++ b/as/main.c
@@ -109,6 +109,7 @@
 main(int argc, char *argv[])
 {
 	char **p;
+	extern int left2right;
 
 	outfile = "a.out";
 
@@ -115,6 +116,12 @@
 	ARGBEGIN {
 	case 'o':
 		outfile = EARGF(usage());
+		break;
+	case 'l':
+		left2right = 1;
+		break;
+	case 'r':
+		left2right = 1;
 		break;
 	default:
 		usage();
--- a/as/parser.c
+++ b/as/parser.c
@@ -275,14 +275,24 @@
 getargs(char *s)
 {
 	Node **ap;
-	static Node *args[NARGS];
+	extern int left2right;
+	static Node *args[NARGS+1];
 
 	if (!s)
 		return NULL;
 
-	for (ap = args; ap < &args[NARGS-1]; ++ap) {
-		if ((*ap = operand(&s)) == NULL)
-			return args;
+	if (!left2right) {
+		ap = args;
+		do {
+			if ((*ap = operand(&s)) == NULL)
+				return args;
+		} while (++ap < &args[NARGS]);
+	} else {
+		ap = &args[NARGS];
+		do {
+			if ((*--ap = operand(&s)) == NULL)
+				return ap+1;
+		} while (ap > args+1);
 	}
 	error("too many arguments in one instruction");
 }
--- a/as/target/x80/x80.dat
+++ b/as/target/x80/x80.dat
@@ -31,6 +31,7 @@
 .STRING	string+	0	none	string	Z80,R800,GB80
 .ASCII	string+	0	none	ascii	Z80,R800,GB80
 .ALIGN	imm16+	0	none	align	Z80,R800,GB80
+.ATT	imm8	0	none	att	Z80,R800,GB80
 .END	none	0	none	end	Z80,R800,GB80
 
 
--- a/as/target/x80/z80.c
+++ b/as/target/x80/z80.c
@@ -8,6 +8,7 @@
 
 TUINT maxaddr = 0xFFFFFFFF;
 int endian = LITTLE_ENDIAN;
+int left2right = 0;
 
 void
 iarch(void)
--- a/as/target/x86/amd64.c
+++ b/as/target/x86/amd64.c
@@ -5,6 +5,7 @@
 
 TUINT maxaddr = 0xFFFFFFFFFFFFFFFF;
 int endian = LITTLE_ENDIAN;
+int left2right = 0;
 
 void
 iarch(void)
--- a/as/target/x86/i386.c
+++ b/as/target/x86/i386.c
@@ -6,6 +6,7 @@
 
 TUINT maxaddr = 0xFFFFFFFF;
 int endian = LITTLE_ENDIAN;
+int left2right = 0;
 
 void
 iarch(void)