objdump_to_h.awk 698 Bytes
Newer Older
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
# labels
/[[:xdigit:]]+ <\w+>:/ {
	# (Note: using $0 instead of $2 would also include the address)
	if (style=="old")
		printf "\t/* %s */\n", $2
	else
		printf "\t\t/* %s */\n", $2
}

# disassembly lines
/[[:xdigit:]]+:/ {
	if (style=="old")
		printf "\t0x%s, /* %9s    %-10s", $2, $1, $3
	else
		printf "\t\thtole32(0x%s), /* %5s  %-5s", $2, $1, $3

	for (i = 4; i <= NF; i++)
		if ($i == ";") {
			# strip comment (anything after and including ';')
			NF = i - 1
			break
		}
	# clear $1 to $3, which re-calculates $0 (= remainder of line)
	$3 = ""
	$2 = ""
	$1 = ""
	gsub("^\\s+", "") # strip leading whitespace

	if (style=="old")
		printf " %-28s */\n", $0
	else
		printf " %-23s */\n", $0
}