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 | b error
|
---|
26 | b member_two
|
---|
27 |
|
---|
28 |
|
---|
29 | #
|
---|
30 | # Struct start / end.
|
---|
31 | #
|
---|
32 | :struct_equ
|
---|
33 | s/_size EQU.*$/_size/
|
---|
34 | :struct
|
---|
35 | s/:$//
|
---|
36 | h
|
---|
37 | s/^/global /
|
---|
38 | s/$/ ; struct/
|
---|
39 | b end
|
---|
40 |
|
---|
41 |
|
---|
42 | #
|
---|
43 | # Struct member
|
---|
44 | # Note: the 't' command doesn't seem to be working right with 's'.
|
---|
45 | #
|
---|
46 | :member
|
---|
47 | s/[[:xdigit:]]* *//
|
---|
48 | s/<gap> *//
|
---|
49 | /^\.[[:alnum:]_.]*[:]* .*$/!t error
|
---|
50 | s/\(\.[[:alnum:]_]*\)[:]* .*$/\1 /
|
---|
51 | G
|
---|
52 | s/^\([^ ]*\) \(.*\)$/global \2\1 ; member/
|
---|
53 | s/\n//m
|
---|
54 |
|
---|
55 | b end
|
---|
56 |
|
---|
57 |
|
---|
58 | #
|
---|
59 | # Struct member, no address. yasm r1842 and later.
|
---|
60 | #
|
---|
61 | :member_two
|
---|
62 | s/[:]* *res[bwdtq] .*$//
|
---|
63 | s/$/ /
|
---|
64 | /^\.[[:alnum:]_.]* *$/!t error
|
---|
65 | G
|
---|
66 | s/^\([^ ]*\) \(.*\)$/global \2\1 ; member2/
|
---|
67 | s/\n//m
|
---|
68 |
|
---|
69 | b end
|
---|
70 |
|
---|
71 |
|
---|
72 | :error
|
---|
73 | s/^/\nSed script logic error!\nBuffer: /
|
---|
74 | s/$/\nHold: /
|
---|
75 | G
|
---|
76 | q 1
|
---|
77 | b end
|
---|
78 |
|
---|
79 |
|
---|
80 | :end
|
---|
81 |
|
---|