ldgen: surround always pre and post

This commit is contained in:
Renz Bagaporo
2021-02-16 13:27:58 +08:00
parent dbdc17cced
commit 7af3d65868
3 changed files with 36 additions and 58 deletions

View File

@@ -276,42 +276,28 @@ class Mapping(Fragment):
class Surround(Flag): class Surround(Flag):
def __init__(self, symbol, pre=True, post=True): def __init__(self, symbol):
self.symbol = symbol self.symbol = symbol
self.pre = pre self.pre = True
self.post = post self.post = True
@staticmethod @staticmethod
def get_grammar(): def get_grammar():
# surround(symbol [, pre, post]) # surround(symbol)
# #
# __symbol_start, __symbol_end is generated before and after # __symbol_start, __symbol_end is generated before and after
# the corresponding input section description, respectively. # the corresponding input section description, respectively.
grammar = (Keyword('surround').suppress() + grammar = (Keyword('surround').suppress() +
Suppress('(') + Suppress('(') +
Fragment.IDENTIFIER.setResultsName('symbol') + Fragment.IDENTIFIER.setResultsName('symbol') +
Mapping.Flag.PRE_POST +
Suppress(')')) Suppress(')'))
def on_parse(tok): grammar.setParseAction(lambda tok: Mapping.Surround(tok.symbol))
if tok.pre == '' and tok.post == '':
res = Mapping.Surround(tok.symbol)
elif tok.pre != '' and tok.post == '':
res = Mapping.Surround(tok.symbol, tok.pre, False)
elif tok.pre == '' and tok.post != '':
res = Mapping.Surround(tok.symbol, False, tok.post)
else:
res = Mapping.Surround(tok.symbol, tok.pre, tok.post)
return res
grammar.setParseAction(on_parse)
return grammar return grammar
def __eq__(self, other): def __eq__(self, other):
return (isinstance(other, Mapping.Surround) and return (isinstance(other, Mapping.Surround) and
self.symbol == other.symbol and self.symbol == other.symbol)
self.pre == other.pre and
self.post == other.post)
class Align(Flag): class Align(Flag):

View File

@@ -906,28 +906,20 @@ entries:
text->iram0_text sort(name) sort(alignment) text->iram0_text sort(name) sort(alignment)
""") """)
def test_emit_flag(self): def test_surround_flag(self):
# Test parsing combinations and orders of flags # Test parsing combinations and orders of flags
test_fragment = self.create_fragment_file(u""" test_fragment = self.create_fragment_file(u"""
[mapping:map] [mapping:map]
archive: libmain.a archive: libmain.a
entries: entries:
obj1 (default); obj1 (default);
text->flash_text surround(sym1), text->flash_text surround(sym1)
rodata->flash_rodata surround(sym2, pre),
data->dram0_data surround(sym3, post),
bss->dram0_bss surround(sym4, pre, post),
common->dram0_bss surround(sym5, pre, post) surround(sym6)
""") """)
fragment_file = FragmentFile(test_fragment, self.sdkconfig) fragment_file = FragmentFile(test_fragment, self.sdkconfig)
fragment = fragment_file.fragments[0] fragment = fragment_file.fragments[0]
expected = [('text', 'flash_text', [Mapping.Surround('sym1', True, True)]), expected = [('text', 'flash_text', [Mapping.Surround('sym1')])]
('rodata', 'flash_rodata', [Mapping.Surround('sym2', True, False)]),
('data', 'dram0_data', [Mapping.Surround('sym3', False, True)]),
('bss', 'dram0_bss', [Mapping.Surround('sym4', True, True)]),
('common', 'dram0_bss', [Mapping.Surround('sym5', True, True), Mapping.Surround('sym6', True, True)])]
actual = fragment.flags[('obj1', None, 'default')] actual = fragment.flags[('obj1', None, 'default')]
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
@@ -946,13 +938,13 @@ entries:
expected = [('text', 'flash_text', [Mapping.Align(4, True, False), expected = [('text', 'flash_text', [Mapping.Align(4, True, False),
Mapping.Keep(), Mapping.Keep(),
Mapping.Surround('sym1', True, True), Mapping.Surround('sym1'),
Mapping.Align(8, True, False), Mapping.Align(8, True, False),
Mapping.Sort('name')]), Mapping.Sort('name')]),
('rodata', 'flash_rodata', [Mapping.Keep(), ('rodata', 'flash_rodata', [Mapping.Keep(),
Mapping.Align(4, True, False), Mapping.Align(4, True, False),
Mapping.Keep(), Mapping.Keep(),
Mapping.Surround('sym1', True, True), Mapping.Surround('sym1'),
Mapping.Align(8, True, False), Mapping.Align(8, True, False),
Mapping.Align(4, True, False), Mapping.Align(4, True, False),
Mapping.Sort('name')])] Mapping.Sort('name')])]
@@ -976,11 +968,11 @@ entries:
expected = [('text', 'flash_text', [Mapping.Align(4, True, False), expected = [('text', 'flash_text', [Mapping.Align(4, True, False),
Mapping.Keep(), Mapping.Keep(),
Mapping.Surround('sym1', True, True), Mapping.Surround('sym1'),
Mapping.Sort('name')]), Mapping.Sort('name')]),
('text', 'flash_text', [Mapping.Align(4, True, False), ('text', 'flash_text', [Mapping.Align(4, True, False),
Mapping.Keep(), Mapping.Keep(),
Mapping.Surround('sym1', True, True), Mapping.Surround('sym1'),
Mapping.Sort('name')])] Mapping.Sort('name')])]
actual = fragment.flags[('obj1', None, 'default')] actual = fragment.flags[('obj1', None, 'default')]
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
@@ -1004,11 +996,11 @@ entries:
expected = [('text', 'flash_text', [Mapping.Align(4, True, False), expected = [('text', 'flash_text', [Mapping.Align(4, True, False),
Mapping.Keep(), Mapping.Keep(),
Mapping.Surround('sym1', True, True), Mapping.Surround('sym1'),
Mapping.Sort('name')]), Mapping.Sort('name')]),
('text', 'flash_text', [Mapping.Align(4, True, False), ('text', 'flash_text', [Mapping.Align(4, True, False),
Mapping.Keep(), Mapping.Keep(),
Mapping.Surround('sym1', True, True), Mapping.Surround('sym1'),
Mapping.Sort('name')])] Mapping.Sort('name')])]
actual = fragment.flags[('obj1', None, 'default')] actual = fragment.flags[('obj1', None, 'default')]
self.assertEqual(expected, actual) self.assertEqual(expected, actual)

