Skip to content
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

Preprocessor for ULP/RTC macros #43

Merged
merged 29 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
79db90f
add units test for the .set directive
wnienhaus Jul 22, 2021
84d734d
add support for left aligned assembler directives (e.g. .set)
wnienhaus Jul 22, 2021
ec81ecc
fix a crash bug where BSS size calculation was attempted on the value…
wnienhaus Jul 22, 2021
c184924
raise error when attempting to store values in .bss section
wnienhaus Jul 29, 2021
25d34b0
fix reference to non-existing variable
wnienhaus Jul 22, 2021
76a81ac
fix typo in comment of instruction definition
wnienhaus Jul 22, 2021
56f4530
add support for the .global directive. only symbols flagged as global…
wnienhaus Jul 22, 2021
9907b10
let SymbolTable.export() optionally export non-global symbols too
wnienhaus Jul 22, 2021
27ab850
support ULP opcodes in upper case
wnienhaus Jul 22, 2021
54b117e
add a compatibility test for the recent fixes and improvements
wnienhaus Jul 22, 2021
feb42dc
add support for evaluating expressions
wnienhaus Jul 22, 2021
87507c9
add a compatibility test for evaluating expressions
wnienhaus Jul 23, 2021
99352a3
docs: add that expressions are now supported
wnienhaus Jul 29, 2021
d76fd26
add preprocessor that can replace simple #define values in code
wnienhaus Jul 23, 2021
4dded94
allow assembler to skip comment removal to avoid removing comments twice
wnienhaus Aug 7, 2021
219f939
fix evaluation of expressions during first assembler pass
wnienhaus Jul 25, 2021
5c3eeb8
remove no-longer-needed pass dependent code from SymbolTable
wnienhaus Jul 26, 2021
3e8c0d5
add support for macros such as WRITE_RTC_REG
wnienhaus Jul 26, 2021
ac1de99
add simple include file processing
wnienhaus Jul 26, 2021
8d88fd1
add support for using a btree database (DefinesDB) to store defines f…
wnienhaus Jul 27, 2021
46f1442
add special handling for the BIT macro used in the esp-idf framework
wnienhaus Jul 27, 2021
2f6ee78
add include processor tool for populating a defines.db from include f…
wnienhaus Jul 28, 2021
69ae946
add compatibility tests using good example code off the net
wnienhaus Jul 28, 2021
4f90f76
add documentation for the preprocessor
wnienhaus Jul 29, 2021
d44384f
fix use of treg field in i_move instruction to match binutils-esp32 o…
wnienhaus Jul 28, 2021
254adf9
allow specifying the address for reg_rd and reg_wr in 32-bit words
wnienhaus Jul 28, 2021
c3bd101
support .int data type
wnienhaus Jul 29, 2021
2a0a39a
refactor: small improvements based on PR comments.
wnienhaus Aug 9, 2021
47d5e8a
Updated LICENSE file and added AUTHORS file
wnienhaus Aug 9, 2021
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
18 changes: 14 additions & 4 deletions esp32_ulp/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@


class SymbolTable:
def __init__(self, symbols, bases):
def __init__(self, symbols, bases, globals):
self._symbols = symbols
self._bases = bases
self._globals = globals
self._pass = None

def set_pass(self, _pass):
Expand Down Expand Up @@ -53,7 +54,9 @@ def dump(self):
print(symbol, entry)

def export(self):
addrs_syms = [(self.resolve_absolute(entry), symbol) for symbol, entry in self._symbols.items()]
addrs_syms = [(self.resolve_absolute(entry), symbol)
for symbol, entry in self._symbols.items()
if symbol in self._globals]
return sorted(addrs_syms)

def to_abs_addr(self, section, offset):
Expand Down Expand Up @@ -93,11 +96,15 @@ def resolve_relative(self, symbol):
from_addr = self.to_abs_addr(self._from_section, self._from_offset)
return sym_addr - from_addr

def set_global(self, symbol):
self._globals[symbol] = True
pass


class Assembler:

def __init__(self, symbols=None, bases=None):
self.symbols = SymbolTable(symbols or {}, bases or {})
def __init__(self, symbols=None, bases=None, globls=None):
self.symbols = SymbolTable(symbols or {}, bases or {}, globls or {})
ThomasWaldmann marked this conversation as resolved.
Show resolved Hide resolved
opcodes.symbols = self.symbols # XXX dirty hack

def init(self, a_pass):
Expand Down Expand Up @@ -236,6 +243,9 @@ def d_set(self, symbol, expr):
value = int(expr) # TODO: support more than just integers
self.symbols.set_sym(symbol, ABS, None, value)

def d_global(self, symbol):
self.symbols.set_global(symbol)

def append_data(self, wordlen, args):
data = [int(arg).to_bytes(wordlen, 'little') for arg in args]
self.append_section(b''.join(data))
Expand Down
31 changes: 30 additions & 1 deletion tests/assemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@
"""


src_global = """\

.global counter
counter:
.long 0

internal:
.long 0

.text
.global entry
entry:
wait 42
halt
"""


def test_parse_line():
a = Assembler()
lines = iter(src.splitlines())
Expand Down Expand Up @@ -90,8 +107,19 @@ def test_assemble_bss_with_value():
assert raised


def test_assemble_global():
a = Assembler()
a.assemble(src_global)
assert a.symbols.has_sym('counter')
assert a.symbols.has_sym('internal')
assert a.symbols.has_sym('entry')

exported_symbols = a.symbols.export()
assert exported_symbols == [(0, 'counter'), (2, 'entry')] # internal not exported


def test_symbols():
st = SymbolTable({}, {})
st = SymbolTable({}, {}, {})
for entry in [
('rel_t4', REL, TEXT, 4),
('abs_t4', ABS, TEXT, 4),
Expand Down Expand Up @@ -148,4 +176,5 @@ def test_symbols():
test_assemble()
test_assemble_bss()
test_assemble_bss_with_value()
test_assemble_global()
test_symbols()