BEGIN {
last_word = 0
}
$1 == ".defword" {
define_word($2, "vor_" $2, $3, $4)
next
}
$1 == ".defvar" {
define_word($2, "vor_get_variable_address", $3)
print("\t.balign\t4")
print("\t.4byte\t" $2 "\n")
next
}
$1 == ".defwort" {
wortname = "vor_" $2
define_word($2, wortname, $3, $4)
print("\t.section\t.text.vor")
print("\t.thumb_func")
print(wortname ":")
print("\tpush\t{lr}")
next
}
$1 == ".dkw" {
define_word($2, "vor_" $2)
kurzwort_body($2, 3)
next
}
$1 == ".dkws" {
define_word($3, "vor_" $3, $2)
kurzwort_body($3, 4)
next
}
$1 == ".worte" {
for (i = 2; i <= NF; i++)
print("\tbl\tvor_" $i)
next
}
$1 == ".wortende" {
print("\tpop\t{pc}")
print("\t.fnsize\t" wortname)
next
}
$1 == ".literal" {
print("\tbl\tvor_lit")
print("\t.4byte\t" $2)
next
}
{ print }
END {
if (last_word)
printf("\t.set\tvor_last_word, %s\n", last_word)
}
function kurzwort_body(name, i) {
print("\t.section\t.text.vor")
print("\t.thumb_func")
print("vor_" name ":")
print("\tpush\t{lr}")
for (; i <= NF; i++) {
if ($i ~ /^#/) {
print("\tbl\tvor_lit")
print("\t.4byte\t" substr($i, 2))
} else {
print("\tbl\tvor_" $i)
}
}
print("\tpop\t{pc}")
print("\t.fnsize\tvor_" name "\n")
}
function define_word(name, to_call, str, flags) {
if (!flags) flags = 0
if (!str) {
str = "\"" name "\""
gsub(/_/, "-", str)
}
printf("\t.rodata\n")
printf("vor_word_%s:\n", name)
printf("\t.4byte\t%s\n", last_word)
last_word = "vor_word_" name
printf("\t.4byte\t%s\n", to_call)
printf("\t.2byte\t%s\n", flags)
printf("\t.2byte\tvor_wordstrsize_%s\n", name)
printf("vor_wordstr_%s:\n", name)
printf("\t.ascii\t%s\n", str)
printf("\t.set\tvor_wordstrsize_%s, . - vor_wordstr_%s\n\n", name, name)
}