scc

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

commit fb9f5ad8b79fff0c06cdef1b2a9e8fa729a95a15
parent ffe76c7c9ca25412638fc552cf6e5c68be1d61ce
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat,  9 Sep 2017 07:02:18 +0200

[as] Use a common regex language

* means 0 or more, but + 1 or more

Diffstat:
Mas/common.dat | 8++++----
Mas/target/x86/gen.awk | 22++++++++++++++--------
2 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/as/common.dat b/as/common.dat @@ -1,6 +1,6 @@ # 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 +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/x86/gen.awk b/as/target/x86/gen.awk @@ -51,22 +51,28 @@ function str2args(s, args, i, out) { split(s, args, /,/) for (i in args) { - if (args[i] == "none") + a = args[i] + if (a == "none") { break - else if (args[i] ~ /imm8/) + } else if (match(a, /^imm8/)) { out = "AIMM8" - else if (args[i] ~ /imm16/) + } else if (match(a, /^imm16/)) { out = "AIMM16" - else if (args[i] ~ /imm32/) + } else if (match(a, /^imm32/)) { out = "AIMM32" - else if (args[i] ~ /imm64/) + } else if (match(a, /^imm64/)) { out = "AIMM64" - else { - print "wrong arg", args[i] + } else { + print "wrong arg", a exit 1 } - if (args[i] ~ /\*$/) + a = substr(a, RLENGTH+1) + if (a ~ /^\+$/) { return out "|AREP" + } else { + print "wrong arg", a + exit 1 + } out = out "," } out = out "0"