Replace the dodgy code generation shell scripts with Lua scripts.

This commit is contained in:
David Given 2022-07-17 14:31:37 +02:00
parent 544e8d474b
commit f8bf333bd4
6 changed files with 102 additions and 136 deletions

View file

@ -1,15 +0,0 @@
#!/bin/sh
: argtype lists all em mnemonics that have an argument type equal to
: one of the letters specified in the argument
case x$# in
x2)
;;
x*) echo "Usage: $0 argtypes <em_table>" 1>&2
exit 1
;;
esac
$ED -s $2 << A
1,/^\$/d
1,/^\$/d
1,/^\$/g/^\(...\) [$1].*/s//\\1/gp
A

View file

@ -1,28 +1,26 @@
normalrule { normalrule {
name = "c_mnem_narg_h", name = "c_mnem_narg_h",
ins = { ins = {
"./m_C_mnem_na", "./make_C_mnem_narg_h.lua",
"util/cmisc+ed", "h/em_table_lib.lua",
"h/em_table", "h/em_table",
"./argtype"
}, },
outleaves = "C_mnem_narg.h", outleaves = "C_mnem_narg.h",
commands = { commands = {
"%{ins} > %{outs}" "$LUA %{ins[1]} < %{ins[3]} > %{outs}"
} }
} }
normalrule { normalrule {
name = "c_mnem_h", name = "c_mnem_h",
ins = { ins = {
"./m_C_mnem", "./make_C_mnem_h.lua",
"util/cmisc+ed", "h/em_table_lib.lua",
"h/em_table", "h/em_table",
"./argtype"
}, },
outleaves = "C_mnem.h", outleaves = "C_mnem.h",
commands = { commands = {
"%{ins} > %{outs}" "$LUA %{ins[1]} < %{ins[3]} > %{outs}"
} }
} }

View file

@ -1,95 +0,0 @@
#!/bin/sh
export ED=$1
EM_TABLE=$2
ARGTYPE=$3
echo "switch(p->em_opcode) {"
for i in - cdflnorswz p b
do
list=`$ARGTYPE $i $EM_TABLE`
case $i in
-) args='()'
echo " /* no arguments */"
;;
cdflnorswz)
args='(p->em_cst)'
echo " /* one integer constant argument */"
;;
p)
args='(p->em_pnam)'
echo " /* a procedure name argument */"
;;
b)
: Grumbl, an instruction label as argument is encoded in a sp_cst2
args='((label) (p->em_cst))'
echo " /* An instruction label argument */"
;;
esac
for i in $list
do
cat << EOF
case op_$i:
C_$i$args;
break;
EOF
done
done
list=$($ARGTYPE g $EM_TABLE | tr -d '\r')
cat << 'EOF'
default:
/* a "g" argument */
if (p->em_argtype == nof_ptyp) {
switch(p->em_opcode) {
default:
EM_error = "Illegal mnemonic";
break;
EOF
for i in $list
do
cat << EOF
case op_$i:
C_${i}_dlb(p->em_dlb, p->em_off);
break;
EOF
done
cat << 'EOF'
}
}
else if (p->em_argtype == sof_ptyp) {
switch(p->em_opcode) {
default:
EM_error = "Illegal mnemonic";
break;
EOF
for i in $list
do
cat << EOF
case op_$i:
C_${i}_dnam(p->em_dnam, p->em_off);
break;
EOF
done
cat << 'EOF'
}
}
else /*argtype == cst_ptyp */ {
switch(p->em_opcode) {
default:
EM_error = "Illegal mnemonic";
break;
EOF
for i in $list
do
cat << EOF
case op_$i:
C_$i(p->em_cst);
break;
EOF
done
cat << 'EOF'
}
}
}
EOF

View file

@ -1,18 +0,0 @@
#!/bin/sh
export ED=$1
EM_TABLE=$2
ARGTYPE=$3
list=$($ARGTYPE w $EM_TABLE | tr -d '\r')
echo "switch(p->em_opcode) {"
for i in $list
do
cat << EOF
case op_$i:
C_${i}_narg();
break;
EOF
done
cat << EOF
default: EM_error = "Illegal mnemonic";
}
EOF

View file

@ -0,0 +1,80 @@
require "h.em_table_lib"
local specs, pseudos, mnems = load_table()
local function makecase(flags, args)
for _, mnem in ipairs(mnems) do
if mnem.flags1:find(flags) then
print(string.format('\tcase op_%s:\n\t\tC_%s%s;\n\t\tbreak;',
mnem.name, mnem.name, args))
end
end
end
print("switch(p->em_opcode) {")
print("\t/* no arguments */")
makecase("^-", "()")
print("\t/* one integer constant argument */")
makecase("^[cdflnorswz]", "(p->em_cst)")
print("\t/* a procedure name argument */")
makecase("^p", "(p->em_pnam)")
print("\t/* An instruction label argument */")
makecase("^b", "((label) (p->em_cst))")
print([[
default:
/* a "g" argument */
if (p->em_argtype == nof_ptyp) {
switch(p->em_opcode) {
default:
EM_error = "Illegal mnemonic";
break;
]])
for _, mnem in ipairs(mnems) do
if mnem.flags1:find("^g") then
print(string.format('\t\t\t\tcase op_%s:', mnem.name))
print(string.format('\t\t\t\t\tC_%s_dlb(p->em_dlb, p->em_off);\n\t\t\t\t\tbreak;',
mnem.name))
end
end
print([[
}
}
else if (p->em_argtype == sof_ptyp) {
switch(p->em_opcode) {
default:
EM_error = "Illegal mnemonic";
break;
]])
for _, mnem in ipairs(mnems) do
if mnem.flags1:find("^g") then
print(string.format('\t\t\t\tcase op_%s:', mnem.name))
print(string.format('\t\t\t\t\tC_%s_dnam(p->em_dnam, p->em_off);\n\t\t\t\t\tbreak;',
mnem.name))
end
end
print([[
}
}
else /*argtype == cst_ptyp */ {
switch(p->em_opcode) {
default:
EM_error = "Illegal mnemonic";
break;
]])
for _, mnem in ipairs(mnems) do
if mnem.flags1:find("^g") then
print(string.format('\t\t\t\tcase op_%s:', mnem.name))
print(string.format('\t\t\t\t\tC_%s(p->em_cst);\n\t\t\t\t\tbreak;',
mnem.name))
end
end
print([[
}
}
}
]])

View file

@ -0,0 +1,16 @@
require "h.em_table_lib"
local specs, pseudos, mnems = load_table()
print("switch(p->em_opcode) {")
for _, mnem in ipairs(mnems) do
if mnem.flags1:find("^w") then
print(string.format('\tcase op_%s:', mnem.name))
print(string.format('\t\tC_%s_narg();\n\t\tbreak;',
mnem.name))
end
end
print([[
default: EM_error = "Illegal mnemonic";
}
]])