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