Skip to content
Snippets Groups Projects
Verified Commit 976c63a8 authored by rahix's avatar rahix
Browse files

refactor(genapi): Save offset


Signed-off-by: default avatarRahix <rahix@rahix.de>
parent 06df747a
No related branches found
No related tags found
No related merge requests found
...@@ -11,6 +11,11 @@ MATCH_DECLARATION = re.compile( ...@@ -11,6 +11,11 @@ MATCH_DECLARATION = re.compile(
MATCH_ARGS = re.compile(r"(?P<type>\w+(?:\*+|\s+))(?P<name>\w+),") MATCH_ARGS = re.compile(r"(?P<type>\w+(?:\*+|\s+))(?P<name>\w+),")
def sizeof(args):
"""Return a string that describes the size of a list of arguments."""
return " + ".join(a["sizeof"] for a in args) if args != [] else "0"
def parse_declarations(source): def parse_declarations(source):
"""Parse all declarations in the given source.""" """Parse all declarations in the given source."""
declarations = [] declarations = []
...@@ -30,6 +35,7 @@ def parse_declarations(source): ...@@ -30,6 +35,7 @@ def parse_declarations(source):
"type": arg_type, "type": arg_type,
"name": arg_name, "name": arg_name,
"sizeof": "sizeof({})".format(arg_type), "sizeof": "sizeof({})".format(arg_type),
"offset": sizeof(args),
}) })
declarations.append({ declarations.append({
...@@ -43,11 +49,6 @@ def parse_declarations(source): ...@@ -43,11 +49,6 @@ def parse_declarations(source):
return declarations return declarations
def sizeof(args):
"""Return a string that describes the size of a list of arguments."""
return " + ".join(a["sizeof"] for a in args) if args != [] else "0"
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description="Generate the API stubs from a header file." description="Generate the API stubs from a header file."
...@@ -112,7 +113,6 @@ def main(): ...@@ -112,7 +113,6 @@ def main():
f_client.write(tmp.format(**decl)) f_client.write(tmp.format(**decl))
for i, arg in enumerate(decl["args"]): for i, arg in enumerate(decl["args"]):
arg["offset"] = sizeof(decl["args"][:i])
tmp = """\ tmp = """\
*({type}*)(buffer + {offset}) = {name}; *({type}*)(buffer + {offset}) = {name};
""" """
...@@ -161,7 +161,6 @@ void __api_dispatch_call(uint32_t id, void*buffer) ...@@ -161,7 +161,6 @@ void __api_dispatch_call(uint32_t id, void*buffer)
for i, arg in enumerate(decl["args"]): for i, arg in enumerate(decl["args"]):
arg["comma"] = "" if i == 0 else "," arg["comma"] = "" if i == 0 else ","
arg["offset"] = sizeof(decl["args"][:i])
tmp = """{comma} tmp = """{comma}
*({type}*)(buffer + {offset})""" *({type}*)(buffer + {offset})"""
f_dispatcher.write(tmp.format(**arg)) f_dispatcher.write(tmp.format(**arg))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment