scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

commit 3e70d6bebe7d1a43654c6ea6301c5783f6ebcf70
parent 4e925d3950f940b0548c667562bbdd0b26215f8a
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  1 Feb 2018 20:59:37 +0100

Merge remote-tracking branch 'simple-cc/master'

Diffstat:
Mas/ins.c | 11+++++++++++
Mas/main.c | 7+++++++
Mas/parser.c | 23++++++++++++++++++-----
Mas/target/x80/x80.dat | 1+
Mas/target/x80/z80.c | 1+
Mas/target/x86/amd64.c | 1+
Mas/target/x86/i386.c | 1+
7 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/as/ins.c b/as/ins.c @@ -247,3 +247,14 @@ include(Op *op, Node **args) { addinput(args[0]->sym->name.buf); } + +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; +} diff --git a/as/main.c b/as/main.c @@ -105,6 +105,7 @@ int main(int argc, char *argv[]) { char **p; + extern int left2right; outfile = "a.out"; @@ -112,6 +113,12 @@ main(int argc, char *argv[]) case 'o': outfile = EARGF(usage()); break; + case 'l': + left2right = 1; + break; + case 'r': + left2right = 1; + break; default: usage(); } ARGEND diff --git a/as/parser.c b/as/parser.c @@ -299,14 +299,24 @@ Node ** 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"); } @@ -411,6 +421,7 @@ getline(FILE *fp, char buff[MAXLINE]) if (c == '/') { if ((c = getc(fp)) != '*') { ungetc(c, fp); + c = '/'; } else { comment(fp); c = ' '; @@ -418,9 +429,11 @@ getline(FILE *fp, char buff[MAXLINE]) } else if (c > UCHAR_MAX) { error("invalid character '%x'", c); } - if (bp == &buff[MAXLINE]) + if (bp == &buff[MAXLINE-1]) error("line too long"); } + *bp = '\0'; + return bp - buff; } diff --git 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 .INCLUDE string 0 none include Z80,R800,GB80 diff --git a/as/target/x80/z80.c b/as/target/x80/z80.c @@ -8,6 +8,7 @@ static char sccsid[] = "@(#) ./as/target/x80/z80.c"; TUINT maxaddr = 0xFFFFFFFF; int endian = LITTLE_ENDIAN; +int left2right = 0; void iarch(void) diff --git a/as/target/x86/amd64.c b/as/target/x86/amd64.c @@ -5,6 +5,7 @@ static char sccsid[] = "@(#) ./as/target/x86/amd64.c"; TUINT maxaddr = 0xFFFFFFFFFFFFFFFF; int endian = LITTLE_ENDIAN; +int left2right = 0; void iarch(void) diff --git a/as/target/x86/i386.c b/as/target/x86/i386.c @@ -6,6 +6,7 @@ static char sccsid[] = "@(#) ./as/target/x86/i386.c"; TUINT maxaddr = 0xFFFFFFFF; int endian = LITTLE_ENDIAN; +int left2right = 0; void iarch(void)