Skip to content

Upstream ls parse #2575

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 2 commits into from
Jul 19, 2018
Merged
Changes from all commits
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
11 changes: 11 additions & 0 deletions scripts/ls_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import subprocess
import sys
import textwrap
import traceback


def epilog():
Expand Down Expand Up @@ -81,6 +82,7 @@ def get_linker_script_data(script):
text = re.sub(r"/\*.*?\*/", " ", text)

close_brace = re.compile(r"\s}(\s*>\s*\w+)?")
uwnknown_cmd = re.compile(r"\sPHDRS\s*{") # only this pattern for now, more might follow!
memory_cmd = re.compile(r"\sMEMORY\s*{")
sections_cmd = re.compile(r"\sSECTIONS\s*{")
assign_current = re.compile(r"\s(?P<sym>\w+)\s*=\s*\.\s*;")
Expand All @@ -102,6 +104,7 @@ def get_linker_script_data(script):
# with the info gleaned from the matched string.
jump_table = {
close_brace : close_brace_fun,
uwnknown_cmd : unknown_cmd_fun,
memory_cmd : memory_cmd_fun,
sections_cmd : sections_cmd_fun,
assign_current : assign_current_fun,
Expand Down Expand Up @@ -146,6 +149,7 @@ def get_linker_script_data(script):
state["MEM"] = False
state["SEC"] = False
state["DEF"] = False
state["UNKNOWN"] = False

i = 0
while i < len(text):
Expand Down Expand Up @@ -274,8 +278,12 @@ def close_brace_fun(state, _, buf):
elif state["MEM"]:
info("Closing memory command")
state["MEM"] = False
elif state["UNKNOWN"]:
info("Closing unknown command")
state["UNKNOWN"] = False
else:
error("Not in block\n%s", buf)
traceback.print_stack()
exit(1)


Expand Down Expand Up @@ -306,6 +314,9 @@ def memory_cmd_fun(state, _, buf):
asrt(not state["MEM"], "encountered MEMORY twice", buf)
state["MEM"] = True

def unknown_cmd_fun(state, _, buf):
asrt(not state["MEM"], "encountered UNKNOWN twice", buf)
state["UNKNOWN"] = True

def match_up_expr_assigns(state):
blocks = set([data["origin"] for data in state["expr-assigns"]])
Expand Down