View File

@@ -1410,29 +1410,29 @@ class FlagTest(GenerationTest):
# #
# flash_rodata # flash_rodata
# *((EXCLUDE_FILE(libfreertos:timers) .rodata ...) C # *((EXCLUDE_FILE(libfreertos:timers) .rodata ...) C
# _sym2_start D.1 # _sym2_start D.1
# . = ALIGN(4) E.1 # . = ALIGN(4) E.1
# KEEP(* (EXCLUDE_FILE(libfreertos:timers) .rodata ...) F # KEEP(* (EXCLUDE_FILE(libfreertos:timers) .rodata ...) F
# _sym2_end D.2 # _sym2_end D.2
# . = ALIGN(4) E.2 # . = ALIGN(4) E.2
# #
# iram0_text # iram0_text
# *(.iram .iram.*) # *(.iram .iram.*)
# . = ALIGN(4) G.1 # . = ALIGN(4) G.1
# _sym1_start H.1 # _sym1_start H.1
# libfreertos.a:croutine(.text .literal ...) I # libfreertos.a:croutine(.text .literal ...) I
# . = ALIGN(4) G.2 # . = ALIGN(4) G.2
# _sym1_end H.2 # _sym1_end H.2
mapping = u""" mapping = u"""
[mapping:test] [mapping:test]
archive: libfreertos.a archive: libfreertos.a
entries: entries:
croutine (noflash_text); croutine (noflash_text);
text->iram0_text align(4, pre, post) surround(sym1, pre, post) #1 text->iram0_text align(4, pre, post) surround(sym1) #1
timers (default); timers (default);
text->flash_text keep sort(name) #2 text->flash_text keep sort(name) #2
timers (default); timers (default);
rodata->flash_rodata surround(sym2, pre, post) align(4, pre, post) #3 rodata->flash_rodata surround(sym2) align(4, pre, post) #3
""" """
self.add_fragments(mapping) self.add_fragments(mapping)
@@ -1475,10 +1475,10 @@ entries:
# are included in the flags. # are included in the flags.
# #
# flash_text # flash_text
# _sym1_start A.1 # _sym1_start A.1
# KEEP(* (EXCLUDE_FILE(libfreertos:croutine).text ...) B # KEEP(* (EXCLUDE_FILE(libfreertos:croutine).text ...) B
# KEEP(libfreertos.a:croutine(...))) C # KEEP(libfreertos.a:croutine(...))) C
# _sym1_end A.2 # _sym1_end A.2
# #
# iram0_text # iram0_text
# *(.iram .iram.*) # *(.iram .iram.*)
@@ -1494,7 +1494,7 @@ entries:
[mapping:test] [mapping:test]
archive: libfreertos.a archive: libfreertos.a
entries: entries:
croutine:prvCheckPendingReadyList (noflash_text) #3 croutine:prvCheckPendingReadyList (noflash_text) #3
""" """
self.generation.mappings = {} self.generation.mappings = {}
@@ -1537,10 +1537,10 @@ entries:
# #
# flash_text # flash_text
# *(EXCLUDE_FILE(libfreertos.a).text ...) # *(EXCLUDE_FILE(libfreertos.a).text ...)
# _sym1_start A.1 # _sym1_start A.1
# KEEP(libfreertos.a(EXCLUDE_FILE(libfreertos:croutine).text.* ...)) B # KEEP(libfreertos.a(EXCLUDE_FILE(libfreertos:croutine).text.* ...)) B
# KEEP(libfreertos.a:croutine(...))) C # KEEP(libfreertos.a:croutine(...))) C
# _sym1_end A.2 # _sym1_end A.2
# #
# iram0_text # iram0_text
# *(.iram .iram.*) # *(.iram .iram.*)
@@ -1552,7 +1552,7 @@ entries:
# 1 # 1
* (default); * (default);
text->flash_text surround(sym1) keep #2 text->flash_text surround(sym1) keep #2
croutine:prvCheckPendingReadyList (noflash_text) #3 croutine:prvCheckPendingReadyList (noflash_text) #3
""" """
self.add_fragments(mapping) self.add_fragments(mapping)
@@ -1594,9 +1594,9 @@ entries:
# #
# flash_text # flash_text
# *(EXCLUDE_FILE(libfreertos.a).text ...) # *(EXCLUDE_FILE(libfreertos.a).text ...)
# _sym1_start A.1 # _sym1_start A.1
# KEEP(libfreertos.a:croutine(...))) B # KEEP(libfreertos.a:croutine(...))) B
# _sym1_end A.2 # _sym1_end A.2
# #
# iram0_text # iram0_text
# *(.iram .iram.*) # *(.iram .iram.*)
@@ -1608,7 +1608,7 @@ entries:
# 1 # 1
croutine (default); croutine (default);
text->flash_text surround(sym1) keep #2 text->flash_text surround(sym1) keep #2
croutine:prvCheckPendingReadyList (noflash_text) #3 croutine:prvCheckPendingReadyList (noflash_text) #3
""" """
self.add_fragments(mapping) self.add_fragments(mapping)
@@ -1644,9 +1644,9 @@ entries:
# Explicit commands are separated from the parent's flags. # Explicit commands are separated from the parent's flags.
# #
# flash_text # flash_text
# _sym1_start A.1 # _sym1_start A.1
# KEEP(* (EXCLUDE_FILE(libfreertos:croutine).text ...) B # KEEP(* (EXCLUDE_FILE(libfreertos:croutine).text ...) B
# _sym1_end A.2 # _sym1_end A.2
# KEEP(libfreertos.a:croutine(...))) C # KEEP(libfreertos.a:croutine(...))) C
# #
# iram0_text # iram0_text
@@ -1663,8 +1663,8 @@ entries:
[mapping:test] [mapping:test]
archive: libfreertos.a archive: libfreertos.a
entries: entries:
croutine (default) #3 croutine (default) #3
croutine:prvCheckPendingReadyList (noflash_text) #4 croutine:prvCheckPendingReadyList (noflash_text) #4
""" """
self.generation.mappings = {} self.generation.mappings = {}
@@ -1706,9 +1706,9 @@ entries:
# #
# flash_text # flash_text
# *(EXCLUDE_FILE(libfreertos.a).text ...) # *(EXCLUDE_FILE(libfreertos.a).text ...)
# _sym1_start A.1 # _sym1_start A.1
# KEEP(libfreertos.a(EXCLUDE_FILE(libfreertos:croutine).text.* ...)) B # KEEP(libfreertos.a(EXCLUDE_FILE(libfreertos:croutine).text.* ...)) B
# _sym1_end A.2 # _sym1_end A.2
# KEEP(libfreertos.a:croutine(...))) C # KEEP(libfreertos.a:croutine(...))) C
# #
# iram0_text # iram0_text