1 | #
|
---|
2 | # Strip stuff lines and spaces we don't care about.
|
---|
3 | #
|
---|
4 | / %line /d
|
---|
5 | /\[section /d
|
---|
6 | /\[bits /d
|
---|
7 | /\[absolute /d
|
---|
8 | / times /d
|
---|
9 | s/ *[[:digit:]]* //
|
---|
10 | /^ *$/d
|
---|
11 | s/ *$//g
|
---|
12 | s/^ *//g
|
---|
13 | /^\.text$/d
|
---|
14 | /^\.data$/d
|
---|
15 | /^\.bss$/d
|
---|
16 | s/[[:space:]][[:space:]]*/ /g
|
---|
17 |
|
---|
18 | #
|
---|
19 | # Figure which type of line this is and process it accordingly.
|
---|
20 | #
|
---|
21 | /^[[:alpha:]_][[:alnum:]_]*:/b struct
|
---|
22 | /^[[:alpha:]_][[:alnum:]_]*_size EQU \$ - .*$/b struct_equ
|
---|
23 | /<gap>/b member
|
---|
24 | /^\.[[:alpha:]_][[:alnum:]_.:]* res.*$/b member_two
|
---|
25 | /^\.[[:alpha:]_][[:alnum:]_.:]*:$/b member_alias
|
---|
26 | b error
|
---|
27 | b member_two
|
---|
28 |
|
---|
29 |
|
---|
30 | #
|
---|
31 | # Struct start / end.
|
---|
32 | #
|
---|
33 | :struct_equ
|
---|
34 | s/_size EQU.*$/_size/
|
---|
35 | :struct
|
---|
36 | s/:$//
|
---|
37 | h
|
---|
38 | s/^/global /
|
---|
39 | s/$/ ; struct/
|
---|
40 | b end
|
---|
41 |
|
---|
42 |
|
---|
43 | #
|
---|
44 | # Struct member
|
---|
45 | # Note: the 't' command doesn't seem to be working right with 's'.
|
---|
46 | #
|
---|
47 | :member
|
---|
48 | s/[[:xdigit:]]* *//
|
---|
49 | s/<gap> *//
|
---|
50 | /^\.[[:alnum:]_.]*[:]* .*$/!t error
|
---|
51 | s/\(\.[[:alnum:]_]*\)[:]* .*$/\1 /
|
---|
52 | G
|
---|
53 | s/^\([^ ]*\) \(.*\)$/global \2\1 ; member/
|
---|
54 | s/\n//m
|
---|
55 |
|
---|
56 | b end
|
---|
57 |
|
---|
58 |
|
---|
59 | #
|
---|
60 | # Struct member, no address. yasm r1842 and later.
|
---|
61 | #
|
---|
62 | :member_two
|
---|
63 | s/[:]* *res[bwdtq] .*$//
|
---|
64 | s/$/ /
|
---|
65 | /^\.[[:alnum:]_.]* *$/!t error
|
---|
66 | G
|
---|
67 | s/^\([^ ]*\) \(.*\)$/global \2\1 ; member2/
|
---|
68 | s/\n//m
|
---|
69 |
|
---|
70 | b end
|
---|
71 |
|
---|
72 | #
|
---|
73 | # Alias member like Host.cr0Fpu in 64-bit. Drop it.
|
---|
74 | #
|
---|
75 | :member_alias
|
---|
76 | d
|
---|
77 | b end
|
---|
78 |
|
---|
79 | :error
|
---|
80 | s/^/\nSed script logic error!\nBuffer: /
|
---|
81 | s/$/\nHold: /
|
---|
82 | G
|
---|
83 | q 1
|
---|
84 | b end
|
---|
85 |
|
---|
86 |
|
---|
87 | :end
|
---|
88 |
|
---|