Replace the terrible ed script in em_code with our new Lua script.

This commit is contained in:
David Given 2022-07-16 13:37:13 +02:00
parent 7298be8964
commit 0eae0d5d71
5 changed files with 30 additions and 61 deletions

View file

@ -1,15 +1,15 @@
normalrule { normalrule {
name = "em_code_ek_h", name = "em_code_ek_h",
ins = { ins = {
"./make.em.gen", "./make_codeek_h.lua",
"util/cmisc+ed", "h/em_table_lib.lua",
"h/em_table",
"./em.nogen", "./em.nogen",
"h/em_table"
}, },
outleaves = { "em_codeEK.h" }, outleaves = { "em_codeEK.h" },
commands = { commands = {
"%{ins[1]} %{ins[2]} %{ins[4]} > %{outs}", "$LUA %{ins[1]} < %{ins[3]} > %{outs}",
"cat %{ins[3]} >> %{outs}" "cat %{ins[4]} >> %{outs}"
} }
} }

View file

@ -1,18 +0,0 @@
#!/bin/sh
echo "/* this part is generated from $2 at: " `date` "*/"
$1 -s $2 <<'EOI'
1,/^$/d
1,/^$/d
1,$s/^\(...\) \(.\).*/\1:\2/
g/:d/s/^\(...\):\(.\).*/#define C_\1(c) CC_opcst(op_\1, c)/
g/:[cslnfzor]/s/^\(...\):\(.\).*/#define C_\1(c) CC_opcst(op_\1, c)/
g/:w/s/^\(...\).*/#define C_\1(w) CC_opcst(op_\1, w)\
#define C_\1_narg() CC_opnarg(op_\1)/
g/:g/s/^\(...\).*/#define C_\1(g) CC_opcst(op_\1, g)\
#define C_\1_dnam(g, o) CC_opdnam(op_\1, g, o)\
#define C_\1_dlb(g, o) CC_opdlb(op_\1, g, o)/
g/:p/s/^\(...\).*/#define C_\1(p) CC_oppnam(op_\1, p)/
g/:b/s/^\(...\).*/#define C_\1(b) CC_opilb(op_\1, b)/
g/:-/s/^\(...\).*/#define C_\1() CC_op(op_\1)/
1,$p
EOI

View file

@ -1,20 +0,0 @@
list=
target=$1
shift
for i
do
echo "+$cc $cflags $i"
if $cc $cflags $i
then
list="$list `basename $i .c`.$suf"
else
exit 1
fi
done
echo "+$ar r libem$target.$libsuf $list"
if $ar r libem$target.$libsuf $list
then
:
else
exit 1
fi

View file

@ -0,0 +1,25 @@
require "h.em_table_lib"
local specs, pseudos, mnems = load_table()
for _, mnem in ipairs(mnems) do
if mnem.flags1:find("^[cslndfzor]") then
print(string.format("#define C_%s(c) CC_opcst(op_%s, c)", mnem.name, mnem.name))
elseif mnem.flags1:find("^w") then
print(string.format("#define C_%s(w) CC_opcst(op_%s, w)", mnem.name, mnem.name))
print(string.format("#define C_%s_narg() CC_opnarg(op_%s)", mnem.name, mnem.name))
elseif mnem.flags1:find("^g") then
print(string.format("#define C_%s(g) CC_opcst(op_%s, g)", mnem.name, mnem.name))
print(string.format("#define C_%s_dnam(g, o) CC_opdnam(op_%s, g, o)", mnem.name, mnem.name))
print(string.format("#define C_%s_dlb(g, o) CC_opdlb(op_%s, g, o)", mnem.name, mnem.name))
elseif mnem.flags1:find("^p") then
print(string.format("#define C_%s(p) CC_oppnam(op_%s, p)", mnem.name, mnem.name))
elseif mnem.flags1:find("^b") then
print(string.format("#define C_%s(b) CC_opilb(op_%s, b)", mnem.name, mnem.name))
elseif mnem.flags1:find("^-") then
print(string.format("#define C_%s() CC_op(op_%s)", mnem.name, mnem.name))
else
error("unsupport em_table flag")
end
end

View file

@ -1,18 +0,0 @@
1i\
/* this part is generated from em_table */
# Remove pseudo instructions
/^\(...\) \([0-9]\).*/d
# Remove opcode constant categories/count
/^\(....\) \([0-9]\).*/d
/^\(.....\) \([0-9]\).*/d
# Below are the actual replacement of opcodes.
s/^\(...\) \(d\).*/#define C_\1(c) CC_opcst(op_\1, c)/
s/^\(...\) \([cslnfzor]\).*/#define C_\1(c) CC_opcst(op_\1, c)/
s/^\(...\) \(w\).*/#define C_\1(w) CC_opcst(op_\1, w)\
#define C_\1_narg() CC_opnarg(op_\1)/
s/^\(...\) \(g\).*/#define C_\1(g) CC_opcst(op_\1, g)\
#define C_\1_dnam(g, o) CC_opdnam(op_\1, g, o)\
#define C_\1_dlb(g, o) CC_opdlb(op_\1, g, o)/
s/^\(...\) \(p\).*/#define C_\1(p) CC_oppnam(op_\1, p)/
s/^\(...\) \(b\).*/#define C_\1(b) CC_opilb(op_\1, b)/
s/^\(...\) \(-\).*/#define C_\1() CC_op(op_\1)/