Skip to content

Commit ce005e3

Browse files
committed
support the ';' line separator character, aka statement separator
binutils-esp32ulp treats the ';' character as a statement separator. Multiple statement separated by this character are treated as if each statement was on its own line. Note: Currently, due to the way labels are detected/handled, there must be a space between a ';' and the next statement, if there is another statement on the same line. This commit contributes to being able to eventually assemble the esp32ulp_all.s test from binutils-esp32ulp and allows us to deal with this line: https://github.com/espressif/binutils-esp32ulp/blob/249ec34cc2c9574a86f3f86bbb175a863f988bcf/gas/testsuite/gas/esp32ulp/esp32/esp32ulp_all.s#L108 The compat tests show how more than 1 statement on a line would be used/handled.
1 parent f4b0720 commit ce005e3

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Diff for: esp32_ulp/assemble.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,13 @@ def parse_line(self, line):
129129
opcode, args = opcode_args[0], ()
130130
return label, opcode, args
131131

132+
def split_statements(self, lines):
133+
for line in lines:
134+
for statement in line.split(';'):
135+
yield statement.rstrip()
132136

133137
def parse(self, lines):
134-
parsed = [self.parse_line(line) for line in lines]
138+
parsed = [self.parse_line(line) for line in self.split_statements(lines)]
135139
return [p for p in parsed if p is not None]
136140

137141

Diff for: tests/assemble.py

+16
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,21 @@ def test_symbols():
244244
assert st.resolve_absolute('const') == 123
245245

246246

247+
def test_support_multiple_statements_per_line():
248+
src = """
249+
label: nop; nop;
250+
wait 42
251+
"""
252+
253+
lines = Assembler().parse(src.splitlines())
254+
255+
assert lines == [
256+
('label', 'nop', ()),
257+
(None, 'nop', ()),
258+
(None, 'wait', ('42',))
259+
]
260+
261+
247262
test_parse_line()
248263
test_parse()
249264
test_assemble()
@@ -254,4 +269,5 @@ def test_symbols():
254269
test_assemble_evalulate_expressions()
255270
test_assemble_optional_comment_removal()
256271
test_assemble_test_regressions_from_evaluation()
272+
test_support_multiple_statements_per_line()
257273
test_symbols()

Diff for: tests/compat/fixes.S

+3
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,7 @@ entry:
2525
reg_rd 12, 7, 0
2626
reg_rd 0x3ff48000, 7, 0
2727

28+
# interpret ; as statement separator - this results in 2 NOP machine instructions
29+
nop; nop;
30+
2831
halt

0 commit comments

Comments
 (0)