Skip to content

Commit 33b4d3d

Browse files
committedAug 5, 2021
support ULP opcodes in upper case
Some open-source out there uses upper case for ULP opcodes. This change allows using such code unmodified instead of crashing with "Unsupported opcode or directive"
1 parent 647355b commit 33b4d3d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
 

‎esp32_ulp/assemble.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def assembler_pass(self, lines):
275275
continue
276276
else:
277277
# machine instruction
278-
func = getattr(opcodes, 'i_' + opcode, None)
278+
func = getattr(opcodes, 'i_' + opcode.lower(), None)
279279
if func is not None:
280280
instruction = func(*args)
281281
self.append_section(instruction.to_bytes(4, 'little'), TEXT)

‎tests/assemble.py

+15
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ def test_assemble_global():
121121
assert exported_symbols == [(0, 'counter'), (1, 'internal'), (2, 'entry')]
122122

123123

124+
def test_assemble_uppercase_opcode():
125+
a = Assembler()
126+
try:
127+
a.assemble(" WAIT 42")
128+
except Exception as e:
129+
if str(e) != "Unknown opcode or directive: WAIT":
130+
# re-raise failures we didn't expect
131+
raise
132+
raised = True
133+
else:
134+
raised = False
135+
assert not raised
136+
137+
124138
def test_symbols():
125139
st = SymbolTable({}, {}, {})
126140
for entry in [
@@ -180,4 +194,5 @@ def test_symbols():
180194
test_assemble_bss()
181195
test_assemble_bss_with_value()
182196
test_assemble_global()
197+
test_assemble_uppercase_opcode()
183198
test_symbols()

0 commit comments

Comments
 (0)