scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 0b5e3f2a9a8748de84f45956ce189fe2ac7332a0
parent a8f970a7e2c9427feac2a8e8b1929eb4f1abdc70
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 27 Sep 2017 12:10:13 +0100

[as-x86] Use unified file for instructions

It is easier to use flags and filter with that flags
instead of creating individual files per cpu.

Diffstat:
Das/common.dat | 6------
Mas/target/i386/target.mk | 8+++-----
Das/target/x86/amd64.dat | 0
Mas/target/x86/gen.awk | 102++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Das/target/x86/i386.dat | 5-----
Aas/target/x86/x86.dat | 11+++++++++++
6 files changed, 68 insertions(+), 64 deletions(-)

diff --git a/as/common.dat b/as/common.dat @@ -1,6 +0,0 @@ -# Tab 16, tabs 16, :set ts=16 -# op args size bytes format -DB imm8+ 0 none defb -DW imm16+ 0 none defw -DD imm32+ 0 none defd -DQ imm64+ 0 none defq diff --git a/as/target/i386/target.mk b/as/target/i386/target.mk @@ -1,15 +1,13 @@ -I386_TBL = common.dat \ - target/x86/i386.dat target/i386/ins.o: target/i386/ins.h target/i386/instbl.o: target/i386/ins.h -target/i386/instbl.c: target/x86/gen.awk $(I386_TBL) +target/i386/instbl.c: target/x86/gen.awk target/x86/x86.dat set -e ;\ rm -f $@;\ trap "rm -f $$$$.c" 0 2 3; \ - cat $(I386_TBL) | \ - awk -f target/x86/gen.awk > $$$$.c && mv $$$$.c $@ + awk -v bits=BITS32 -f target/x86/gen.awk \ + < target/x86/x86.dat > $$$$.c && mv $$$$.c $@ OBJ-i386 = $(OBJ) \ target/i386/instbl.o \ diff --git a/as/target/x86/amd64.dat b/as/target/x86/amd64.dat diff --git a/as/target/x86/gen.awk b/as/target/x86/gen.awk @@ -1,59 +1,65 @@ -BEGIN { - FS = "\t" - printf "#include \"../../../inc/scc.h\"\n"\ - "#include \"../../as.h\"\n"\ - "#include \"../x86/proc.h\"\n"\ - "#include \"ins.h\"\n\n" - nop = 0; nvar = 0 +BEGIN { + print "bits=",bits > "/dev/stderr" + FS = "\t" + printf "#include \"../../../inc/scc.h\"\n"\ + "#include \"../../as.h\"\n"\ + "#include \"../x86/proc.h\"\n"\ + "#include \"ins.h\"\n\n" + nop = 0; nvar = 0 } - {sub(/#.*/,"")} -/^$/ {next} - { - if (opstart[$1] == 0) { - opstart[$1] = nvar - opnames[nop++] = $1 - } - opcount[$1]++ - opargs[nvar] = $2 - opsize[nvar] = $3 - opbytes[nvar] = ($4 == "none") ? "" : $4 - opformat[nvar++] = $5 - formats[$5] = 1 + {sub(/#.*/,"")} + +$6 !~ bits {next} + +/^$/ {next} + + { + if (opstart[$1] == 0) { + opstart[$1] = nvar + opnames[nop++] = $1 + } + opcount[$1]++ + opargs[nvar] = $2 + opsize[nvar] = $3 + opbytes[nvar] = ($4 == "none") ? "" : $4 + opformat[nvar++] = $5 + formats[$5] = 1 } -END { - for (i in formats) - printf "Format %s;\n", i +END { + for (i in formats) + printf "Format %s;\n", i - printf "int nr_ins = %d;\n\n", nop - print "struct ins instab[] = {" - for (i = 0; i < nop; i++) { - n = opnames[i] - start = opstart[n] - end = start + opcount[n] - printf "\t{.str = \"%s\", .begin = %d, .end = %d},\n", - n, start, end | "sort" - } - close("sort") - printf "};\n\n" + printf "int nr_ins = %d;\n\n", nop + print "struct ins instab[] = {" + for (i = 0; i < nop; i++) { + n = opnames[i] + start = opstart[n] + end = start + opcount[n] + printf "\t{.str = \"%s\", .begin = %d, .end = %d},\n", + n, start, end | "sort" + } + close("sort") + printf "};\n\n" - print "struct op optab[] = {" - for (i = 0; i < nvar; i++) { - printf "\t{\n" \ - "\t\t.size = %d,\n"\ - "\t\t.format = %s,\n", - opsize[i], opformat[i] + print "struct op optab[] = {" + for (i = 0; i < nvar; i++) { + printf "\t{\n" \ + "\t\t.size = %d,\n"\ + "\t\t.format = %s,\n", + opsize[i], opformat[i] - if (opbytes[i] != "") - printf "\t\t.bytes = (char []) {%s},\n", opbytes[i] + if (opbytes[i] != "") + printf "\t\t.bytes = (char []) {%s},\n", + opbytes[i] - a = str2args(opargs[i]) - if (a != "") - printf "\t\t.args = (char []) {%s}\n", a + a = str2args(opargs[i]) + if (a != "") + printf "\t\t.args = (char []) {%s}\n", a - print "\t}," - } - print "};" + print "\t}," + } + print "};" } function str2args(s, args, i, out) diff --git a/as/target/x86/i386.dat b/as/target/x86/i386.dat @@ -1,5 +0,0 @@ -# Tab 16, tabs 16, :set ts=16 -# op args size bytes format -EQU imm32 0 none equ -NOP none 1 0x90 direct -RET none 1 0xc3 direct diff --git a/as/target/x86/x86.dat b/as/target/x86/x86.dat @@ -0,0 +1,11 @@ +# Tab 16, tabs 16, :set ts=16 +# op args size bytes format cpu +DB imm8+ 0 none defb BITS16,BITS32,BITS64 +DW imm16+ 0 none defw BITS16,BITS32,BITS64 +DD imm32+ 0 none defd BITS16,BITS32,BITS64 +DQ imm64+ 0 none defq BITS16,BITS32,BITS64 +EQU imm16 0 none equ BITS16 +EQU imm32 0 none equ BITS32 +EQU imm64 0 none equ BITS64 +NOP none 1 0x90 direct BITS16,BITS32,BITS64 +RET none 1 0xc3 direct BITS16,BITS32,BITS64