blob: 2a2de593193a7f387a807fa358a2dfa4de912b34 [file] [log] [blame]
Elvira Khabirova09294222015-08-04 01:47:02 +03001function compare_indices(i1, v1, i2, v2) {
2 c1 = strtonum(sprintf("%s", i1))
3 c2 = strtonum(sprintf("%s", i2))
4 if (c1 < c2)
5 return -1
6 return (c1 != c2)
7}
8function what_is(what_idx, type_idx, special, item)
9{
10 type_idx = array[what_idx]["type"]
11 special = array[what_idx]["special"]
12 switch (special) {
13 case "base_type":
14 switch (array[what_idx]["encoding"]) {
15 case 5: # signed
16 printf("%s ", "int" \
17 8*array[what_idx]["byte_size"] "_t")
18 break
19 case 7: # unsigned
20 printf("%s ", "uint" \
21 8*array[what_idx]["byte_size"] "_t")
22 break
23 default: # float, signed/unsigned char
24 printf("%s ", array[what_idx]["name"])
25 break
26 }
27 break
28 case "enumeration_type":
29 printf("%s ", "uint" 8*array[type_idx]["byte_size"] "_t")
30 break
31 case "pointer_type":
32 printf("%s", "mpers_ptr_t ")
33 break
34 case "array_type":
35 what_is(type_idx)
36 to_return = array[what_idx]["upper_bound"]
37 return to_return
38 break
39 case "structure_type":
40 case "union_type":
41 if (special == "structure_type") {
42 print "struct {"
43 } else {
44 print "union {"
45 }
46 for (item in array) {
47 if ("parent" in array[item] && array[item]["parent"] \
48 == what_idx) {
49 returned = what_is(item)
50 printf("%s", array[item]["name"])
51 if (returned) {
52 printf("%s", "[" returned "]")
53 }
54 print ";"
55 }
56 }
57 printf("%s", "} ")
58 break
59 case "typedef":
60 return what_is(type_idx)
61 break
62 case "member":
63 return what_is(type_idx)
64 break
65 default:
66 what_is(type_idx)
67 break
68 }
69 return 0
70}
71BEGIN {
72 print "#include <inttypes.h>"
73}
74/^<[[:xdigit:]]+>/ {
75 match($0, /([[:alnum:]]+)><([[:alnum:]]+)/, matches)
76 level = matches[1]
77 idx = "0x" matches[2]
78 array[idx]["idx"] = idx
79 parent[level] = idx
80 if (level > 1) {
81 array[idx]["parent"] = parent[level-1]
82 }
83}
84/^DW_AT_data_member_location/ {
85 match($0, /[[:digit:]]+/, temparray)
86 array[idx]["location"] = temparray[1]
87}
88/^DW_AT_name/ {
89 match($0, /:[[:space:]]+([[:alpha:]_][[:alnum:]_[:space:]]*)/, temparray)
90 array[idx]["name"] = temparray[1]
91}
92/^DW_AT_byte_size/ {
93 match($0, /[[:digit:]]+/, temparray)
94 array[idx]["byte_size"] = temparray[0]
95}
96/^DW_AT_encoding/ {
97 match($0, /[[:digit:]]+/, temparray)
98 array[idx]["encoding"] = temparray[0]
99}
100/^DW_AT_type/ {
101 match($0, /:[[:space:]]+<(0x[[:xdigit:]]*)>$/, temparray)
102 array[idx]["type"] = temparray[1]
103}
104/^DW_AT_upper_bound/ {
105 match($0, /[[:digit:]]+/, temparray)
106 array[parent[level-1]]["upper_bound"] = temparray[0] + 1
107}
108/^Abbrev Number:[^(]+\(DW_TAG_/ {
109 if (match($0, /typedef|union_type|structure_type|pointer_type\
110|enumeration_type|array_type|base_type|member/, temparray)) {
111 array[idx]["special"] = temparray[0]
112 }
113}
114END {
115 PROCINFO["sorted_in"] = "compare_indices"
116 for (item in array) {
117 if (array[item]["special"] == "pointer_type") {
118 print "typedef uint" \
119 8*array[item]["byte_size"] "_t mpers_ptr_t;"
120 break
121 }
122 }
123 for (item in array) {
124 if (array[item]["name"] == VAR_NAME) {
125 type=array[item]["type"]
126 print "typedef"
127 what_is(array[item]["type"])
128 print ARCH_FLAG "_" array[type]["name"] ";"
129 print "#define MPERS_" \
130 ARCH_FLAG "_" array[type]["name"] " " \
131 ARCH_FLAG "_" array[type]["name"]
132 break
133 }
134 }
135}