From a54ddbb9482d5683def4bb8a01f846216fdd6768 Mon Sep 17 00:00:00 2001 From: Sarapulov Vasilii Date: Thu, 1 Aug 2024 21:40:57 +0300 Subject: [PATCH 1/3] fix: fix global data types dumping Signed-off-by: Sarapulov Vasilii --- src/scripts/global_variables_handling.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/scripts/global_variables_handling.py b/src/scripts/global_variables_handling.py index a6cb73d..bebab7a 100644 --- a/src/scripts/global_variables_handling.py +++ b/src/scripts/global_variables_handling.py @@ -2,6 +2,7 @@ # pylint: disable = import-error import re +import math from java.lang import String @@ -40,7 +41,10 @@ def read_structure(code_unit, program): elif component.isPointer(): pointer_address = address_factory.getAddress(str(component.getValue())) pointer = listing.getCodeUnitAt(pointer_address) - current_component_value = pointer.getLabel() + if pointer is not None: + current_component_value = pointer.getLabel() + else: + current_component_value = "" else: current_component_value = str(component.getValue()) struct += f"{current_component_value}, " @@ -70,7 +74,7 @@ def get_array_declaration(code_unit): variable_declaration_string = \ f'{array_type[:array_type.index("[")]} {str(code_unit.getLabel())}' + \ array_type[array_type.index("["):] - if string_array.count("0x0") == int(array_type[array_type.index("[") + 1:-1]): + if string_array.count("0x0") == math.prod(int(i) for i in re.findall(r'\[(\d*)\]', array_type)): variable_declaration_string += " = {0}" elif string_array is not None: variable_declaration_string += " = " + string_array From 356116d412b8f69080ce24c2037686e53bc1d9b7 Mon Sep 17 00:00:00 2001 From: Sarapulov Vasilii Date: Thu, 1 Aug 2024 22:50:44 +0300 Subject: [PATCH 2/3] feat: smoke test addition Signed-off-by: Sarapulov Vasilii --- src/scripts/global_variables_handling.py | 3 ++- src/tests/user_tests.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/scripts/global_variables_handling.py b/src/scripts/global_variables_handling.py index bebab7a..bea59e9 100644 --- a/src/scripts/global_variables_handling.py +++ b/src/scripts/global_variables_handling.py @@ -74,7 +74,8 @@ def get_array_declaration(code_unit): variable_declaration_string = \ f'{array_type[:array_type.index("[")]} {str(code_unit.getLabel())}' + \ array_type[array_type.index("["):] - if string_array.count("0x0") == math.prod(int(i) for i in re.findall(r'\[(\d*)\]', array_type)): + if string_array is not None and\ + string_array.count("0x0") == math.prod(int(i) for i in re.findall(r'\[(\d*)\]', array_type)): variable_declaration_string += " = {0}" elif string_array is not None: variable_declaration_string += " = " + string_array diff --git a/src/tests/user_tests.py b/src/tests/user_tests.py index a6f35d8..17c8499 100644 --- a/src/tests/user_tests.py +++ b/src/tests/user_tests.py @@ -43,3 +43,9 @@ def test_avl(clean): def test_linpack(clean): """Recompiles AVL tree binary""" assert compile_binary("linpack") == 0 + +def test_export_c_code(): + """Postprocessor test""" + for binary in os.listdir(INPUT_DIRECTORY): + export_c_code(f"{INPUT_DIRECTORY}{binary}", OUTPUT_PATH) + assert True From 8f354450c86a51b0eda436740ce0d3abe38f6b25 Mon Sep 17 00:00:00 2001 From: Sarapulov Vasilii Date: Thu, 1 Aug 2024 22:53:39 +0300 Subject: [PATCH 3/3] fix: pylint Signed-off-by: Sarapulov Vasilii --- src/scripts/global_variables_handling.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/scripts/global_variables_handling.py b/src/scripts/global_variables_handling.py index bea59e9..52485d5 100644 --- a/src/scripts/global_variables_handling.py +++ b/src/scripts/global_variables_handling.py @@ -75,7 +75,8 @@ def get_array_declaration(code_unit): f'{array_type[:array_type.index("[")]} {str(code_unit.getLabel())}' + \ array_type[array_type.index("["):] if string_array is not None and\ - string_array.count("0x0") == math.prod(int(i) for i in re.findall(r'\[(\d*)\]', array_type)): + string_array.count("0x0") ==\ + math.prod(int(i) for i in re.findall(r'\[(\d*)\]', array_type)): variable_declaration_string += " = {0}" elif string_array is not None: variable_declaration_string += " = " + string_array