summary refs log tree commit diff stats
path: root/pp.awk
blob: 3c13872fa82f51bda9ae6698cdec0ff2d7a9f1db (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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)
}