Skip to content

Commit 0650a05

Browse files
alexdowadrichfelker
authored andcommitted
factor common awk functions for CFI generation scripts into new file
There is a lot which could be common between i386 and x86_64, but none of it will be useful for any other arch. These should be useful for all archs, however.
1 parent 2d51c4a commit 0650a05

File tree

3 files changed

+27
-28
lines changed

3 files changed

+27
-28
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ $(foreach s,$(wildcard src/*/$(ARCH)*/*.s),$(eval $(call mkasmdep,$(s))))
122122
# Choose invocation of assembler to be used
123123
# $(1) is input file, $(2) is output file, $(3) is assembler flags
124124
ifeq ($(ADD_CFI),yes)
125-
AS_CMD = LC_ALL=C awk -f tools/add-cfi.$(ARCH).awk $< | $(CC) -x assembler -c -o $@ -
125+
AS_CMD = LC_ALL=C awk -f tools/add-cfi.common.awk -f tools/add-cfi.$(ARCH).awk $< | $(CC) -x assembler -c -o $@ -
126126
else
127127
AS_CMD = $(CC) -c -o $@ $<
128128
endif

tools/add-cfi.common.awk

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function hex2int(str, i) {
2+
str = tolower(str)
3+
4+
for (i = 1; i <= 16; i++) {
5+
char = substr("0123456789abcdef", i, 1)
6+
lookup[char] = i-1
7+
}
8+
9+
result = 0
10+
for (i = 1; i <= length(str); i++) {
11+
result = result * 16
12+
char = substr(str, i, 1)
13+
result = result + lookup[char]
14+
}
15+
return result
16+
}
17+
18+
function parse_const(str) {
19+
sign = sub(/^-/, "", str)
20+
hex = sub(/^0x/, "", str)
21+
if (hex)
22+
n = hex2int(str)
23+
else
24+
n = str+0
25+
return sign ? -n : n
26+
}

tools/add-cfi.i386.awk

-27
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,6 @@ BEGIN {
2222
called = ""
2323
}
2424

25-
function hex2int(str, i) {
26-
str = tolower(str)
27-
28-
for (i = 1; i <= 16; i++) {
29-
char = substr("0123456789abcdef", i, 1)
30-
lookup[char] = i-1
31-
}
32-
33-
result = 0
34-
for (i = 1; i <= length(str); i++) {
35-
result = result * 16
36-
char = substr(str, i, 1)
37-
result = result + lookup[char]
38-
}
39-
return result
40-
}
41-
42-
function parse_const(str) {
43-
sign = sub(/^-/, "", str)
44-
hex = sub(/^0x/, "", str)
45-
if (hex)
46-
n = hex2int(str)
47-
else
48-
n = str+0
49-
return sign ? -n : n
50-
}
51-
5225
function get_const1() {
5326
# for instructions with 2 operands, get 1st operand (assuming it is constant)
5427
match($0, /-?(0x[0-9a-fA-F]+|[0-9]+),/)

0 commit comments

Comments
 (0)