1 |
|
---|
2 | # Check for markers (typically in comments).
|
---|
3 | /ASM-INC/basm-inc
|
---|
4 | /ASM-NOINC/basm-noinc
|
---|
5 |
|
---|
6 | # Newline escapes.
|
---|
7 | :check-newline-escape
|
---|
8 | /\\$/!bno-more-newline-escapes
|
---|
9 | N
|
---|
10 | b check-newline-escape
|
---|
11 | :no-more-newline-escapes
|
---|
12 |
|
---|
13 | # Strip comments and trailing space.
|
---|
14 | s/[[:space:]][[:space:]]*\/\*.*$//g
|
---|
15 | s/[[:space:]][[:space:]]*\/\/.*$//g
|
---|
16 | s/[[:space:]][[:space:]]*$//g
|
---|
17 |
|
---|
18 | # Try identify the statement.
|
---|
19 | /#[[:space:]]*define[[:space:]]/bdefine
|
---|
20 | /#[[:space:]]*ifdef[[:space:]]/bifdef
|
---|
21 | /#[[:space:]]*ifndef[[:space:]]/bifndef
|
---|
22 | /#[[:space:]]*if[[:space:]]/bif
|
---|
23 | /#[[:space:]]*elif[[:space:]]/belif
|
---|
24 | /#[[:space:]]*else$/belse
|
---|
25 | /#[[:space:]]*endif$/bendif
|
---|
26 |
|
---|
27 | # Not recognized, drop it.
|
---|
28 | :asm-noinc
|
---|
29 | d
|
---|
30 | b end
|
---|
31 |
|
---|
32 | #
|
---|
33 | # Defines needs some extra massaging to work in yasm.
|
---|
34 | # Things like trailing type indicators ('U', 'ULL' ++) does not go down well.
|
---|
35 | #
|
---|
36 | :define
|
---|
37 | /\$/d
|
---|
38 | s/#\([[:space:]]*\)define/\1%define/
|
---|
39 |
|
---|
40 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U$/\1/
|
---|
41 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)U\([[:space:]]*\))$/\1\2)/
|
---|
42 | s/\([[:space:]][0-9][0-9]*\)U[[:space:]]*$/\1/
|
---|
43 | s/\([[:space:]][0-9][0-9]*\)U\([[:space:]]*\))$/\1\2)/
|
---|
44 |
|
---|
45 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL$/\1/
|
---|
46 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)UL\([[:space:]]*\))$/\1\2)/
|
---|
47 | s/\([[:space:]][0-9][0-9]*\)UL[[:space:]]*$/\1/
|
---|
48 | s/\([[:space:]][0-9][0-9]*\)UL\([[:space:]]*\))$/\1\2)/
|
---|
49 |
|
---|
50 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL$/\1/
|
---|
51 | s/\([[:space:]]0[xX][0-9a-fA-F][0-9a-fA-F]*\)ULL\([[:space:]]*\))$/\1\2)/
|
---|
52 | s/\([[:space:]][0-9][0-9]*\)ULL[[:space:]]*$/\1/
|
---|
53 | s/\([[:space:]][0-9][0-9]*\)ULL\([[:space:]]*\))$/\1\2)/
|
---|
54 |
|
---|
55 | s/UINT64_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
56 | s/UINT64_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
57 | s/UINT32_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
58 | s/UINT32_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
59 | s/UINT16_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
60 | s/UINT16_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
61 | s/UINT8_C([[:space:]]*\(0[xX][0-9a-fA-F][0-9a-fA-F]*\)[[:space:]]*)/\1/
|
---|
62 | s/UINT8_C([[:space:]]*\([0-9][0-9]*\)[[:space:]]*)/\1/
|
---|
63 |
|
---|
64 | b end
|
---|
65 |
|
---|
66 | #
|
---|
67 | # Conditional statements, 1:1.
|
---|
68 | #
|
---|
69 | :ifdef
|
---|
70 | s/#\([[:space:]]*\)ifdef/\1%ifdef/
|
---|
71 | b end
|
---|
72 |
|
---|
73 | :ifndef
|
---|
74 | s/#\([[:space:]]*\)ifndef/\1%ifndef/
|
---|
75 | b end
|
---|
76 |
|
---|
77 | :if
|
---|
78 | s/#\([[:space:]]*\)if/\1%if/
|
---|
79 | b end
|
---|
80 |
|
---|
81 | :elif
|
---|
82 | s/#\([[:space:]]*\)elif/\1%elif/
|
---|
83 | b end
|
---|
84 |
|
---|
85 | :else
|
---|
86 | s/#\([[:space:]]*\)else.*$/\1%else/
|
---|
87 | b end
|
---|
88 |
|
---|
89 | :endif
|
---|
90 | s/#\([[:space:]]*\)endif.*$/\1%endif/
|
---|
91 | b end
|
---|
92 |
|
---|
93 | #
|
---|
94 | # Assembly statement... may need adjusting when used.
|
---|
95 | #
|
---|
96 | :asm-inc
|
---|
97 | b end
|
---|
98 |
|
---|
99 | :end
|
---|
100 |
|
---|