Skip to content

More fixes towards v1.0 #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions esp32_ulp/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,21 @@ def parse_line(self, line):
"""
if not line:
return
has_label = line[0] not in '\t .'
has_label = ':' in line
if has_label:
label_line = line.split(None, 1)
orig_line = line.strip()
label_line = orig_line.split(':', 1)
if len(label_line) == 2:
label, line = label_line
else: # 1
label, line = label_line[0], None
label = label.rstrip(':')

if label.strip('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_$.'): # if any chars remain
# if label contains other chars than allowed, it's not a label
label, line = None, orig_line
else:
label, line = None, line.lstrip()
if line is None:
if not line:
opcode, args = None, ()
else:
opcode_args = line.split(None, 1)
Expand Down
25 changes: 25 additions & 0 deletions tests/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,30 @@ def test_parse_line():
assert a.parse_line(next(lines)) == (None, '.data', ()) # test left-aligned directive is not treated as label


def test_parse_labels_correctly():
"""
description of what defines a label
https://sourceware.org/binutils/docs/as/Statements.html
https://sourceware.org/binutils/docs/as/Labels.html
"""
a = Assembler()
assert a.parse_line('label: .set const, 42') == ('label', '.set', ('const', '42',))
assert a.parse_line('label:.set const, 42') == ('label', '.set', ('const', '42',))
assert a.parse_line('label:') == ('label', None, ())
assert a.parse_line(' label:') == ('label', None, ())
assert a.parse_line(' label: ') == ('label', None, ())
assert a.parse_line('nop ') == (None, 'nop', ())
assert a.parse_line('.set c, 1 ') == (None, '.set', ('c', '1',))
assert a.parse_line('invalid : nop') == (None, 'invalid', (': nop',)) # no whitespace between label and colon
assert a.parse_line('.string "hello world"') == (None, '.string', ('"hello world"',))
assert a.parse_line('.string "hello : world"') == (None, '.string', ('"hello : world"',)) # colon in string
assert a.parse_line('label::') == ('label', ':', ())
assert a.parse_line('label: :') == ('label', ':', ())
assert a.parse_line('a_label:') == ('a_label', None, ())
assert a.parse_line('$label:') == ('$label', None, ())
assert a.parse_line('.label:') == ('.label', None, ())


def test_parse():
a = Assembler()
lines = remove_comments(src)
Expand Down Expand Up @@ -260,6 +284,7 @@ def test_support_multiple_statements_per_line():


test_parse_line()
test_parse_labels_correctly()
test_parse()
test_assemble()
test_assemble_bss()
Expand Down