summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlepelog <lepelog@users.noreply.github.com>2021-01-25 20:09:55 +0100
committerGitHub <noreply@github.com>2021-01-25 14:09:55 -0500
commitd301beca776579d3cc899cd0acf0cda79342cfc1 (patch)
tree07f8cf80de4885c22ef07e08ef59008a1f1e27de
parentec9b03241dbc98fe47836092a8535a65f937889a (diff)
change split.py to output extern vars/functions into generate CPP (#98)
* change split.py to output extern vars/functions into generate CPP also change demangling to use short type names * don't take files for extern funcs/vars anymore Co-authored-by: Pheenoh <pheenoh@gmail.com>
-rw-r--r--tools/splitter/demangle.py21
-rw-r--r--tools/splitter/split.py56
2 files changed, 25 insertions, 52 deletions
diff --git a/tools/splitter/demangle.py b/tools/splitter/demangle.py
index e0fb342c1e..5eb89c8add 100644
--- a/tools/splitter/demangle.py
+++ b/tools/splitter/demangle.py
@@ -10,14 +10,21 @@ types = {
'l': 'long',
's': 'short',
'c': 'char',
- 'f': 'float',
- 'd': 'double',
+ 'f': 'f32',
+ 'd': 'f64',
'v': 'void',
'x': 'long long',
'b': 'bool',
'e': 'varargs...',
}
+short_type_names = {
+ 'char': '8',
+ 'short': '16',
+ 'long' : '32',
+ 'long long': '64',
+}
+
# {'defctor', 'ops',}
special_funcs = {
@@ -55,9 +62,13 @@ class Param:
ret = ''
if self.is_const:
ret += 'const '
- if self.is_unsigned:
- ret += 'unsigned '
- ret += self.name
+ if self.name in short_type_names:
+ ret += 'u' if self.is_unsigned else 's'
+ ret += short_type_names[self.name]
+ else:
+ if self.is_unsigned:
+ ret += 'unsigned '
+ ret += self.name
for _ in range(self.pointer_lvl):
ret += '*'
if self.is_ref:
diff --git a/tools/splitter/split.py b/tools/splitter/split.py
index db60a9dabe..731d7750fb 100644
--- a/tools/splitter/split.py
+++ b/tools/splitter/split.py
@@ -20,7 +20,7 @@ import IPython
SDA_BASE = 0x80458580
SDA2_BASE = 0x80459A00
-__version__ = 'v0.3'
+__version__ = 'v0.4'
def function_global_search(lines: List[Line]) -> Iterable[Line]:
@@ -165,16 +165,6 @@ def emit_cxx_extern_vars(tu_file: str, labels: Iterable[str]) -> str:
)
@click.option('--s-include-base', type=str, default='funcs')
@click.option(
- '--extern-functions-file',
- type=PathPath(file_okay=True, dir_okay=False),
- default='include/functions.h',
-)
-@click.option(
- '--extern-variables-file',
- type=PathPath(file_okay=True, dir_okay=False),
- default='include/variables.h',
-)
-@click.option(
'--framework-map-file',
type=PathPath(file_okay=True, dir_okay=False),
default='frameworkF.map',
@@ -194,8 +184,6 @@ def split(
cxx_out,
funcs_out,
s_include_base,
- extern_functions_file,
- extern_variables_file,
framework_map_file,
ldscript_file,
from_line,
@@ -216,15 +204,6 @@ def split(
(from_line - 1 if from_line else 0) : (to_line - 1 if to_line else -1)
]
- logger.info('reading extern func/vars files')
- extern_funcs_src = extern_functions_file.read_text()
- extern_vars_src = extern_variables_file.read_text()
-
- include_re = re.compile(r'#include "(.*)"')
-
- for include in include_re.findall(extern_funcs_src):
- extern_funcs_src += (Path('include') / include).read_text()
-
logger.info('parsing map file')
framework_map = parse_framework_map(framework_map_file)
logger.debug(f'loaded {len(framework_map)} symbols from map')
@@ -262,19 +241,6 @@ def split(
if line.body.opcode[0] in {'l', 's'}: # load and store instructions, ish
loaded_labels |= set(find_labels_in_operands(line.body.operands))
- # -- dump new variable labels to variables.h
- logger.info('dumping variable labels to extern vars header')
- vars_new = set()
- for label in loaded_labels:
- if label not in extern_vars_src:
- logger.debug(f'adding extern var {label} to {extern_variables_file}')
- vars_new.add(label)
-
- if len(vars_new) > 0:
- with open(extern_variables_file, 'a') as f:
- f.write('\n\n')
- f.write(emit_cxx_extern_vars(cxx_out.name, vars_new))
-
# -- find all defined functions and split them
functions = list(find_functions(lines, framework_map))
logger.info('splitting functions')
@@ -324,18 +290,6 @@ def split(
for func in functions:
func_labels.add(func.name)
- # get rid of stuff already in functions.h. extremely hacky
- funcs_new_labels = set()
- for label in func_labels:
- if label not in extern_funcs_src:
- logger.info(f'adding extern func {label} to {extern_functions_file}')
- funcs_new_labels.add(label)
-
- if len(funcs_new_labels) > 0:
- with open(extern_functions_file, 'a') as f:
- f.write('\n\n')
- f.write(emit_cxx_extern_fns(cxx_out.name, funcs_new_labels))
-
# -- write asm stubs to cxx_out (could've done this as part of previous loop but imo this is cleaner)
logger.info(f'emitting c++ asm stubs to {cxx_out}')
with open(cxx_out, 'w') as f:
@@ -344,6 +298,14 @@ def split(
)
f.write('#include "global.h"\n\n')
+ # extern functions
+ f.write(emit_cxx_extern_fns(cxx_out.name, func_labels))
+ f.write('\n\n')
+
+ # extern variables
+ f.write(emit_cxx_extern_vars(cxx_out.name, loaded_labels))
+ f.write('\n\n')
+
f.write('extern "C" {\n')
for func in functions:
logger.debug(f'emitting asm stub for {func.name}')