From 38623541b057b443d57f229625438bcfc2270bdf Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 01:02:05 -0500 Subject: [PATCH 01/41] Set tree-sitter-cpp to v20.0.5 tag. --- suite/auto-sync/vendor/tree-sitter-cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suite/auto-sync/vendor/tree-sitter-cpp b/suite/auto-sync/vendor/tree-sitter-cpp index a714740214..e0c1678a78 160000 --- a/suite/auto-sync/vendor/tree-sitter-cpp +++ b/suite/auto-sync/vendor/tree-sitter-cpp @@ -1 +1 @@ -Subproject commit a71474021410973b29bfe99440d57bcd750246b1 +Subproject commit e0c1678a78731e78655b7d953efb4daecf58be46 From c4250ac779e664bac6d69af198a5928ce39abae0 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 02:46:22 -0500 Subject: [PATCH 02/41] Fix Python TS bindings to <0.22.0. Building the tree-sitter-cpp library on our own will be removed in py-tree-sitter v0.22.0. As long as the tree-sitter-cpp doesn;t have Python bindings (see: https://github.com/tree-sitter/tree-sitter-cpp/issues/250) we have to stick to <0.22.0 --- suite/auto-sync/Updater/CppTranslator/Configurator.py | 6 ++++-- suite/auto-sync/Updater/CppTranslator/CppTranslator.py | 4 +--- suite/auto-sync/Updater/CppTranslator/TemplateCollector.py | 3 +-- suite/auto-sync/Updater/requirements.txt | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/suite/auto-sync/Updater/CppTranslator/Configurator.py b/suite/auto-sync/Updater/CppTranslator/Configurator.py index ed781c06b5..c032fd1097 100644 --- a/suite/auto-sync/Updater/CppTranslator/Configurator.py +++ b/suite/auto-sync/Updater/CppTranslator/Configurator.py @@ -68,13 +68,15 @@ def ts_compile_cpp(self) -> None: ts_grammar_path = get_path("{VENDOR_DIR}").joinpath("tree-sitter-cpp") if not Path.exists(ts_grammar_path): fail_exit(f"Could not load the tree-sitter grammar at '{ts_grammar_path}'") - Language.build_library(str(self.ts_shared_object), [ts_grammar_path]) + # build_library wll be deprecated in 0.22.0. But CPP tree-sitter doesn't have Python bindings. + # So we stick with it. + Language.build_library(str(self.ts_shared_object), [str(ts_grammar_path)]) def ts_set_cpp_language(self) -> None: log.info(f"Load language '{self.ts_shared_object}'") if not Path.exists(self.ts_shared_object): fail_exit(f"Could not load the tree-sitter language shared object at '{self.ts_shared_object}'") - self.ts_cpp_lang = Language(self.ts_shared_object, "cpp") + self.ts_cpp_lang = Language(str(self.ts_shared_object), "cpp") def init_parser(self) -> None: log.debug("Init parser") diff --git a/suite/auto-sync/Updater/CppTranslator/CppTranslator.py b/suite/auto-sync/Updater/CppTranslator/CppTranslator.py index 3a2465a99a..11a556cdfb 100755 --- a/suite/auto-sync/Updater/CppTranslator/CppTranslator.py +++ b/suite/auto-sync/Updater/CppTranslator/CppTranslator.py @@ -2,13 +2,11 @@ from pathlib import Path import termcolor -from tree_sitter import Language, Parser, Tree, Node +from tree_sitter import Language, Parser, Tree, Node, Query import argparse import logging as log import sys -from tree_sitter.binding import Query - from CppTranslator.Configurator import Configurator from Helper import convert_loglevel, print_prominent_warning, get_header, run_clang_format, get_path from CppTranslator.Patches.GetRegFromClass import GetRegFromClass diff --git a/suite/auto-sync/Updater/CppTranslator/TemplateCollector.py b/suite/auto-sync/Updater/CppTranslator/TemplateCollector.py index 5f8451b572..c5fe8e2ae7 100644 --- a/suite/auto-sync/Updater/CppTranslator/TemplateCollector.py +++ b/suite/auto-sync/Updater/CppTranslator/TemplateCollector.py @@ -1,10 +1,9 @@ import re from pathlib import Path -from tree_sitter import Language, Parser +from tree_sitter import Language, Parser, Query, Node import logging as log -from tree_sitter.binding import Query, Node from CppTranslator.Patches.HelperMethods import get_text diff --git a/suite/auto-sync/Updater/requirements.txt b/suite/auto-sync/Updater/requirements.txt index a48c72c228..dd1326b486 100644 --- a/suite/auto-sync/Updater/requirements.txt +++ b/suite/auto-sync/Updater/requirements.txt @@ -1,2 +1,2 @@ termcolor>=2.3.0 -tree_sitter>=0.20.2 +tree_sitter<0.22.0 From 1939cfe8f61080c97424e75baa4a4487ebd33ad4 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 04:05:19 -0500 Subject: [PATCH 03/41] Restructure auto-sync scripts to allow packaging. --- suite/auto-sync/Updater/.gitignore | 2 - suite/auto-sync/Updater/README.md | 7 - suite/auto-sync/Updater/requirements.txt | 2 - suite/auto-sync/pyproject.toml | 12 + .../{Updater => src/autosync}/ASUpdater.py | 12 +- .../autosync}/HeaderPatcher.py | 0 .../{Updater => src/autosync}/Helper.py | 2 +- .../{Updater => src/autosync}/IncGenerator.py | 2 +- .../autosync}/PathVarHandler.py | 4 +- .../autosync/cpptranslator}/Configurator.py | 2 +- .../autosync/cpptranslator}/CppTranslator.py | 126 +-- .../autosync/cpptranslator}/Differ.py | 4 +- .../cpptranslator}/Patches/AddCSDetail.py | 4 +- .../cpptranslator}/Patches/AddOperand.py | 4 +- .../autosync/cpptranslator}/Patches/Assert.py | 2 +- .../cpptranslator}/Patches/BitCastStdArray.py | 4 +- .../Patches/CheckDecoderStatus.py | 4 +- .../Patches/ClassConstructorDef.py | 2 +- .../cpptranslator}/Patches/ClassesDef.py | 4 +- .../Patches/ConstMCInstParameter.py | 4 +- .../cpptranslator}/Patches/ConstMCOperand.py | 4 +- .../cpptranslator}/Patches/CppInitCast.py | 4 +- .../cpptranslator}/Patches/CreateOperand0.py | 4 +- .../cpptranslator}/Patches/CreateOperand1.py | 4 +- .../Patches/DeclarationInConditionClause.py | 4 +- .../Patches/DecodeInstruction.py | 4 +- .../cpptranslator}/Patches/DecoderCast.py | 2 +- .../Patches/DecoderParameter.py | 2 +- .../cpptranslator}/Patches/FallThrough.py | 2 +- .../cpptranslator}/Patches/FeatureBits.py | 4 +- .../cpptranslator}/Patches/FeatureBitsDecl.py | 2 +- .../cpptranslator}/Patches/FieldFromInstr.py | 4 +- .../cpptranslator}/Patches/GetNumOperands.py | 4 +- .../cpptranslator}/Patches/GetOpcode.py | 4 +- .../cpptranslator}/Patches/GetOperand.py | 4 +- .../Patches/GetOperandRegImm.py | 4 +- .../cpptranslator}/Patches/GetRegClass.py | 4 +- .../cpptranslator}/Patches/GetRegFromClass.py | 4 +- .../cpptranslator}/Patches/GetSubReg.py | 4 +- .../cpptranslator}/Patches/HelperMethods.py | 4 +- .../cpptranslator}/Patches/Includes.py | 4 +- .../Patches/InlineToStaticInline.py | 4 +- .../cpptranslator}/Patches/IsOptionalDef.py | 4 +- .../cpptranslator}/Patches/IsPredicate.py | 4 +- .../cpptranslator}/Patches/IsRegImm.py | 4 +- .../cpptranslator}/Patches/LLVMFallThrough.py | 2 +- .../cpptranslator}/Patches/LLVMunreachable.py | 4 +- .../Patches/MethodToFunctions.py | 4 +- .../Patches/MethodTypeQualifier.py | 4 +- .../cpptranslator}/Patches/NamespaceAnon.py | 4 +- .../cpptranslator}/Patches/NamespaceArch.py | 4 +- .../cpptranslator}/Patches/NamespaceLLVM.py | 4 +- .../cpptranslator}/Patches/OutStreamParam.py | 4 +- .../autosync/cpptranslator}/Patches/Patch.py | 0 .../Patches/PredicateBlockFunctions.py | 4 +- .../cpptranslator}/Patches/PrintAnnotation.py | 2 +- .../Patches/PrintRegImmShift.py | 4 +- .../Patches/QualifiedIdentifier.py | 4 +- .../cpptranslator}/Patches/ReferencesDecl.py | 4 +- .../Patches/RegClassContains.py | 4 +- .../cpptranslator}/Patches/STIArgument.py | 4 +- .../cpptranslator}/Patches/STIFeatureBits.py | 4 +- .../cpptranslator}/Patches/STParameter.py | 4 +- .../cpptranslator}/Patches/SetOpcode.py | 4 +- .../cpptranslator}/Patches/SignExtend.py | 6 +- .../cpptranslator}/Patches/SizeAssignments.py | 4 +- .../cpptranslator}/Patches/StreamOperation.py | 4 +- .../Patches/TemplateDeclaration.py | 6 +- .../Patches/TemplateDefinition.py | 6 +- .../Patches/TemplateParamDecl.py | 4 +- .../cpptranslator}/Patches/TemplateRefs.py | 6 +- .../cpptranslator}/Patches/UseMarkup.py | 2 +- .../Patches/UsingDeclaration.py | 2 +- .../autosync/cpptranslator}/README.md | 0 .../cpptranslator}/TemplateCollector.py | 2 +- .../cpptranslator/Tests/test_config.json | 18 + .../cpptranslator/Tests/test_patches.py | 796 ++++++++++++++++++ .../autosync/cpptranslator}/arch_config.json | 0 .../cpptranslator}/saved_patches.json | 0 .../{Updater => src/autosync}/path_vars.json | 3 +- 80 files changed, 1018 insertions(+), 204 deletions(-) delete mode 100644 suite/auto-sync/Updater/.gitignore delete mode 100644 suite/auto-sync/Updater/README.md delete mode 100644 suite/auto-sync/Updater/requirements.txt create mode 100644 suite/auto-sync/pyproject.toml rename suite/auto-sync/{Updater => src/autosync}/ASUpdater.py (95%) rename suite/auto-sync/{Updater => src/autosync}/HeaderPatcher.py (100%) rename suite/auto-sync/{Updater => src/autosync}/Helper.py (98%) rename suite/auto-sync/{Updater => src/autosync}/IncGenerator.py (99%) rename suite/auto-sync/{Updater => src/autosync}/PathVarHandler.py (92%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Configurator.py (98%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/CppTranslator.py (79%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Differ.py (99%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/AddCSDetail.py (96%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/AddOperand.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/Assert.py (91%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/BitCastStdArray.py (94%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/CheckDecoderStatus.py (88%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/ClassConstructorDef.py (92%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/ClassesDef.py (92%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/ConstMCInstParameter.py (88%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/ConstMCOperand.py (88%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/CppInitCast.py (86%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/CreateOperand0.py (93%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/CreateOperand1.py (94%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/DeclarationInConditionClause.py (91%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/DecodeInstruction.py (92%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/DecoderCast.py (94%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/DecoderParameter.py (93%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/FallThrough.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/FeatureBits.py (88%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/FeatureBitsDecl.py (92%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/FieldFromInstr.py (93%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/GetNumOperands.py (89%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/GetOpcode.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/GetOperand.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/GetOperandRegImm.py (89%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/GetRegClass.py (87%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/GetRegFromClass.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/GetSubReg.py (88%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/HelperMethods.py (98%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/Includes.py (98%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/InlineToStaticInline.py (88%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/IsOptionalDef.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/IsPredicate.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/IsRegImm.py (89%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/LLVMFallThrough.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/LLVMunreachable.py (87%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/MethodToFunctions.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/MethodTypeQualifier.py (89%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/NamespaceAnon.py (84%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/NamespaceArch.py (91%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/NamespaceLLVM.py (86%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/OutStreamParam.py (89%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/Patch.py (100%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/PredicateBlockFunctions.py (91%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/PrintAnnotation.py (91%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/PrintRegImmShift.py (87%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/QualifiedIdentifier.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/ReferencesDecl.py (85%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/RegClassContains.py (89%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/STIArgument.py (87%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/STIFeatureBits.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/STParameter.py (89%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/SetOpcode.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/SignExtend.py (86%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/SizeAssignments.py (86%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/StreamOperation.py (96%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/TemplateDeclaration.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/TemplateDefinition.py (91%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/TemplateParamDecl.py (91%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/TemplateRefs.py (85%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/UseMarkup.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/Patches/UsingDeclaration.py (90%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/README.md (100%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/TemplateCollector.py (99%) create mode 100644 suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json create mode 100644 suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/arch_config.json (100%) rename suite/auto-sync/{Updater/CppTranslator => src/autosync/cpptranslator}/saved_patches.json (100%) rename suite/auto-sync/{Updater => src/autosync}/path_vars.json (85%) diff --git a/suite/auto-sync/Updater/.gitignore b/suite/auto-sync/Updater/.gitignore deleted file mode 100644 index 999f4888f7..0000000000 --- a/suite/auto-sync/Updater/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*/.idea/ - diff --git a/suite/auto-sync/Updater/README.md b/suite/auto-sync/Updater/README.md deleted file mode 100644 index c9d825851f..0000000000 --- a/suite/auto-sync/Updater/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# The update scripts for auto-sync - -## Updating only the `inc` files - -```cmd -> ./IncGenerator.py ... -``` diff --git a/suite/auto-sync/Updater/requirements.txt b/suite/auto-sync/Updater/requirements.txt deleted file mode 100644 index dd1326b486..0000000000 --- a/suite/auto-sync/Updater/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -termcolor>=2.3.0 -tree_sitter<0.22.0 diff --git a/suite/auto-sync/pyproject.toml b/suite/auto-sync/pyproject.toml new file mode 100644 index 0000000000..c17eac8de2 --- /dev/null +++ b/suite/auto-sync/pyproject.toml @@ -0,0 +1,12 @@ +[project] +name = "autosync" +version = "0.1.0" +dependencies = [ + "termcolor >= 2.3.0", + "tree_sitter < 0.22.0", +] +requires-python = ">= 3.11" + +[tool.setuptools] +packages = ["autosync", "autosync.cpptranslator"] +package-dir = {"" = "src"} diff --git a/suite/auto-sync/Updater/ASUpdater.py b/suite/auto-sync/src/autosync/ASUpdater.py similarity index 95% rename from suite/auto-sync/Updater/ASUpdater.py rename to suite/auto-sync/src/autosync/ASUpdater.py index 9440583f1c..8ed8df3295 100755 --- a/suite/auto-sync/Updater/ASUpdater.py +++ b/suite/auto-sync/src/autosync/ASUpdater.py @@ -9,13 +9,13 @@ import logging as log from enum import StrEnum -from CppTranslator.Configurator import Configurator -from CppTranslator.CppTranslator import Translator -from IncGenerator import IncGenerator -from Helper import get_path, convert_loglevel, check_py_version, fail_exit -from HeaderPatcher import HeaderPatcher +from autosync.cpptranslator.CppTranslator import Translator +from autosync.Helper import get_path, convert_loglevel, check_py_version, fail_exit +from autosync.HeaderPatcher import HeaderPatcher from pathlib import Path +from autosync.IncGenerator import IncGenerator + class USteps(StrEnum): INC_GEN = "IncGen" @@ -121,7 +121,7 @@ def translate(self) -> None: def diff(self) -> None: translator_config = get_path("{CPP_TRANSLATOR_CONFIG}") configurator = Configurator(self.arch, translator_config) - from CppTranslator.Differ import Differ + from autosync.cpptranslator.Differ import Differ differ = Differ(configurator, self.differ_no_auto_apply) differ.diff() diff --git a/suite/auto-sync/Updater/HeaderPatcher.py b/suite/auto-sync/src/autosync/HeaderPatcher.py similarity index 100% rename from suite/auto-sync/Updater/HeaderPatcher.py rename to suite/auto-sync/src/autosync/HeaderPatcher.py diff --git a/suite/auto-sync/Updater/Helper.py b/suite/auto-sync/src/autosync/Helper.py similarity index 98% rename from suite/auto-sync/Updater/Helper.py rename to suite/auto-sync/src/autosync/Helper.py index dbdc5a6dc2..9391b0f45d 100644 --- a/suite/auto-sync/Updater/Helper.py +++ b/suite/auto-sync/src/autosync/Helper.py @@ -7,7 +7,7 @@ import termcolor -from PathVarHandler import PathVarHandler +from autosync.PathVarHandler import PathVarHandler from tree_sitter import Node diff --git a/suite/auto-sync/Updater/IncGenerator.py b/suite/auto-sync/src/autosync/IncGenerator.py similarity index 99% rename from suite/auto-sync/Updater/IncGenerator.py rename to suite/auto-sync/src/autosync/IncGenerator.py index 665e5507a1..129a52318f 100644 --- a/suite/auto-sync/Updater/IncGenerator.py +++ b/suite/auto-sync/src/autosync/IncGenerator.py @@ -7,7 +7,7 @@ import logging as log -from Helper import fail_exit, get_path +from autosync.Helper import fail_exit, get_path from pathlib import Path inc_tables = [ diff --git a/suite/auto-sync/Updater/PathVarHandler.py b/suite/auto-sync/src/autosync/PathVarHandler.py similarity index 92% rename from suite/auto-sync/Updater/PathVarHandler.py rename to suite/auto-sync/src/autosync/PathVarHandler.py index 9e7b6128a8..e7bc5582c6 100644 --- a/suite/auto-sync/Updater/PathVarHandler.py +++ b/suite/auto-sync/src/autosync/PathVarHandler.py @@ -28,8 +28,8 @@ def __init__(self) -> None: # The main directories self.paths["{CS_ROOT}"] = Path(repo_root) self.paths["{AUTO_SYNC_ROOT}"] = Path(repo_root).joinpath("suite/auto-sync/") - self.paths["{AUTO_SYNC_UPDATER_DIR}"] = self.paths["{AUTO_SYNC_ROOT}"].joinpath("Updater/") - path_config_file = self.paths["{AUTO_SYNC_UPDATER_DIR}"].joinpath("path_vars.json") + self.paths["{AUTO_SYNC_SRC}"] = self.paths["{AUTO_SYNC_ROOT}"].joinpath("src/autosync/") + path_config_file = self.paths["{AUTO_SYNC_SRC}"].joinpath("path_vars.json") # Load variables with open(path_config_file) as f: diff --git a/suite/auto-sync/Updater/CppTranslator/Configurator.py b/suite/auto-sync/src/autosync/cpptranslator/Configurator.py similarity index 98% rename from suite/auto-sync/Updater/CppTranslator/Configurator.py rename to suite/auto-sync/src/autosync/cpptranslator/Configurator.py index c032fd1097..281e02a8a9 100644 --- a/suite/auto-sync/Updater/CppTranslator/Configurator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Configurator.py @@ -1,7 +1,7 @@ import json from pathlib import Path -from Helper import get_path, fail_exit +from autosync.Helper import get_path, fail_exit from tree_sitter import Language, Parser import logging as log diff --git a/suite/auto-sync/Updater/CppTranslator/CppTranslator.py b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py similarity index 79% rename from suite/auto-sync/Updater/CppTranslator/CppTranslator.py rename to suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py index 11a556cdfb..b7780bad50 100755 --- a/suite/auto-sync/Updater/CppTranslator/CppTranslator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py @@ -7,69 +7,69 @@ import logging as log import sys -from CppTranslator.Configurator import Configurator -from Helper import convert_loglevel, print_prominent_warning, get_header, run_clang_format, get_path -from CppTranslator.Patches.GetRegFromClass import GetRegFromClass -from CppTranslator.Patches.AddCSDetail import AddCSDetail -from CppTranslator.Patches.AddOperand import AddOperand -from CppTranslator.Patches.Assert import Assert -from CppTranslator.Patches.BitCastStdArray import BitCastStdArray -from CppTranslator.Patches.CheckDecoderStatus import CheckDecoderStatus -from CppTranslator.Patches.ClassConstructorDef import ClassConstructorDef -from CppTranslator.Patches.ClassesDef import ClassesDef -from CppTranslator.Patches.ConstMCInstParameter import ConstMCInstParameter -from CppTranslator.Patches.ConstMCOperand import ConstMCOperand -from CppTranslator.Patches.CppInitCast import CppInitCast -from CppTranslator.Patches.CreateOperand0 import CreateOperand0 -from CppTranslator.Patches.CreateOperand1 import CreateOperand1 -from CppTranslator.Patches.DeclarationInConditionClause import DeclarationInConditionalClause -from CppTranslator.Patches.DecodeInstruction import DecodeInstruction -from CppTranslator.Patches.DecoderCast import DecoderCast -from CppTranslator.Patches.DecoderParameter import DecoderParameter -from CppTranslator.Patches.FallThrough import FallThrough -from CppTranslator.Patches.FeatureBits import FeatureBits -from CppTranslator.Patches.FeatureBitsDecl import FeatureBitsDecl -from CppTranslator.Patches.FieldFromInstr import FieldFromInstr -from CppTranslator.Patches.GetNumOperands import GetNumOperands -from CppTranslator.Patches.GetOpcode import GetOpcode -from CppTranslator.Patches.GetOperandRegImm import GetOperandRegImm -from CppTranslator.Patches.GetOperand import GetOperand -from CppTranslator.Patches.GetRegClass import GetRegClass -from CppTranslator.Patches.GetSubReg import GetSubReg -from CppTranslator.Patches.Includes import Includes -from CppTranslator.Patches.InlineToStaticInline import InlineToStaticInline -from CppTranslator.Patches.IsRegImm import IsOperandRegImm -from CppTranslator.Patches.IsOptionalDef import IsOptionalDef -from CppTranslator.Patches.IsPredicate import IsPredicate -from CppTranslator.Patches.LLVMFallThrough import LLVMFallThrough -from CppTranslator.Patches.LLVMunreachable import LLVMUnreachable -from CppTranslator.Patches.MethodToFunctions import MethodToFunction -from CppTranslator.Patches.MethodTypeQualifier import MethodTypeQualifier -from CppTranslator.Patches.NamespaceLLVM import NamespaceLLVM -from CppTranslator.Patches.NamespaceAnon import NamespaceAnon -from CppTranslator.Patches.NamespaceArch import NamespaceArch -from CppTranslator.Patches.OutStreamParam import OutStreamParam -from CppTranslator.Patches.PredicateBlockFunctions import PredicateBlockFunctions -from CppTranslator.Patches.PrintAnnotation import PrintAnnotation -from CppTranslator.Patches.PrintRegImmShift import PrintRegImmShift -from CppTranslator.Patches.QualifiedIdentifier import QualifiedIdentifier -from CppTranslator.Patches.Patch import Patch -from CppTranslator.Patches.ReferencesDecl import ReferencesDecl -from CppTranslator.Patches.RegClassContains import RegClassContains -from CppTranslator.Patches.STIArgument import STIArgument -from CppTranslator.Patches.STIFeatureBits import STIFeatureBits -from CppTranslator.Patches.STParameter import SubtargetInfoParam -from CppTranslator.Patches.SetOpcode import SetOpcode -from CppTranslator.Patches.SignExtend import SignExtend -from CppTranslator.Patches.SizeAssignments import SizeAssignment -from CppTranslator.Patches.StreamOperation import StreamOperations -from CppTranslator.Patches.TemplateDeclaration import TemplateDeclaration -from CppTranslator.Patches.TemplateDefinition import TemplateDefinition -from CppTranslator.Patches.TemplateParamDecl import TemplateParamDecl -from CppTranslator.Patches.TemplateRefs import TemplateRefs -from CppTranslator.Patches.UseMarkup import UseMarkup -from CppTranslator.Patches.UsingDeclaration import UsingDeclaration -from CppTranslator.TemplateCollector import TemplateCollector +from autosync.cpptranslator.Configurator import Configurator +from autosync.Helper import convert_loglevel, print_prominent_warning, get_header, run_clang_format, get_path +from autosync.cpptranslator.Patches.GetRegFromClass import GetRegFromClass +from autosync.cpptranslator.Patches.AddCSDetail import AddCSDetail +from autosync.cpptranslator.Patches.AddOperand import AddOperand +from autosync.cpptranslator.Patches.Assert import Assert +from autosync.cpptranslator.Patches.BitCastStdArray import BitCastStdArray +from autosync.cpptranslator.Patches.CheckDecoderStatus import CheckDecoderStatus +from autosync.cpptranslator.Patches.ClassConstructorDef import ClassConstructorDef +from autosync.cpptranslator.Patches.ClassesDef import ClassesDef +from autosync.cpptranslator.Patches.ConstMCInstParameter import ConstMCInstParameter +from autosync.cpptranslator.Patches.ConstMCOperand import ConstMCOperand +from autosync.cpptranslator.Patches.CppInitCast import CppInitCast +from autosync.cpptranslator.Patches.CreateOperand0 import CreateOperand0 +from autosync.cpptranslator.Patches.CreateOperand1 import CreateOperand1 +from autosync.cpptranslator.Patches.DeclarationInConditionClause import DeclarationInConditionalClause +from autosync.cpptranslator.Patches.DecodeInstruction import DecodeInstruction +from autosync.cpptranslator.Patches.DecoderCast import DecoderCast +from autosync.cpptranslator.Patches.DecoderParameter import DecoderParameter +from autosync.cpptranslator.Patches.FallThrough import FallThrough +from autosync.cpptranslator.Patches.FeatureBits import FeatureBits +from autosync.cpptranslator.Patches.FeatureBitsDecl import FeatureBitsDecl +from autosync.cpptranslator.Patches.FieldFromInstr import FieldFromInstr +from autosync.cpptranslator.Patches.GetNumOperands import GetNumOperands +from autosync.cpptranslator.Patches.GetOpcode import GetOpcode +from autosync.cpptranslator.Patches.GetOperandRegImm import GetOperandRegImm +from autosync.cpptranslator.Patches.GetOperand import GetOperand +from autosync.cpptranslator.Patches.GetRegClass import GetRegClass +from autosync.cpptranslator.Patches.GetSubReg import GetSubReg +from autosync.cpptranslator.Patches.Includes import Includes +from autosync.cpptranslator.Patches.InlineToStaticInline import InlineToStaticInline +from autosync.cpptranslator.Patches.IsRegImm import IsOperandRegImm +from autosync.cpptranslator.Patches.IsOptionalDef import IsOptionalDef +from autosync.cpptranslator.Patches.IsPredicate import IsPredicate +from autosync.cpptranslator.Patches.LLVMFallThrough import LLVMFallThrough +from autosync.cpptranslator.Patches.LLVMunreachable import LLVMUnreachable +from autosync.cpptranslator.Patches.MethodToFunctions import MethodToFunction +from autosync.cpptranslator.Patches.MethodTypeQualifier import MethodTypeQualifier +from autosync.cpptranslator.Patches.NamespaceLLVM import NamespaceLLVM +from autosync.cpptranslator.Patches.NamespaceAnon import NamespaceAnon +from autosync.cpptranslator.Patches.NamespaceArch import NamespaceArch +from autosync.cpptranslator.Patches.OutStreamParam import OutStreamParam +from autosync.cpptranslator.Patches.PredicateBlockFunctions import PredicateBlockFunctions +from autosync.cpptranslator.Patches.PrintAnnotation import PrintAnnotation +from autosync.cpptranslator.Patches.PrintRegImmShift import PrintRegImmShift +from autosync.cpptranslator.Patches.QualifiedIdentifier import QualifiedIdentifier +from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.ReferencesDecl import ReferencesDecl +from autosync.cpptranslator.Patches.RegClassContains import RegClassContains +from autosync.cpptranslator.Patches.STIArgument import STIArgument +from autosync.cpptranslator.Patches.STIFeatureBits import STIFeatureBits +from autosync.cpptranslator.Patches.STParameter import SubtargetInfoParam +from autosync.cpptranslator.Patches.SetOpcode import SetOpcode +from autosync.cpptranslator.Patches.SignExtend import SignExtend +from autosync.cpptranslator.Patches.SizeAssignments import SizeAssignment +from autosync.cpptranslator.Patches.StreamOperation import StreamOperations +from autosync.cpptranslator.Patches.TemplateDeclaration import TemplateDeclaration +from autosync.cpptranslator.Patches.TemplateDefinition import TemplateDefinition +from autosync.cpptranslator.Patches.TemplateParamDecl import TemplateParamDecl +from autosync.cpptranslator.Patches.TemplateRefs import TemplateRefs +from autosync.cpptranslator.Patches.UseMarkup import UseMarkup +from autosync.cpptranslator.Patches.UsingDeclaration import UsingDeclaration +from autosync.cpptranslator.TemplateCollector import TemplateCollector class Translator: diff --git a/suite/auto-sync/Updater/CppTranslator/Differ.py b/suite/auto-sync/src/autosync/cpptranslator/Differ.py similarity index 99% rename from suite/auto-sync/Updater/CppTranslator/Differ.py rename to suite/auto-sync/src/autosync/cpptranslator/Differ.py index b3dd44f778..c1aba32a89 100755 --- a/suite/auto-sync/Updater/CppTranslator/Differ.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Differ.py @@ -11,8 +11,8 @@ import logging as log import sys -from CppTranslator.Configurator import Configurator -from Helper import ( +from autosync.cpptranslator.Configurator import Configurator +from autosync.Helper import ( convert_loglevel, find_id_by_type, print_prominent_info, diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/AddCSDetail.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py similarity index 96% rename from suite/auto-sync/Updater/CppTranslator/Patches/AddCSDetail.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py index 818e1e1d9e..06a5017009 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/AddCSDetail.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py @@ -3,8 +3,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_MCInst_var_name, template_param_list_to_dict -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name, template_param_list_to_dict +from autosync.cpptranslator.Patches.Patch import Patch class AddCSDetail(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/AddOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/AddOperand.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py index 0ccc954e30..a949139985 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/AddOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class AddOperand(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/Assert.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py similarity index 91% rename from suite/auto-sync/Updater/CppTranslator/Patches/Assert.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py index e8e3f68ecf..edb8f90c9a 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/Assert.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py @@ -1,5 +1,5 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class Assert(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/BitCastStdArray.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py similarity index 94% rename from suite/auto-sync/Updater/CppTranslator/Patches/BitCastStdArray.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py index 0a41c88227..cd89288f74 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/BitCastStdArray.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class BitCastStdArray(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/CheckDecoderStatus.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py similarity index 88% rename from suite/auto-sync/Updater/CppTranslator/Patches/CheckDecoderStatus.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py index 07b0c12848..395ee55cf6 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/CheckDecoderStatus.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class CheckDecoderStatus(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/ClassConstructorDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py similarity index 92% rename from suite/auto-sync/Updater/CppTranslator/Patches/ClassConstructorDef.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py index 9d6724a1c5..916f797db3 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/ClassConstructorDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py @@ -1,5 +1,5 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class ClassConstructorDef(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/ClassesDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py similarity index 92% rename from suite/auto-sync/Updater/CppTranslator/Patches/ClassesDef.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py index 2945fe27fa..b5299e16c3 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/ClassesDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py @@ -3,8 +3,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class ClassesDef(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/ConstMCInstParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py similarity index 88% rename from suite/auto-sync/Updater/CppTranslator/Patches/ConstMCInstParameter.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py index 1e940f943f..49e0db275d 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/ConstMCInstParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class ConstMCInstParameter(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/ConstMCOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py similarity index 88% rename from suite/auto-sync/Updater/CppTranslator/Patches/ConstMCOperand.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py index 38a8f36fd1..44ac0bf9eb 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/ConstMCOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class ConstMCOperand(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/CppInitCast.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py similarity index 86% rename from suite/auto-sync/Updater/CppTranslator/Patches/CppInitCast.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py index 00a8114e05..40fdc6b28f 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/CppInitCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class CppInitCast(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/CreateOperand0.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py similarity index 93% rename from suite/auto-sync/Updater/CppTranslator/Patches/CreateOperand0.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py index c5c46abe80..955cc15f7d 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/CreateOperand0.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class CreateOperand0(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/CreateOperand1.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py similarity index 94% rename from suite/auto-sync/Updater/CppTranslator/Patches/CreateOperand1.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py index 5aec70f40a..55e5789bca 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/CreateOperand1.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_MCInst_var_name -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.Patch import Patch class CreateOperand1(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/DeclarationInConditionClause.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py similarity index 91% rename from suite/auto-sync/Updater/CppTranslator/Patches/DeclarationInConditionClause.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py index fc6ecf108c..c81eed4c5c 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/DeclarationInConditionClause.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_capture_node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node +from autosync.cpptranslator.Patches.Patch import Patch class DeclarationInConditionalClause(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/DecodeInstruction.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py similarity index 92% rename from suite/auto-sync/Updater/CppTranslator/Patches/DecodeInstruction.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py index 170514c739..e6ffc913ef 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/DecodeInstruction.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class DecodeInstruction(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/DecoderCast.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py similarity index 94% rename from suite/auto-sync/Updater/CppTranslator/Patches/DecoderCast.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py index 605cccc562..3417b46e3d 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/DecoderCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class DecoderCast(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/DecoderParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py similarity index 93% rename from suite/auto-sync/Updater/CppTranslator/Patches/DecoderParameter.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py index af1af91e48..da2a05493d 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/DecoderParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class DecoderParameter(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/FallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/FallThrough.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py index a9f8cd14c4..4ed5b4427f 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/FallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py @@ -1,5 +1,5 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class FallThrough(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/FeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py similarity index 88% rename from suite/auto-sync/Updater/CppTranslator/Patches/FeatureBits.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py index 278060d6f6..e77fe30223 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/FeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_MCInst_var_name -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.Patch import Patch class FeatureBits(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/FeatureBitsDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py similarity index 92% rename from suite/auto-sync/Updater/CppTranslator/Patches/FeatureBitsDecl.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py index aebc487e1b..c091073582 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/FeatureBitsDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class FeatureBitsDecl(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py similarity index 93% rename from suite/auto-sync/Updater/CppTranslator/Patches/FieldFromInstr.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py index 64f6616aff..930f38cd22 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/FieldFromInstr.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py @@ -3,8 +3,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_function_params_of_node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_function_params_of_node +from autosync.cpptranslator.Patches.Patch import Patch class FieldFromInstr(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/GetNumOperands.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py similarity index 89% rename from suite/auto-sync/Updater/CppTranslator/Patches/GetNumOperands.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py index bf85c2b90e..0a3f7192a7 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/GetNumOperands.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class GetNumOperands(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/GetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/GetOpcode.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py index 7d1cd946d9..2ba9f95fc6 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/GetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class GetOpcode(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/GetOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/GetOperand.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py index 66199d3c31..27e0dce196 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/GetOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class GetOperand(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/GetOperandRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py similarity index 89% rename from suite/auto-sync/Updater/CppTranslator/Patches/GetOperandRegImm.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py index f3bda3d517..2cffabff13 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/GetOperandRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_capture_node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node +from autosync.cpptranslator.Patches.Patch import Patch class GetOperandRegImm(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/GetRegClass.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py similarity index 87% rename from suite/auto-sync/Updater/CppTranslator/Patches/GetRegClass.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py index 9dca7ee584..49ab599eb2 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/GetRegClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_capture_node, get_MCInst_var_name -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node, get_MCInst_var_name +from autosync.cpptranslator.Patches.Patch import Patch class GetRegClass(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/GetRegFromClass.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/GetRegFromClass.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py index 980981a79b..f6b032250f 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/GetRegFromClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_capture_node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node +from autosync.cpptranslator.Patches.Patch import Patch class GetRegFromClass(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/GetSubReg.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py similarity index 88% rename from suite/auto-sync/Updater/CppTranslator/Patches/GetSubReg.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py index 60e579404d..6cb271f68c 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/GetSubReg.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_MCInst_var_name -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.Patch import Patch class GetSubReg(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/HelperMethods.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py similarity index 98% rename from suite/auto-sync/Updater/CppTranslator/Patches/HelperMethods.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py index 9232e980d9..a78127ff04 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/HelperMethods.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py @@ -3,7 +3,7 @@ from tree_sitter import Node import logging as log -from Helper import fail_exit +from autosync.Helper import fail_exit def get_function_params_of_node(n: Node) -> Node: @@ -193,7 +193,7 @@ def parse_function_capture( case _: raise NotImplementedError(f"Node type {node.type} not handled.") - from CppTranslator.TemplateCollector import TemplateCollector + from autosync.cpptranslator.TemplateCollector import TemplateCollector return TemplateCollector.templ_params_to_list(temp_args), st_class_ids, ret_type, func_name, func_params, comp_stmt diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/Includes.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py similarity index 98% rename from suite/auto-sync/Updater/CppTranslator/Patches/Includes.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py index 154dd1242a..d34a6fc0ee 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/Includes.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class Includes(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/InlineToStaticInline.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py similarity index 88% rename from suite/auto-sync/Updater/CppTranslator/Patches/InlineToStaticInline.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py index ffffc811d2..1b920255c3 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/InlineToStaticInline.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class InlineToStaticInline(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/IsOptionalDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/IsOptionalDef.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py index d289d2e002..1793ae95a3 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/IsOptionalDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class IsOptionalDef(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/IsPredicate.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/IsPredicate.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py index d2b3862d9f..8c71dbda10 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/IsPredicate.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class IsPredicate(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/IsRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py similarity index 89% rename from suite/auto-sync/Updater/CppTranslator/Patches/IsRegImm.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py index 49cc5cd9cf..0376dd6849 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/IsRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class IsOperandRegImm(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/LLVMFallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/LLVMFallThrough.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py index 7e7e3c6c20..2c45f4f41e 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/LLVMFallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class LLVMFallThrough(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/LLVMunreachable.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py similarity index 87% rename from suite/auto-sync/Updater/CppTranslator/Patches/LLVMunreachable.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py index f4f34816b5..4e07bd1c0c 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/LLVMunreachable.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class LLVMUnreachable(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/MethodToFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/MethodToFunctions.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py index 4f7fe98ff3..16822b671f 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/MethodToFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class MethodToFunction(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/MethodTypeQualifier.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py similarity index 89% rename from suite/auto-sync/Updater/CppTranslator/Patches/MethodTypeQualifier.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py index 7d08adca7e..056eb3de56 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/MethodTypeQualifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class MethodTypeQualifier(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/NamespaceAnon.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py similarity index 84% rename from suite/auto-sync/Updater/CppTranslator/Patches/NamespaceAnon.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py index 82b55575c3..a25c5cdb27 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/NamespaceAnon.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class NamespaceAnon(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/NamespaceArch.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py similarity index 91% rename from suite/auto-sync/Updater/CppTranslator/Patches/NamespaceArch.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py index 1d708a353d..84cd11e681 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/NamespaceArch.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, namespace_enum, namespace_fcn_def, namespace_struct -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, namespace_enum, namespace_fcn_def, namespace_struct +from autosync.cpptranslator.Patches.Patch import Patch class NamespaceArch(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/NamespaceLLVM.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py similarity index 86% rename from suite/auto-sync/Updater/CppTranslator/Patches/NamespaceLLVM.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py index 5f737cbb45..a8d5c4cb8d 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/NamespaceLLVM.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class NamespaceLLVM(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/OutStreamParam.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py similarity index 89% rename from suite/auto-sync/Updater/CppTranslator/Patches/OutStreamParam.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py index b85261c6aa..0ee9897451 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/OutStreamParam.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class OutStreamParam(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/Patch.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Patch.py similarity index 100% rename from suite/auto-sync/Updater/CppTranslator/Patches/Patch.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/Patch.py diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/PredicateBlockFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py similarity index 91% rename from suite/auto-sync/Updater/CppTranslator/Patches/PredicateBlockFunctions.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py index 57ae872652..b62cdbc9f5 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/PredicateBlockFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_MCInst_var_name -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.Patch import Patch class PredicateBlockFunctions(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/PrintAnnotation.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py similarity index 91% rename from suite/auto-sync/Updater/CppTranslator/Patches/PrintAnnotation.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py index f780754330..8195cc216b 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/PrintAnnotation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py @@ -1,5 +1,5 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class PrintAnnotation(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/PrintRegImmShift.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py similarity index 87% rename from suite/auto-sync/Updater/CppTranslator/Patches/PrintRegImmShift.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py index da0da5422f..b7594be55f 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/PrintRegImmShift.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_MCInst_var_name -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.Patch import Patch class PrintRegImmShift(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/QualifiedIdentifier.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/QualifiedIdentifier.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py index 1c56797663..7ca8dec07a 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/QualifiedIdentifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class QualifiedIdentifier(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/ReferencesDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py similarity index 85% rename from suite/auto-sync/Updater/CppTranslator/Patches/ReferencesDecl.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py index 1948514e0e..892499e41b 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/ReferencesDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class ReferencesDecl(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/RegClassContains.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py similarity index 89% rename from suite/auto-sync/Updater/CppTranslator/Patches/RegClassContains.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py index 34816528b2..98534b5f1b 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/RegClassContains.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_capture_node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node +from autosync.cpptranslator.Patches.Patch import Patch class RegClassContains(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/STIArgument.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py similarity index 87% rename from suite/auto-sync/Updater/CppTranslator/Patches/STIArgument.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py index fb8d6d6590..f756555019 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/STIArgument.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class STIArgument(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/STIFeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/STIFeatureBits.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py index 275a0d63e0..0980919a08 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/STIFeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class STIFeatureBits(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/STParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py similarity index 89% rename from suite/auto-sync/Updater/CppTranslator/Patches/STParameter.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py index d08e7c38d2..f53a4fc8e7 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/STParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class SubtargetInfoParam(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/SetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/SetOpcode.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py index 1c2e94db57..887ebb95dd 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/SetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class SetOpcode(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/SignExtend.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py similarity index 86% rename from suite/auto-sync/Updater/CppTranslator/Patches/SignExtend.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py index aac3b46eb6..79c929c4d5 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/SignExtend.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch -from CppTranslator.TemplateCollector import TemplateCollector +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.TemplateCollector import TemplateCollector class SignExtend(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/SizeAssignments.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py similarity index 86% rename from suite/auto-sync/Updater/CppTranslator/Patches/SizeAssignments.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py index 08a5119e61..ceac9ff1ac 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/SizeAssignments.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text, get_function_params_of_node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text, get_function_params_of_node +from autosync.cpptranslator.Patches.Patch import Patch class SizeAssignment(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/StreamOperation.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py similarity index 96% rename from suite/auto-sync/Updater/CppTranslator/Patches/StreamOperation.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py index 405fb6c6f2..55804a7b2d 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/StreamOperation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class StreamOperations(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/TemplateDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/TemplateDeclaration.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py index 9141c32780..1962ea364f 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/TemplateDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py @@ -1,9 +1,9 @@ import logging as log from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import parse_function_capture -from CppTranslator.Patches.Patch import Patch -from CppTranslator.TemplateCollector import TemplateCollector, TemplateRefInstance +from autosync.cpptranslator.Patches.HelperMethods import parse_function_capture +from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.TemplateCollector import TemplateCollector, TemplateRefInstance class TemplateDeclaration(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/TemplateDefinition.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py similarity index 91% rename from suite/auto-sync/Updater/CppTranslator/Patches/TemplateDefinition.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py index 2a7b6a79e6..9a5400787f 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/TemplateDefinition.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py @@ -3,9 +3,9 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import parse_function_capture -from CppTranslator.Patches.Patch import Patch -from CppTranslator.TemplateCollector import TemplateCollector, TemplateRefInstance +from autosync.cpptranslator.Patches.HelperMethods import parse_function_capture +from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.TemplateCollector import TemplateCollector, TemplateRefInstance class TemplateDefinition(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/TemplateParamDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py similarity index 91% rename from suite/auto-sync/Updater/CppTranslator/Patches/TemplateParamDecl.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py index 5a3b066a89..6031175599 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/TemplateParamDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch class TemplateParamDecl(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/TemplateRefs.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py similarity index 85% rename from suite/auto-sync/Updater/CppTranslator/Patches/TemplateRefs.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py index 12cc271bae..caf6b8aa30 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/TemplateRefs.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py @@ -1,8 +1,8 @@ from tree_sitter import Node -from CppTranslator.Patches.HelperMethods import get_text -from CppTranslator.Patches.Patch import Patch -from CppTranslator.TemplateCollector import TemplateCollector +from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.TemplateCollector import TemplateCollector class TemplateRefs(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/UseMarkup.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/UseMarkup.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py index 5dac967b11..7610c45453 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/UseMarkup.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py @@ -1,5 +1,5 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class UseMarkup(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/Patches/UsingDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py similarity index 90% rename from suite/auto-sync/Updater/CppTranslator/Patches/UsingDeclaration.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py index 705171a5c5..c150df1f24 100644 --- a/suite/auto-sync/Updater/CppTranslator/Patches/UsingDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from CppTranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.Patch import Patch class UsingDeclaration(Patch): diff --git a/suite/auto-sync/Updater/CppTranslator/README.md b/suite/auto-sync/src/autosync/cpptranslator/README.md similarity index 100% rename from suite/auto-sync/Updater/CppTranslator/README.md rename to suite/auto-sync/src/autosync/cpptranslator/README.md diff --git a/suite/auto-sync/Updater/CppTranslator/TemplateCollector.py b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py similarity index 99% rename from suite/auto-sync/Updater/CppTranslator/TemplateCollector.py rename to suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py index c5fe8e2ae7..dadc692d64 100644 --- a/suite/auto-sync/Updater/CppTranslator/TemplateCollector.py +++ b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py @@ -4,7 +4,7 @@ from tree_sitter import Language, Parser, Query, Node import logging as log -from CppTranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.HelperMethods import get_text class TemplateRefInstance: diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json new file mode 100644 index 0000000000..c5bc9e44f0 --- /dev/null +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json @@ -0,0 +1,18 @@ +{ + "General": { + "patch_persistence_file": "", + "translation_out_dir": "", + "diff_out_dir": "", + "diff_color_new": "green", + "diff_color_old": "light_blue", + "diff_color_saved": "yellow", + "diff_color_edited": "light_magenta", + "nodes_to_diff": [] + }, + "ARCH": { + "files_to_translate": [], + "files_for_template_search": [], + "templates_with_arg_deduction": [], + "manually_edited_files": [] + } +} diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py new file mode 100644 index 0000000000..28c08e36c0 --- /dev/null +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -0,0 +1,796 @@ +#!/usr/bin/env python3 +# SPDX-FileCopyrightText: 2024 Rot127 +# SPDX-License-Identifier: LGPL-3.0-only +import unittest +from pathlib import Path + +from tree_sitter import Query, Node + +import autosync.cpptranslator.Patches as Patches +from autosync.cpptranslator import CppTranslator + +from autosync.cpptranslator.Configurator import Configurator + + +class TestPatches(unittest.TestCase): + + @classmethod + def setUpClass(cls): + configurator = Configurator("ARCH", Path("test_config.json")) + cls.translator = CppTranslator.Translator(configurator) + cls.ts_cpp_lang = configurator.get_cpp_lang() + cls.parser = configurator.get_parser() + + def test_addcsdetail(self): + patch = Patches.AddCSDetail.AddCSDetail(0, "ARCH") + syntax = ( + b"void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O) { int i = OpNo; }" + ) + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_addoperand(self): + patch = Patches.AddOperand.AddOperand(0) + syntax = b"MI.addOperand(OPERAND)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_assert(self): + patch = Patches.Assert.Assert(0) + syntax = b"assert(0 == 0)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_bitcaststdarray(self): + patch = Patches.BitCastStdArray.BitCastStdArray(0) + syntax = b"auto S = bit_cast>(Imm);" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_checkdecoderstatus(self): + patch = Patches.CheckDecoderStatus.CheckDecoderStatus(0) + syntax = b"Check(S, functions())" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_classesdef(self): + patch = Patches.ClassesDef.ClassesDef(0) + syntax = b"Class definitions" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_constmcinstparameter(self): + patch = Patches.ConstMCInstParameter.ConstMCInstParameter(0) + syntax = b"const MCInst *MI" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_constmcoperand(self): + patch = Patches.ConstMCOperand.ConstMCOperand(0) + syntax = b"const MCOperand op" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_cppinitcast(self): + patch = Patches.CppInitCast.CppInitCast(0) + syntax = b"int(0x0000)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_createoperand0(self): + patch = Patches.CreateOperand0.CreateOperand0(0) + syntax = b"Inst.addOperand(MCOperand::createReg(REGISTER));" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_createoperand1(self): + patch = Patches.CreateOperand1.CreateOperand1(0) + syntax = b"MI.insert(0, MCOperand::createReg(REGISTER));" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_declarationinconditionclause(self): + patch = Patches.DeclarationInConditionClause.DeclarationInConditionalClause(0) + syntax = b"if (int i = 0) {}}" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_decodeinstruction(self): + patch = Patches.DecodeInstruction.DecodeInstruction(0) + syntax = b"decodeInstruction(MI, this, STI)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_decodercast(self): + patch = Patches.DecoderCast.DecoderCast(0) + syntax = ( + b"const MCDisassembler *Dis = static_cast(Decoder);" + ) + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_decoderparameter(self): + patch = Patches.DecoderParameter.DecoderParameter(0) + syntax = b"const MCDisassembler *Decoder" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_fallthrough(self): + patch = Patches.FallThrough.FallThrough(0) + syntax = b"[[fallthrough]]" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_featurebitsdecl(self): + patch = Patches.FeatureBitsDecl.FeatureBitsDecl(0) + syntax = b"featureBits = 0x00" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_featurebits(self): + patch = Patches.FeatureBits.FeatureBits(0, b"ARCH") + syntax = b"featureBits[FLAG]" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_fieldfrominstr(self): + patch = Patches.FieldFromInstr.FieldFromInstr(0) + syntax = b"fieldFromInstr(...)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_getnumoperands(self): + patch = Patches.GetNumOperands.GetNumOperands(0) + syntax = b"MI.getNumOperands()" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_getopcode(self): + patch = Patches.GetOpcode.GetOpcode(0) + syntax = b"Inst.getOpcode()" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_getoperand(self): + patch = Patches.GetOperand.GetOperand(0) + syntax = b"MI.getOperand(...)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_getoperandregimm(self): + patch = Patches.GetOperandRegImm.GetOperandRegImm(0) + syntax = b"OPERAND.getReg()" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_getregclass(self): + patch = Patches.GetRegClass.GetRegClass(0) + syntax = b"MRI.getRegClass(RegClass)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_getregfromclass(self): + patch = Patches.GetRegFromClass.GetRegFromClass(0) + syntax = b"ARCHMCRegisterClasses[ARCH::FPR128RegClassID].getRegister(RegNo);" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_getsubreg(self): + patch = Patches.GetSubReg.GetSubReg(0) + syntax = b"MRI.getSubReg(...);" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_includes(self): + patch = Patches.Includes.Includes(0, "ARCH") + syntax = b"#include some_llvm_header.h" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_inlinetostaticinline(self): + patch = Patches.InlineToStaticInline.InlineToStaticInline(0) + syntax = b"inline void FUNCTION(...) {...}" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_isoptionaldef(self): + patch = Patches.IsOptionalDef.IsOptionalDef(0) + syntax = b"OpInfo[i].isOptionalDef()" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_ispredicate(self): + patch = Patches.IsPredicate.IsPredicate(0) + syntax = b"OpInfo[i].isPredicate()" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_isregimm(self): + patch = Patches.IsRegImm.IsOperandRegImm(0) + syntax = b"OPERAND.isReg()" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_llvmfallthrough(self): + patch = Patches.LLVMFallThrough.LLVMFallThrough(0) + syntax = b"LLVM_FALLTHROUGH" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_llvmunreachable(self): + patch = Patches.LLVMunreachable.LLVMUnreachable(0) + syntax = b'llvm_unreachable("Error msg")' + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_methodtofunctions(self): + patch = Patches.MethodToFunctions.MethodToFunction(0) + syntax = b"void CLASS::METHOD_NAME(int a) {}" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_methodtypequalifier(self): + patch = Patches.MethodTypeQualifier.MethodTypeQualifier(0) + syntax = b"void a_const_method() const {}" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_namespaceanon(self): + patch = Patches.NamespaceAnon.NamespaceAnon(0) + syntax = b"namespace {CONTENT}" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_namespacearch(self): + patch = Patches.NamespaceArch.NamespaceArch(0) + syntax = b"namespace ArchSpecificNamespace {CONTENT}" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_namespacellvm(self): + patch = Patches.NamespaceLLVM.NamespaceLLVM(0) + syntax = b"namespace {CONTENT}" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_outstreamparam(self): + patch = Patches.OutStreamParam.OutStreamParam(0) + syntax = b"raw_ostream &OS" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_predicateblockfunctions(self): + patch = Patches.PredicateBlockFunctions.PredicateBlockFunctions(0) + syntax = b"VPTBlock.instrInVPTBlock()" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_printregimmshift(self): + patch = Patches.PrintRegImmShift.PrintRegImmShift(0) + syntax = b"printRegImmShift(...)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_qualifiedidentifier(self): + patch = Patches.QualifiedIdentifier.QualifiedIdentifier(0) + syntax = b"NAMESPACE::ID" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_referencesdecl(self): + patch = Patches.ReferencesDecl.ReferencesDecl(0) + syntax = b"TYPE &Param" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_regclasscontains(self): + patch = Patches.RegClassContains.RegClassContains(0) + syntax = b"...getRegClass(CLASS).contains(Reg)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_setopcode(self): + patch = Patches.SetOpcode.SetOpcode(0) + syntax = b"Inst.setOpcode(...)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_signextend(self): + patch = Patches.SignExtend.SignExtend(0) + syntax = b"SignExtend32(...)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_sizeassignments(self): + patch = Patches.SizeAssignments.SizeAssignment(0) + syntax = b"Size = " + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_stiargument(self): + patch = Patches.STIArgument.STIArgument(0) + syntax = b"printSomeOperand(MI, NUM, STI, NUM)" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_stifeaturebits(self): + patch = Patches.STIFeatureBits.STIFeatureBits(0, b"ARCH") + syntax = b"STI.getFeatureBits()[FLAG]" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_streamoperation(self): + patch = Patches.STParameter.SubtargetInfoParam(0) + syntax = b"OS << ..." + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_templatedeclaration(self): + patch = Patches.StreamOperation.StreamOperations(0) + syntax = b"template void func();" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_templatedefinition(self): + patch = Patches.TemplateDeclaration.TemplateDeclaration(0) + syntax = b"template void func() {}" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_templateparamdecl(self): + patch = Patches.TemplateDefinition.TemplateDefinition(0) + syntax = b"ArrayRef x;" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_templaterefs(self): + patch = Patches.TemplateParamDecl.TemplateParamDecl(0) + syntax = b"TemplateFunction" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + + def test_usemarkup(self): + patch = Patches.TemplateRefs.TemplateRefs(0) + syntax = b"UseMarkup()" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + for cb in captures_bundle: + assert patch.get_patch(cb, syntax, **kwargs) == b"" diff --git a/suite/auto-sync/Updater/CppTranslator/arch_config.json b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json similarity index 100% rename from suite/auto-sync/Updater/CppTranslator/arch_config.json rename to suite/auto-sync/src/autosync/cpptranslator/arch_config.json diff --git a/suite/auto-sync/Updater/CppTranslator/saved_patches.json b/suite/auto-sync/src/autosync/cpptranslator/saved_patches.json similarity index 100% rename from suite/auto-sync/Updater/CppTranslator/saved_patches.json rename to suite/auto-sync/src/autosync/cpptranslator/saved_patches.json diff --git a/suite/auto-sync/Updater/path_vars.json b/suite/auto-sync/src/autosync/path_vars.json similarity index 85% rename from suite/auto-sync/Updater/path_vars.json rename to suite/auto-sync/src/autosync/path_vars.json index a7ad7f81aa..baaf45537b 100644 --- a/suite/auto-sync/Updater/path_vars.json +++ b/suite/auto-sync/src/autosync/path_vars.json @@ -5,9 +5,8 @@ "{LLVM_INCLUDE_DIR}": "{AUTO_SYNC_ROOT}/llvm-capstone/llvm/include", "{VENDOR_DIR}": "{AUTO_SYNC_ROOT}/vendor/", - "{AUTO_SYNC_UPDATER_DIR}": "{AUTO_SYNC_ROOT}/Updater/", - "{CPP_TRANSLATOR_DIR}": "{AUTO_SYNC_ROOT}/Updater/CppTranslator/", + "{CPP_TRANSLATOR_DIR}": "{AUTO_SYNC_SRC}/cpptranslator/", "{CPP_TRANSLATOR_CONFIG}": "{CPP_TRANSLATOR_DIR}/arch_config.json", "{INC_PATCH_DIR}": "{AUTO_SYNC_ROOT}/inc_patches/", From 6db4e94974d708f679f30884a7472935fee15c65 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 04:38:59 -0500 Subject: [PATCH 04/41] Add formatting check to CI --- .github/workflows/auto-sync.yml | 16 ++++++++++++++++ suite/auto-sync/pyproject.toml | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 .github/workflows/auto-sync.yml diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml new file mode 100644 index 0000000000..8bd57dc43f --- /dev/null +++ b/.github/workflows/auto-sync.yml @@ -0,0 +1,16 @@ +name: Auto-Sync +on: + push: + paths: + - "suite/auto-sync/**" + pull_request: + +jobs: + check: + runs-on: ubuntu-latest + steps: + - name: Check formatting + uses: omnilib/ufmt@action-v1 + with: + path: "suite/auto-sync/src/**" + python-version: "3.x" diff --git a/suite/auto-sync/pyproject.toml b/suite/auto-sync/pyproject.toml index c17eac8de2..be210a7243 100644 --- a/suite/auto-sync/pyproject.toml +++ b/suite/auto-sync/pyproject.toml @@ -4,6 +4,9 @@ version = "0.1.0" dependencies = [ "termcolor >= 2.3.0", "tree_sitter < 0.22.0", + "black == 22.6.0", + "ufmt == 2.0.0", + "usort == 1.0.4", ] requires-python = ">= 3.11" From 40a060a1a978bf670f6b77df6fcd39129841937f Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 04:55:58 -0500 Subject: [PATCH 05/41] Run ufmt --- .gitignore | 3 + suite/auto-sync/.gitignore | 3 +- suite/auto-sync/src/autosync/ASUpdater.py | 38 +++- suite/auto-sync/src/autosync/HeaderPatcher.py | 8 +- suite/auto-sync/src/autosync/Helper.py | 11 +- suite/auto-sync/src/autosync/IncGenerator.py | 21 +- .../auto-sync/src/autosync/PathVarHandler.py | 10 +- .../autosync/cpptranslator/Configurator.py | 13 +- .../autosync/cpptranslator/CppTranslator.py | 92 ++++++--- .../src/autosync/cpptranslator/Differ.py | 188 ++++++++++++++---- .../cpptranslator/Patches/AddCSDetail.py | 44 +++- .../cpptranslator/Patches/AddOperand.py | 3 +- .../autosync/cpptranslator/Patches/Assert.py | 2 +- .../cpptranslator/Patches/BitCastStdArray.py | 37 +++- .../Patches/CheckDecoderStatus.py | 3 +- .../Patches/ClassConstructorDef.py | 2 +- .../cpptranslator/Patches/ClassesDef.py | 8 +- .../Patches/ConstMCInstParameter.py | 3 +- .../cpptranslator/Patches/ConstMCOperand.py | 3 +- .../cpptranslator/Patches/CppInitCast.py | 10 +- .../cpptranslator/Patches/CreateOperand0.py | 10 +- .../cpptranslator/Patches/CreateOperand1.py | 12 +- .../Patches/DeclarationInConditionClause.py | 5 +- .../Patches/DecodeInstruction.py | 11 +- .../cpptranslator/Patches/DecoderCast.py | 3 +- .../cpptranslator/Patches/DecoderParameter.py | 3 +- .../cpptranslator/Patches/FallThrough.py | 2 +- .../cpptranslator/Patches/FeatureBits.py | 13 +- .../cpptranslator/Patches/FeatureBitsDecl.py | 3 +- .../cpptranslator/Patches/FieldFromInstr.py | 13 +- .../cpptranslator/Patches/GetNumOperands.py | 3 +- .../cpptranslator/Patches/GetOpcode.py | 3 +- .../cpptranslator/Patches/GetOperand.py | 3 +- .../cpptranslator/Patches/GetOperandRegImm.py | 5 +- .../cpptranslator/Patches/GetRegClass.py | 13 +- .../cpptranslator/Patches/GetRegFromClass.py | 5 +- .../cpptranslator/Patches/GetSubReg.py | 9 +- .../cpptranslator/Patches/HelperMethods.py | 27 ++- .../cpptranslator/Patches/Includes.py | 18 +- .../Patches/InlineToStaticInline.py | 8 +- .../cpptranslator/Patches/IsOptionalDef.py | 3 +- .../cpptranslator/Patches/IsPredicate.py | 3 +- .../cpptranslator/Patches/IsRegImm.py | 3 +- .../cpptranslator/Patches/LLVMFallThrough.py | 9 +- .../cpptranslator/Patches/LLVMunreachable.py | 3 +- .../Patches/MethodToFunctions.py | 7 +- .../Patches/MethodTypeQualifier.py | 3 +- .../cpptranslator/Patches/NamespaceAnon.py | 9 +- .../cpptranslator/Patches/NamespaceArch.py | 23 ++- .../cpptranslator/Patches/NamespaceLLVM.py | 3 +- .../cpptranslator/Patches/OutStreamParam.py | 3 +- .../autosync/cpptranslator/Patches/Patch.py | 3 +- .../Patches/PredicateBlockFunctions.py | 5 +- .../cpptranslator/Patches/PrintAnnotation.py | 2 +- .../cpptranslator/Patches/PrintRegImmShift.py | 5 +- .../Patches/QualifiedIdentifier.py | 3 +- .../cpptranslator/Patches/ReferencesDecl.py | 11 +- .../cpptranslator/Patches/RegClassContains.py | 9 +- .../cpptranslator/Patches/STIArgument.py | 3 +- .../cpptranslator/Patches/STIFeatureBits.py | 3 +- .../cpptranslator/Patches/STParameter.py | 3 +- .../cpptranslator/Patches/SetOpcode.py | 3 +- .../cpptranslator/Patches/SignExtend.py | 2 +- .../cpptranslator/Patches/SizeAssignments.py | 15 +- .../cpptranslator/Patches/StreamOperation.py | 30 ++- .../Patches/TemplateDeclaration.py | 32 ++- .../Patches/TemplateDefinition.py | 32 ++- .../Patches/TemplateParamDecl.py | 4 +- .../cpptranslator/Patches/TemplateRefs.py | 3 +- .../cpptranslator/Patches/UseMarkup.py | 2 +- .../cpptranslator/Patches/UsingDeclaration.py | 3 +- .../cpptranslator/TemplateCollector.py | 78 ++++++-- .../cpptranslator/Tests/test_patches.py | 9 +- 73 files changed, 700 insertions(+), 300 deletions(-) diff --git a/.gitignore b/.gitignore index 2ffc794f2b..be66ce7bfb 100644 --- a/.gitignore +++ b/.gitignore @@ -141,3 +141,6 @@ android-ndk-* # python virtual env .venv/ + +# Auto-sync files +suite/auto-sync/src/autosync.egg-info diff --git a/suite/auto-sync/.gitignore b/suite/auto-sync/.gitignore index c0de2866fa..ac78135860 100644 --- a/suite/auto-sync/.gitignore +++ b/suite/auto-sync/.gitignore @@ -1,5 +1,6 @@ build/ vendor/llvm_root */.idea -Updater/config.json +src/auto-sync/config.json +src/autosync.egg-info diff --git a/suite/auto-sync/src/autosync/ASUpdater.py b/suite/auto-sync/src/autosync/ASUpdater.py index 8ed8df3295..5246819f45 100755 --- a/suite/auto-sync/src/autosync/ASUpdater.py +++ b/suite/auto-sync/src/autosync/ASUpdater.py @@ -1,18 +1,18 @@ #!/usr/bin/env python3 import argparse + +import logging as log import os import shutil import subprocess import sys - -import logging as log from enum import StrEnum +from pathlib import Path from autosync.cpptranslator.CppTranslator import Translator -from autosync.Helper import get_path, convert_loglevel, check_py_version, fail_exit from autosync.HeaderPatcher import HeaderPatcher -from pathlib import Path +from autosync.Helper import check_py_version, convert_loglevel, fail_exit, get_path from autosync.IncGenerator import IncGenerator @@ -108,7 +108,9 @@ def check_tree_sitter(self) -> None: ts_dir = get_path("{VENDOR_DIR}").joinpath("tree-sitter-cpp") if not ts_dir.exists(): log.info("tree-sitter was not fetched. Cloning it now...") - subprocess.run(["git", "submodule", "update", "--init", "--recursive"], check=True) + subprocess.run( + ["git", "submodule", "update", "--init", "--recursive"], check=True + ) def translate(self) -> None: self.check_tree_sitter() @@ -151,11 +153,23 @@ def parse_args() -> argparse.Namespace: description="Capstones architecture module updater.", ) parser.add_argument( - "-a", dest="arch", help="Name of target architecture.", choices=["ARM", "PPC", "AArch64", "Alpha"], required=True + "-a", + dest="arch", + help="Name of target architecture.", + choices=["ARM", "PPC", "AArch64", "Alpha"], + required=True, ) - parser.add_argument("-d", dest="no_clean", help="Don't clean build dir before updating.", action="store_true") parser.add_argument( - "-w", dest="write", help="Write generated/translated files to arch//", action="store_true" + "-d", + dest="no_clean", + help="Don't clean build dir before updating.", + action="store_true", + ) + parser.add_argument( + "-w", + dest="write", + help="Write generated/translated files to arch//", + action="store_true", ) parser.add_argument( "-v", @@ -223,6 +237,12 @@ def parse_args() -> argparse.Namespace: ) Updater = ASUpdater( - args.arch, args.write, args.steps, args.inc_list, args.no_clean, args.refactor, args.no_auto_apply + args.arch, + args.write, + args.steps, + args.inc_list, + args.no_clean, + args.refactor, + args.no_auto_apply, ) Updater.update() diff --git a/suite/auto-sync/src/autosync/HeaderPatcher.py b/suite/auto-sync/src/autosync/HeaderPatcher.py index 1243c90a0d..ab41d392bc 100755 --- a/suite/auto-sync/src/autosync/HeaderPatcher.py +++ b/suite/auto-sync/src/autosync/HeaderPatcher.py @@ -12,8 +12,12 @@ def parse_args() -> argparse.Namespace: prog="PatchHeaders", description="Patches generated enums into the main arch header file.", ) - parser.add_argument("--header", dest="header", help="Path header file.", type=Path, required=True) - parser.add_argument("--inc", dest="inc", help="Path inc file.", type=Path, required=True) + parser.add_argument( + "--header", dest="header", help="Path header file.", type=Path, required=True + ) + parser.add_argument( + "--inc", dest="inc", help="Path inc file.", type=Path, required=True + ) arguments = parser.parse_args() return arguments diff --git a/suite/auto-sync/src/autosync/Helper.py b/suite/auto-sync/src/autosync/Helper.py index 9391b0f45d..2d5626a2e4 100644 --- a/suite/auto-sync/src/autosync/Helper.py +++ b/suite/auto-sync/src/autosync/Helper.py @@ -6,9 +6,9 @@ from pathlib import Path import termcolor +from tree_sitter import Node from autosync.PathVarHandler import PathVarHandler -from tree_sitter import Node def convert_loglevel(level: str) -> int: @@ -140,7 +140,14 @@ def get_header() -> str: def run_clang_format(out_paths: list[Path]): for out_file in out_paths: log.info(f"Format {out_file}") - subprocess.run(["clang-format-18", f"-style=file:{get_path('{CS_CLANG_FORMAT_FILE}')}", "-i", out_file]) + subprocess.run( + [ + "clang-format-18", + f"-style=file:{get_path('{CS_CLANG_FORMAT_FILE}')}", + "-i", + out_file, + ] + ) def get_path(config_path: str) -> Path: diff --git a/suite/auto-sync/src/autosync/IncGenerator.py b/suite/auto-sync/src/autosync/IncGenerator.py index 129a52318f..5ab79c3a92 100644 --- a/suite/auto-sync/src/autosync/IncGenerator.py +++ b/suite/auto-sync/src/autosync/IncGenerator.py @@ -1,14 +1,13 @@ #!/usr/bin/env python3 +import logging as log import os import re import shutil import subprocess - -import logging as log +from pathlib import Path from autosync.Helper import fail_exit, get_path -from pathlib import Path inc_tables = [ { @@ -71,7 +70,9 @@ def __init__(self, arch: str, inc_list: list) -> None: self.patches_dir_path: Path = get_path("{INC_PATCH_DIR}") self.llvm_include_dir: Path = get_path("{LLVM_INCLUDE_DIR}") self.output_dir: Path = get_path("{BUILD_DIR}") - self.llvm_target_dir: Path = get_path("{LLVM_TARGET_DIR}").joinpath(f"{self.arch_dir_name}") + self.llvm_target_dir: Path = get_path("{LLVM_TARGET_DIR}").joinpath( + f"{self.arch_dir_name}" + ) self.llvm_tblgen: Path = get_path("{LLVM_TBLGEN_BIN}") self.output_dir_c_inc = get_path("{C_INC_OUT_DIR}") self.output_dir_cpp_inc = get_path("{CPP_INC_OUT_DIR}") @@ -110,12 +111,18 @@ def move_mapping_files(self) -> None: if self.arch == "AArch64": # We have to rename the file SystemRegister -> SystemOperands - sys_ops_table_file = self.output_dir_c_inc.joinpath("AArch64GenSystemRegister.inc") - new_sys_ops_file = self.output_dir_c_inc.joinpath("AArch64GenSystemOperands.inc") + sys_ops_table_file = self.output_dir_c_inc.joinpath( + "AArch64GenSystemRegister.inc" + ) + new_sys_ops_file = self.output_dir_c_inc.joinpath( + "AArch64GenSystemOperands.inc" + ) if "SystemOperand" not in self.inc_list: return elif not sys_ops_table_file.exists(): - fail_exit(f"{sys_ops_table_file} does not exist. But it should have been generated.") + fail_exit( + f"{sys_ops_table_file} does not exist. But it should have been generated." + ) shutil.move(sys_ops_table_file, new_sys_ops_file) def gen_incs(self) -> None: diff --git a/suite/auto-sync/src/autosync/PathVarHandler.py b/suite/auto-sync/src/autosync/PathVarHandler.py index e7bc5582c6..a4fd30ccc8 100644 --- a/suite/auto-sync/src/autosync/PathVarHandler.py +++ b/suite/auto-sync/src/autosync/PathVarHandler.py @@ -20,7 +20,11 @@ class PathVarHandler(metaclass=Singleton): def __init__(self) -> None: try: - res = subprocess.run(["git", "rev-parse", "--show-toplevel"], check=True, stdout=subprocess.PIPE) + res = subprocess.run( + ["git", "rev-parse", "--show-toplevel"], + check=True, + stdout=subprocess.PIPE, + ) except subprocess.CalledProcessError: log.fatal("Could not get repository top level directory.") exit(1) @@ -28,7 +32,9 @@ def __init__(self) -> None: # The main directories self.paths["{CS_ROOT}"] = Path(repo_root) self.paths["{AUTO_SYNC_ROOT}"] = Path(repo_root).joinpath("suite/auto-sync/") - self.paths["{AUTO_SYNC_SRC}"] = self.paths["{AUTO_SYNC_ROOT}"].joinpath("src/autosync/") + self.paths["{AUTO_SYNC_SRC}"] = self.paths["{AUTO_SYNC_ROOT}"].joinpath( + "src/autosync/" + ) path_config_file = self.paths["{AUTO_SYNC_SRC}"].joinpath("path_vars.json") # Load variables diff --git a/suite/auto-sync/src/autosync/cpptranslator/Configurator.py b/suite/auto-sync/src/autosync/cpptranslator/Configurator.py index 281e02a8a9..e740c00435 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Configurator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Configurator.py @@ -1,9 +1,10 @@ import json +import logging as log from pathlib import Path -from autosync.Helper import get_path, fail_exit from tree_sitter import Language, Parser -import logging as log + +from autosync.Helper import fail_exit, get_path class Configurator: @@ -60,7 +61,9 @@ def load_config(self) -> None: with open(self.config_path) as f: conf = json.loads(f.read()) if self.arch not in conf: - fail_exit(f"{self.arch} has no configuration. Please add them in {self.config_path}!") + fail_exit( + f"{self.arch} has no configuration. Please add them in {self.config_path}!" + ) self.config = conf def ts_compile_cpp(self) -> None: @@ -75,7 +78,9 @@ def ts_compile_cpp(self) -> None: def ts_set_cpp_language(self) -> None: log.info(f"Load language '{self.ts_shared_object}'") if not Path.exists(self.ts_shared_object): - fail_exit(f"Could not load the tree-sitter language shared object at '{self.ts_shared_object}'") + fail_exit( + f"Could not load the tree-sitter language shared object at '{self.ts_shared_object}'" + ) self.ts_cpp_lang = Language(str(self.ts_shared_object), "cpp") def init_parser(self) -> None: diff --git a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py index b7780bad50..6e1656c6f0 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py @@ -1,15 +1,13 @@ #!/usr/bin/env python3 -from pathlib import Path - -import termcolor -from tree_sitter import Language, Parser, Tree, Node, Query import argparse import logging as log import sys +from pathlib import Path + +import termcolor +from tree_sitter import Language, Node, Parser, Query, Tree from autosync.cpptranslator.Configurator import Configurator -from autosync.Helper import convert_loglevel, print_prominent_warning, get_header, run_clang_format, get_path -from autosync.cpptranslator.Patches.GetRegFromClass import GetRegFromClass from autosync.cpptranslator.Patches.AddCSDetail import AddCSDetail from autosync.cpptranslator.Patches.AddOperand import AddOperand from autosync.cpptranslator.Patches.Assert import Assert @@ -22,7 +20,9 @@ from autosync.cpptranslator.Patches.CppInitCast import CppInitCast from autosync.cpptranslator.Patches.CreateOperand0 import CreateOperand0 from autosync.cpptranslator.Patches.CreateOperand1 import CreateOperand1 -from autosync.cpptranslator.Patches.DeclarationInConditionClause import DeclarationInConditionalClause +from autosync.cpptranslator.Patches.DeclarationInConditionClause import ( + DeclarationInConditionalClause, +) from autosync.cpptranslator.Patches.DecodeInstruction import DecodeInstruction from autosync.cpptranslator.Patches.DecoderCast import DecoderCast from autosync.cpptranslator.Patches.DecoderParameter import DecoderParameter @@ -32,36 +32,39 @@ from autosync.cpptranslator.Patches.FieldFromInstr import FieldFromInstr from autosync.cpptranslator.Patches.GetNumOperands import GetNumOperands from autosync.cpptranslator.Patches.GetOpcode import GetOpcode -from autosync.cpptranslator.Patches.GetOperandRegImm import GetOperandRegImm from autosync.cpptranslator.Patches.GetOperand import GetOperand +from autosync.cpptranslator.Patches.GetOperandRegImm import GetOperandRegImm from autosync.cpptranslator.Patches.GetRegClass import GetRegClass +from autosync.cpptranslator.Patches.GetRegFromClass import GetRegFromClass from autosync.cpptranslator.Patches.GetSubReg import GetSubReg from autosync.cpptranslator.Patches.Includes import Includes from autosync.cpptranslator.Patches.InlineToStaticInline import InlineToStaticInline -from autosync.cpptranslator.Patches.IsRegImm import IsOperandRegImm from autosync.cpptranslator.Patches.IsOptionalDef import IsOptionalDef from autosync.cpptranslator.Patches.IsPredicate import IsPredicate +from autosync.cpptranslator.Patches.IsRegImm import IsOperandRegImm from autosync.cpptranslator.Patches.LLVMFallThrough import LLVMFallThrough from autosync.cpptranslator.Patches.LLVMunreachable import LLVMUnreachable from autosync.cpptranslator.Patches.MethodToFunctions import MethodToFunction from autosync.cpptranslator.Patches.MethodTypeQualifier import MethodTypeQualifier -from autosync.cpptranslator.Patches.NamespaceLLVM import NamespaceLLVM from autosync.cpptranslator.Patches.NamespaceAnon import NamespaceAnon from autosync.cpptranslator.Patches.NamespaceArch import NamespaceArch +from autosync.cpptranslator.Patches.NamespaceLLVM import NamespaceLLVM from autosync.cpptranslator.Patches.OutStreamParam import OutStreamParam -from autosync.cpptranslator.Patches.PredicateBlockFunctions import PredicateBlockFunctions +from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.Patches.PredicateBlockFunctions import ( + PredicateBlockFunctions, +) from autosync.cpptranslator.Patches.PrintAnnotation import PrintAnnotation from autosync.cpptranslator.Patches.PrintRegImmShift import PrintRegImmShift from autosync.cpptranslator.Patches.QualifiedIdentifier import QualifiedIdentifier -from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.Patches.ReferencesDecl import ReferencesDecl from autosync.cpptranslator.Patches.RegClassContains import RegClassContains -from autosync.cpptranslator.Patches.STIArgument import STIArgument -from autosync.cpptranslator.Patches.STIFeatureBits import STIFeatureBits -from autosync.cpptranslator.Patches.STParameter import SubtargetInfoParam from autosync.cpptranslator.Patches.SetOpcode import SetOpcode from autosync.cpptranslator.Patches.SignExtend import SignExtend from autosync.cpptranslator.Patches.SizeAssignments import SizeAssignment +from autosync.cpptranslator.Patches.STIArgument import STIArgument +from autosync.cpptranslator.Patches.STIFeatureBits import STIFeatureBits +from autosync.cpptranslator.Patches.STParameter import SubtargetInfoParam from autosync.cpptranslator.Patches.StreamOperation import StreamOperations from autosync.cpptranslator.Patches.TemplateDeclaration import TemplateDeclaration from autosync.cpptranslator.Patches.TemplateDefinition import TemplateDefinition @@ -70,6 +73,13 @@ from autosync.cpptranslator.Patches.UseMarkup import UseMarkup from autosync.cpptranslator.Patches.UsingDeclaration import UsingDeclaration from autosync.cpptranslator.TemplateCollector import TemplateCollector +from autosync.Helper import ( + convert_loglevel, + get_header, + get_path, + print_prominent_warning, + run_clang_format, +) class Translator: @@ -168,9 +178,13 @@ def __init__(self, configure: Configurator): self.ts_cpp_lang = self.configurator.get_cpp_lang() self.parser = self.configurator.get_parser() - self.src_paths: [Path] = [get_path(sp["in"]) for sp in self.conf["files_to_translate"]] + self.src_paths: [Path] = [ + get_path(sp["in"]) for sp in self.conf["files_to_translate"] + ] t_out_dir: Path = get_path(self.conf_general["translation_out_dir"]) - self.out_paths: [Path] = [t_out_dir.joinpath(sp["out"]) for sp in self.conf["files_to_translate"]] + self.out_paths: [Path] = [ + t_out_dir.joinpath(sp["out"]) for sp in self.conf["files_to_translate"] + ] self.collect_template_instances() self.init_patches() @@ -186,7 +200,9 @@ def read_src_file(self, src_path: Path) -> None: def init_patches(self): log.debug("Init patches") - priorities = dict(sorted(self.patch_priorities.items(), key=lambda item: item[1])) + priorities = dict( + sorted(self.patch_priorities.items(), key=lambda item: item[1]) + ) for ptype, p in priorities.items(): match ptype: case RegClassContains.__name__: @@ -349,8 +365,13 @@ def patch_src(self, p_list: [(bytes, Node)]) -> None: def apply_patch(self, patch: Patch) -> bool: """Tests if the given patch should be applied for the current architecture or file.""" - has_apply_only = len(patch.apply_only_to["files"]) > 0 or len(patch.apply_only_to["archs"]) > 0 - has_do_not_apply = len(patch.do_not_apply["files"]) > 0 or len(patch.do_not_apply["archs"]) > 0 + has_apply_only = ( + len(patch.apply_only_to["files"]) > 0 + or len(patch.apply_only_to["archs"]) > 0 + ) + has_do_not_apply = ( + len(patch.do_not_apply["files"]) > 0 or len(patch.do_not_apply["archs"]) > 0 + ) if not (has_apply_only or has_do_not_apply): # Lists empty. @@ -372,7 +393,9 @@ def apply_patch(self, patch: Patch) -> bool: exit(1) def translate(self) -> None: - for self.current_src_path_in, self.current_src_path_out in zip(self.src_paths, self.out_paths): + for self.current_src_path_in, self.current_src_path_out in zip( + self.src_paths, self.out_paths + ): log.info(f"Translate '{self.current_src_path_in}'") self.parse(self.current_src_path_in) patch: Patch @@ -396,7 +419,9 @@ def translate(self) -> None: # Add it to the bundle. captures_bundle[-1].append(q) - log.debug(f"Patch {patch.__class__.__name__} (to patch: {len(captures_bundle)}).") + log.debug( + f"Patch {patch.__class__.__name__} (to patch: {len(captures_bundle)})." + ) p_list: (bytes, Node) = list() cb: [(Node, str)] @@ -418,8 +443,12 @@ def translate(self) -> None: def collect_template_instances(self): search_paths = [get_path(p) for p in self.conf["files_for_template_search"]] - temp_arg_deduction = [p.encode("utf8") for p in self.conf["templates_with_arg_deduction"]] - self.template_collector = TemplateCollector(self.parser, self.ts_cpp_lang, search_paths, temp_arg_deduction) + temp_arg_deduction = [ + p.encode("utf8") for p in self.conf["templates_with_arg_deduction"] + ] + self.template_collector = TemplateCollector( + self.parser, self.ts_cpp_lang, search_paths, temp_arg_deduction + ) self.template_collector.collect() def get_patch_kwargs(self, patch): @@ -433,7 +462,8 @@ def remark_manual_files(self) -> None: if len(manual_edited) > 0: msg += ( termcolor.colored( - "The following files are too complex to translate! Please check them by hand.", attrs=["bold"] + "The following files are too complex to translate! Please check them by hand.", + attrs=["bold"], ) + "\n" ) @@ -450,7 +480,11 @@ def parse_args() -> argparse.Namespace: description="Capstones C++ to C translator for LLVM source files", ) parser.add_argument( - "-a", dest="arch", help="Name of target architecture.", choices=["ARM", "PPC", "AArch64", "Alpha"], required=True + "-a", + dest="arch", + help="Name of target architecture.", + choices=["ARM", "PPC", "AArch64", "Alpha"], + required=True, ) parser.add_argument( "-v", @@ -460,7 +494,11 @@ def parse_args() -> argparse.Namespace: default="info", ) parser.add_argument( - "-c", dest="config_path", help="Config file for architectures.", default="arch_config.json", type=Path + "-c", + dest="config_path", + help="Config file for architectures.", + default="arch_config.json", + type=Path, ) arguments = parser.parse_args() return arguments diff --git a/suite/auto-sync/src/autosync/cpptranslator/Differ.py b/suite/auto-sync/src/autosync/cpptranslator/Differ.py index c1aba32a89..75a1c7851e 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/Differ.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Differ.py @@ -1,29 +1,29 @@ #!/usr/bin/env python3 +import argparse +import difflib as dl import json +import logging as log +import sys from enum import StrEnum from pathlib import Path +from shutil import copy2 from typing import Iterator -from tree_sitter import Language, Parser, Tree, Node -from shutil import copy2 -import argparse -import difflib as dl -import logging as log -import sys +from tree_sitter import Language, Node, Parser, Tree from autosync.cpptranslator.Configurator import Configurator from autosync.Helper import ( + bold, + colored, convert_loglevel, find_id_by_type, + get_path, + get_sha256, print_prominent_info, - bold, - colored, - separator_line_1, - separator_line_2, print_prominent_warning, - get_sha256, run_clang_format, - get_path, + separator_line_1, + separator_line_2, ) @@ -35,7 +35,13 @@ class PatchCoord: start_point: tuple[int, int] end_point: tuple[int, int] - def __init__(self, start_byte: int, end_byte: int, start_point: tuple[int, int], end_point: tuple[int, int]): + def __init__( + self, + start_byte: int, + end_byte: int, + start_point: tuple[int, int], + end_point: tuple[int, int], + ): self.start_byte = start_byte self.end_byte = end_byte self.start_point = start_point @@ -58,7 +64,9 @@ def __str__(self) -> str: @staticmethod def get_coordinates_from_node(node: Node): - return PatchCoord(node.start_byte, node.end_byte, node.start_point, node.end_point) + return PatchCoord( + node.start_byte, node.end_byte, node.start_point, node.end_point + ) class ApplyType(StrEnum): @@ -81,7 +89,13 @@ class Patch: new_hash: str def __init__( - self, node_id: str, old: bytes, new: bytes, coord: PatchCoord, apply: ApplyType, edit: bytes = None + self, + node_id: str, + old: bytes, + new: bytes, + coord: PatchCoord, + apply: ApplyType, + edit: bytes = None, ) -> None: if apply == ApplyType.SAVED: raise NotImplementedError("Not yet implemented.") @@ -163,16 +177,23 @@ def __init__(self, configurator: Configurator, no_auto_apply: bool): self.differ = dl.Differ() t_out_dir: Path = get_path(self.conf_general["translation_out_dir"]) - self.translated_files = [t_out_dir.joinpath(sp["out"]) for sp in self.conf_arch["files_to_translate"]] + self.translated_files = [ + t_out_dir.joinpath(sp["out"]) for sp in self.conf_arch["files_to_translate"] + ] cs_arch_src: Path = get_path("{CS_ARCH_MODULE_DIR}") - cs_arch_src = cs_arch_src.joinpath(self.arch if self.arch != "PPC" else "PowerPC") + cs_arch_src = cs_arch_src.joinpath( + self.arch if self.arch != "PPC" else "PowerPC" + ) self.old_files = [ - cs_arch_src.joinpath(f"{cs_arch_src}/" + sp["out"]) for sp in self.conf_arch["files_to_translate"] + cs_arch_src.joinpath(f"{cs_arch_src}/" + sp["out"]) + for sp in self.conf_arch["files_to_translate"] ] self.load_persistence_file() def load_persistence_file(self) -> None: - self.persistence_filepath = get_path(self.conf_general["patch_persistence_file"]) + self.persistence_filepath = get_path( + self.conf_general["patch_persistence_file"] + ) if not self.persistence_filepath.exists(): self.saved_patches = dict() return @@ -181,7 +202,9 @@ def load_persistence_file(self) -> None: try: self.saved_patches = json.load(f) except json.decoder.JSONDecodeError as e: - log.fatal(f"Persistence file {bold(self.persistence_filepath.name)} corrupt.") + log.fatal( + f"Persistence file {bold(self.persistence_filepath.name)} corrupt." + ) log.fatal("Delete it or fix it by hand.") log.fatal(f"JSON Exception: {e}") exit(1) @@ -208,7 +231,12 @@ def copy_files(self) -> None: self.diff_dest_files.append(dest) def get_diff_intro_msg( - self, old_filename: Path, new_filename: Path, current: int, total: int, num_diffs: int + self, + old_filename: Path, + new_filename: Path, + current: int, + total: int, + num_diffs: int, ) -> str: color_new = self.conf_general["diff_color_new"] color_old = self.conf_general["diff_color_old"] @@ -229,7 +257,9 @@ def get_diff_node_id(self, node: Node) -> bytes: if n["node_type"] == node.type: id_types = n["identifier_node_type"] if not id_types: - log.fatal(f"Diffing: Node of type {node.type} has not identifier type specified.") + log.fatal( + f"Diffing: Node of type {node.type} has not identifier type specified." + ) exit(1) identifier = "" for id_type in id_types: @@ -251,7 +281,9 @@ def parse_file(self, file: Path) -> dict: tree: Tree = self.parser.parse(content, keep_text=True) - node_types_to_diff = [n["node_type"] for n in self.conf_general["nodes_to_diff"]] + node_types_to_diff = [ + n["node_type"] for n in self.conf_general["nodes_to_diff"] + ] content = None if file.suffix == ".h": # Header file. Get the content in between the include guard @@ -287,7 +319,9 @@ def print_diff(self, diff_lines: list[str], node_id: str, current: int, total: i print(f"{bold('Patch:')} {current}/{total}\n") print(f"{bold('Node:')} {node_id}") print(f"{bold('Color:')} {colored('NEW FILE - (Just translated)', new_color)}") - print(f"{bold('Color:')} {colored('OLD FILE - (Currently in Capstone)', old_color)}\n") + print( + f"{bold('Color:')} {colored('OLD FILE - (Currently in Capstone)', old_color)}\n" + ) print(separator_line_1()) for line in diff_lines: if line[0] == "+": @@ -307,7 +341,9 @@ def no_difference(diff_lines: Iterator[str]) -> bool: return False return True - def print_prompt(self, saved_diff_present: bool = False, saved_choice: ApplyType = None) -> str: + def print_prompt( + self, saved_diff_present: bool = False, saved_choice: ApplyType = None + ) -> str: new_color = self.conf_general["diff_color_new"] old_color = self.conf_general["diff_color_old"] edited_color = self.conf_general["diff_color_edited"] @@ -319,11 +355,15 @@ def print_prompt(self, saved_diff_present: bool = False, saved_choice: ApplyType ) return choice - def get_saved_choice_prompt(self, saved_diff_present: bool = False, saved_choice: ApplyType = None): + def get_saved_choice_prompt( + self, saved_diff_present: bool = False, saved_choice: ApplyType = None + ): new_color = self.conf_general["diff_color_new"] old_color = self.conf_general["diff_color_old"] edited_color = self.conf_general["diff_color_edited"] - saved_color = self.conf_general["diff_color_saved"] if saved_diff_present else "dark_grey" + saved_color = ( + self.conf_general["diff_color_saved"] if saved_diff_present else "dark_grey" + ) saved_selection = f"{bold('s', saved_color)}" if saved_choice == ApplyType.OLD: saved_selection += f" ({colored('old', old_color)}) " @@ -335,7 +375,9 @@ def get_saved_choice_prompt(self, saved_diff_present: bool = False, saved_choice saved_selection += f" ({colored('none', 'dark_grey')}) " return saved_selection - def print_prompt_help(self, saved_diff_present: bool = False, saved_choice: ApplyType = None) -> None: + def print_prompt_help( + self, saved_diff_present: bool = False, saved_choice: ApplyType = None + ) -> None: new_color = self.conf_general["diff_color_new"] old_color = self.conf_general["diff_color_old"] edited_color = self.conf_general["diff_color_edited"] @@ -352,7 +394,9 @@ def print_prompt_help(self, saved_diff_present: bool = False, saved_choice: Appl f"?\t\t- Show this help\n\n" ) - def get_user_choice(self, saved_diff_present: bool, saved_choice: ApplyType) -> ApplyType: + def get_user_choice( + self, saved_diff_present: bool, saved_choice: ApplyType + ) -> ApplyType: while True: choice = self.print_prompt(saved_diff_present, saved_choice) if choice not in ["O", "o", "n", "e", "s", "p", "q", "?", "help"]: @@ -391,10 +435,18 @@ def saved_patch_matches(self, saved: dict) -> bool: new_hash = "" return saved["old_hash"] == old_hash and saved["new_hash"] == new_hash - def create_patch(self, coord: PatchCoord, choice: ApplyType, saved_patch: dict = None): + def create_patch( + self, coord: PatchCoord, choice: ApplyType, saved_patch: dict = None + ): old = self.cur_old_node.text if self.cur_old_node else b"" new = self.cur_new_node.text if self.cur_new_node else b"" - return Patch(self.cur_nid, old, new, coord, saved_patch["apply_type"] if saved_patch else choice) + return Patch( + self.cur_nid, + old, + new, + coord, + saved_patch["apply_type"] if saved_patch else choice, + ) def add_patch( self, @@ -412,7 +464,12 @@ def add_patch( else: self.patches.append(self.current_patch) - def diff_nodes(self, old_filepath: Path, new_nodes: dict[bytes, Node], old_nodes: dict[bytes, Node]) -> list[Patch]: + def diff_nodes( + self, + old_filepath: Path, + new_nodes: dict[bytes, Node], + old_nodes: dict[bytes, Node], + ) -> list[Patch]: """ Asks the user for each different node, which version should be written. It writes the choice to a file, so the previous choice can be applied again if nothing changed. @@ -422,8 +479,18 @@ def diff_nodes(self, old_filepath: Path, new_nodes: dict[bytes, Node], old_nodes # a) we need to apply the patches backwards (so the coordinates in the file don't change. # b) If there is an old node, which is not present in the new file, we search for # a node which is adjacent (random node order wouldn't allow this). - new_nodes = {k: v for k, v in sorted(new_nodes.items(), key=lambda item: item[1].start_byte, reverse=True)} - old_nodes = {k: v for k, v in sorted(old_nodes.items(), key=lambda item: item[1].start_byte, reverse=True)} + new_nodes = { + k: v + for k, v in sorted( + new_nodes.items(), key=lambda item: item[1].start_byte, reverse=True + ) + } + old_nodes = { + k: v + for k, v in sorted( + old_nodes.items(), key=lambda item: item[1].start_byte, reverse=True + ) + } # Collect all node ids of this file node_ids = set() @@ -451,8 +518,16 @@ def diff_nodes(self, old_filepath: Path, new_nodes: dict[bytes, Node], old_nodes if self.cur_nid in old_nodes: self.cur_old_node = old_nodes[self.cur_nid] - n = self.cur_new_node.text.decode("utf8").splitlines() if self.cur_new_node else [""] - o = self.cur_old_node.text.decode("utf8").splitlines() if self.cur_old_node else [""] + n = ( + self.cur_new_node.text.decode("utf8").splitlines() + if self.cur_new_node + else [""] + ) + o = ( + self.cur_old_node.text.decode("utf8").splitlines() + if self.cur_old_node + else [""] + ) diff_lines = list(self.differ.compare(o, n)) if self.no_difference(diff_lines): @@ -473,7 +548,11 @@ def diff_nodes(self, old_filepath: Path, new_nodes: dict[bytes, Node], old_nodes j = old_node_ids.index(self.cur_nid) while j >= 0 and (old_node_ids[j] not in new_nodes.keys()): j -= 1 - ref_new: Node = new_nodes[old_node_ids[j]] if old_node_ids[j] in new_nodes.keys() else new_nodes[0] + ref_new: Node = ( + new_nodes[old_node_ids[j]] + if old_node_ids[j] in new_nodes.keys() + else new_nodes[0] + ) ref_end_byte = ref_new.start_byte patch_coord = PatchCoord( ref_end_byte - 1, @@ -484,7 +563,10 @@ def diff_nodes(self, old_filepath: Path, new_nodes: dict[bytes, Node], old_nodes save_exists = False saved = None - if old_filepath.name in self.saved_patches and self.cur_nid in self.saved_patches[old_filepath.name]: + if ( + old_filepath.name in self.saved_patches + and self.cur_nid in self.saved_patches[old_filepath.name] + ): saved: dict = self.saved_patches[old_filepath.name][self.cur_nid] save_exists = True if self.saved_patch_matches(saved) and not self.no_auto_apply: @@ -500,7 +582,9 @@ def diff_nodes(self, old_filepath: Path, new_nodes: dict[bytes, Node], old_nodes continue self.print_diff(diff_lines, self.cur_nid, i + 1, len(node_ids)) - choice = self.get_user_choice(save_exists, None if not saved else saved["apply_type"]) + choice = self.get_user_choice( + save_exists, None if not saved else saved["apply_type"] + ) if choice == ApplyType.OLD: if not self.cur_old_node: # No data in old node. Skip @@ -514,7 +598,9 @@ def diff_nodes(self, old_filepath: Path, new_nodes: dict[bytes, Node], old_nodes if not save_exists: print(bold("Save does not exist.")) continue - self.add_patch(saved["apply_type"], consec_old, old_filepath, patch_coord) + self.add_patch( + saved["apply_type"], consec_old, old_filepath, patch_coord + ) elif choice == ApplyType.OLD_ALL: self.add_patch(ApplyType.OLD, consec_old, old_filepath, patch_coord) elif choice == ApplyType.EDIT: @@ -558,10 +644,16 @@ def diff(self) -> None: old_filepath = old_file[k]["filepath"] new_filepath = new_file[k]["filepath"] diffs_to_process = max(len(new_file[k]["nodes"]), len(old_file[k]["nodes"])) - print_prominent_info(self.get_diff_intro_msg(old_filepath, new_filepath, k + 1, i, diffs_to_process)) + print_prominent_info( + self.get_diff_intro_msg( + old_filepath, new_filepath, k + 1, i, diffs_to_process + ) + ) if diffs_to_process == 0: continue - patches[new_filepath] = self.diff_nodes(old_filepath, new_file[k]["nodes"], old_file[k]["nodes"]) + patches[new_filepath] = self.diff_nodes( + old_filepath, new_file[k]["nodes"], old_file[k]["nodes"] + ) self.patch_files(patches) log.info("Done") @@ -603,7 +695,11 @@ def parse_args() -> argparse.Namespace: action="store_true", ) parser.add_argument( - "-a", dest="arch", help="Name of target architecture.", choices=["ARM", "PPC, AArch64", "Alpha"], required=True + "-a", + dest="arch", + help="Name of target architecture.", + choices=["ARM", "PPC, AArch64", "Alpha"], + required=True, ) parser.add_argument( "-v", @@ -613,7 +709,11 @@ def parse_args() -> argparse.Namespace: default="info", ) parser.add_argument( - "-c", dest="config_path", help="Config file for architectures.", default="arch_config.json", type=Path + "-c", + dest="config_path", + help="Config file for architectures.", + default="arch_config.json", + type=Path, ) arguments = parser.parse_args() return arguments diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py index 06a5017009..685674852d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py @@ -1,11 +1,15 @@ import logging as log import re -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name, template_param_list_to_dict +from autosync.cpptranslator.Patches.HelperMethods import ( + get_MCInst_var_name, + get_text, + template_param_list_to_dict, +) from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class AddCSDetail(Patch): """ @@ -33,7 +37,11 @@ def __init__(self, priority: int, arch: str): super().__init__(priority) self.arch = arch self.apply_only_to = { - "files": ["ARMInstPrinter.cpp", "PPCInstPrinter.cpp", "AArch64InstPrinter.cpp"], + "files": [ + "ARMInstPrinter.cpp", + "PPCInstPrinter.cpp", + "AArch64InstPrinter.cpp", + ], "archs": list(), } @@ -68,15 +76,31 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: comp = get_text(src, comp.start_byte, comp.end_byte) return b"void " + fcn_id + params + b"{ " + add_cs_detail + comp.strip(b"{") - def get_add_cs_detail(self, src: bytes, fcn_def: Node, fcn_id: bytes, params: bytes) -> bytes: - op_group_enum = self.arch.encode("utf8") + b"_OP_GROUP_" + fcn_id[5:] # Remove "print" from function id + def get_add_cs_detail( + self, src: bytes, fcn_def: Node, fcn_id: bytes, params: bytes + ) -> bytes: + op_group_enum = ( + self.arch.encode("utf8") + b"_OP_GROUP_" + fcn_id[5:] + ) # Remove "print" from function id is_template = fcn_def.prev_sibling.type == "template_parameter_list" - op_num_var_name = b"OpNum" if b"OpNum" in params else (b"OpNo" if b"OpNo" in params else b"-.-") + op_num_var_name = ( + b"OpNum" + if b"OpNum" in params + else (b"OpNo" if b"OpNo" in params else b"-.-") + ) if not is_template and op_num_var_name in params: # Standard printOperand() parameters mcinst_var = get_MCInst_var_name(src, fcn_def) - return b"add_cs_detail(" + mcinst_var + b", " + op_group_enum + b", " + op_num_var_name + b");" + return ( + b"add_cs_detail(" + + mcinst_var + + b", " + + op_group_enum + + b", " + + op_num_var_name + + b");" + ) elif op_group_enum == b"ARM_OP_GROUP_RegImmShift": return b"add_cs_detail(MI, " + op_group_enum + b", ShOpc, ShImm);" elif is_template and op_num_var_name in params: @@ -84,7 +108,9 @@ def get_add_cs_detail(self, src: bytes, fcn_def: Node, fcn_id: bytes, params: by templ_p = template_param_list_to_dict(fcn_def.prev_sibling) cs_args = b"" for tp in templ_p: - op_group_enum = b"CONCAT(" + op_group_enum + b", " + tp["identifier"] + b")" + op_group_enum = ( + b"CONCAT(" + op_group_enum + b", " + tp["identifier"] + b")" + ) cs_args += b", " + tp["identifier"] return ( b"add_cs_detail(" diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py index a949139985..88ea1a1c13 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class AddOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py index edb8f90c9a..555451026d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py @@ -1,5 +1,5 @@ -from tree_sitter import Node from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class Assert(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py index cd89288f74..18ea391399 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class BitCastStdArray(Patch): @@ -46,14 +45,36 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: arr_name: bytes = captures[1][0].text array_type: Node = captures[3][0] cast_target: bytes = captures[4][0].text.strip(b"()") - array_templ_args: bytes = array_type.named_children[0].named_children[1].named_children[1].text.strip(b"<>") + array_templ_args: bytes = ( + array_type.named_children[0] + .named_children[1] + .named_children[1] + .text.strip(b"<>") + ) arr_type = array_templ_args.split(b",")[0] arr_len = array_templ_args.split(b",")[1] return ( b"union {\n" - + b" typeof(" + cast_target + b") In;\n" - + b" " + arr_type + b" Out[" + arr_len + b"];\n" - + b"} U_" + arr_name + b";\n" - + b"U_" + arr_name + b".In = " + cast_target + b";\n" - + arr_type + b" *" + arr_name + b" = U_" + arr_name + b".Out;" + + b" typeof(" + + cast_target + + b") In;\n" + + b" " + + arr_type + + b" Out[" + + arr_len + + b"];\n" + + b"} U_" + + arr_name + + b";\n" + + b"U_" + + arr_name + + b".In = " + + cast_target + + b";\n" + + arr_type + + b" *" + + arr_name + + b" = U_" + + arr_name + + b".Out;" ) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py index 395ee55cf6..410f220c3b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class CheckDecoderStatus(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py index 916f797db3..9e3b216478 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py @@ -1,5 +1,5 @@ -from tree_sitter import Node from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class ClassConstructorDef(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py index b5299e16c3..d58e5f9973 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py @@ -1,11 +1,11 @@ import logging as log import re -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class ClassesDef(Patch): """ @@ -31,7 +31,9 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: for field_decl in field_decl_list.named_children: if ( field_decl.type in "field_declaration" - and ("function_declarator" in [t.type for t in field_decl.named_children]) + and ( + "function_declarator" in [t.type for t in field_decl.named_children] + ) ) or field_decl.type == "template_declaration": # Keep comments sibling = field_decl.prev_named_sibling diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py index 49e0db275d..738c028647 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class ConstMCInstParameter(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py index 44ac0bf9eb..2d1317fee6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class ConstMCOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py index 40fdc6b28f..db8ff025dd 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class CppInitCast(Patch): @@ -14,7 +13,12 @@ def __init__(self, priority: int): super().__init__(priority) def get_search_pattern(self) -> str: - return "(call_expression" " (primitive_type) @cast_type" " (argument_list) @cast_target" ") @cast" + return ( + "(call_expression" + " (primitive_type) @cast_type" + " (argument_list) @cast_target" + ") @cast" + ) def get_main_capture_name(self) -> str: return "cast" diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py index 955cc15f7d..c6d8be1d07 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py @@ -1,10 +1,10 @@ import re -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class CreateOperand0(Patch): """ @@ -44,7 +44,11 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: op_create_args: Node = captures[4][0] # Capstone spells the function with capital letter 'C' for whatever reason. - fcn = re.sub(b"create", b"Create", get_text(src, op_create_fcn.start_byte, op_create_fcn.end_byte)) + fcn = re.sub( + b"create", + b"Create", + get_text(src, op_create_fcn.start_byte, op_create_fcn.end_byte), + ) inst = get_text(src, inst_var.start_byte, inst_var.end_byte) args = get_text(src, op_create_args.start_byte, op_create_args.end_byte) if args[0] == b"(" and args[-1] == b")": diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py index 55e5789bca..59676456e2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py @@ -1,10 +1,10 @@ import re -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class CreateOperand1(Patch): """ @@ -50,7 +50,11 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: insert_arg_t = get_text(src, insert_arg.start_byte, insert_arg.end_byte) # Capstone spells the function with capital letter 'C' for whatever reason. - fcn = re.sub(b"create", b"Create", get_text(src, op_create_fcn.start_byte, op_create_fcn.end_byte)) + fcn = re.sub( + b"create", + b"Create", + get_text(src, op_create_fcn.start_byte, op_create_fcn.end_byte), + ) inst = get_text(src, inst_var.start_byte, inst_var.end_byte) args = get_text(src, op_create_args.start_byte, op_create_args.end_byte) return ( diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py index c81eed4c5c..cc9ecad083 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node +from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class DeclarationInConditionalClause(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py index e6ffc913ef..b16bac9b5f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class DecodeInstruction(Patch): @@ -31,8 +30,12 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: args_text = get_text(src, arg_list.start_byte, arg_list.end_byte).strip(b"()") table, mi_inst, opcode_var, address, this, sti = args_text.split(b",") - is_32bit = table[-2:].decode("utf8") == "32" or opcode_var[-2:].decode("utf8") == "32" - is_16bit = table[-2:].decode("utf8") == "16" or opcode_var[-2:].decode("utf8") == "16" + is_32bit = ( + table[-2:].decode("utf8") == "32" or opcode_var[-2:].decode("utf8") == "32" + ) + is_16bit = ( + table[-2:].decode("utf8") == "16" or opcode_var[-2:].decode("utf8") == "16" + ) args = table + b", " + mi_inst + b", " + opcode_var + b", " + address if is_16bit and not is_32bit: diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py index 3417b46e3d..f4dd36167a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py @@ -1,6 +1,5 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class DecoderCast(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py index da2a05493d..2927e26705 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py @@ -1,6 +1,5 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class DecoderParameter(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py index 4ed5b4427f..bced2a1a6b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py @@ -1,5 +1,5 @@ -from tree_sitter import Node from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class FallThrough(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py index e77fe30223..9fa4135bce 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py @@ -1,6 +1,6 @@ -from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class FeatureBits(Patch): @@ -30,4 +30,11 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: qualified_id: Node = captures[2][0] flag = get_text(src, qualified_id.start_byte, qualified_id.end_byte) mcinst_var_name = get_MCInst_var_name(src, qualified_id) - return self.arch + b"_getFeatureBits(" + mcinst_var_name + b"->csh->mode, " + flag + b")" + return ( + self.arch + + b"_getFeatureBits(" + + mcinst_var_name + + b"->csh->mode, " + + flag + + b")" + ) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py index c091073582..cd78d97daf 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py @@ -1,6 +1,5 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class FeatureBitsDecl(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py index 930f38cd22..2f3655324d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py @@ -1,11 +1,14 @@ import logging as log import re -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_function_params_of_node +from autosync.cpptranslator.Patches.HelperMethods import ( + get_function_params_of_node, + get_text, +) from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class FieldFromInstr(Patch): """ @@ -32,7 +35,9 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: ffi_call: Node = captures[0][0] ffi_first_arg: Node = captures[2][0] param_list_caller = get_function_params_of_node(ffi_call) - ffi_first_arg_text = get_text(src, ffi_first_arg.start_byte, ffi_first_arg.end_byte).decode("utf8") + ffi_first_arg_text = get_text( + src, ffi_first_arg.start_byte, ffi_first_arg.end_byte + ).decode("utf8") # Determine width of instruction by the variable name. if ffi_first_arg_text[-2:] == "32": diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py index 0a3f7192a7..ae2b3e291d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class GetNumOperands(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py index 2ba9f95fc6..fc78f5270e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class GetOpcode(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py index 27e0dce196..8f3c9983b0 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class GetOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py index 2cffabff13..911baec002 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node +from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class GetOperandRegImm(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py index 49ab599eb2..a5e3b364a9 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py @@ -1,7 +1,10 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node, get_MCInst_var_name +from autosync.cpptranslator.Patches.HelperMethods import ( + get_capture_node, + get_MCInst_var_name, + get_text, +) from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class GetRegClass(Patch): @@ -31,6 +34,8 @@ def get_main_capture_name(self) -> str: def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: arg_list: Node = get_capture_node(captures, "arg_list") args = get_text(src, arg_list.start_byte, arg_list.end_byte).strip(b"()") - mcinst_var = get_MCInst_var_name(src, get_capture_node(captures, "get_reg_class")) + mcinst_var = get_MCInst_var_name( + src, get_capture_node(captures, "get_reg_class") + ) res = b"MCRegisterInfo_getRegClass(" + mcinst_var + b"->MRI, " + args + b")" return res diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py index f6b032250f..a85c4e90c3 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node +from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class GetRegFromClass(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py index 6cb271f68c..e4b3ef6c68 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class GetSubReg(Patch): @@ -31,6 +30,8 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: # Get arg list op_create_args: Node = captures[2][0] - args = get_text(src, op_create_args.start_byte, op_create_args.end_byte).strip(b"()") + args = get_text(src, op_create_args.start_byte, op_create_args.end_byte).strip( + b"()" + ) mcinst_var_name = get_MCInst_var_name(src, op_create_args) return b"MCRegisterInfo_getSubReg(" + mcinst_var_name + b"->MRI, " + args + b")" diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py index a78127ff04..23eeb5a59b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py @@ -1,10 +1,10 @@ -import re - -from tree_sitter import Node import logging as log +import re from autosync.Helper import fail_exit +from tree_sitter import Node + def get_function_params_of_node(n: Node) -> Node: """ @@ -46,7 +46,9 @@ def get_MCInst_var_name(src: bytes, n: Node) -> bytes: def template_param_list_to_dict(param_list: Node) -> [dict]: if param_list.type != "template_parameter_list": - log.fatal(f"Wrong node type '{param_list.type}'. Not 'template_parameter_list'.") + log.fatal( + f"Wrong node type '{param_list.type}'. Not 'template_parameter_list'." + ) exit(1) pl = list() for c in param_list.named_children: @@ -64,7 +66,9 @@ def template_param_list_to_dict(param_list: Node) -> [dict]: def parameter_declaration_to_dict(param_decl: Node) -> dict: if param_decl.type != "parameter_declaration": - log.fatal(f"Wrong node type '{param_decl.type}'. Should be 'parameter_declaration'.") + log.fatal( + f"Wrong node type '{param_decl.type}'. Should be 'parameter_declaration'." + ) exit(1) return { "prim_type": param_decl.children[0].type == "primitive_type", @@ -152,7 +156,9 @@ def namespace_struct(src: bytes, ns_id: bytes, struct: Node) -> bytes: tid = get_text(src, type_id.start_byte, type_id.end_byte) fields = get_text(src, field_list.start_byte, field_list.end_byte) - typed_struct = b"typedef struct " + tid + b" " + fields + b"\n " + ns_id + b"_" + tid + typed_struct = ( + b"typedef struct " + tid + b" " + fields + b"\n " + ns_id + b"_" + tid + ) return typed_struct @@ -195,7 +201,14 @@ def parse_function_capture( from autosync.cpptranslator.TemplateCollector import TemplateCollector - return TemplateCollector.templ_params_to_list(temp_args), st_class_ids, ret_type, func_name, func_params, comp_stmt + return ( + TemplateCollector.templ_params_to_list(temp_args), + st_class_ids, + ret_type, + func_name, + func_params, + comp_stmt, + ) def get_capture_node(captures: [(Node, str)], name: str) -> Node: diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py index d34a6fc0ee..bf23cb270d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py @@ -1,10 +1,10 @@ import logging as log -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class Includes(Patch): """ @@ -34,11 +34,17 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: include_text = get_text(src, captures[0][0].start_byte, captures[0][0].end_byte) # Special cases, which appear somewhere in the code. if b"GenDisassemblerTables.inc" in include_text: - return b'#include "' + bytes(self.arch, "utf8") + b'GenDisassemblerTables.inc"\n\n' + return ( + b'#include "' + + bytes(self.arch, "utf8") + + b'GenDisassemblerTables.inc"\n\n' + ) elif b"GenAsmWriter.inc" in include_text: return b'#include "' + bytes(self.arch, "utf8") + b'GenAsmWriter.inc"\n\n' elif b"GenSystemOperands.inc" in include_text: - return b'#include "' + bytes(self.arch, "utf8") + b'GenSystemOperands.inc"\n\n' + return ( + b'#include "' + bytes(self.arch, "utf8") + b'GenSystemOperands.inc"\n\n' + ) if self.include_count[filename] > 1: # Only the first include is replaced with all CS includes. @@ -245,4 +251,6 @@ def get_AArch64_includes(filename: str) -> bytes: def get_general_macros(): - return b"#define CONCAT(a, b) CONCAT_(a, b)\n" b"#define CONCAT_(a, b) a ## _ ## b\n" + return ( + b"#define CONCAT(a, b) CONCAT_(a, b)\n" b"#define CONCAT_(a, b) a ## _ ## b\n" + ) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py index 1b920255c3..d980b4b785 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class InlineToStaticInline(Patch): @@ -20,7 +19,10 @@ def __init__(self, priority: int): def get_search_pattern(self) -> str: return ( - "(function_definition" ' ((storage_class_specifier) @scs (#eq? @scs "inline"))' " (_)+" ") @inline_def" + "(function_definition" + ' ((storage_class_specifier) @scs (#eq? @scs "inline"))' + " (_)+" + ") @inline_def" ) def get_main_capture_name(self) -> str: diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py index 1793ae95a3..ee1695cb44 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class IsOptionalDef(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py index 8c71dbda10..98fa7c3c5f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class IsPredicate(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py index 0376dd6849..3d286d2bc5 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class IsOperandRegImm(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py index 2c45f4f41e..e01284af5c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py @@ -1,6 +1,5 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class LLVMFallThrough(Patch): @@ -12,7 +11,11 @@ def __init__(self, priority: int): super().__init__(priority) def get_search_pattern(self) -> str: - return "(expression_statement" ' ((identifier) @id (#eq? @id "LLVM_FALLTHROUGH"))' ") @llvm_fall_through" + return ( + "(expression_statement" + ' ((identifier) @id (#eq? @id "LLVM_FALLTHROUGH"))' + ") @llvm_fall_through" + ) def get_main_capture_name(self) -> str: return "llvm_fall_through" diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py index 4e07bd1c0c..d84d640f1a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class LLVMUnreachable(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py index 16822b671f..90cebd35fb 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class MethodToFunction(Patch): @@ -35,6 +34,8 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: name = captures[1][0] parameter_list = captures[2][0] name = get_text(src, name.start_byte, name.end_byte) - parameter_list = get_text(src, parameter_list.start_byte, parameter_list.end_byte) + parameter_list = get_text( + src, parameter_list.start_byte, parameter_list.end_byte + ) res = name + parameter_list return res diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py index 056eb3de56..38fa68d1e2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class MethodTypeQualifier(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py index a25c5cdb27..dd17633d28 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class NamespaceAnon(Patch): @@ -16,7 +15,11 @@ def __init__(self, priority: int): super().__init__(priority) def get_search_pattern(self) -> str: - return "(namespace_definition" " (declaration_list) @decl_list" ") @namespace_def" + return ( + "(namespace_definition" + " (declaration_list) @decl_list" + ") @namespace_def" + ) def get_main_capture_name(self) -> str: return "namespace_def" diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py index 84cd11e681..adcb69d3e8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py @@ -1,7 +1,11 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, namespace_enum, namespace_fcn_def, namespace_struct +from autosync.cpptranslator.Patches.HelperMethods import ( + get_text, + namespace_enum, + namespace_fcn_def, + namespace_struct, +) from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class NamespaceArch(Patch): @@ -16,7 +20,12 @@ def __init__(self, priority: int): super().__init__(priority) def get_search_pattern(self) -> str: - return "(namespace_definition" " (namespace_identifier)" " (declaration_list) @decl_list" ") @namespace_def" + return ( + "(namespace_definition" + " (namespace_identifier)" + " (declaration_list) @decl_list" + ") @namespace_def" + ) def get_main_capture_name(self) -> str: return "namespace_def" @@ -24,7 +33,11 @@ def get_main_capture_name(self) -> str: def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: namespace = captures[0][0] decl_list = captures[1][0] - namespace_id = get_text(src, namespace.named_children[0].start_byte, namespace.named_children[0].end_byte) + namespace_id = get_text( + src, + namespace.named_children[0].start_byte, + namespace.named_children[0].end_byte, + ) # We need to prepend the namespace id to all enum members, function declarators and struct types. # Because in the generated files they are accessed via NAMESPACE::X which becomes NAMESPACE_X. diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py index a8d5c4cb8d..cd57cbd2ef 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class NamespaceLLVM(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py index 0ee9897451..a88a71f97a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class OutStreamParam(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Patch.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Patch.py index ed87f67967..48de8a1470 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/Patch.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/Patch.py @@ -1,6 +1,7 @@ -from tree_sitter import Node import logging as log +from tree_sitter import Node + class Patch: priority: int = None diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py index b62cdbc9f5..3cb4332b8b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class PredicateBlockFunctions(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py index 8195cc216b..85ac788643 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py @@ -1,5 +1,5 @@ -from tree_sitter import Node from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class PrintAnnotation(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py index b7594be55f..d8ef5f0144 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_MCInst_var_name +from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class PrintRegImmShift(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py index 7ca8dec07a..fa990b4474 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class QualifiedIdentifier(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py index 892499e41b..a46a5e7875 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py @@ -1,10 +1,10 @@ import re -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class ReferencesDecl(Patch): """ @@ -18,7 +18,12 @@ def __init__(self, priority: int): super().__init__(priority) def get_search_pattern(self) -> str: - return "[" "(reference_declarator)" "(type_identifier) (abstract_reference_declarator)" "] @reference_decl" + return ( + "[" + "(reference_declarator)" + "(type_identifier) (abstract_reference_declarator)" + "] @reference_decl" + ) def get_main_capture_name(self) -> str: return "reference_decl" diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py index 98534b5f1b..0e59e06682 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_capture_node +from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class RegClassContains(Patch): @@ -32,6 +31,8 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: reg_class_getter: Node = get_capture_node(captures, "reg_class") arg_list: Node = get_capture_node(captures, "arg_list") args = get_text(src, arg_list.start_byte, arg_list.end_byte).strip(b"()") - reg_class = get_text(src, reg_class_getter.start_byte, reg_class_getter.end_byte) + reg_class = get_text( + src, reg_class_getter.start_byte, reg_class_getter.end_byte + ) res = b"MCRegisterClass_contains(" + reg_class + b", " + args + b")" return res diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py index f756555019..7170e1ee4a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class STIArgument(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py index 0980919a08..ead593c67d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class STIFeatureBits(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py index f53a4fc8e7..23f0fedd3e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class SubtargetInfoParam(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py index 887ebb95dd..2d33f0e8c6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class SetOpcode(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py index 79c929c4d5..bd50fb742e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py @@ -1,7 +1,7 @@ -from tree_sitter import Node from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import TemplateCollector +from tree_sitter import Node class SignExtend(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py index ceac9ff1ac..433416bb83 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py @@ -1,10 +1,13 @@ import re -from tree_sitter import Node - -from autosync.cpptranslator.Patches.HelperMethods import get_text, get_function_params_of_node +from autosync.cpptranslator.Patches.HelperMethods import ( + get_function_params_of_node, + get_text, +) from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class SizeAssignment(Patch): """ @@ -18,7 +21,11 @@ def __init__(self, priority: int): super().__init__(priority) def get_search_pattern(self) -> str: - return "(assignment_expression" ' ((identifier) @id (#eq? @id "Size"))' ") @assign" + return ( + "(assignment_expression" + ' ((identifier) @id (#eq? @id "Size"))' + ") @assign" + ) def get_main_capture_name(self) -> str: return "assign" diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py index 55804a7b2d..582ee7a795 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py @@ -1,7 +1,6 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class StreamOperations(Patch): @@ -58,11 +57,22 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: + b', "' + b"%s" * len(string_ops) + b'", ' - + b", ".join([get_text(src, o.start_byte, o.end_byte) for o in string_ops]) + + b", ".join( + [ + get_text(src, o.start_byte, o.end_byte) + for o in string_ops + ] + ) + b");\n" ) string_ops.clear() - res += b"SStream_concat1(" + s_name + b", " + get_text(src, op.start_byte, op.end_byte) + b");\n" + res += ( + b"SStream_concat1(" + + s_name + + b", " + + get_text(src, op.start_byte, op.end_byte) + + b");\n" + ) else: string_ops.append(op) i += 1 @@ -75,14 +85,22 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: + b', "' + b"%s" * len(string_ops) + b'", ' - + b", ".join([get_text(src, o.start_byte, o.end_byte) for o in string_ops]) + + b", ".join( + [get_text(src, o.start_byte, o.end_byte) for o in string_ops] + ) + b");\n" ) string_ops.clear() last_op_text = get_text(src, last_op.start_byte, last_op.end_byte) if last_op.type == "char_literal": - res += b"SStream_concat0(" + s_name + b", " + last_op_text.replace(b"'", b'"') + b");\n" + res += ( + b"SStream_concat0(" + + s_name + + b", " + + last_op_text.replace(b"'", b'"') + + b");\n" + ) else: res += b"SStream_concat0(" + s_name + b", " + last_op_text + b");" stream = captures[0][0] diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py index 1962ea364f..090c0b3583 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py @@ -1,9 +1,12 @@ import logging as log -from tree_sitter import Node from autosync.cpptranslator.Patches.HelperMethods import parse_function_capture from autosync.cpptranslator.Patches.Patch import Patch -from autosync.cpptranslator.TemplateCollector import TemplateCollector, TemplateRefInstance +from autosync.cpptranslator.TemplateCollector import ( + TemplateCollector, + TemplateRefInstance, +) +from tree_sitter import Node class TemplateDeclaration(Patch): @@ -37,13 +40,24 @@ def get_search_pattern(self) -> str: def get_main_capture_name(self) -> str: return "template_decl" - def get_patch(self, captures: list[tuple[Node, str]], src: bytes, **kwargs) -> bytes: + def get_patch( + self, captures: list[tuple[Node, str]], src: bytes, **kwargs + ) -> bytes: t_params, sc, tid, f_name, f_params, _ = parse_function_capture(captures, src) if f_name in self.collector.templates_with_arg_deduction: return sc + tid + b" " + f_name + f_params + b";" - declaration = b"#define DECLARE_" + f_name + b"(" + b", ".join(t_params) + b")\n" - declaration += sc + b" " + tid + b" " + TemplateCollector.get_macro_c_call(f_name, t_params, f_params) + b";" + declaration = ( + b"#define DECLARE_" + f_name + b"(" + b", ".join(t_params) + b")\n" + ) + declaration += ( + sc + + b" " + + tid + + b" " + + TemplateCollector.get_macro_c_call(f_name, t_params, f_params) + + b";" + ) declaration = declaration.replace(b"\n", b" \\\n") + b"\n" template_instance: TemplateRefInstance @@ -52,7 +66,13 @@ def get_patch(self, captures: list[tuple[Node, str]], src: bytes, **kwargs) -> b self.collector.log_missing_ref_and_exit(f_name) for template_instance in self.collector.template_refs[f_name]: - d = b"DECLARE_" + f_name + b"(" + b", ".join(template_instance.get_args_for_decl()) + b");\n" + d = ( + b"DECLARE_" + + f_name + + b"(" + + b", ".join(template_instance.get_args_for_decl()) + + b");\n" + ) if d in declared_implementations: continue declared_implementations.append(d) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py index 9a5400787f..9f2d9be953 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py @@ -1,11 +1,14 @@ import logging as log import re -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import parse_function_capture from autosync.cpptranslator.Patches.Patch import Patch -from autosync.cpptranslator.TemplateCollector import TemplateCollector, TemplateRefInstance +from autosync.cpptranslator.TemplateCollector import ( + TemplateCollector, + TemplateRefInstance, +) + +from tree_sitter import Node class TemplateDefinition(Patch): @@ -40,14 +43,23 @@ def get_search_pattern(self) -> str: def get_main_capture_name(self) -> str: return "template_def" - def get_patch(self, captures: list[tuple[Node, str]], src: bytes, **kwargs) -> bytes: - t_params, sc, tid, f_name, f_params, f_compound = parse_function_capture(captures, src) + def get_patch( + self, captures: list[tuple[Node, str]], src: bytes, **kwargs + ) -> bytes: + t_params, sc, tid, f_name, f_params, f_compound = parse_function_capture( + captures, src + ) if f_name in self.collector.templates_with_arg_deduction: return sc + tid + b" " + f_name + f_params + f_compound definition = b"#define DEFINE_" + f_name + b"(" + b", ".join(t_params) + b")\n" definition += ( - sc + b" " + tid + b" " + TemplateCollector.get_macro_c_call(f_name, t_params, f_params) + f_compound + sc + + b" " + + tid + + b" " + + TemplateCollector.get_macro_c_call(f_name, t_params, f_params) + + f_compound ) # Remove // comments definition = re.sub(b" *//.*", b"", definition) @@ -59,7 +71,13 @@ def get_patch(self, captures: list[tuple[Node, str]], src: bytes, **kwargs) -> b self.collector.log_missing_ref_and_exit(f_name) for template_instance in self.collector.template_refs[f_name]: - d = b"DEFINE_" + f_name + b"(" + b", ".join(template_instance.get_args_for_decl()) + b");\n" + d = ( + b"DEFINE_" + + f_name + + b"(" + + b", ".join(template_instance.get_args_for_decl()) + + b");\n" + ) if d in declared_implementations: continue declared_implementations.append(d) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py index 6031175599..356bc4858e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py @@ -1,10 +1,10 @@ import logging as log -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node + class TemplateParamDecl(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py index caf6b8aa30..9d8e43724d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py @@ -1,8 +1,7 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import TemplateCollector +from tree_sitter import Node class TemplateRefs(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py index 7610c45453..cce0fb6579 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py @@ -1,5 +1,5 @@ -from tree_sitter import Node from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class UseMarkup(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py index c150df1f24..347a794369 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py @@ -1,6 +1,5 @@ -from tree_sitter import Node - from autosync.cpptranslator.Patches.Patch import Patch +from tree_sitter import Node class UsingDeclaration(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py index dadc692d64..ab91ecc04b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py +++ b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py @@ -1,8 +1,8 @@ +import logging as log import re from pathlib import Path -from tree_sitter import Language, Parser, Query, Node -import logging as log +from tree_sitter import Language, Node, Parser, Query from autosync.cpptranslator.Patches.HelperMethods import get_text @@ -26,7 +26,9 @@ class TemplateRefInstance: # (parameters are set by the template parameters of the calling function). caller_param_indices: [{str: int}] = list() - def __init__(self, name: bytes, args: bytes, start_point, start_byte, end_point, end_byte): + def __init__( + self, name: bytes, args: bytes, start_point, start_byte, end_point, end_byte + ): self.name = name self.args = args self.start_point = start_point @@ -40,7 +42,14 @@ def __eq__(self, other): return ( self.name == other.name and self.args == other.args - and any([a == b for a, b in zip(self.caller_param_indices, other.caller_param_indices)]) + and any( + [ + a == b + for a, b in zip( + self.caller_param_indices, other.caller_param_indices + ) + ] + ) and self.start_byte == other.start_byte and self.start_point == other.start_point and self.end_byte == other.end_byte @@ -74,7 +83,13 @@ class TemplateCollector: incomplete_template_refs: {bytes: [TemplateRefInstance]} = dict() sources: [{str: bytes}] = list() - def __init__(self, ts_parser: Parser, ts_cpp: Language, searchable_files: [Path], temp_arg_deduction: [bytes]): + def __init__( + self, + ts_parser: Parser, + ts_cpp: Language, + searchable_files: [Path], + temp_arg_deduction: [bytes], + ): self.parser = ts_parser self.lang_cpp = ts_cpp self.searchable_files = searchable_files @@ -99,10 +114,17 @@ def collect(self): args = get_text(src, templ_args.start_byte, templ_args.end_byte) ti = TemplateRefInstance( - name, args, cb[0][0].start_point, cb[0][0].start_byte, cb[0][0].end_point, cb[0][0].end_byte + name, + args, + cb[0][0].start_point, + cb[0][0].start_byte, + cb[0][0].end_point, + cb[0][0].end_byte, ) - log.debug(f"Found new template ref: {name.decode('utf8')}{args.decode('utf8')}") + log.debug( + f"Found new template ref: {name.decode('utf8')}{args.decode('utf8')}" + ) if not self.contains_template_dependent_param(src, ti, cb[0]): if name not in self.template_refs: @@ -117,7 +139,10 @@ def collect(self): def resolve_dependencies(self): # Resolve dependencies of templates until nothing new was resolved. prev_len = 0 - while len(self.incomplete_template_refs) > 0 and len(self.incomplete_template_refs) != prev_len: + while ( + len(self.incomplete_template_refs) > 0 + and len(self.incomplete_template_refs) != prev_len + ): # Dict with new template calls which were previously incomplete # because one or more parameters were unknown. new_completed_tcs: {str: list} = dict() @@ -133,7 +158,9 @@ def resolve_dependencies(self): for caller_template in tc_instance_list: incomplete_tc: TemplateRefInstance for incomplete_tc in self.incomplete_template_refs[caller_name]: - new_tc: TemplateRefInstance = self.get_completed_tc(caller_template, incomplete_tc) + new_tc: TemplateRefInstance = self.get_completed_tc( + caller_template, incomplete_tc + ) callee_name = new_tc.name if callee_name not in new_completed_tcs: new_completed_tcs[callee_name] = list() @@ -148,11 +175,22 @@ def resolve_dependencies(self): self.template_refs[templ_name] = tc_list prev_len = len(self.incomplete_template_refs) if prev_len > 0: - log.info(f"Unresolved template calls: {self.incomplete_template_refs.keys()}. Patch them by hand!") + log.info( + f"Unresolved template calls: {self.incomplete_template_refs.keys()}. Patch them by hand!" + ) @staticmethod - def get_completed_tc(tc: TemplateRefInstance, itc: TemplateRefInstance) -> TemplateRefInstance: - new_tc = TemplateRefInstance(itc.name, itc.args, itc.start_byte, itc.start_byte, itc.end_point, itc.end_byte) + def get_completed_tc( + tc: TemplateRefInstance, itc: TemplateRefInstance + ) -> TemplateRefInstance: + new_tc = TemplateRefInstance( + itc.name, + itc.args, + itc.start_byte, + itc.start_byte, + itc.end_point, + itc.end_byte, + ) for indices in itc.caller_param_indices: if tc.name not in indices: # Index of other caller function. Skip. @@ -164,7 +202,9 @@ def get_completed_tc(tc: TemplateRefInstance, itc: TemplateRefInstance) -> Templ new_tc.templ_name = new_tc.name + new_tc.args return new_tc - def contains_template_dependent_param(self, src, ti: TemplateRefInstance, parse_tree: (Node, str)) -> bool: + def contains_template_dependent_param( + self, src, ti: TemplateRefInstance, parse_tree: (Node, str) + ) -> bool: """Here we check if one of the template parameters of the given template call, is a parameter of the callers template definition. @@ -200,14 +240,20 @@ def contains_template_dependent_param(self, src, ti: TemplateRefInstance, parse_ return False caller_fcn_id = node.named_children[2].named_children[0] - caller_fcn_name = get_text(src, caller_fcn_id.start_byte, caller_fcn_id.end_byte) - caller_templ_params = get_text(src, node.prev_sibling.start_byte, node.prev_sibling.end_byte) + caller_fcn_name = get_text( + src, caller_fcn_id.start_byte, caller_fcn_id.end_byte + ) + caller_templ_params = get_text( + src, node.prev_sibling.start_byte, node.prev_sibling.end_byte + ) pl = TemplateCollector.templ_params_to_list(caller_templ_params) has_parameter_dependency = False for i, param in enumerate(pl): if param in ti.args_list: has_parameter_dependency = True - ti.caller_param_indices.append({caller_fcn_name: i, "self_i": ti.args_list.index(param)}) + ti.caller_param_indices.append( + {caller_fcn_name: i, "self_i": ti.args_list.index(param)} + ) if not has_parameter_dependency: return False diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index 28c08e36c0..a8efc7fba7 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -4,16 +4,15 @@ import unittest from pathlib import Path -from tree_sitter import Query, Node - import autosync.cpptranslator.Patches as Patches from autosync.cpptranslator import CppTranslator from autosync.cpptranslator.Configurator import Configurator +from tree_sitter import Node, Query -class TestPatches(unittest.TestCase): +class TestPatches(unittest.TestCase): @classmethod def setUpClass(cls): configurator = Configurator("ARCH", Path("test_config.json")) @@ -23,9 +22,7 @@ def setUpClass(cls): def test_addcsdetail(self): patch = Patches.AddCSDetail.AddCSDetail(0, "ARCH") - syntax = ( - b"void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O) { int i = OpNo; }" - ) + syntax = b"void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O) { int i = OpNo; }" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() From 28d17d07c76da9a898c0f9dd2727178eac357439 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 05:11:19 -0500 Subject: [PATCH 06/41] Manually run Py formatting workflow --- .github/workflows/auto-sync.yml | 14 ++++++++++---- suite/auto-sync/pyproject.toml | 7 ++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 8bd57dc43f..c0b2fb5e27 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -9,8 +9,14 @@ jobs: check: runs-on: ubuntu-latest steps: - - name: Check formatting - uses: omnilib/ufmt@action-v1 + - name: Set up Python + uses: actions/setup-python@v4 with: - path: "suite/auto-sync/src/**" - python-version: "3.x" + python-version: '3.11' + - name: Install auto-sync package + run: | + cd suite/auto-sync/ + pip install -e . + - name: Check formatting + run: | + ufmt check src diff --git a/suite/auto-sync/pyproject.toml b/suite/auto-sync/pyproject.toml index be210a7243..6cc1ced38d 100644 --- a/suite/auto-sync/pyproject.toml +++ b/suite/auto-sync/pyproject.toml @@ -4,9 +4,10 @@ version = "0.1.0" dependencies = [ "termcolor >= 2.3.0", "tree_sitter < 0.22.0", - "black == 22.6.0", - "ufmt == 2.0.0", - "usort == 1.0.4", + "black >= 24.3.0", + "ufmt >= 2.5.1", + "usort >= 1.0.8", + "setuptools >= 69.2.0", ] requires-python = ">= 3.11" From 452d3c0b3b110985dbd47b93259fe2d63dbe73cc Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 05:16:31 -0500 Subject: [PATCH 07/41] Add Patch tests to workflow --- .github/workflows/auto-sync.yml | 13 ++++++++++--- .../autosync/cpptranslator/Tests/test_patches.py | 3 ++- suite/auto-sync/src/autosync/path_vars.json | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index c0b2fb5e27..69b368f7ee 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -8,15 +8,22 @@ on: jobs: check: runs-on: ubuntu-latest + defaults: + run: + working-directory: suite/auto-sync/ steps: - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.11' + - name: Check out repository + uses: actions/checkout@v4 - name: Install auto-sync package run: | - cd suite/auto-sync/ - pip install -e . + pip install . - name: Check formatting run: | - ufmt check src + ufmt check src/autosync + - name: CppTranslator - Patch tests + run: | + python -m unittest discover src/autosync/cpptranslator/Tests/ \ No newline at end of file diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index a8efc7fba7..3eab774459 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -8,6 +8,7 @@ from autosync.cpptranslator import CppTranslator from autosync.cpptranslator.Configurator import Configurator +from autosync.Helper import get_path from tree_sitter import Node, Query @@ -15,7 +16,7 @@ class TestPatches(unittest.TestCase): @classmethod def setUpClass(cls): - configurator = Configurator("ARCH", Path("test_config.json")) + configurator = Configurator("ARCH", get_path("{CPP_TRANSLATOR_TEST_CONFIG}")) cls.translator = CppTranslator.Translator(configurator) cls.ts_cpp_lang = configurator.get_cpp_lang() cls.parser = configurator.get_parser() diff --git a/suite/auto-sync/src/autosync/path_vars.json b/suite/auto-sync/src/autosync/path_vars.json index baaf45537b..cc4f3ebaf9 100644 --- a/suite/auto-sync/src/autosync/path_vars.json +++ b/suite/auto-sync/src/autosync/path_vars.json @@ -8,6 +8,8 @@ "{CPP_TRANSLATOR_DIR}": "{AUTO_SYNC_SRC}/cpptranslator/", "{CPP_TRANSLATOR_CONFIG}": "{CPP_TRANSLATOR_DIR}/arch_config.json", + "{CPP_TRANSLATOR_TEST_DIR}": "{CPP_TRANSLATOR_DIR}/Tests/", + "{CPP_TRANSLATOR_TEST_CONFIG}": "{CPP_TRANSLATOR_TEST_DIR}/test_config.json", "{INC_PATCH_DIR}": "{AUTO_SYNC_ROOT}/inc_patches/", "{CS_INCLUDE_DIR}": "{CS_ROOT}/include/capstone/", From cf34ceb113de8bda8e86b4a8ecc203a2568528be Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 05:43:05 -0500 Subject: [PATCH 08/41] Replace ufmt with simple usort and black chaining. --- .github/workflows/auto-sync.yml | 3 ++- suite/auto-sync/format_py.sh | 4 ++++ suite/auto-sync/pyproject.toml | 1 - .../src/autosync/cpptranslator/Patches/AddCSDetail.py | 4 ++-- .../src/autosync/cpptranslator/Patches/AddOperand.py | 3 ++- suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py | 3 ++- .../src/autosync/cpptranslator/Patches/BitCastStdArray.py | 3 ++- .../src/autosync/cpptranslator/Patches/CheckDecoderStatus.py | 3 ++- .../src/autosync/cpptranslator/Patches/ClassConstructorDef.py | 3 ++- .../src/autosync/cpptranslator/Patches/ClassesDef.py | 4 ++-- .../autosync/cpptranslator/Patches/ConstMCInstParameter.py | 3 ++- .../src/autosync/cpptranslator/Patches/ConstMCOperand.py | 3 ++- .../src/autosync/cpptranslator/Patches/CppInitCast.py | 3 ++- .../src/autosync/cpptranslator/Patches/CreateOperand0.py | 4 ++-- .../src/autosync/cpptranslator/Patches/CreateOperand1.py | 4 ++-- .../cpptranslator/Patches/DeclarationInConditionClause.py | 3 ++- .../src/autosync/cpptranslator/Patches/DecodeInstruction.py | 3 ++- .../src/autosync/cpptranslator/Patches/DecoderCast.py | 3 ++- .../src/autosync/cpptranslator/Patches/DecoderParameter.py | 3 ++- .../src/autosync/cpptranslator/Patches/FallThrough.py | 3 ++- .../src/autosync/cpptranslator/Patches/FeatureBits.py | 3 ++- .../src/autosync/cpptranslator/Patches/FeatureBitsDecl.py | 3 ++- .../src/autosync/cpptranslator/Patches/FieldFromInstr.py | 4 ++-- .../src/autosync/cpptranslator/Patches/GetNumOperands.py | 3 ++- .../auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py | 3 ++- .../src/autosync/cpptranslator/Patches/GetOperand.py | 3 ++- .../src/autosync/cpptranslator/Patches/GetOperandRegImm.py | 3 ++- .../src/autosync/cpptranslator/Patches/GetRegClass.py | 3 ++- .../src/autosync/cpptranslator/Patches/GetRegFromClass.py | 3 ++- .../auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py | 3 ++- .../src/autosync/cpptranslator/Patches/HelperMethods.py | 4 ++-- .../auto-sync/src/autosync/cpptranslator/Patches/Includes.py | 4 ++-- .../autosync/cpptranslator/Patches/InlineToStaticInline.py | 3 ++- .../src/autosync/cpptranslator/Patches/IsOptionalDef.py | 3 ++- .../src/autosync/cpptranslator/Patches/IsPredicate.py | 3 ++- .../auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py | 3 ++- .../src/autosync/cpptranslator/Patches/LLVMFallThrough.py | 3 ++- .../src/autosync/cpptranslator/Patches/LLVMunreachable.py | 3 ++- .../src/autosync/cpptranslator/Patches/MethodToFunctions.py | 3 ++- .../src/autosync/cpptranslator/Patches/MethodTypeQualifier.py | 3 ++- .../src/autosync/cpptranslator/Patches/NamespaceAnon.py | 3 ++- .../src/autosync/cpptranslator/Patches/NamespaceArch.py | 3 ++- .../src/autosync/cpptranslator/Patches/NamespaceLLVM.py | 3 ++- .../src/autosync/cpptranslator/Patches/OutStreamParam.py | 3 ++- .../autosync/cpptranslator/Patches/PredicateBlockFunctions.py | 3 ++- .../src/autosync/cpptranslator/Patches/PrintAnnotation.py | 3 ++- .../src/autosync/cpptranslator/Patches/PrintRegImmShift.py | 3 ++- .../src/autosync/cpptranslator/Patches/QualifiedIdentifier.py | 3 ++- .../src/autosync/cpptranslator/Patches/ReferencesDecl.py | 4 ++-- .../src/autosync/cpptranslator/Patches/RegClassContains.py | 3 ++- .../src/autosync/cpptranslator/Patches/STIArgument.py | 3 ++- .../src/autosync/cpptranslator/Patches/STIFeatureBits.py | 3 ++- .../src/autosync/cpptranslator/Patches/STParameter.py | 3 ++- .../auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py | 3 ++- .../src/autosync/cpptranslator/Patches/SignExtend.py | 3 ++- .../src/autosync/cpptranslator/Patches/SizeAssignments.py | 4 ++-- .../src/autosync/cpptranslator/Patches/StreamOperation.py | 3 ++- .../src/autosync/cpptranslator/Patches/TemplateDeclaration.py | 3 ++- .../src/autosync/cpptranslator/Patches/TemplateDefinition.py | 4 ++-- .../src/autosync/cpptranslator/Patches/TemplateParamDecl.py | 4 ++-- .../src/autosync/cpptranslator/Patches/TemplateRefs.py | 3 ++- .../auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py | 3 ++- .../src/autosync/cpptranslator/Patches/UsingDeclaration.py | 3 ++- .../src/autosync/cpptranslator/Tests/test_patches.py | 4 ++-- 64 files changed, 128 insertions(+), 75 deletions(-) create mode 100755 suite/auto-sync/format_py.sh diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 69b368f7ee..26df7d264b 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -23,7 +23,8 @@ jobs: pip install . - name: Check formatting run: | - ufmt check src/autosync + python3.11 -m usort check src/autosync + python3.11 -m black --check src/autosync - name: CppTranslator - Patch tests run: | python -m unittest discover src/autosync/cpptranslator/Tests/ \ No newline at end of file diff --git a/suite/auto-sync/format_py.sh b/suite/auto-sync/format_py.sh new file mode 100755 index 0000000000..5f0d5d9dc5 --- /dev/null +++ b/suite/auto-sync/format_py.sh @@ -0,0 +1,4 @@ +#!/usr/bin/bash + +python3.11 -m usort format src/autosync +python3.11 -m black src/autosync diff --git a/suite/auto-sync/pyproject.toml b/suite/auto-sync/pyproject.toml index 6cc1ced38d..ec6d5b557e 100644 --- a/suite/auto-sync/pyproject.toml +++ b/suite/auto-sync/pyproject.toml @@ -5,7 +5,6 @@ dependencies = [ "termcolor >= 2.3.0", "tree_sitter < 0.22.0", "black >= 24.3.0", - "ufmt >= 2.5.1", "usort >= 1.0.8", "setuptools >= 69.2.0", ] diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py index 685674852d..d80cbf30d2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py @@ -1,6 +1,8 @@ import logging as log import re +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import ( get_MCInst_var_name, get_text, @@ -8,8 +10,6 @@ ) from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class AddCSDetail(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py index 88ea1a1c13..a949139985 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class AddOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py index 555451026d..ada0a786a7 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class Assert(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py index 18ea391399..0fd4f8272e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class BitCastStdArray(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py index 410f220c3b..395ee55cf6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class CheckDecoderStatus(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py index 9e3b216478..4b06a0bca6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class ClassConstructorDef(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py index d58e5f9973..7f806fa2be 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py @@ -1,11 +1,11 @@ import logging as log import re +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class ClassesDef(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py index 738c028647..49e0db275d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class ConstMCInstParameter(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py index 2d1317fee6..44ac0bf9eb 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class ConstMCOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py index db8ff025dd..ca9de65810 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class CppInitCast(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py index c6d8be1d07..0503f249da 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py @@ -1,10 +1,10 @@ import re +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class CreateOperand0(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py index 59676456e2..53e3562401 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py @@ -1,10 +1,10 @@ import re +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class CreateOperand1(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py index cc9ecad083..471ae31a47 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class DeclarationInConditionalClause(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py index b16bac9b5f..b6c0ee63e4 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class DecodeInstruction(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py index f4dd36167a..3417b46e3d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class DecoderCast(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py index 2927e26705..da2a05493d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class DecoderParameter(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py index bced2a1a6b..95285712e1 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class FallThrough(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py index 9fa4135bce..09c3404115 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class FeatureBits(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py index cd78d97daf..c091073582 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class FeatureBitsDecl(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py index 2f3655324d..d228063f6b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py @@ -1,14 +1,14 @@ import logging as log import re +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import ( get_function_params_of_node, get_text, ) from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class FieldFromInstr(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py index ae2b3e291d..0a3f7192a7 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class GetNumOperands(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py index fc78f5270e..2ba9f95fc6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class GetOpcode(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py index 8f3c9983b0..27e0dce196 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class GetOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py index 911baec002..d76371868f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class GetOperandRegImm(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py index a5e3b364a9..831a1bbd25 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py @@ -1,10 +1,11 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import ( get_capture_node, get_MCInst_var_name, get_text, ) from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class GetRegClass(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py index a85c4e90c3..56d08fe2ef 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class GetRegFromClass(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py index e4b3ef6c68..8ce0002a19 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class GetSubReg(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py index 23eeb5a59b..cbd3faaf4b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py @@ -1,10 +1,10 @@ import logging as log import re -from autosync.Helper import fail_exit - from tree_sitter import Node +from autosync.Helper import fail_exit + def get_function_params_of_node(n: Node) -> Node: """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py index bf23cb270d..ffae8a99c4 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py @@ -1,10 +1,10 @@ import logging as log +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class Includes(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py index d980b4b785..0698d05c03 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class InlineToStaticInline(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py index ee1695cb44..1793ae95a3 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class IsOptionalDef(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py index 98fa7c3c5f..8c71dbda10 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class IsPredicate(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py index 3d286d2bc5..0376dd6849 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class IsOperandRegImm(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py index e01284af5c..ed2cdccc3b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class LLVMFallThrough(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py index d84d640f1a..4e07bd1c0c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class LLVMUnreachable(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py index 90cebd35fb..4377fd30e8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class MethodToFunction(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py index 38fa68d1e2..056eb3de56 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class MethodTypeQualifier(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py index dd17633d28..5c5f7a0be4 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class NamespaceAnon(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py index adcb69d3e8..3862c361a8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py @@ -1,3 +1,5 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import ( get_text, namespace_enum, @@ -5,7 +7,6 @@ namespace_struct, ) from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class NamespaceArch(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py index cd57cbd2ef..a8d5c4cb8d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class NamespaceLLVM(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py index a88a71f97a..0ee9897451 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class OutStreamParam(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py index 3cb4332b8b..e82b4ff03b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class PredicateBlockFunctions(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py index 85ac788643..096a0d91d1 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class PrintAnnotation(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py index d8ef5f0144..cdedcf4eed 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class PrintRegImmShift(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py index fa990b4474..7ca8dec07a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class QualifiedIdentifier(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py index a46a5e7875..396c09e0b3 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py @@ -1,10 +1,10 @@ import re +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class ReferencesDecl(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py index 0e59e06682..955e41e06a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class RegClassContains(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py index 7170e1ee4a..f756555019 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class STIArgument(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py index ead593c67d..0980919a08 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class STIFeatureBits(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py index 23f0fedd3e..f53a4fc8e7 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class SubtargetInfoParam(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py index 2d33f0e8c6..887ebb95dd 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class SetOpcode(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py index bd50fb742e..9d2df5b159 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py @@ -1,7 +1,8 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import TemplateCollector -from tree_sitter import Node class SignExtend(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py index 433416bb83..406e9b83fd 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py @@ -1,13 +1,13 @@ import re +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import ( get_function_params_of_node, get_text, ) from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class SizeAssignment(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py index 582ee7a795..b4d231ae6a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py @@ -1,6 +1,7 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node class StreamOperations(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py index 090c0b3583..d088aac0c5 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py @@ -1,12 +1,13 @@ import logging as log +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import parse_function_capture from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import ( TemplateCollector, TemplateRefInstance, ) -from tree_sitter import Node class TemplateDeclaration(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py index 9f2d9be953..a13ff38165 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py @@ -1,6 +1,8 @@ import logging as log import re +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import parse_function_capture from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import ( @@ -8,8 +10,6 @@ TemplateRefInstance, ) -from tree_sitter import Node - class TemplateDefinition(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py index 356bc4858e..6031175599 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py @@ -1,10 +1,10 @@ import logging as log +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch -from tree_sitter import Node - class TemplateParamDecl(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py index 9d8e43724d..caf6b8aa30 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py @@ -1,7 +1,8 @@ +from tree_sitter import Node + from autosync.cpptranslator.Patches.HelperMethods import get_text from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import TemplateCollector -from tree_sitter import Node class TemplateRefs(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py index cce0fb6579..09b2c752aa 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class UseMarkup(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py index 347a794369..c150df1f24 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py @@ -1,6 +1,7 @@ -from autosync.cpptranslator.Patches.Patch import Patch from tree_sitter import Node +from autosync.cpptranslator.Patches.Patch import Patch + class UsingDeclaration(Patch): """ diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index 3eab774459..272716ec00 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -4,14 +4,14 @@ import unittest from pathlib import Path +from tree_sitter import Node, Query + import autosync.cpptranslator.Patches as Patches from autosync.cpptranslator import CppTranslator from autosync.cpptranslator.Configurator import Configurator from autosync.Helper import get_path -from tree_sitter import Node, Query - class TestPatches(unittest.TestCase): @classmethod From e1fef6a55152b1d02b52eb52d1eb9909e9701f6e Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 05:47:25 -0500 Subject: [PATCH 09/41] Remove usort check because it differs locally to Github although same version is used. --- .github/workflows/auto-sync.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 26df7d264b..dabf0e089b 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -23,7 +23,6 @@ jobs: pip install . - name: Check formatting run: | - python3.11 -m usort check src/autosync python3.11 -m black --check src/autosync - name: CppTranslator - Patch tests run: | From 34933ae107f2152abf8ac2656c2f5a99e1c563c1 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 05:57:16 -0500 Subject: [PATCH 10/41] Move requirements for AS into pyproject.toml --- dev_requirements.txt | 4 ---- suite/auto-sync/pyproject.toml | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) delete mode 100644 dev_requirements.txt diff --git a/dev_requirements.txt b/dev_requirements.txt deleted file mode 100644 index 9904cf7c3d..0000000000 --- a/dev_requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -tree-sitter==0.20.1 -termcolor==2.2.0 -cmake==3.27.9 -ninja==1.11.1.1 diff --git a/suite/auto-sync/pyproject.toml b/suite/auto-sync/pyproject.toml index ec6d5b557e..f934f0da53 100644 --- a/suite/auto-sync/pyproject.toml +++ b/suite/auto-sync/pyproject.toml @@ -7,6 +7,9 @@ dependencies = [ "black >= 24.3.0", "usort >= 1.0.8", "setuptools >= 69.2.0", + "ninja >= 1.11.1.1", + "cmake >= 3.28.3", + "reuse >= 3.0.1", ] requires-python = ">= 3.11" From b9b6f47f8f1816211f358f772c7af9ec602aa131 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 05:57:32 -0500 Subject: [PATCH 11/41] Update README.md --- suite/auto-sync/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/suite/auto-sync/README.md b/suite/auto-sync/README.md index 2051168dff..eec3daa751 100644 --- a/suite/auto-sync/README.md +++ b/suite/auto-sync/README.md @@ -20,7 +20,6 @@ sudo apt install python3-venv # Setup virtual environment in Capstone root dir python3 -m venv ./.venv source ./.venv/bin/activate -pip3 install -r dev_requirements.txt ``` Clone C++ grammar @@ -28,6 +27,7 @@ Clone C++ grammar ``` cd suite/auto-sync/ git submodule update --init --recursive ./vendor/ +pip install -e . ``` ## Update @@ -35,7 +35,7 @@ git submodule update --init --recursive ./vendor/ Check if your architecture is supported. ``` -./Updater/ASUpdater.py -h +./src/autosync/ASUpdater.py -h ``` Clone Capstones LLVM fork and build `llvm-tblgen` @@ -55,7 +55,7 @@ cd ../../ Run the updater ``` -./Updater/ASUpdater.py -a +./src/autosync/ASUpdater.py -a ``` ## Post-processing steps From c674c6ad405162725c48e53f4abf4f41ee7259ef Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 06:05:58 -0500 Subject: [PATCH 12/41] Add tests for inc generation. --- .github/workflows/auto-sync.yml | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index dabf0e089b..b9c4bc84d6 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -16,14 +16,38 @@ jobs: uses: actions/setup-python@v4 with: python-version: '3.11' + - name: Check out repository uses: actions/checkout@v4 + + - name: Install clang-format + run: sudo apt install clang-format-18 + - name: Install auto-sync package run: | pip install . + - name: Check formatting run: | python3.11 -m black --check src/autosync + + - name: Build llvm-tblgen + run: | + git clone git@github.com:capstone-engine/llvm-capstone.git + cd llvm-capstone + mkdir build + cd build + cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm + cmake --build . --target llvm-tblgen --config Debug + cd ../../ + + - name: Test generationof inc files + run: | + ./src/autosync/ASUpdater.py -a AArch64 -s IncGen + ./src/autosync/ASUpdater.py -a Alpha -s IncGen + ./src/autosync/ASUpdater.py -a ARM -s IncGen + ./src/autosync/ASUpdater.py -a PPC -s IncGen + - name: CppTranslator - Patch tests run: | - python -m unittest discover src/autosync/cpptranslator/Tests/ \ No newline at end of file + python -m unittest discover src/autosync/cpptranslator/Tests/ From d0fc56c8e1a2cee5c753fa30ccd8037c6d4f47b3 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 06:11:20 -0500 Subject: [PATCH 13/41] Add clang-format to pypackage dependencies. --- .github/workflows/auto-sync.yml | 3 --- suite/auto-sync/README.md | 6 ------ suite/auto-sync/pyproject.toml | 1 + suite/auto-sync/src/autosync/Helper.py | 2 +- 4 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index b9c4bc84d6..8eda66f3ec 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -20,9 +20,6 @@ jobs: - name: Check out repository uses: actions/checkout@v4 - - name: Install clang-format - run: sudo apt install clang-format-18 - - name: Install auto-sync package run: | pip install . diff --git a/suite/auto-sync/README.md b/suite/auto-sync/README.md index eec3daa751..a6826b75dd 100644 --- a/suite/auto-sync/README.md +++ b/suite/auto-sync/README.md @@ -5,12 +5,6 @@ Unfortunately not all architectures are supported yet. ## Install dependencies -Install clang-format - -``` -sudo apt install clang-format-18 -``` - Setup Python environment and Tree-sitter ``` diff --git a/suite/auto-sync/pyproject.toml b/suite/auto-sync/pyproject.toml index f934f0da53..26b111bd52 100644 --- a/suite/auto-sync/pyproject.toml +++ b/suite/auto-sync/pyproject.toml @@ -10,6 +10,7 @@ dependencies = [ "ninja >= 1.11.1.1", "cmake >= 3.28.3", "reuse >= 3.0.1", + "clang-format >= 18.1.1", ] requires-python = ">= 3.11" diff --git a/suite/auto-sync/src/autosync/Helper.py b/suite/auto-sync/src/autosync/Helper.py index 2d5626a2e4..c37e91d1ee 100644 --- a/suite/auto-sync/src/autosync/Helper.py +++ b/suite/auto-sync/src/autosync/Helper.py @@ -142,7 +142,7 @@ def run_clang_format(out_paths: list[Path]): log.info(f"Format {out_file}") subprocess.run( [ - "clang-format-18", + "clang-format", f"-style=file:{get_path('{CS_CLANG_FORMAT_FILE}')}", "-i", out_file, From 56bb737d986dd029980109b778e86f8fb2dd235a Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 06:14:42 -0500 Subject: [PATCH 14/41] Use https to clone, not ssh --- .github/workflows/auto-sync.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 8eda66f3ec..62b0f4cdc8 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -30,7 +30,7 @@ jobs: - name: Build llvm-tblgen run: | - git clone git@github.com:capstone-engine/llvm-capstone.git + git clone https://github.com/capstone-engine/llvm-capstone.git cd llvm-capstone mkdir build cd build From a5516f89c3e2ab6c4c6d89b4d7eddf8495de7591 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 06:27:34 -0500 Subject: [PATCH 15/41] Rename HelerMethods -> Helper --- suite/auto-sync/src/autosync/ASUpdater.py | 1 + .../src/autosync/cpptranslator/Patches/AddCSDetail.py | 2 +- .../src/autosync/cpptranslator/Patches/AddOperand.py | 2 +- .../src/autosync/cpptranslator/Patches/BitCastStdArray.py | 2 +- .../src/autosync/cpptranslator/Patches/CheckDecoderStatus.py | 2 +- .../src/autosync/cpptranslator/Patches/ClassesDef.py | 2 +- .../autosync/cpptranslator/Patches/ConstMCInstParameter.py | 2 +- .../src/autosync/cpptranslator/Patches/ConstMCOperand.py | 2 +- .../src/autosync/cpptranslator/Patches/CppInitCast.py | 2 +- .../src/autosync/cpptranslator/Patches/CreateOperand0.py | 2 +- .../src/autosync/cpptranslator/Patches/CreateOperand1.py | 2 +- .../cpptranslator/Patches/DeclarationInConditionClause.py | 2 +- .../src/autosync/cpptranslator/Patches/DecodeInstruction.py | 2 +- .../src/autosync/cpptranslator/Patches/FeatureBits.py | 2 +- .../src/autosync/cpptranslator/Patches/FieldFromInstr.py | 5 +---- .../src/autosync/cpptranslator/Patches/GetNumOperands.py | 2 +- .../src/autosync/cpptranslator/Patches/GetOpcode.py | 2 +- .../src/autosync/cpptranslator/Patches/GetOperand.py | 2 +- .../src/autosync/cpptranslator/Patches/GetOperandRegImm.py | 2 +- .../src/autosync/cpptranslator/Patches/GetRegClass.py | 2 +- .../src/autosync/cpptranslator/Patches/GetRegFromClass.py | 2 +- .../src/autosync/cpptranslator/Patches/GetSubReg.py | 2 +- .../cpptranslator/Patches/{HelperMethods.py => Helper.py} | 0 .../auto-sync/src/autosync/cpptranslator/Patches/Includes.py | 2 +- .../autosync/cpptranslator/Patches/InlineToStaticInline.py | 2 +- .../src/autosync/cpptranslator/Patches/IsOptionalDef.py | 2 +- .../src/autosync/cpptranslator/Patches/IsPredicate.py | 2 +- .../auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py | 2 +- .../src/autosync/cpptranslator/Patches/LLVMunreachable.py | 2 +- .../src/autosync/cpptranslator/Patches/MethodToFunctions.py | 2 +- .../autosync/cpptranslator/Patches/MethodTypeQualifier.py | 2 +- .../src/autosync/cpptranslator/Patches/NamespaceAnon.py | 2 +- .../src/autosync/cpptranslator/Patches/NamespaceArch.py | 2 +- .../src/autosync/cpptranslator/Patches/NamespaceLLVM.py | 2 +- .../src/autosync/cpptranslator/Patches/OutStreamParam.py | 2 +- .../cpptranslator/Patches/PredicateBlockFunctions.py | 2 +- .../src/autosync/cpptranslator/Patches/PrintRegImmShift.py | 2 +- .../autosync/cpptranslator/Patches/QualifiedIdentifier.py | 2 +- .../src/autosync/cpptranslator/Patches/ReferencesDecl.py | 2 +- .../src/autosync/cpptranslator/Patches/RegClassContains.py | 2 +- .../src/autosync/cpptranslator/Patches/STIArgument.py | 2 +- .../src/autosync/cpptranslator/Patches/STIFeatureBits.py | 2 +- .../src/autosync/cpptranslator/Patches/STParameter.py | 2 +- .../src/autosync/cpptranslator/Patches/SetOpcode.py | 2 +- .../src/autosync/cpptranslator/Patches/SignExtend.py | 2 +- .../src/autosync/cpptranslator/Patches/SizeAssignments.py | 5 +---- .../src/autosync/cpptranslator/Patches/StreamOperation.py | 2 +- .../autosync/cpptranslator/Patches/TemplateDeclaration.py | 2 +- .../src/autosync/cpptranslator/Patches/TemplateDefinition.py | 2 +- .../src/autosync/cpptranslator/Patches/TemplateParamDecl.py | 2 +- .../src/autosync/cpptranslator/Patches/TemplateRefs.py | 2 +- .../src/autosync/cpptranslator/TemplateCollector.py | 2 +- 52 files changed, 51 insertions(+), 56 deletions(-) rename suite/auto-sync/src/autosync/cpptranslator/Patches/{HelperMethods.py => Helper.py} (100%) diff --git a/suite/auto-sync/src/autosync/ASUpdater.py b/suite/auto-sync/src/autosync/ASUpdater.py index 5246819f45..64ea144bc1 100755 --- a/suite/auto-sync/src/autosync/ASUpdater.py +++ b/suite/auto-sync/src/autosync/ASUpdater.py @@ -10,6 +10,7 @@ from enum import StrEnum from pathlib import Path +from autosync.cpptranslator.Configurator import Configurator from autosync.cpptranslator.CppTranslator import Translator from autosync.HeaderPatcher import HeaderPatcher from autosync.Helper import check_py_version, convert_loglevel, fail_exit, get_path diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py index d80cbf30d2..33cf87c557 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py @@ -3,7 +3,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import ( +from autosync.cpptranslator.Patches.Helper import ( get_MCInst_var_name, get_text, template_param_list_to_dict, diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py index a949139985..c85d9a41ec 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py index 0fd4f8272e..53b00a6b6f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py index 395ee55cf6..5e3f22c798 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py index 7f806fa2be..f0fd31b7fc 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py @@ -3,7 +3,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py index 49e0db275d..c65c51dd6d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py index 44ac0bf9eb..b10dad7a05 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py index ca9de65810..fe772ce20d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py index 0503f249da..9e5792fdcf 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py @@ -2,7 +2,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py index 53e3562401..8f8382093d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py @@ -2,7 +2,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text +from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py index 471ae31a47..ca70407ba2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text +from autosync.cpptranslator.Patches.Helper import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py index b6c0ee63e4..c13120f61d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py index 09c3404115..21172d4d49 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text +from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py index d228063f6b..5ecd59e9d7 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py @@ -3,10 +3,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import ( - get_function_params_of_node, - get_text, -) +from autosync.cpptranslator.Patches.Helper import get_function_params_of_node, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py index 0a3f7192a7..09b1b5eb07 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py index 2ba9f95fc6..7952e3b1f2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py index 27e0dce196..e860cacba0 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py index d76371868f..4fe1e0a666 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text +from autosync.cpptranslator.Patches.Helper import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py index 831a1bbd25..56c981fa01 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import ( +from autosync.cpptranslator.Patches.Helper import ( get_capture_node, get_MCInst_var_name, get_text, diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py index 56d08fe2ef..22055c2fad 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text +from autosync.cpptranslator.Patches.Helper import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py index 8ce0002a19..6f59470347 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text +from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Helper.py similarity index 100% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/HelperMethods.py rename to suite/auto-sync/src/autosync/cpptranslator/Patches/Helper.py diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py index ffae8a99c4..127359fe25 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py @@ -2,7 +2,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py index 0698d05c03..dd89078a45 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py index 1793ae95a3..397efdc4a2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py index 8c71dbda10..2184d029d2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py index 0376dd6849..2c3d6261f6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py index 4e07bd1c0c..7a181df3da 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py index 4377fd30e8..74616cb04f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py index 056eb3de56..c35b59e819 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py index 5c5f7a0be4..1580ce06b1 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py index 3862c361a8..8b09573a2c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import ( +from autosync.cpptranslator.Patches.Helper import ( get_text, namespace_enum, namespace_fcn_def, diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py index a8d5c4cb8d..234309f108 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py index 0ee9897451..d4655c7ef9 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py index e82b4ff03b..c7879a32ed 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text +from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py index cdedcf4eed..0028cb6971 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_MCInst_var_name, get_text +from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py index 7ca8dec07a..3e57c42144 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py index 396c09e0b3..176f60e88c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py @@ -2,7 +2,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py index 955e41e06a..d4e816fa3d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_capture_node, get_text +from autosync.cpptranslator.Patches.Helper import get_capture_node, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py index f756555019..da4271fbce 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py index 0980919a08..d585614a58 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py index f53a4fc8e7..39775f8b1b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py index 887ebb95dd..4609c038eb 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py index 9d2df5b159..00fe1de544 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import TemplateCollector diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py index 406e9b83fd..a9e20233b2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py @@ -2,10 +2,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import ( - get_function_params_of_node, - get_text, -) +from autosync.cpptranslator.Patches.Helper import get_function_params_of_node, get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py index b4d231ae6a..fdae2e02f5 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py index d088aac0c5..bf54440770 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py @@ -2,7 +2,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import parse_function_capture +from autosync.cpptranslator.Patches.Helper import parse_function_capture from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import ( TemplateCollector, diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py index a13ff38165..6220ac1147 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py @@ -3,7 +3,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import parse_function_capture +from autosync.cpptranslator.Patches.Helper import parse_function_capture from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import ( TemplateCollector, diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py index 6031175599..aeec604322 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py @@ -2,7 +2,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py index caf6b8aa30..2e85439918 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text from autosync.cpptranslator.Patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import TemplateCollector diff --git a/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py index ab91ecc04b..a02e461301 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py +++ b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py @@ -4,7 +4,7 @@ from tree_sitter import Language, Node, Parser, Query -from autosync.cpptranslator.Patches.HelperMethods import get_text +from autosync.cpptranslator.Patches.Helper import get_text class TemplateRefInstance: From 6ebfc7b94639d4429f13951bfb6a1d469fe920ac Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 06:35:13 -0500 Subject: [PATCH 16/41] Make patches directory a submodule for pip install . --- suite/auto-sync/pyproject.toml | 2 +- .../autosync/cpptranslator/CppTranslator.py | 120 +++++++++--------- .../cpptranslator/TemplateCollector.py | 2 +- .../{Patches => patches}/AddCSDetail.py | 4 +- .../{Patches => patches}/AddOperand.py | 4 +- .../{Patches => patches}/Assert.py | 2 +- .../{Patches => patches}/BitCastStdArray.py | 4 +- .../CheckDecoderStatus.py | 4 +- .../ClassConstructorDef.py | 2 +- .../{Patches => patches}/ClassesDef.py | 4 +- .../ConstMCInstParameter.py | 4 +- .../{Patches => patches}/ConstMCOperand.py | 4 +- .../{Patches => patches}/CppInitCast.py | 4 +- .../{Patches => patches}/CreateOperand0.py | 4 +- .../{Patches => patches}/CreateOperand1.py | 4 +- .../DeclarationInConditionClause.py | 4 +- .../{Patches => patches}/DecodeInstruction.py | 4 +- .../{Patches => patches}/DecoderCast.py | 2 +- .../{Patches => patches}/DecoderParameter.py | 2 +- .../{Patches => patches}/FallThrough.py | 2 +- .../{Patches => patches}/FeatureBits.py | 4 +- .../{Patches => patches}/FeatureBitsDecl.py | 2 +- .../{Patches => patches}/FieldFromInstr.py | 4 +- .../{Patches => patches}/GetNumOperands.py | 4 +- .../{Patches => patches}/GetOpcode.py | 4 +- .../{Patches => patches}/GetOperand.py | 4 +- .../{Patches => patches}/GetOperandRegImm.py | 4 +- .../{Patches => patches}/GetRegClass.py | 4 +- .../{Patches => patches}/GetRegFromClass.py | 4 +- .../{Patches => patches}/GetSubReg.py | 4 +- .../{Patches => patches}/Helper.py | 0 .../{Patches => patches}/Includes.py | 4 +- .../InlineToStaticInline.py | 4 +- .../{Patches => patches}/IsOptionalDef.py | 4 +- .../{Patches => patches}/IsPredicate.py | 4 +- .../{Patches => patches}/IsRegImm.py | 4 +- .../{Patches => patches}/LLVMFallThrough.py | 2 +- .../{Patches => patches}/LLVMunreachable.py | 4 +- .../{Patches => patches}/MethodToFunctions.py | 4 +- .../MethodTypeQualifier.py | 4 +- .../{Patches => patches}/NamespaceAnon.py | 4 +- .../{Patches => patches}/NamespaceArch.py | 4 +- .../{Patches => patches}/NamespaceLLVM.py | 4 +- .../{Patches => patches}/OutStreamParam.py | 4 +- .../{Patches => patches}/Patch.py | 0 .../PredicateBlockFunctions.py | 4 +- .../{Patches => patches}/PrintAnnotation.py | 2 +- .../{Patches => patches}/PrintRegImmShift.py | 4 +- .../QualifiedIdentifier.py | 4 +- .../{Patches => patches}/ReferencesDecl.py | 4 +- .../{Patches => patches}/RegClassContains.py | 4 +- .../{Patches => patches}/STIArgument.py | 4 +- .../{Patches => patches}/STIFeatureBits.py | 4 +- .../{Patches => patches}/STParameter.py | 4 +- .../{Patches => patches}/SetOpcode.py | 4 +- .../{Patches => patches}/SignExtend.py | 4 +- .../{Patches => patches}/SizeAssignments.py | 4 +- .../{Patches => patches}/StreamOperation.py | 4 +- .../TemplateDeclaration.py | 4 +- .../TemplateDefinition.py | 4 +- .../{Patches => patches}/TemplateParamDecl.py | 4 +- .../{Patches => patches}/TemplateRefs.py | 4 +- .../{Patches => patches}/UseMarkup.py | 2 +- .../{Patches => patches}/UsingDeclaration.py | 2 +- .../cpptranslator/patches/__init__.py | 0 65 files changed, 170 insertions(+), 170 deletions(-) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/AddCSDetail.py (97%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/AddOperand.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/Assert.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/BitCastStdArray.py (95%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/CheckDecoderStatus.py (89%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/ClassConstructorDef.py (92%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/ClassesDef.py (92%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/ConstMCInstParameter.py (88%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/ConstMCOperand.py (88%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/CppInitCast.py (88%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/CreateOperand0.py (94%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/CreateOperand1.py (95%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/DeclarationInConditionClause.py (92%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/DecodeInstruction.py (93%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/DecoderCast.py (94%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/DecoderParameter.py (93%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/FallThrough.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/FeatureBits.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/FeatureBitsDecl.py (92%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/FieldFromInstr.py (95%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/GetNumOperands.py (89%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/GetOpcode.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/GetOperand.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/GetOperandRegImm.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/GetRegClass.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/GetRegFromClass.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/GetSubReg.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/Helper.py (100%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/Includes.py (98%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/InlineToStaticInline.py (89%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/IsOptionalDef.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/IsPredicate.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/IsRegImm.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/LLVMFallThrough.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/LLVMunreachable.py (87%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/MethodToFunctions.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/MethodTypeQualifier.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/NamespaceAnon.py (86%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/NamespaceArch.py (94%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/NamespaceLLVM.py (87%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/OutStreamParam.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/Patch.py (100%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/PredicateBlockFunctions.py (92%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/PrintAnnotation.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/PrintRegImmShift.py (89%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/QualifiedIdentifier.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/ReferencesDecl.py (87%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/RegClassContains.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/STIArgument.py (88%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/STIFeatureBits.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/STParameter.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/SetOpcode.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/SignExtend.py (92%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/SizeAssignments.py (89%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/StreamOperation.py (97%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/TemplateDeclaration.py (95%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/TemplateDefinition.py (95%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/TemplateParamDecl.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/TemplateRefs.py (91%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/UseMarkup.py (90%) rename suite/auto-sync/src/autosync/cpptranslator/{Patches => patches}/UsingDeclaration.py (90%) create mode 100644 suite/auto-sync/src/autosync/cpptranslator/patches/__init__.py diff --git a/suite/auto-sync/pyproject.toml b/suite/auto-sync/pyproject.toml index 26b111bd52..0e934732fc 100644 --- a/suite/auto-sync/pyproject.toml +++ b/suite/auto-sync/pyproject.toml @@ -15,5 +15,5 @@ dependencies = [ requires-python = ">= 3.11" [tool.setuptools] -packages = ["autosync", "autosync.cpptranslator"] +packages = ["autosync", "autosync.cpptranslator", "autosync.cpptranslator.patches"] package-dir = {"" = "src"} diff --git a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py index 6e1656c6f0..40b16b6ac5 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py @@ -8,70 +8,70 @@ from tree_sitter import Language, Node, Parser, Query, Tree from autosync.cpptranslator.Configurator import Configurator -from autosync.cpptranslator.Patches.AddCSDetail import AddCSDetail -from autosync.cpptranslator.Patches.AddOperand import AddOperand -from autosync.cpptranslator.Patches.Assert import Assert -from autosync.cpptranslator.Patches.BitCastStdArray import BitCastStdArray -from autosync.cpptranslator.Patches.CheckDecoderStatus import CheckDecoderStatus -from autosync.cpptranslator.Patches.ClassConstructorDef import ClassConstructorDef -from autosync.cpptranslator.Patches.ClassesDef import ClassesDef -from autosync.cpptranslator.Patches.ConstMCInstParameter import ConstMCInstParameter -from autosync.cpptranslator.Patches.ConstMCOperand import ConstMCOperand -from autosync.cpptranslator.Patches.CppInitCast import CppInitCast -from autosync.cpptranslator.Patches.CreateOperand0 import CreateOperand0 -from autosync.cpptranslator.Patches.CreateOperand1 import CreateOperand1 -from autosync.cpptranslator.Patches.DeclarationInConditionClause import ( +from autosync.cpptranslator.patches.AddCSDetail import AddCSDetail +from autosync.cpptranslator.patches.AddOperand import AddOperand +from autosync.cpptranslator.patches.Assert import Assert +from autosync.cpptranslator.patches.BitCastStdArray import BitCastStdArray +from autosync.cpptranslator.patches.CheckDecoderStatus import CheckDecoderStatus +from autosync.cpptranslator.patches.ClassConstructorDef import ClassConstructorDef +from autosync.cpptranslator.patches.ClassesDef import ClassesDef +from autosync.cpptranslator.patches.ConstMCInstParameter import ConstMCInstParameter +from autosync.cpptranslator.patches.ConstMCOperand import ConstMCOperand +from autosync.cpptranslator.patches.CppInitCast import CppInitCast +from autosync.cpptranslator.patches.CreateOperand0 import CreateOperand0 +from autosync.cpptranslator.patches.CreateOperand1 import CreateOperand1 +from autosync.cpptranslator.patches.DeclarationInConditionClause import ( DeclarationInConditionalClause, ) -from autosync.cpptranslator.Patches.DecodeInstruction import DecodeInstruction -from autosync.cpptranslator.Patches.DecoderCast import DecoderCast -from autosync.cpptranslator.Patches.DecoderParameter import DecoderParameter -from autosync.cpptranslator.Patches.FallThrough import FallThrough -from autosync.cpptranslator.Patches.FeatureBits import FeatureBits -from autosync.cpptranslator.Patches.FeatureBitsDecl import FeatureBitsDecl -from autosync.cpptranslator.Patches.FieldFromInstr import FieldFromInstr -from autosync.cpptranslator.Patches.GetNumOperands import GetNumOperands -from autosync.cpptranslator.Patches.GetOpcode import GetOpcode -from autosync.cpptranslator.Patches.GetOperand import GetOperand -from autosync.cpptranslator.Patches.GetOperandRegImm import GetOperandRegImm -from autosync.cpptranslator.Patches.GetRegClass import GetRegClass -from autosync.cpptranslator.Patches.GetRegFromClass import GetRegFromClass -from autosync.cpptranslator.Patches.GetSubReg import GetSubReg -from autosync.cpptranslator.Patches.Includes import Includes -from autosync.cpptranslator.Patches.InlineToStaticInline import InlineToStaticInline -from autosync.cpptranslator.Patches.IsOptionalDef import IsOptionalDef -from autosync.cpptranslator.Patches.IsPredicate import IsPredicate -from autosync.cpptranslator.Patches.IsRegImm import IsOperandRegImm -from autosync.cpptranslator.Patches.LLVMFallThrough import LLVMFallThrough -from autosync.cpptranslator.Patches.LLVMunreachable import LLVMUnreachable -from autosync.cpptranslator.Patches.MethodToFunctions import MethodToFunction -from autosync.cpptranslator.Patches.MethodTypeQualifier import MethodTypeQualifier -from autosync.cpptranslator.Patches.NamespaceAnon import NamespaceAnon -from autosync.cpptranslator.Patches.NamespaceArch import NamespaceArch -from autosync.cpptranslator.Patches.NamespaceLLVM import NamespaceLLVM -from autosync.cpptranslator.Patches.OutStreamParam import OutStreamParam -from autosync.cpptranslator.Patches.Patch import Patch -from autosync.cpptranslator.Patches.PredicateBlockFunctions import ( +from autosync.cpptranslator.patches.DecodeInstruction import DecodeInstruction +from autosync.cpptranslator.patches.DecoderCast import DecoderCast +from autosync.cpptranslator.patches.DecoderParameter import DecoderParameter +from autosync.cpptranslator.patches.FallThrough import FallThrough +from autosync.cpptranslator.patches.FeatureBits import FeatureBits +from autosync.cpptranslator.patches.FeatureBitsDecl import FeatureBitsDecl +from autosync.cpptranslator.patches.FieldFromInstr import FieldFromInstr +from autosync.cpptranslator.patches.GetNumOperands import GetNumOperands +from autosync.cpptranslator.patches.GetOpcode import GetOpcode +from autosync.cpptranslator.patches.GetOperand import GetOperand +from autosync.cpptranslator.patches.GetOperandRegImm import GetOperandRegImm +from autosync.cpptranslator.patches.GetRegClass import GetRegClass +from autosync.cpptranslator.patches.GetRegFromClass import GetRegFromClass +from autosync.cpptranslator.patches.GetSubReg import GetSubReg +from autosync.cpptranslator.patches.Includes import Includes +from autosync.cpptranslator.patches.InlineToStaticInline import InlineToStaticInline +from autosync.cpptranslator.patches.IsOptionalDef import IsOptionalDef +from autosync.cpptranslator.patches.IsPredicate import IsPredicate +from autosync.cpptranslator.patches.IsRegImm import IsOperandRegImm +from autosync.cpptranslator.patches.LLVMFallThrough import LLVMFallThrough +from autosync.cpptranslator.patches.LLVMunreachable import LLVMUnreachable +from autosync.cpptranslator.patches.MethodToFunctions import MethodToFunction +from autosync.cpptranslator.patches.MethodTypeQualifier import MethodTypeQualifier +from autosync.cpptranslator.patches.NamespaceAnon import NamespaceAnon +from autosync.cpptranslator.patches.NamespaceArch import NamespaceArch +from autosync.cpptranslator.patches.NamespaceLLVM import NamespaceLLVM +from autosync.cpptranslator.patches.OutStreamParam import OutStreamParam +from autosync.cpptranslator.patches.Patch import Patch +from autosync.cpptranslator.patches.PredicateBlockFunctions import ( PredicateBlockFunctions, ) -from autosync.cpptranslator.Patches.PrintAnnotation import PrintAnnotation -from autosync.cpptranslator.Patches.PrintRegImmShift import PrintRegImmShift -from autosync.cpptranslator.Patches.QualifiedIdentifier import QualifiedIdentifier -from autosync.cpptranslator.Patches.ReferencesDecl import ReferencesDecl -from autosync.cpptranslator.Patches.RegClassContains import RegClassContains -from autosync.cpptranslator.Patches.SetOpcode import SetOpcode -from autosync.cpptranslator.Patches.SignExtend import SignExtend -from autosync.cpptranslator.Patches.SizeAssignments import SizeAssignment -from autosync.cpptranslator.Patches.STIArgument import STIArgument -from autosync.cpptranslator.Patches.STIFeatureBits import STIFeatureBits -from autosync.cpptranslator.Patches.STParameter import SubtargetInfoParam -from autosync.cpptranslator.Patches.StreamOperation import StreamOperations -from autosync.cpptranslator.Patches.TemplateDeclaration import TemplateDeclaration -from autosync.cpptranslator.Patches.TemplateDefinition import TemplateDefinition -from autosync.cpptranslator.Patches.TemplateParamDecl import TemplateParamDecl -from autosync.cpptranslator.Patches.TemplateRefs import TemplateRefs -from autosync.cpptranslator.Patches.UseMarkup import UseMarkup -from autosync.cpptranslator.Patches.UsingDeclaration import UsingDeclaration +from autosync.cpptranslator.patches.PrintAnnotation import PrintAnnotation +from autosync.cpptranslator.patches.PrintRegImmShift import PrintRegImmShift +from autosync.cpptranslator.patches.QualifiedIdentifier import QualifiedIdentifier +from autosync.cpptranslator.patches.ReferencesDecl import ReferencesDecl +from autosync.cpptranslator.patches.RegClassContains import RegClassContains +from autosync.cpptranslator.patches.SetOpcode import SetOpcode +from autosync.cpptranslator.patches.SignExtend import SignExtend +from autosync.cpptranslator.patches.SizeAssignments import SizeAssignment +from autosync.cpptranslator.patches.STIArgument import STIArgument +from autosync.cpptranslator.patches.STIFeatureBits import STIFeatureBits +from autosync.cpptranslator.patches.STParameter import SubtargetInfoParam +from autosync.cpptranslator.patches.StreamOperation import StreamOperations +from autosync.cpptranslator.patches.TemplateDeclaration import TemplateDeclaration +from autosync.cpptranslator.patches.TemplateDefinition import TemplateDefinition +from autosync.cpptranslator.patches.TemplateParamDecl import TemplateParamDecl +from autosync.cpptranslator.patches.TemplateRefs import TemplateRefs +from autosync.cpptranslator.patches.UseMarkup import UseMarkup +from autosync.cpptranslator.patches.UsingDeclaration import UsingDeclaration from autosync.cpptranslator.TemplateCollector import TemplateCollector from autosync.Helper import ( convert_loglevel, diff --git a/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py index a02e461301..b0543756e3 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py +++ b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py @@ -4,7 +4,7 @@ from tree_sitter import Language, Node, Parser, Query -from autosync.cpptranslator.Patches.Helper import get_text +from autosync.cpptranslator.patches.Helper import get_text class TemplateRefInstance: diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py b/suite/auto-sync/src/autosync/cpptranslator/patches/AddCSDetail.py similarity index 97% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/AddCSDetail.py index 33cf87c557..c807f62fd1 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddCSDetail.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/AddCSDetail.py @@ -3,12 +3,12 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import ( +from autosync.cpptranslator.patches.Helper import ( get_MCInst_var_name, get_text, template_param_list_to_dict, ) -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class AddCSDetail(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py b/suite/auto-sync/src/autosync/cpptranslator/patches/AddOperand.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/AddOperand.py index c85d9a41ec..5f75102516 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/AddOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/AddOperand.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class AddOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Assert.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/Assert.py index ada0a786a7..cfdcb8e712 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/Assert.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Assert.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class Assert(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py b/suite/auto-sync/src/autosync/cpptranslator/patches/BitCastStdArray.py similarity index 95% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/BitCastStdArray.py index 53b00a6b6f..bb725935c4 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/BitCastStdArray.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/BitCastStdArray.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class BitCastStdArray(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CheckDecoderStatus.py similarity index 89% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/CheckDecoderStatus.py index 5e3f22c798..477ee1a1f5 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CheckDecoderStatus.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CheckDecoderStatus.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class CheckDecoderStatus(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ClassConstructorDef.py similarity index 92% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/ClassConstructorDef.py index 4b06a0bca6..47f4b96a08 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassConstructorDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ClassConstructorDef.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class ClassConstructorDef(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ClassesDef.py similarity index 92% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/ClassesDef.py index f0fd31b7fc..45f753d85a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ClassesDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ClassesDef.py @@ -3,8 +3,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class ClassesDef(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCInstParameter.py similarity index 88% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCInstParameter.py index c65c51dd6d..4920b0de6a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCInstParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCInstParameter.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class ConstMCInstParameter(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCOperand.py similarity index 88% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCOperand.py index b10dad7a05..1b844b4c73 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ConstMCOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCOperand.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class ConstMCOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CppInitCast.py similarity index 88% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/CppInitCast.py index fe772ce20d..ef125823b0 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CppInitCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CppInitCast.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class CppInitCast(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand0.py similarity index 94% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand0.py index 9e5792fdcf..7f87f105a0 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand0.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand0.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class CreateOperand0(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py similarity index 95% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py index 8f8382093d..2da8967036 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/CreateOperand1.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text +from autosync.cpptranslator.patches.Patch import Patch class CreateOperand1(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py b/suite/auto-sync/src/autosync/cpptranslator/patches/DeclarationInConditionClause.py similarity index 92% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/DeclarationInConditionClause.py index ca70407ba2..ca7820234d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DeclarationInConditionClause.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/DeclarationInConditionClause.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_capture_node, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_capture_node, get_text +from autosync.cpptranslator.patches.Patch import Patch class DeclarationInConditionalClause(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py b/suite/auto-sync/src/autosync/cpptranslator/patches/DecodeInstruction.py similarity index 93% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/DecodeInstruction.py index c13120f61d..8f0cd725c6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecodeInstruction.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/DecodeInstruction.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class DecodeInstruction(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py b/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderCast.py similarity index 94% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/DecoderCast.py index 3417b46e3d..4bf86675b3 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderCast.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class DecoderCast(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py b/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderParameter.py similarity index 93% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/DecoderParameter.py index da2a05493d..f0d860a229 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/DecoderParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderParameter.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class DecoderParameter(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FallThrough.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/FallThrough.py index 95285712e1..19a3181bea 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FallThrough.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class FallThrough(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py index 21172d4d49..a9ca421cbe 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text +from autosync.cpptranslator.patches.Patch import Patch class FeatureBits(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBitsDecl.py similarity index 92% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBitsDecl.py index c091073582..c71ce578ea 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FeatureBitsDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBitsDecl.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class FeatureBitsDecl(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py similarity index 95% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py index 5ecd59e9d7..a0a4f384d7 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/FieldFromInstr.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py @@ -3,8 +3,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_function_params_of_node, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_function_params_of_node, get_text +from autosync.cpptranslator.patches.Patch import Patch class FieldFromInstr(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetNumOperands.py similarity index 89% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/GetNumOperands.py index 09b1b5eb07..13bc46eda8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetNumOperands.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetNumOperands.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class GetNumOperands(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOpcode.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/GetOpcode.py index 7952e3b1f2..304818c9f2 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOpcode.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class GetOpcode(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperand.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/GetOperand.py index e860cacba0..ca1363c2fa 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperand.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class GetOperand(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperandRegImm.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/GetOperandRegImm.py index 4fe1e0a666..57661c4f67 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetOperandRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperandRegImm.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_capture_node, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_capture_node, get_text +from autosync.cpptranslator.patches.Patch import Patch class GetOperandRegImm(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py index 56c981fa01..fcc3c23447 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py @@ -1,11 +1,11 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import ( +from autosync.cpptranslator.patches.Helper import ( get_capture_node, get_MCInst_var_name, get_text, ) -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class GetRegClass(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegFromClass.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/GetRegFromClass.py index 22055c2fad..e216ad3c4a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetRegFromClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegFromClass.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_capture_node, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_capture_node, get_text +from autosync.cpptranslator.patches.Patch import Patch class GetRegFromClass(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetSubReg.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/GetSubReg.py index 6f59470347..210b689185 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/GetSubReg.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetSubReg.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text +from autosync.cpptranslator.patches.Patch import Patch class GetSubReg(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Helper.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py similarity index 100% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/Helper.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py similarity index 98% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py index 127359fe25..c6fb4e22cd 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/Includes.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class Includes(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py b/suite/auto-sync/src/autosync/cpptranslator/patches/InlineToStaticInline.py similarity index 89% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/InlineToStaticInline.py index dd89078a45..ca628b47df 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/InlineToStaticInline.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/InlineToStaticInline.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class InlineToStaticInline(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py b/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py index 397efdc4a2..bc2406d4d4 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsOptionalDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class IsOptionalDef(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py b/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py index 2184d029d2..362ba58478 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsPredicate.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class IsPredicate(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/patches/IsRegImm.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/IsRegImm.py index 2c3d6261f6..fcfb6b4328 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/IsRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/IsRegImm.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class IsOperandRegImm(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMFallThrough.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/LLVMFallThrough.py index ed2cdccc3b..92a17d3276 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMFallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMFallThrough.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class LLVMFallThrough(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py b/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMunreachable.py similarity index 87% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/LLVMunreachable.py index 7a181df3da..a3702fd77c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/LLVMunreachable.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMunreachable.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class LLVMUnreachable(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/patches/MethodToFunctions.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/MethodToFunctions.py index 74616cb04f..da1d17cdd3 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodToFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/MethodToFunctions.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class MethodToFunction(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py b/suite/auto-sync/src/autosync/cpptranslator/patches/MethodTypeQualifier.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/MethodTypeQualifier.py index c35b59e819..2d12dec36d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/MethodTypeQualifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/MethodTypeQualifier.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class MethodTypeQualifier(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceAnon.py similarity index 86% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceAnon.py index 1580ce06b1..043c883d62 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceAnon.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceAnon.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class NamespaceAnon(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceArch.py similarity index 94% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceArch.py index 8b09573a2c..f6d3921557 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceArch.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceArch.py @@ -1,12 +1,12 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import ( +from autosync.cpptranslator.patches.Helper import ( get_text, namespace_enum, namespace_fcn_def, namespace_struct, ) -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class NamespaceArch(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py similarity index 87% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py index 234309f108..55e82077ed 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/NamespaceLLVM.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class NamespaceLLVM(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py b/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py index d4655c7ef9..dc8f4dbd56 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/OutStreamParam.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class OutStreamParam(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/Patch.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Patch.py similarity index 100% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/Patch.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/Patch.py diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/patches/PredicateBlockFunctions.py similarity index 92% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/PredicateBlockFunctions.py index c7879a32ed..f7effb33ad 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PredicateBlockFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/PredicateBlockFunctions.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text +from autosync.cpptranslator.patches.Patch import Patch class PredicateBlockFunctions(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py b/suite/auto-sync/src/autosync/cpptranslator/patches/PrintAnnotation.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/PrintAnnotation.py index 096a0d91d1..e0281204f5 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintAnnotation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/PrintAnnotation.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class PrintAnnotation(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py b/suite/auto-sync/src/autosync/cpptranslator/patches/PrintRegImmShift.py similarity index 89% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/PrintRegImmShift.py index 0028cb6971..96e6b8d1b4 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/PrintRegImmShift.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/PrintRegImmShift.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_MCInst_var_name, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text +from autosync.cpptranslator.patches.Patch import Patch class PrintRegImmShift(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py b/suite/auto-sync/src/autosync/cpptranslator/patches/QualifiedIdentifier.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/QualifiedIdentifier.py index 3e57c42144..a9e446df0f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/QualifiedIdentifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/QualifiedIdentifier.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class QualifiedIdentifier(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ReferencesDecl.py similarity index 87% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/ReferencesDecl.py index 176f60e88c..b6975694cc 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/ReferencesDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ReferencesDecl.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class ReferencesDecl(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py b/suite/auto-sync/src/autosync/cpptranslator/patches/RegClassContains.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/RegClassContains.py index d4e816fa3d..aee2a51bfb 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/RegClassContains.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/RegClassContains.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_capture_node, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_capture_node, get_text +from autosync.cpptranslator.patches.Patch import Patch class RegClassContains(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py b/suite/auto-sync/src/autosync/cpptranslator/patches/STIArgument.py similarity index 88% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/STIArgument.py index da4271fbce..6dbb98172b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIArgument.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/STIArgument.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class STIArgument(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py index d585614a58..063d3da0c3 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STIFeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class STIFeatureBits(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py b/suite/auto-sync/src/autosync/cpptranslator/patches/STParameter.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/STParameter.py index 39775f8b1b..1214ce0131 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/STParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/STParameter.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class SubtargetInfoParam(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/patches/SetOpcode.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/SetOpcode.py index 4609c038eb..a83df74d6b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/SetOpcode.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class SetOpcode(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py b/suite/auto-sync/src/autosync/cpptranslator/patches/SignExtend.py similarity index 92% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/SignExtend.py index 00fe1de544..769bb464c8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SignExtend.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/SignExtend.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import TemplateCollector diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py b/suite/auto-sync/src/autosync/cpptranslator/patches/SizeAssignments.py similarity index 89% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/SizeAssignments.py index a9e20233b2..282abebf54 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/SizeAssignments.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/SizeAssignments.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_function_params_of_node, get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_function_params_of_node, get_text +from autosync.cpptranslator.patches.Patch import Patch class SizeAssignment(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py b/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py similarity index 97% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py index fdae2e02f5..c5104346d8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/StreamOperation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class StreamOperations(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDeclaration.py similarity index 95% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDeclaration.py index bf54440770..94179f31be 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDeclaration.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import parse_function_capture -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import parse_function_capture +from autosync.cpptranslator.patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import ( TemplateCollector, TemplateRefInstance, diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDefinition.py similarity index 95% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDefinition.py index 6220ac1147..bf6b73099a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateDefinition.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDefinition.py @@ -3,8 +3,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import parse_function_capture -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import parse_function_capture +from autosync.cpptranslator.patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import ( TemplateCollector, TemplateRefInstance, diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateParamDecl.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/TemplateParamDecl.py index aeec604322..27fd9e559a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateParamDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateParamDecl.py @@ -2,8 +2,8 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch class TemplateParamDecl(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateRefs.py similarity index 91% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/TemplateRefs.py index 2e85439918..d7bcdac7d1 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/TemplateRefs.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateRefs.py @@ -1,7 +1,7 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Helper import get_text -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Helper import get_text +from autosync.cpptranslator.patches.Patch import Patch from autosync.cpptranslator.TemplateCollector import TemplateCollector diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py b/suite/auto-sync/src/autosync/cpptranslator/patches/UseMarkup.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/UseMarkup.py index 09b2c752aa..5cc9450649 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/UseMarkup.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/UseMarkup.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class UseMarkup(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/patches/UsingDeclaration.py similarity index 90% rename from suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py rename to suite/auto-sync/src/autosync/cpptranslator/patches/UsingDeclaration.py index c150df1f24..72dbfcb62a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Patches/UsingDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/UsingDeclaration.py @@ -1,6 +1,6 @@ from tree_sitter import Node -from autosync.cpptranslator.Patches.Patch import Patch +from autosync.cpptranslator.patches.Patch import Patch class UsingDeclaration(Patch): diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/__init__.py b/suite/auto-sync/src/autosync/cpptranslator/patches/__init__.py new file mode 100644 index 0000000000..e69de29bb2 From e9118a03081657627f6436774979798d1545abb3 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 06:37:33 -0500 Subject: [PATCH 17/41] Move llvm clone to vendor dir. --- suite/auto-sync/README.md | 2 +- suite/auto-sync/src/autosync/path_vars.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/suite/auto-sync/README.md b/suite/auto-sync/README.md index a6826b75dd..6297230dfb 100644 --- a/suite/auto-sync/README.md +++ b/suite/auto-sync/README.md @@ -35,7 +35,7 @@ Check if your architecture is supported. Clone Capstones LLVM fork and build `llvm-tblgen` ``` -git clone https://github.com/capstone-engine/llvm-capstone +git clone https://github.com/capstone-engine/llvm-capstone vendor/llvm_root/ cd llvm-capstone git checkout auto-sync mkdir build diff --git a/suite/auto-sync/src/autosync/path_vars.json b/suite/auto-sync/src/autosync/path_vars.json index cc4f3ebaf9..0cec2d364f 100644 --- a/suite/auto-sync/src/autosync/path_vars.json +++ b/suite/auto-sync/src/autosync/path_vars.json @@ -1,8 +1,8 @@ { - "{LLVM_ROOT}": "{AUTO_SYNC_ROOT}/llvm-capstone/", - "{LLVM_TARGET_DIR}": "{AUTO_SYNC_ROOT}/llvm-capstone/llvm/lib/Target/", - "{LLVM_TBLGEN_BIN}": "{AUTO_SYNC_ROOT}/llvm-capstone/build/bin/llvm-tblgen", - "{LLVM_INCLUDE_DIR}": "{AUTO_SYNC_ROOT}/llvm-capstone/llvm/include", + "{LLVM_ROOT}": "{AUTO_SYNC_ROOT}/vendor/llvm_root//", + "{LLVM_TARGET_DIR}": "{LLVM_ROOT}/llvm/lib/Target/", + "{LLVM_TBLGEN_BIN}": "{LLVM_ROOT}/build/bin/llvm-tblgen", + "{LLVM_INCLUDE_DIR}": "{LLVM_ROOT}/llvm/include", "{VENDOR_DIR}": "{AUTO_SYNC_ROOT}/vendor/", From e0c930faad1a55005c07161fb3d8ed32813acb36 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 07:32:27 -0500 Subject: [PATCH 18/41] Fix path issues (dirs no created automatically etc.) --- .github/workflows/auto-sync.yml | 6 +-- .../auto-sync/src/autosync/PathVarHandler.py | 39 ++++++++++++++--- .../autosync/cpptranslator/CppTranslator.py | 2 +- .../src/autosync/cpptranslator/Differ.py | 8 ++-- .../src/autosync/cpptranslator/README.md | 3 -- .../cpptranslator/Tests/test_config.json | 3 -- .../autosync/cpptranslator/arch_config.json | 3 -- suite/auto-sync/src/autosync/path_vars.json | 42 ++++++++++--------- 8 files changed, 62 insertions(+), 44 deletions(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 62b0f4cdc8..6d0a25aba7 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -30,13 +30,13 @@ jobs: - name: Build llvm-tblgen run: | - git clone https://github.com/capstone-engine/llvm-capstone.git - cd llvm-capstone + git clone https://github.com/capstone-engine/llvm-capstone.git vendor/llvm_root + cd vendor/llvm_root mkdir build cd build cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../llvm cmake --build . --target llvm-tblgen --config Debug - cd ../../ + cd ../../../ - name: Test generationof inc files run: | diff --git a/suite/auto-sync/src/autosync/PathVarHandler.py b/suite/auto-sync/src/autosync/PathVarHandler.py index a4fd30ccc8..8fd069c3e5 100644 --- a/suite/auto-sync/src/autosync/PathVarHandler.py +++ b/suite/auto-sync/src/autosync/PathVarHandler.py @@ -16,7 +16,6 @@ def __call__(cls, *args, **kwargs): class PathVarHandler(metaclass=Singleton): - paths = {} def __init__(self) -> None: try: @@ -30,6 +29,7 @@ def __init__(self) -> None: exit(1) repo_root = res.stdout.decode("utf8").strip("\n") # The main directories + self.paths: dict[str:Path] = dict() self.paths["{CS_ROOT}"] = Path(repo_root) self.paths["{AUTO_SYNC_ROOT}"] = Path(repo_root).joinpath("suite/auto-sync/") self.paths["{AUTO_SYNC_SRC}"] = self.paths["{AUTO_SYNC_ROOT}"].joinpath( @@ -41,8 +41,11 @@ def __init__(self) -> None: with open(path_config_file) as f: vars = json.load(f) + paths = vars["paths"] + create_during_runtime = vars["create_during_runtime"] + missing = list() - for p_name, path in vars.items(): + for p_name, path in paths.items(): resolved = path for var_id in re.findall(r"\{.+}", resolved): if var_id not in self.paths: @@ -50,11 +53,15 @@ def __init__(self) -> None: f"{var_id} hasn't been added to the PathVarsHandler, yet. The var must be defined in a previous entry." ) exit(1) - resolved = re.sub(var_id, str(self.paths[var_id]), resolved) + resolved: str = re.sub(var_id, str(self.paths[var_id]), resolved) log.debug(f"Set {p_name} = {resolved}") - if not Path(resolved).exists(): + if not Path(resolved).exists() and ( + p_name not in create_during_runtime + ): missing.append(resolved) - self.paths[p_name] = resolved + elif var_id in create_during_runtime: + self.create_path(var_id, resolved) + self.paths[p_name] = Path(resolved) if len(missing) > 0: log.fatal(f"Some paths from config file are missing!") for m in missing: @@ -69,5 +76,25 @@ def get_path(self, name: str) -> Path: def complete_path(self, path_str: str) -> Path: resolved = path_str for p_name in re.findall(r"\{.+}", path_str): - resolved = re.sub(p_name, self.get_path(p_name), resolved) + resolved = re.sub(p_name, str(self.get_path(p_name)), resolved) return Path(resolved) + + @staticmethod + def create_path(var_id: str, path: str): + pp = Path(path) + if pp.exists(): + return + + postfix = var_id.strip("}").split("_")[-1] + if postfix == "FILE": + if not pp.parent.exists(): + pp.parent.mkdir(parents=True) + pp.touch() + elif postfix == "DIR": + pp.mkdir(parents=True) + else: + from autosync.Helper import fail_exit + + fail_exit( + f"The var_id: {var_id} must end in _FILE or _DIR. It ends in '{postfix}'" + ) diff --git a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py index 40b16b6ac5..7a5730af8f 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py @@ -181,7 +181,7 @@ def __init__(self, configure: Configurator): self.src_paths: [Path] = [ get_path(sp["in"]) for sp in self.conf["files_to_translate"] ] - t_out_dir: Path = get_path(self.conf_general["translation_out_dir"]) + t_out_dir: Path = get_path("{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}") self.out_paths: [Path] = [ t_out_dir.joinpath(sp["out"]) for sp in self.conf["files_to_translate"] ] diff --git a/suite/auto-sync/src/autosync/cpptranslator/Differ.py b/suite/auto-sync/src/autosync/cpptranslator/Differ.py index 75a1c7851e..3f276fc7f9 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/Differ.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Differ.py @@ -176,7 +176,7 @@ def __init__(self, configurator: Configurator, no_auto_apply: bool): self.parser = self.configurator.get_parser() self.differ = dl.Differ() - t_out_dir: Path = get_path(self.conf_general["translation_out_dir"]) + t_out_dir: Path = get_path("{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}") self.translated_files = [ t_out_dir.joinpath(sp["out"]) for sp in self.conf_arch["files_to_translate"] ] @@ -191,9 +191,7 @@ def __init__(self, configurator: Configurator, no_auto_apply: bool): self.load_persistence_file() def load_persistence_file(self) -> None: - self.persistence_filepath = get_path( - self.conf_general["patch_persistence_file"] - ) + self.persistence_filepath = get_path("{CPP_TRANSLATOR_PATH_PERSISTENCE_FILE}") if not self.persistence_filepath.exists(): self.saved_patches = dict() return @@ -224,7 +222,7 @@ def copy_files(self) -> None: Copy translated files to diff directory for editing. """ log.info("Copy files for editing") - diff_dir: Path = get_path(self.conf_general["diff_out_dir"]) + diff_dir: Path = get_path("{CPP_TRANSLATOR_DIFF_OUT_DIR}") for f in self.translated_files: dest = diff_dir.joinpath(f.name) copy2(f, dest) diff --git a/suite/auto-sync/src/autosync/cpptranslator/README.md b/suite/auto-sync/src/autosync/cpptranslator/README.md index 243d41b052..c7c1c3701a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/README.md +++ b/suite/auto-sync/src/autosync/cpptranslator/README.md @@ -13,9 +13,6 @@ The configuration for each architecture is set in `arch_config.json`. The config values have the following meaning: - `General`: Settings valid for all architectures. - - `patch_persistent_file`: Path to the file which saves the selections from the `Differ`. - - `translation_out_dir`: Path to the directory where the `CppTranslator` stores its files. - - `diff_out_dir`: Path to the directory where the `Differ` stores its files. - `diff_color_new`: Color in the `Differ` for translated content. - `diff_color_old`: Color in the `Differ` for old/current Capstone content. - `diff_color_saved`: Color in the `Differ` for saved content. diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json index c5bc9e44f0..92d55e80a5 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json @@ -1,8 +1,5 @@ { "General": { - "patch_persistence_file": "", - "translation_out_dir": "", - "diff_out_dir": "", "diff_color_new": "green", "diff_color_old": "light_blue", "diff_color_saved": "yellow", diff --git a/suite/auto-sync/src/autosync/cpptranslator/arch_config.json b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json index 714c54451a..b33e9b1372 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/arch_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json @@ -1,8 +1,5 @@ { "General": { - "patch_persistence_file": "{CPP_TRANSLATOR_DIR}/saved_patches.json", - "translation_out_dir": "{BUILD_DIR}/translate_out/", - "diff_out_dir": "{BUILD_DIR}/diff_out/", "diff_color_new": "green", "diff_color_old": "light_blue", "diff_color_saved": "yellow", diff --git a/suite/auto-sync/src/autosync/path_vars.json b/suite/auto-sync/src/autosync/path_vars.json index 0cec2d364f..1a61077958 100644 --- a/suite/auto-sync/src/autosync/path_vars.json +++ b/suite/auto-sync/src/autosync/path_vars.json @@ -1,23 +1,25 @@ { - "{LLVM_ROOT}": "{AUTO_SYNC_ROOT}/vendor/llvm_root//", - "{LLVM_TARGET_DIR}": "{LLVM_ROOT}/llvm/lib/Target/", - "{LLVM_TBLGEN_BIN}": "{LLVM_ROOT}/build/bin/llvm-tblgen", - "{LLVM_INCLUDE_DIR}": "{LLVM_ROOT}/llvm/include", - - "{VENDOR_DIR}": "{AUTO_SYNC_ROOT}/vendor/", - - "{CPP_TRANSLATOR_DIR}": "{AUTO_SYNC_SRC}/cpptranslator/", - "{CPP_TRANSLATOR_CONFIG}": "{CPP_TRANSLATOR_DIR}/arch_config.json", - "{CPP_TRANSLATOR_TEST_DIR}": "{CPP_TRANSLATOR_DIR}/Tests/", - "{CPP_TRANSLATOR_TEST_CONFIG}": "{CPP_TRANSLATOR_TEST_DIR}/test_config.json", - "{INC_PATCH_DIR}": "{AUTO_SYNC_ROOT}/inc_patches/", - - "{CS_INCLUDE_DIR}": "{CS_ROOT}/include/capstone/", - "{CS_ARCH_MODULE_DIR}": "{CS_ROOT}/arch/", - "{CS_CLANG_FORMAT_FILE}": "{CS_ROOT}/.clang-format", - - "{BUILD_DIR}": "{AUTO_SYNC_ROOT}/build/", - "{C_INC_OUT_DIR}": "{BUILD_DIR}/llvm_c_inc/", - "{CPP_INC_OUT_DIR}": "{BUILD_DIR}/llvm_cpp_inc/" + "paths": { + "{LLVM_ROOT}": "{AUTO_SYNC_ROOT}/vendor/llvm_root//", + "{LLVM_TARGET_DIR}": "{LLVM_ROOT}/llvm/lib/Target/", + "{LLVM_TBLGEN_BIN}": "{LLVM_ROOT}/build/bin/llvm-tblgen", + "{LLVM_INCLUDE_DIR}": "{LLVM_ROOT}/llvm/include/", + "{VENDOR_DIR}": "{AUTO_SYNC_ROOT}/vendor/", + "{BUILD_DIR}": "{AUTO_SYNC_ROOT}/build/", + "{C_INC_OUT_DIR}": "{BUILD_DIR}/llvm_c_inc/", + "{CPP_INC_OUT_DIR}": "{BUILD_DIR}/llvm_cpp_inc/", + "{CPP_TRANSLATOR_DIR}": "{AUTO_SYNC_SRC}/cpptranslator/", + "{CPP_TRANSLATOR_CONFIG}": "{CPP_TRANSLATOR_DIR}/arch_config.json", + "{CPP_TRANSLATOR_TEST_DIR}": "{CPP_TRANSLATOR_DIR}/Tests/", + "{CPP_TRANSLATOR_TEST_CONFIG}": "{CPP_TRANSLATOR_TEST_DIR}/test_config.json", + "{CPP_TRANSLATOR_PATH_PERSISTENCE_FILE}": "{CPP_TRANSLATOR_DIR}/saved_patches.json", + "{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}": "{BUILD_DIR}/translate_out/", + "{CPP_TRANSLATOR_DIFF_OUT_DIR}": "{BUILD_DIR}/diff_out/", + "{INC_PATCH_DIR}": "{AUTO_SYNC_ROOT}/inc_patches/", + "{CS_INCLUDE_DIR}": "{CS_ROOT}/include/capstone/", + "{CS_ARCH_MODULE_DIR}": "{CS_ROOT}/arch/", + "{CS_CLANG_FORMAT_FILE}": "{CS_ROOT}/.clang-format" + }, + "create_during_runtime": ["{BUILD_DIR}", "{C_INC_OUT_DIR}", "{CPP_INC_OUT_DIR}", "{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}", "{CPP_TRANSLATOR_DIFF_OUT_DIR}"] } From e359e88188c87b585e795500c53f707ca3ba5021 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Thu, 21 Mar 2024 07:57:00 -0500 Subject: [PATCH 19/41] Add license info to auto-sync --- .reuse/dep5 | 10 ++++++++++ .reuse/reuse-bak/dep5 | 20 +++++++++++++++++++ .../templates/license-template.jinja2 | 9 +++++++++ LICENSES/BSD-3-Clause.txt | 11 ++++++++++ suite/auto-sync/README.md | 6 ++++++ suite/auto-sync/pyproject.toml | 4 ++++ suite/auto-sync/src/autosync/ASUpdater.py | 3 +++ suite/auto-sync/src/autosync/HeaderPatcher.py | 3 +++ suite/auto-sync/src/autosync/Helper.py | 3 +++ suite/auto-sync/src/autosync/IncGenerator.py | 3 +++ .../auto-sync/src/autosync/PathVarHandler.py | 3 +++ .../autosync/cpptranslator/Configurator.py | 3 +++ .../autosync/cpptranslator/CppTranslator.py | 4 ++++ .../src/autosync/cpptranslator/Differ.py | 4 ++++ .../src/autosync/cpptranslator/README.md | 5 +++++ .../cpptranslator/TemplateCollector.py | 3 +++ .../cpptranslator/Tests/test_patches.py | 4 ++++ .../cpptranslator/patches/AddCSDetail.py | 3 +++ .../cpptranslator/patches/AddOperand.py | 3 +++ .../autosync/cpptranslator/patches/Assert.py | 3 +++ .../cpptranslator/patches/BitCastStdArray.py | 3 +++ .../patches/CheckDecoderStatus.py | 3 +++ .../patches/ClassConstructorDef.py | 3 +++ .../cpptranslator/patches/ClassesDef.py | 3 +++ .../patches/ConstMCInstParameter.py | 3 +++ .../cpptranslator/patches/ConstMCOperand.py | 3 +++ .../cpptranslator/patches/CppInitCast.py | 3 +++ .../cpptranslator/patches/CreateOperand0.py | 3 +++ .../cpptranslator/patches/CreateOperand1.py | 3 +++ .../patches/DeclarationInConditionClause.py | 3 +++ .../patches/DecodeInstruction.py | 3 +++ .../cpptranslator/patches/DecoderCast.py | 3 +++ .../cpptranslator/patches/DecoderParameter.py | 3 +++ .../cpptranslator/patches/FallThrough.py | 3 +++ .../cpptranslator/patches/FeatureBits.py | 3 +++ .../cpptranslator/patches/FeatureBitsDecl.py | 3 +++ .../cpptranslator/patches/FieldFromInstr.py | 3 +++ .../cpptranslator/patches/GetNumOperands.py | 3 +++ .../cpptranslator/patches/GetOpcode.py | 3 +++ .../cpptranslator/patches/GetOperand.py | 3 +++ .../cpptranslator/patches/GetOperandRegImm.py | 3 +++ .../cpptranslator/patches/GetRegClass.py | 3 +++ .../cpptranslator/patches/GetRegFromClass.py | 3 +++ .../cpptranslator/patches/GetSubReg.py | 3 +++ .../autosync/cpptranslator/patches/Helper.py | 3 +++ .../cpptranslator/patches/Includes.py | 3 +++ .../patches/InlineToStaticInline.py | 3 +++ .../cpptranslator/patches/IsOptionalDef.py | 3 +++ .../cpptranslator/patches/IsPredicate.py | 3 +++ .../cpptranslator/patches/IsRegImm.py | 3 +++ .../cpptranslator/patches/LLVMFallThrough.py | 3 +++ .../cpptranslator/patches/LLVMunreachable.py | 3 +++ .../patches/MethodToFunctions.py | 3 +++ .../patches/MethodTypeQualifier.py | 3 +++ .../cpptranslator/patches/NamespaceAnon.py | 3 +++ .../cpptranslator/patches/NamespaceArch.py | 3 +++ .../cpptranslator/patches/NamespaceLLVM.py | 3 +++ .../cpptranslator/patches/OutStreamParam.py | 3 +++ .../autosync/cpptranslator/patches/Patch.py | 3 +++ .../patches/PredicateBlockFunctions.py | 3 +++ .../cpptranslator/patches/PrintAnnotation.py | 3 +++ .../cpptranslator/patches/PrintRegImmShift.py | 3 +++ .../patches/QualifiedIdentifier.py | 3 +++ .../cpptranslator/patches/ReferencesDecl.py | 3 +++ .../cpptranslator/patches/RegClassContains.py | 3 +++ .../cpptranslator/patches/STIArgument.py | 3 +++ .../cpptranslator/patches/STIFeatureBits.py | 3 +++ .../cpptranslator/patches/STParameter.py | 3 +++ .../cpptranslator/patches/SetOpcode.py | 3 +++ .../cpptranslator/patches/SignExtend.py | 3 +++ .../cpptranslator/patches/SizeAssignments.py | 3 +++ .../cpptranslator/patches/StreamOperation.py | 3 +++ .../patches/TemplateDeclaration.py | 3 +++ .../patches/TemplateDefinition.py | 3 +++ .../patches/TemplateParamDecl.py | 3 +++ .../cpptranslator/patches/TemplateRefs.py | 3 +++ .../cpptranslator/patches/UseMarkup.py | 3 +++ .../cpptranslator/patches/UsingDeclaration.py | 3 +++ 78 files changed, 281 insertions(+) create mode 100644 .reuse/dep5 create mode 100644 .reuse/reuse-bak/dep5 create mode 100644 .reuse/reuse-bak/templates/license-template.jinja2 create mode 100644 LICENSES/BSD-3-Clause.txt diff --git a/.reuse/dep5 b/.reuse/dep5 new file mode 100644 index 0000000000..fc755a7014 --- /dev/null +++ b/.reuse/dep5 @@ -0,0 +1,10 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: CapstoneEngine +Upstream-Contact: <> +Source: https://github.com/capstone-engine/capstone + +# Sample paragraph, commented out: +# +# Files: src/* +# Copyright: $YEAR $NAME <$CONTACT> +# License: ... diff --git a/.reuse/reuse-bak/dep5 b/.reuse/reuse-bak/dep5 new file mode 100644 index 0000000000..33b023fc42 --- /dev/null +++ b/.reuse/reuse-bak/dep5 @@ -0,0 +1,20 @@ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: CapstoneEngine +Source: https://github.com/capstone-engine/capstone + +Files: src/autosync/cpptranslator/Tests/test_config.json +Copyright: 2022 Rot127 +License: BSD-3 + +Files: src/autosync/cpptranslator/arch_config.json +Copyright: 2022 Rot127 +License: BSD-3 + +Files: src/autosync/cpptranslator/saved_patches.json +Copyright: 2022 Rot127 +License: BSD-3 + +Files: src/autosync/path_vars.json +Copyright: 2022 Rot127 +License: BSD-3 + diff --git a/.reuse/reuse-bak/templates/license-template.jinja2 b/.reuse/reuse-bak/templates/license-template.jinja2 new file mode 100644 index 0000000000..51a9c95680 --- /dev/null +++ b/.reuse/reuse-bak/templates/license-template.jinja2 @@ -0,0 +1,9 @@ +{% for copyright_line in copyright_lines %} +{{ copyright_line }} +{% endfor %} +{% for contributor_line in contributor_lines %} +SPDX-FileContributor: {{ contributor_line }} +{% endfor %} +{% for expression in spdx_expressions %} +SPDX-License-Identifier: {{ expression }} +{% endfor %} diff --git a/LICENSES/BSD-3-Clause.txt b/LICENSES/BSD-3-Clause.txt new file mode 100644 index 0000000000..ea890afbc7 --- /dev/null +++ b/LICENSES/BSD-3-Clause.txt @@ -0,0 +1,11 @@ +Copyright (c) . + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/suite/auto-sync/README.md b/suite/auto-sync/README.md index 6297230dfb..93d82d109e 100644 --- a/suite/auto-sync/README.md +++ b/suite/auto-sync/README.md @@ -1,3 +1,9 @@ + + # Architecture updater This is Capstones updater for some architectures. diff --git a/suite/auto-sync/pyproject.toml b/suite/auto-sync/pyproject.toml index 0e934732fc..ffa1f5aff5 100644 --- a/suite/auto-sync/pyproject.toml +++ b/suite/auto-sync/pyproject.toml @@ -1,3 +1,7 @@ +# Copyright © 2022 Rot127 +# Copyright © 2024 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + [project] name = "autosync" version = "0.1.0" diff --git a/suite/auto-sync/src/autosync/ASUpdater.py b/suite/auto-sync/src/autosync/ASUpdater.py index 64ea144bc1..4f952c1082 100755 --- a/suite/auto-sync/src/autosync/ASUpdater.py +++ b/suite/auto-sync/src/autosync/ASUpdater.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import argparse import logging as log diff --git a/suite/auto-sync/src/autosync/HeaderPatcher.py b/suite/auto-sync/src/autosync/HeaderPatcher.py index ab41d392bc..d8f5da0581 100755 --- a/suite/auto-sync/src/autosync/HeaderPatcher.py +++ b/suite/auto-sync/src/autosync/HeaderPatcher.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import argparse import logging as log import re diff --git a/suite/auto-sync/src/autosync/Helper.py b/suite/auto-sync/src/autosync/Helper.py index c37e91d1ee..86eeef882c 100644 --- a/suite/auto-sync/src/autosync/Helper.py +++ b/suite/auto-sync/src/autosync/Helper.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import hashlib import logging as log import shutil diff --git a/suite/auto-sync/src/autosync/IncGenerator.py b/suite/auto-sync/src/autosync/IncGenerator.py index 5ab79c3a92..f81351d538 100644 --- a/suite/auto-sync/src/autosync/IncGenerator.py +++ b/suite/auto-sync/src/autosync/IncGenerator.py @@ -1,5 +1,8 @@ #!/usr/bin/env python3 +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log import os import re diff --git a/suite/auto-sync/src/autosync/PathVarHandler.py b/suite/auto-sync/src/autosync/PathVarHandler.py index 8fd069c3e5..ffe9256866 100644 --- a/suite/auto-sync/src/autosync/PathVarHandler.py +++ b/suite/auto-sync/src/autosync/PathVarHandler.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import json import logging as log import re diff --git a/suite/auto-sync/src/autosync/cpptranslator/Configurator.py b/suite/auto-sync/src/autosync/cpptranslator/Configurator.py index e740c00435..ba19fa0de1 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Configurator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Configurator.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import json import logging as log from pathlib import Path diff --git a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py index 7a5730af8f..c6cd7b87b2 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 + +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import argparse import logging as log import sys diff --git a/suite/auto-sync/src/autosync/cpptranslator/Differ.py b/suite/auto-sync/src/autosync/cpptranslator/Differ.py index 3f276fc7f9..2877154856 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/Differ.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Differ.py @@ -1,4 +1,8 @@ #!/usr/bin/env python3 + +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import argparse import difflib as dl import json diff --git a/suite/auto-sync/src/autosync/cpptranslator/README.md b/suite/auto-sync/src/autosync/cpptranslator/README.md index c7c1c3701a..bd4b8f44d4 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/README.md +++ b/suite/auto-sync/src/autosync/cpptranslator/README.md @@ -1,3 +1,8 @@ + + # C++ Translator Capstone uses source files from LLVM to disassemble opcodes. diff --git a/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py index b0543756e3..abab53dc5c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py +++ b/suite/auto-sync/src/autosync/cpptranslator/TemplateCollector.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log import re from pathlib import Path diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index 272716ec00..e0414e85cc 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -1,6 +1,10 @@ #!/usr/bin/env python3 + +# Copyright © 2022 Rot127 # SPDX-FileCopyrightText: 2024 Rot127 +# SPDX-License-Identifier: BSD-3 # SPDX-License-Identifier: LGPL-3.0-only + import unittest from pathlib import Path diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/AddCSDetail.py b/suite/auto-sync/src/autosync/cpptranslator/patches/AddCSDetail.py index c807f62fd1..9b3fef2f30 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/AddCSDetail.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/AddCSDetail.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log import re diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/AddOperand.py b/suite/auto-sync/src/autosync/cpptranslator/patches/AddOperand.py index 5f75102516..c0858f538f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/AddOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/AddOperand.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/Assert.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Assert.py index cfdcb8e712..ce439dc2c8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/Assert.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Assert.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/BitCastStdArray.py b/suite/auto-sync/src/autosync/cpptranslator/patches/BitCastStdArray.py index bb725935c4..2491de114c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/BitCastStdArray.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/BitCastStdArray.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/CheckDecoderStatus.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CheckDecoderStatus.py index 477ee1a1f5..1b683ed79b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/CheckDecoderStatus.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CheckDecoderStatus.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/ClassConstructorDef.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ClassConstructorDef.py index 47f4b96a08..e7b69a463c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/ClassConstructorDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ClassConstructorDef.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/ClassesDef.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ClassesDef.py index 45f753d85a..7309ea2fe9 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/ClassesDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ClassesDef.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log import re diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCInstParameter.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCInstParameter.py index 4920b0de6a..7be334afc8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCInstParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCInstParameter.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCOperand.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCOperand.py index 1b844b4c73..d679193902 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ConstMCOperand.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/CppInitCast.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CppInitCast.py index ef125823b0..e2c3e5c40b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/CppInitCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CppInitCast.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand0.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand0.py index 7f87f105a0..04fb8d3212 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand0.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand0.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import re from tree_sitter import Node diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py index 2da8967036..5fa0312804 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import re from tree_sitter import Node diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/DeclarationInConditionClause.py b/suite/auto-sync/src/autosync/cpptranslator/patches/DeclarationInConditionClause.py index ca7820234d..884a148a1d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/DeclarationInConditionClause.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/DeclarationInConditionClause.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_capture_node, get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/DecodeInstruction.py b/suite/auto-sync/src/autosync/cpptranslator/patches/DecodeInstruction.py index 8f0cd725c6..2ac5637f0e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/DecodeInstruction.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/DecodeInstruction.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderCast.py b/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderCast.py index 4bf86675b3..097f6c9906 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderCast.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderCast.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderParameter.py b/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderParameter.py index f0d860a229..de7ac3531d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/DecoderParameter.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/FallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FallThrough.py index 19a3181bea..455b125bac 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/FallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FallThrough.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py index a9ca421cbe..8a8f7ae3fc 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBitsDecl.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBitsDecl.py index c71ce578ea..233d2608b3 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBitsDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBitsDecl.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py index a0a4f384d7..62216f3a3c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log import re diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/GetNumOperands.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetNumOperands.py index 13bc46eda8..f7025b5a44 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/GetNumOperands.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetNumOperands.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/GetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOpcode.py index 304818c9f2..c0251603ac 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/GetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOpcode.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperand.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperand.py index ca1363c2fa..63ad395af8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperand.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperand.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperandRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperandRegImm.py index 57661c4f67..c47b390389 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperandRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetOperandRegImm.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_capture_node, get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py index fcc3c23447..2d8fff4cdf 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import ( diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegFromClass.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegFromClass.py index e216ad3c4a..22aebfb192 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegFromClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegFromClass.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_capture_node, get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/GetSubReg.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetSubReg.py index 210b689185..6b73cf3f3f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/GetSubReg.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetSubReg.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py index cbd3faaf4b..3d495d2d80 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log import re diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py index c6fb4e22cd..fc604863cf 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log from tree_sitter import Node diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/InlineToStaticInline.py b/suite/auto-sync/src/autosync/cpptranslator/patches/InlineToStaticInline.py index ca628b47df..8d07e8e099 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/InlineToStaticInline.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/InlineToStaticInline.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py b/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py index bc2406d4d4..73962b951e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py b/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py index 362ba58478..42e76f13a0 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/IsRegImm.py b/suite/auto-sync/src/autosync/cpptranslator/patches/IsRegImm.py index fcfb6b4328..7fe5f14267 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/IsRegImm.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/IsRegImm.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMFallThrough.py b/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMFallThrough.py index 92a17d3276..25b80a4c38 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMFallThrough.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMFallThrough.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMunreachable.py b/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMunreachable.py index a3702fd77c..1bd243a66e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMunreachable.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/LLVMunreachable.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/MethodToFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/patches/MethodToFunctions.py index da1d17cdd3..c4f2a21ede 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/MethodToFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/MethodToFunctions.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/MethodTypeQualifier.py b/suite/auto-sync/src/autosync/cpptranslator/patches/MethodTypeQualifier.py index 2d12dec36d..2f6010d806 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/MethodTypeQualifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/MethodTypeQualifier.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceAnon.py b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceAnon.py index 043c883d62..460d9348eb 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceAnon.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceAnon.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceArch.py b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceArch.py index f6d3921557..14181aeebe 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceArch.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceArch.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import ( diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py index 55e82077ed..63e0593992 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py b/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py index dc8f4dbd56..b0b054e811 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/Patch.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Patch.py index 48de8a1470..6f82a0b494 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/Patch.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Patch.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log from tree_sitter import Node diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/PredicateBlockFunctions.py b/suite/auto-sync/src/autosync/cpptranslator/patches/PredicateBlockFunctions.py index f7effb33ad..d4b4203276 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/PredicateBlockFunctions.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/PredicateBlockFunctions.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/PrintAnnotation.py b/suite/auto-sync/src/autosync/cpptranslator/patches/PrintAnnotation.py index e0281204f5..c01a6327f4 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/PrintAnnotation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/PrintAnnotation.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/PrintRegImmShift.py b/suite/auto-sync/src/autosync/cpptranslator/patches/PrintRegImmShift.py index 96e6b8d1b4..e9057bf214 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/PrintRegImmShift.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/PrintRegImmShift.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_MCInst_var_name, get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/QualifiedIdentifier.py b/suite/auto-sync/src/autosync/cpptranslator/patches/QualifiedIdentifier.py index a9e446df0f..f0db97ed42 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/QualifiedIdentifier.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/QualifiedIdentifier.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/ReferencesDecl.py b/suite/auto-sync/src/autosync/cpptranslator/patches/ReferencesDecl.py index b6975694cc..8435333d26 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/ReferencesDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/ReferencesDecl.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import re from tree_sitter import Node diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/RegClassContains.py b/suite/auto-sync/src/autosync/cpptranslator/patches/RegClassContains.py index aee2a51bfb..bf55563dfd 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/RegClassContains.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/RegClassContains.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_capture_node, get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/STIArgument.py b/suite/auto-sync/src/autosync/cpptranslator/patches/STIArgument.py index 6dbb98172b..091b10122e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/STIArgument.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/STIArgument.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py index 063d3da0c3..2f35782f80 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/STParameter.py b/suite/auto-sync/src/autosync/cpptranslator/patches/STParameter.py index 1214ce0131..cf3fd1ed72 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/STParameter.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/STParameter.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/SetOpcode.py b/suite/auto-sync/src/autosync/cpptranslator/patches/SetOpcode.py index a83df74d6b..ca46405ff6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/SetOpcode.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/SetOpcode.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/SignExtend.py b/suite/auto-sync/src/autosync/cpptranslator/patches/SignExtend.py index 769bb464c8..457e92e5f9 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/SignExtend.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/SignExtend.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/SizeAssignments.py b/suite/auto-sync/src/autosync/cpptranslator/patches/SizeAssignments.py index 282abebf54..e9c8bccaa9 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/SizeAssignments.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/SizeAssignments.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import re from tree_sitter import Node diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py b/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py index c5104346d8..3bffe3cacc 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/StreamOperation.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDeclaration.py index 94179f31be..8842ba42cf 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDeclaration.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log from tree_sitter import Node diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDefinition.py b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDefinition.py index bf6b73099a..4487cb7e67 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDefinition.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateDefinition.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log import re diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateParamDecl.py b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateParamDecl.py index 27fd9e559a..2b2eb9b8ff 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateParamDecl.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateParamDecl.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + import logging as log from tree_sitter import Node diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateRefs.py b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateRefs.py index d7bcdac7d1..c858043455 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateRefs.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/TemplateRefs.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Helper import get_text diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/UseMarkup.py b/suite/auto-sync/src/autosync/cpptranslator/patches/UseMarkup.py index 5cc9450649..7cfbae38c6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/UseMarkup.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/UseMarkup.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/UsingDeclaration.py b/suite/auto-sync/src/autosync/cpptranslator/patches/UsingDeclaration.py index 72dbfcb62a..cd56280fd7 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/UsingDeclaration.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/UsingDeclaration.py @@ -1,3 +1,6 @@ +# Copyright © 2022 Rot127 +# SPDX-License-Identifier: BSD-3 + from tree_sitter import Node from autosync.cpptranslator.patches.Patch import Patch From aaece205d44e4cb734277de7f498f4160f7a63d9 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 04:58:15 -0500 Subject: [PATCH 20/41] Properly implement all Patch tests. --- .../cpptranslator/Tests/template_src.c | 7 + .../cpptranslator/Tests/test_config.json | 2 +- .../cpptranslator/Tests/test_patches.py | 522 ++++++++++++++---- .../cpptranslator/patches/CreateOperand1.py | 2 +- .../cpptranslator/patches/FeatureBits.py | 2 +- .../cpptranslator/patches/FieldFromInstr.py | 4 +- .../cpptranslator/patches/GetRegClass.py | 2 +- .../autosync/cpptranslator/patches/Helper.py | 9 +- .../cpptranslator/patches/Includes.py | 2 + .../cpptranslator/patches/IsOptionalDef.py | 2 +- .../cpptranslator/patches/IsPredicate.py | 2 +- .../cpptranslator/patches/NamespaceLLVM.py | 2 +- .../cpptranslator/patches/OutStreamParam.py | 6 +- .../cpptranslator/patches/STIFeatureBits.py | 4 +- 14 files changed, 456 insertions(+), 112 deletions(-) create mode 100644 suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c b/suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c new file mode 100644 index 0000000000..4bc6f3f3f4 --- /dev/null +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2024 Rot127 +// SPDX-License-Identifier: LGPL-3.0-only + +int main() { + tfunction(); + tfunction(); +} diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json index 92d55e80a5..558c0d9218 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json @@ -8,7 +8,7 @@ }, "ARCH": { "files_to_translate": [], - "files_for_template_search": [], + "files_for_template_search": ["{CPP_TRANSLATOR_TEST_DIR}/template_src.c"], "templates_with_arg_deduction": [], "manually_edited_files": [] } diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index e0414e85cc..2349748b7c 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -6,14 +6,14 @@ # SPDX-License-Identifier: LGPL-3.0-only import unittest -from pathlib import Path from tree_sitter import Node, Query -import autosync.cpptranslator.Patches as Patches +import autosync.cpptranslator.patches as Patches from autosync.cpptranslator import CppTranslator from autosync.cpptranslator.Configurator import Configurator +from autosync.cpptranslator.TemplateCollector import TemplateCollector from autosync.Helper import get_path @@ -24,10 +24,13 @@ def setUpClass(cls): cls.translator = CppTranslator.Translator(configurator) cls.ts_cpp_lang = configurator.get_cpp_lang() cls.parser = configurator.get_parser() + cls.template_collector = TemplateCollector( + configurator.get_parser(), configurator.get_cpp_lang(), [], [] + ) def test_addcsdetail(self): patch = Patches.AddCSDetail.AddCSDetail(0, "ARCH") - syntax = b"void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O) { int i = OpNo; }" + syntax = b"int i = x; void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O) { int i = OpNo; }" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -36,8 +39,17 @@ def test_addcsdetail(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b"void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O){ " + b"add_cs_detail(MI, ARCH_OP_GROUP_ThumbLdrLabelOperand, OpNo); " + b"int i = OpNo; " + b"}" + ), + ) def test_addoperand(self): patch = Patches.AddOperand.AddOperand(0) @@ -50,8 +62,12 @@ def test_addoperand(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"MCInst_addOperand2(MI, (OPERAND))", + ) def test_assert(self): patch = Patches.Assert.Assert(0) @@ -64,6 +80,7 @@ def test_assert(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") @@ -78,8 +95,20 @@ def test_bitcaststdarray(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b"union {\n" + b" typeof(Imm) In;\n" + b" int32_t Out[ 2];\n" + b"} U_S;\n" + b"U_S.In = Imm" + b";\n" + b"int32_t *S = U_S.Out;" + ), + ) def test_checkdecoderstatus(self): patch = Patches.CheckDecoderStatus.CheckDecoderStatus(0) @@ -92,12 +121,32 @@ def test_checkdecoderstatus(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"Check(&S, functions())" + ) def test_classesdef(self): patch = Patches.ClassesDef.ClassesDef(0) - syntax = b"Class definitions" + syntax = b"""class AArch64Disassembler : public MCDisassembler { + std::unique_ptr const MCII; + +public: + AArch64Disassembler(const MCSubtargetInfo &STI, MCContext &Ctx, + MCInstrInfo const *MCII) + : MCDisassembler(STI, Ctx), MCII(MCII) {} + + ~AArch64Disassembler() override = default; + + MCDisassembler::DecodeStatus + getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef Bytes, + uint64_t Address, raw_ostream &CStream) const override; + + uint64_t suggestBytesToSkip(ArrayRef Bytes, + uint64_t Address) const override; +}; +""" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -106,12 +155,22 @@ def test_classesdef(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b"MCDisassembler::DecodeStatus\n" + b" getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef Bytes,\n" + b" uint64_t Address, raw_ostream &CStream) const override;\n" + b"uint64_t suggestBytesToSkip(ArrayRef Bytes,\n" + b" uint64_t Address) const override;\n" + ), + ) def test_constmcinstparameter(self): patch = Patches.ConstMCInstParameter.ConstMCInstParameter(0) - syntax = b"const MCInst *MI" + syntax = b"void function(const MCInst *MI);" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -120,12 +179,14 @@ def test_constmcinstparameter(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"MCInst *MI") def test_constmcoperand(self): patch = Patches.ConstMCOperand.ConstMCOperand(0) - syntax = b"const MCOperand op" + syntax = b"const MCOperand op = { 0 };" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -134,8 +195,11 @@ def test_constmcoperand(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"MCOperand op = { 0 };" + ) def test_cppinitcast(self): patch = Patches.CppInitCast.CppInitCast(0) @@ -148,8 +212,9 @@ def test_cppinitcast(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"((int)(0x0000))") def test_createoperand0(self): patch = Patches.CreateOperand0.CreateOperand0(0) @@ -162,12 +227,16 @@ def test_createoperand0(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"MCOperand_CreateReg0(Inst, (REGISTER))", + ) def test_createoperand1(self): patch = Patches.CreateOperand1.CreateOperand1(0) - syntax = b"MI.insert(0, MCOperand::createReg(REGISTER));" + syntax = b"MI.insert(I, MCOperand::createReg(REGISTER));" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -176,12 +245,16 @@ def test_createoperand1(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"MCInst_insert0(MI, I, MCOperand_CreateReg1(MI, (REGISTER)))", + ) def test_declarationinconditionclause(self): patch = Patches.DeclarationInConditionClause.DeclarationInConditionalClause(0) - syntax = b"if (int i = 0) {}}" + syntax = b"if (int i = 0) {}" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -190,22 +263,45 @@ def test_declarationinconditionclause(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"int i = 0;\nif (i)\n{}" + ) def test_decodeinstruction(self): patch = Patches.DecodeInstruction.DecodeInstruction(0) - syntax = b"decodeInstruction(MI, this, STI)" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + syntax = ( + b"decodeInstruction(DecoderTableThumb16, MI, Insn16, Address, this, STI);" + ) captures_bundle: [[(Node, str)]] = list() for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): if q[1] == patch.get_main_capture_name(): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"decodeInstruction_2(DecoderTableThumb16, MI, Insn16, Address)", + ) + + syntax = b"decodeInstruction(Table[i], MI, Insn16, Address, this, STI);" + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) + for cb in captures_bundle: + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"decodeInstruction_2(Table[i], MI, Insn16, Address)", + ) def test_decodercast(self): patch = Patches.DecoderCast.DecoderCast(0) @@ -220,12 +316,13 @@ def test_decodercast(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") def test_decoderparameter(self): patch = Patches.DecoderParameter.DecoderParameter(0) - syntax = b"const MCDisassembler *Decoder" + syntax = b"void function(const MCDisassembler *Decoder);" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -234,8 +331,11 @@ def test_decoderparameter(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"const void *Decoder" + ) def test_fallthrough(self): patch = Patches.FallThrough.FallThrough(0) @@ -248,26 +348,29 @@ def test_fallthrough(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"// fall through") def test_featurebitsdecl(self): patch = Patches.FeatureBitsDecl.FeatureBitsDecl(0) - syntax = b"featureBits = 0x00" + syntax = b"const FeatureBitset &FeatureBits = ((const MCDisassembler*)Decoder)->getSubtargetInfo().getFeatureBits();" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + ast = self.parser.parse(syntax, keep_text=True) + for q in query.captures(ast.root_node): if q[1] == patch.get_main_capture_name(): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") def test_featurebits(self): patch = Patches.FeatureBits.FeatureBits(0, b"ARCH") - syntax = b"featureBits[FLAG]" + syntax = b"bool hasD32 = featureBits[ARCH::HasV8Ops];" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -276,26 +379,48 @@ def test_featurebits(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"ARCH_getFeatureBits(Inst->csh->mode, ARCH::HasV8Ops)", + ) def test_fieldfrominstr(self): patch = Patches.FieldFromInstr.FieldFromInstr(0) - syntax = b"fieldFromInstr(...)" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + syntax = b"unsigned Rm = fieldFromInstruction(Inst16, 0, 4);" captures_bundle: [[(Node, str)]] = list() for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): if q[1] == patch.get_main_capture_name(): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"fieldFromInstruction_2(Inst16, 0, 4)", + ) + + syntax = b"void function(MCInst *MI, unsigned Val) { unsigned Rm = fieldFromInstruction(Val, 0, 4); }" + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) + for cb in captures_bundle: + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"fieldFromInstruction_4(Val, 0, 4)", + ) def test_getnumoperands(self): patch = Patches.GetNumOperands.GetNumOperands(0) - syntax = b"MI.getNumOperands()" + syntax = b"MI.getNumOperands();" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -304,12 +429,15 @@ def test_getnumoperands(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"MCInst_getNumOperands(MI)" + ) def test_getopcode(self): patch = Patches.GetOpcode.GetOpcode(0) - syntax = b"Inst.getOpcode()" + syntax = b"Inst.getOpcode();" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -318,12 +446,15 @@ def test_getopcode(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"MCInst_getOpcode(Inst)" + ) def test_getoperand(self): patch = Patches.GetOperand.GetOperand(0) - syntax = b"MI.getOperand(...)" + syntax = b"MI.getOperand(0);" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -332,8 +463,11 @@ def test_getoperand(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"MCInst_getOperand(MI, (0))" + ) def test_getoperandregimm(self): patch = Patches.GetOperandRegImm.GetOperandRegImm(0) @@ -346,12 +480,15 @@ def test_getoperandregimm(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"MCOperand_getReg(OPERAND)" + ) def test_getregclass(self): patch = Patches.GetRegClass.GetRegClass(0) - syntax = b"MRI.getRegClass(RegClass)" + syntax = b"MRI.getRegClass(RegClass);" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -360,8 +497,12 @@ def test_getregclass(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"MCRegisterInfo_getRegClass(Inst->MRI, RegClass)", + ) def test_getregfromclass(self): patch = Patches.GetRegFromClass.GetRegFromClass(0) @@ -374,12 +515,16 @@ def test_getregfromclass(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"ARCHMCRegisterClasses[ARCH::FPR128RegClassID].RegsBegin[RegNo]", + ) def test_getsubreg(self): patch = Patches.GetSubReg.GetSubReg(0) - syntax = b"MRI.getSubReg(...);" + syntax = b"MRI.getSubReg(REGISTER);" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -388,13 +533,17 @@ def test_getsubreg(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"MCRegisterInfo_getSubReg(Inst->MRI, REGISTER)", + ) def test_includes(self): - patch = Patches.Includes.Includes(0, "ARCH") - syntax = b"#include some_llvm_header.h" - kwargs = self.translator.get_patch_kwargs(patch) + patch = Patches.Includes.Includes(0, "TEST_ARCH") + syntax = b'#include "some_llvm_header.h"' + kwargs = {"filename": "test_filename"} query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): @@ -402,12 +551,22 @@ def test_includes(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b"#include \n" + b"#include \n" + b"#include \n" + b"#include \n\n" + b"test_output" + ), + ) def test_inlinetostaticinline(self): patch = Patches.InlineToStaticInline.InlineToStaticInline(0) - syntax = b"inline void FUNCTION(...) {...}" + syntax = b"inline void FUNCTION() {}" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -416,8 +575,12 @@ def test_inlinetostaticinline(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"static inline void FUNCTION() {}", + ) def test_isoptionaldef(self): patch = Patches.IsOptionalDef.IsOptionalDef(0) @@ -430,8 +593,12 @@ def test_isoptionaldef(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"MCOperandInfo_isOptionalDef(&OpInfo[i])", + ) def test_ispredicate(self): patch = Patches.IsPredicate.IsPredicate(0) @@ -444,8 +611,12 @@ def test_ispredicate(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"MCOperandInfo_isPredicate(&OpInfo[i])", + ) def test_isregimm(self): patch = Patches.IsRegImm.IsOperandRegImm(0) @@ -458,12 +629,15 @@ def test_isregimm(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"MCOperand_isReg(OPERAND)" + ) def test_llvmfallthrough(self): patch = Patches.LLVMFallThrough.LLVMFallThrough(0) - syntax = b"LLVM_FALLTHROUGH" + syntax = b"LLVM_FALLTHROUGH;" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -472,6 +646,7 @@ def test_llvmfallthrough(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") @@ -486,8 +661,11 @@ def test_llvmunreachable(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b'assert(0 && "Error msg")' + ) def test_methodtofunctions(self): patch = Patches.MethodToFunctions.MethodToFunction(0) @@ -500,8 +678,11 @@ def test_methodtofunctions(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"METHOD_NAME(int a)" + ) def test_methodtypequalifier(self): patch = Patches.MethodTypeQualifier.MethodTypeQualifier(0) @@ -514,12 +695,13 @@ def test_methodtypequalifier(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"a_const_method()") def test_namespaceanon(self): patch = Patches.NamespaceAnon.NamespaceAnon(0) - syntax = b"namespace {CONTENT}" + syntax = b"namespace { int a = 0; }" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -528,12 +710,13 @@ def test_namespaceanon(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b" int a = 0; ") def test_namespacearch(self): patch = Patches.NamespaceArch.NamespaceArch(0) - syntax = b"namespace ArchSpecificNamespace {CONTENT}" + syntax = b"namespace ArchSpecificNamespace { int a = 0; }" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -542,12 +725,20 @@ def test_namespacearch(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b"// CS namespace begin: ArchSpecificNamespace\n\n" + b"int a = 0;\n\n" + b"// CS namespace end: ArchSpecificNamespace\n\n" + ), + ) def test_namespacellvm(self): patch = Patches.NamespaceLLVM.NamespaceLLVM(0) - syntax = b"namespace {CONTENT}" + syntax = b"namespace llvm {int a = 0}" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -556,12 +747,13 @@ def test_namespacellvm(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"int a = 0") def test_outstreamparam(self): patch = Patches.OutStreamParam.OutStreamParam(0) - syntax = b"raw_ostream &OS" + syntax = b"void function(int a, raw_ostream &OS);" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -570,12 +762,15 @@ def test_outstreamparam(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"(int a, SStream *OS)" + ) def test_predicateblockfunctions(self): patch = Patches.PredicateBlockFunctions.PredicateBlockFunctions(0) - syntax = b"VPTBlock.instrInVPTBlock()" + syntax = b"void function(MCInst *MI) { VPTBlock.instrInVPTBlock(); }" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -584,12 +779,31 @@ def test_predicateblockfunctions(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) + for cb in captures_bundle: + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"VPTBlock_instrInVPTBlock(&(MI->csh->VPTBlock))", + ) + + def test_predicateblockfunctions(self): + patch = Patches.PrintAnnotation.PrintAnnotation(0) + syntax = b"printAnnotation();" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") def test_printregimmshift(self): patch = Patches.PrintRegImmShift.PrintRegImmShift(0) - syntax = b"printRegImmShift(...)" + syntax = b"printRegImmShift(0)" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -598,8 +812,11 @@ def test_printregimmshift(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"printRegImmShift(Inst, 0)" + ) def test_qualifiedidentifier(self): patch = Patches.QualifiedIdentifier.QualifiedIdentifier(0) @@ -612,12 +829,13 @@ def test_qualifiedidentifier(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"NAMESPACE_ID") def test_referencesdecl(self): patch = Patches.ReferencesDecl.ReferencesDecl(0) - syntax = b"TYPE &Param" + syntax = b"int &Param = 0;" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -626,12 +844,13 @@ def test_referencesdecl(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"*Param") def test_regclasscontains(self): patch = Patches.RegClassContains.RegClassContains(0) - syntax = b"...getRegClass(CLASS).contains(Reg)" + syntax = b"if (MRI.getRegClass(AArch64::GPR32RegClassID).contains(Reg)) {}" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -640,12 +859,16 @@ def test_regclasscontains(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"MCRegisterClass_contains(MRI.getRegClass(AArch64::GPR32RegClassID), Reg)", + ) def test_setopcode(self): patch = Patches.SetOpcode.SetOpcode(0) - syntax = b"Inst.setOpcode(...)" + syntax = b"Inst.setOpcode(0)" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -654,12 +877,15 @@ def test_setopcode(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"MCInst_setOpcode(Inst, (0))" + ) def test_signextend(self): patch = Patches.SignExtend.SignExtend(0) - syntax = b"SignExtend32(...)" + syntax = b"SignExtend32(0)" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -668,12 +894,15 @@ def test_signextend(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b"SignExtend32((0), A)" + ) def test_sizeassignments(self): patch = Patches.SizeAssignments.SizeAssignment(0) - syntax = b"Size = " + syntax = b"void function(int &Size) { Size = 0; }" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -682,8 +911,9 @@ def test_sizeassignments(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"*Size = 0") def test_stiargument(self): patch = Patches.STIArgument.STIArgument(0) @@ -696,12 +926,13 @@ def test_stiargument(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"(MI, NUM, NUM)") def test_stifeaturebits(self): patch = Patches.STIFeatureBits.STIFeatureBits(0, b"ARCH") - syntax = b"STI.getFeatureBits()[FLAG]" + syntax = b"STI.getFeatureBits()[ARCH::FLAG];" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -710,12 +941,16 @@ def test_stifeaturebits(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"ARCH_getFeatureBits(Inst->csh->mode, ARCH::FLAG)", + ) - def test_streamoperation(self): + def test_stifeaturebits(self): patch = Patches.STParameter.SubtargetInfoParam(0) - syntax = b"OS << ..." + syntax = b"void function(MCSubtargetInfo &STI);" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -724,26 +959,91 @@ def test_streamoperation(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"()") - def test_templatedeclaration(self): + def test_streamoperation(self): patch = Patches.StreamOperation.StreamOperations(0) - syntax = b"template void func();" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + syntax = b"{ OS << 'a'; }" captures_bundle: [[(Node, str)]] = list() for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): if q[1] == patch.get_main_capture_name(): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), b'SStream_concat0(OS, "a");\n' + ) + + syntax = b'{ OS << "aaaa" << "bbbb" << "cccc"; }' + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) + for cb in captures_bundle: + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b'SStream_concat(OS, "%s%s", "aaaa", "bbbb");\nSStream_concat0(OS, "cccc");' + ), + ) + + syntax = b'{ OS << "aaaa" << \'a\' << "cccc"; }' + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) + for cb in captures_bundle: + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b'SStream_concat(OS, "%s", "aaaa");\n' + b"SStream_concat1(OS, 'a');\n" + b'SStream_concat0(OS, "cccc");' + ), + ) + + def test_templatedeclaration(self): + patch = Patches.TemplateDeclaration.TemplateDeclaration( + 0, self.template_collector + ) + syntax = b"template void tfunction();" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) + for cb in captures_bundle: + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b"#define DECLARE_tfunction(A, B) \\\n" + b" void CONCAT(tfunction, CONCAT(A, B))();\n" + b"DECLARE_tfunction(int, int);\n" + b"DECLARE_tfunction(int, char);\n" + ), + ) def test_templatedefinition(self): - patch = Patches.TemplateDeclaration.TemplateDeclaration(0) - syntax = b"template void func() {}" + patch = Patches.TemplateDefinition.TemplateDefinition( + 0, self.template_collector + ) + syntax = b"template void tfunction() {}" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -752,12 +1052,21 @@ def test_templatedefinition(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + ( + b"#define DEFINE_tfunction(A, B) \\\n" + b" void CONCAT(tfunction, CONCAT(A, B))(){}\n" + b"DEFINE_tfunction(int, int);\n" + b"DEFINE_tfunction(int, char);\n" + ), + ) def test_templateparamdecl(self): - patch = Patches.TemplateDefinition.TemplateDefinition(0) - syntax = b"ArrayRef x;" + patch = Patches.TemplateParamDecl.TemplateParamDecl(0) + syntax = b"void function(ArrayRef x);" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -766,12 +1075,13 @@ def test_templateparamdecl(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"const uint8_t *x") def test_templaterefs(self): - patch = Patches.TemplateParamDecl.TemplateParamDecl(0) - syntax = b"TemplateFunction" + patch = Patches.TemplateRefs.TemplateRefs(0) + syntax = b"TemplateFunction();" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() @@ -780,11 +1090,15 @@ def test_templaterefs(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.assertEqual( + patch.get_patch(cb, syntax, **kwargs), + b"CONCAT(TemplateFunction, CONCAT(A, B))", + ) def test_usemarkup(self): - patch = Patches.TemplateRefs.TemplateRefs(0) + patch = Patches.UseMarkup.UseMarkup(0) syntax = b"UseMarkup()" kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) @@ -794,5 +1108,21 @@ def test_usemarkup(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) + for cb in captures_bundle: + assert patch.get_patch(cb, syntax, **kwargs) == b"getUseMarkup()" + + def test_usingdecl(self): + patch = Patches.UsingDeclaration.UsingDeclaration(0) + syntax = b"using namespace llvm;" + kwargs = self.translator.get_patch_kwargs(patch) + query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) + captures_bundle: [[(Node, str)]] = list() + for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): + if q[1] == patch.get_main_capture_name(): + captures_bundle.append([q]) + else: + captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: assert patch.get_patch(cb, syntax, **kwargs) == b"" diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py index 5fa0312804..2fbb442778 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/CreateOperand1.py @@ -69,7 +69,7 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: + b"MCOperand_" + fcn + b"1(" - + get_MCInst_var_name(src, inst_var) + + inst + b", " + args + b"))" diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py index 8a8f7ae3fc..2f37bd7d77 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FeatureBits.py @@ -10,7 +10,7 @@ class FeatureBits(Patch): """ Patch featureBits[FLAG] - to ARCH_getFeatureBits(Inst->csh->mode, ...) + to ARCH_getFeatureBits(Inst->csh->mode, FLAG) """ def __init__(self, priority: int, arch: bytes): diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py index 62216f3a3c..8133e7b683 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/FieldFromInstr.py @@ -12,8 +12,8 @@ class FieldFromInstr(Patch): """ - Patch fieldFromInstr(...) - to fieldFromInstr_(...) + Patch fieldFromInstruction(...) + to fieldFromInstruction_(...) """ def __init__(self, priority: int): diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py index 2d8fff4cdf..7d3ff62d0e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/GetRegClass.py @@ -14,7 +14,7 @@ class GetRegClass(Patch): """ Patch MRI.getRegClass(...) - to MCRegisterClass_getRegClass(MI->MRI, ...) + to MCRegisterInfo_getRegClass(Inst->MRI, ...) """ def __init__(self, priority: int): diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py index 3d495d2d80..dface4ae22 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py @@ -36,9 +36,12 @@ def get_MCInst_var_name(src: bytes, n: Node) -> bytes: """Searches for the name of the parameter of type MCInst and returns it.""" params = get_function_params_of_node(n) mcinst_var_name = b"" - for p in params.named_children: - p_text = get_text(src, p.start_byte, p.end_byte) - if b"MCInst" in p_text: + + if params: + for p in params.named_children: + p_text = get_text(src, p.start_byte, p.end_byte) + if b"MCInst" not in p_text: + continue mcinst_var_name = p_text.split((b"&" if b"&" in p_text else b"*"))[1] break if mcinst_var_name == b"": diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py index fc604863cf..7d8da36f8b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Includes.py @@ -62,6 +62,8 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: return res + get_PPC_includes(filename) + get_general_macros() case "AArch64": return res + get_AArch64_includes(filename) + get_general_macros() + case "TEST_ARCH": + return res + b"test_output" case _: log.fatal(f"Includes of {self.arch} not handled.") exit(1) diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py b/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py index 73962b951e..51eafbc7c6 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/IsOptionalDef.py @@ -37,4 +37,4 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: index = captures[2][0] op_info_var = get_text(src, op_info_var.start_byte, op_info_var.end_byte) index = get_text(src, index.start_byte, index.end_byte) - return b"MCOperandInfo_isOptionalDef(&" + op_info_var + b"[" + index + b"])" + return b"MCOperandInfo_isOptionalDef(&" + op_info_var + index + b")" diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py b/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py index 42e76f13a0..a7b26641ba 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/IsPredicate.py @@ -37,4 +37,4 @@ def get_patch(self, captures: [(Node, str)], src: bytes, **kwargs) -> bytes: index = captures[2][0] op_info_var = get_text(src, op_info_var.start_byte, op_info_var.end_byte) index = get_text(src, index.start_byte, index.end_byte) - return b"MCOperandInfo_isPredicate(&" + op_info_var + b"[" + index + b"])" + return b"MCOperandInfo_isPredicate(&" + op_info_var + index + b")" diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py index 63e0593992..16526f5ea1 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/NamespaceLLVM.py @@ -9,7 +9,7 @@ class NamespaceLLVM(Patch): """ - Patch namespace {CONTENT} + Patch namespace llvm {CONTENT} to CONTENT Only for anonymous or llvm namespaces diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py b/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py index b0b054e811..e9473d1a2e 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/OutStreamParam.py @@ -9,8 +9,10 @@ class OutStreamParam(Patch): """ - Patch raw_ostream &OS - to SStream *OS + Patches the parameter list only: + + Patch void function(int a, raw_ostream &OS) + to void function(int a, SStream *OS) """ def __init__(self, priority: int): diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py b/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py index 2f35782f80..29e44cddb8 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/STIFeatureBits.py @@ -9,8 +9,8 @@ class STIFeatureBits(Patch): """ - Patch STI.getFeatureBits()[FLAG] - to ARCH_getFeatureBits(Inst->csh->mode, ...) + Patch STI.getFeatureBits()[ARCH::FLAG] + to ARCH_getFeatureBits(Inst->csh->mode, ARCH::FLAG) """ def __init__(self, priority: int, arch: bytes): From 02f21ae552ff27e5e5d548b843b5f1e90ed9d519 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 05:17:58 -0500 Subject: [PATCH 21/41] Extract method to test patching result. --- .../cpptranslator/Tests/test_patches.py | 1035 ++++------------- 1 file changed, 207 insertions(+), 828 deletions(-) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index 2349748b7c..163cdb247f 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -28,10 +28,11 @@ def setUpClass(cls): configurator.get_parser(), configurator.get_cpp_lang(), [], [] ) - def test_addcsdetail(self): - patch = Patches.AddCSDetail.AddCSDetail(0, "ARCH") - syntax = b"int i = x; void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O) { int i = OpNo; }" - kwargs = self.translator.get_patch_kwargs(patch) + def check_patching_result(self, patch, syntax, expected, filename=""): + if filename: + kwargs = {"filename": filename} + else: + kwargs = self.translator.get_patch_kwargs(patch) query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) captures_bundle: [[(Node, str)]] = list() for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): @@ -39,93 +40,56 @@ def test_addcsdetail(self): captures_bundle.append([q]) else: captures_bundle[-1].append(q) + self.assertGreater(len(captures_bundle), 0) for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b"void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O){ " - b"add_cs_detail(MI, ARCH_OP_GROUP_ThumbLdrLabelOperand, OpNo); " - b"int i = OpNo; " - b"}" - ), - ) + self.assertEqual(patch.get_patch(cb, syntax, **kwargs), expected) + + def test_addcsdetail(self): + patch = Patches.AddCSDetail.AddCSDetail(0, "ARCH") + syntax = b"int i = x; void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O) { int i = OpNo; }" + self.check_patching_result( + patch, + syntax, + b"void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O){ " + b"add_cs_detail(MI, ARCH_OP_GROUP_ThumbLdrLabelOperand, OpNo); " + b"int i = OpNo; " + b"}", + ) def test_addoperand(self): patch = Patches.AddOperand.AddOperand(0) syntax = b"MI.addOperand(OPERAND)" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"MCInst_addOperand2(MI, (OPERAND))", - ) + self.check_patching_result( + patch, + syntax, + b"MCInst_addOperand2(MI, (OPERAND))", + ) def test_assert(self): patch = Patches.Assert.Assert(0) syntax = b"assert(0 == 0)" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.check_patching_result(patch, syntax, b"") def test_bitcaststdarray(self): patch = Patches.BitCastStdArray.BitCastStdArray(0) syntax = b"auto S = bit_cast>(Imm);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b"union {\n" - b" typeof(Imm) In;\n" - b" int32_t Out[ 2];\n" - b"} U_S;\n" - b"U_S.In = Imm" - b";\n" - b"int32_t *S = U_S.Out;" - ), - ) + self.check_patching_result( + patch, + syntax, + b"union {\n" + b" typeof(Imm) In;\n" + b" int32_t Out[ 2];\n" + b"} U_S;\n" + b"U_S.In = Imm" + b";\n" + b"int32_t *S = U_S.Out;", + ) def test_checkdecoderstatus(self): patch = Patches.CheckDecoderStatus.CheckDecoderStatus(0) syntax = b"Check(S, functions())" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"Check(&S, functions())" - ) + self.check_patching_result(patch, syntax, b"Check(&S, functions())") def test_classesdef(self): patch = Patches.ClassesDef.ClassesDef(0) @@ -147,982 +111,397 @@ def test_classesdef(self): uint64_t Address) const override; }; """ - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b"MCDisassembler::DecodeStatus\n" - b" getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef Bytes,\n" - b" uint64_t Address, raw_ostream &CStream) const override;\n" - b"uint64_t suggestBytesToSkip(ArrayRef Bytes,\n" - b" uint64_t Address) const override;\n" - ), - ) + self.check_patching_result( + patch, + syntax, + b"MCDisassembler::DecodeStatus\n" + b" getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef Bytes,\n" + b" uint64_t Address, raw_ostream &CStream) const override;\n" + b"uint64_t suggestBytesToSkip(ArrayRef Bytes,\n" + b" uint64_t Address) const override;\n", + ) def test_constmcinstparameter(self): patch = Patches.ConstMCInstParameter.ConstMCInstParameter(0) syntax = b"void function(const MCInst *MI);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"MCInst *MI") + expected = b"MCInst *MI" + self.check_patching_result(patch, syntax, expected) def test_constmcoperand(self): patch = Patches.ConstMCOperand.ConstMCOperand(0) syntax = b"const MCOperand op = { 0 };" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"MCOperand op = { 0 };" - ) + self.check_patching_result(patch, syntax, b"MCOperand op = { 0 };") def test_cppinitcast(self): patch = Patches.CppInitCast.CppInitCast(0) syntax = b"int(0x0000)" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"((int)(0x0000))") + self.check_patching_result(patch, syntax, b"((int)(0x0000))") def test_createoperand0(self): patch = Patches.CreateOperand0.CreateOperand0(0) syntax = b"Inst.addOperand(MCOperand::createReg(REGISTER));" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"MCOperand_CreateReg0(Inst, (REGISTER))", - ) + self.check_patching_result( + patch, + syntax, + b"MCOperand_CreateReg0(Inst, (REGISTER))", + ) def test_createoperand1(self): patch = Patches.CreateOperand1.CreateOperand1(0) syntax = b"MI.insert(I, MCOperand::createReg(REGISTER));" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"MCInst_insert0(MI, I, MCOperand_CreateReg1(MI, (REGISTER)))", - ) + self.check_patching_result( + patch, + syntax, + b"MCInst_insert0(MI, I, MCOperand_CreateReg1(MI, (REGISTER)))", + ) def test_declarationinconditionclause(self): patch = Patches.DeclarationInConditionClause.DeclarationInConditionalClause(0) syntax = b"if (int i = 0) {}" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"int i = 0;\nif (i)\n{}" - ) + self.check_patching_result(patch, syntax, b"int i = 0;\nif (i)\n{}") def test_decodeinstruction(self): patch = Patches.DecodeInstruction.DecodeInstruction(0) - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) syntax = ( b"decodeInstruction(DecoderTableThumb16, MI, Insn16, Address, this, STI);" ) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"decodeInstruction_2(DecoderTableThumb16, MI, Insn16, Address)", - ) + self.check_patching_result( + patch, + syntax, + b"decodeInstruction_2(DecoderTableThumb16, MI, Insn16, Address)", + ) syntax = b"decodeInstruction(Table[i], MI, Insn16, Address, this, STI);" - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"decodeInstruction_2(Table[i], MI, Insn16, Address)", - ) + self.check_patching_result( + patch, + syntax, + b"decodeInstruction_2(Table[i], MI, Insn16, Address)", + ) def test_decodercast(self): patch = Patches.DecoderCast.DecoderCast(0) syntax = ( b"const MCDisassembler *Dis = static_cast(Decoder);" ) - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.check_patching_result(patch, syntax, b"") def test_decoderparameter(self): patch = Patches.DecoderParameter.DecoderParameter(0) syntax = b"void function(const MCDisassembler *Decoder);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"const void *Decoder" - ) + self.check_patching_result(patch, syntax, b"const void *Decoder") def test_fallthrough(self): patch = Patches.FallThrough.FallThrough(0) syntax = b"[[fallthrough]]" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"// fall through") + self.check_patching_result(patch, syntax, b"// fall through") def test_featurebitsdecl(self): patch = Patches.FeatureBitsDecl.FeatureBitsDecl(0) syntax = b"const FeatureBitset &FeatureBits = ((const MCDisassembler*)Decoder)->getSubtargetInfo().getFeatureBits();" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - ast = self.parser.parse(syntax, keep_text=True) - for q in query.captures(ast.root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.check_patching_result(patch, syntax, b"") def test_featurebits(self): patch = Patches.FeatureBits.FeatureBits(0, b"ARCH") syntax = b"bool hasD32 = featureBits[ARCH::HasV8Ops];" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"ARCH_getFeatureBits(Inst->csh->mode, ARCH::HasV8Ops)", - ) + self.check_patching_result( + patch, + syntax, + b"ARCH_getFeatureBits(Inst->csh->mode, ARCH::HasV8Ops)", + ) def test_fieldfrominstr(self): patch = Patches.FieldFromInstr.FieldFromInstr(0) - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) syntax = b"unsigned Rm = fieldFromInstruction(Inst16, 0, 4);" - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"fieldFromInstruction_2(Inst16, 0, 4)", - ) + self.check_patching_result( + patch, + syntax, + b"fieldFromInstruction_2(Inst16, 0, 4)", + ) syntax = b"void function(MCInst *MI, unsigned Val) { unsigned Rm = fieldFromInstruction(Val, 0, 4); }" - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"fieldFromInstruction_4(Val, 0, 4)", - ) + self.check_patching_result( + patch, + syntax, + b"fieldFromInstruction_4(Val, 0, 4)", + ) def test_getnumoperands(self): patch = Patches.GetNumOperands.GetNumOperands(0) syntax = b"MI.getNumOperands();" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"MCInst_getNumOperands(MI)" - ) + self.check_patching_result(patch, syntax, b"MCInst_getNumOperands(MI)") def test_getopcode(self): patch = Patches.GetOpcode.GetOpcode(0) syntax = b"Inst.getOpcode();" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"MCInst_getOpcode(Inst)" - ) + self.check_patching_result(patch, syntax, b"MCInst_getOpcode(Inst)") def test_getoperand(self): patch = Patches.GetOperand.GetOperand(0) syntax = b"MI.getOperand(0);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"MCInst_getOperand(MI, (0))" - ) + self.check_patching_result(patch, syntax, b"MCInst_getOperand(MI, (0))") def test_getoperandregimm(self): patch = Patches.GetOperandRegImm.GetOperandRegImm(0) syntax = b"OPERAND.getReg()" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"MCOperand_getReg(OPERAND)" - ) + self.check_patching_result(patch, syntax, b"MCOperand_getReg(OPERAND)") def test_getregclass(self): patch = Patches.GetRegClass.GetRegClass(0) syntax = b"MRI.getRegClass(RegClass);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"MCRegisterInfo_getRegClass(Inst->MRI, RegClass)", - ) + expected = b"MCRegisterInfo_getRegClass(Inst->MRI, RegClass)" + self.check_patching_result(patch, syntax, expected) def test_getregfromclass(self): patch = Patches.GetRegFromClass.GetRegFromClass(0) syntax = b"ARCHMCRegisterClasses[ARCH::FPR128RegClassID].getRegister(RegNo);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"ARCHMCRegisterClasses[ARCH::FPR128RegClassID].RegsBegin[RegNo]", - ) + self.check_patching_result( + patch, + syntax, + b"ARCHMCRegisterClasses[ARCH::FPR128RegClassID].RegsBegin[RegNo]", + ) def test_getsubreg(self): patch = Patches.GetSubReg.GetSubReg(0) syntax = b"MRI.getSubReg(REGISTER);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"MCRegisterInfo_getSubReg(Inst->MRI, REGISTER)", - ) + self.check_patching_result( + patch, + syntax, + b"MCRegisterInfo_getSubReg(Inst->MRI, REGISTER)", + ) def test_includes(self): patch = Patches.Includes.Includes(0, "TEST_ARCH") syntax = b'#include "some_llvm_header.h"' - kwargs = {"filename": "test_filename"} - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b"#include \n" - b"#include \n" - b"#include \n" - b"#include \n\n" - b"test_output" - ), - ) + self.check_patching_result( + patch, + syntax, + b"#include \n" + b"#include \n" + b"#include \n" + b"#include \n\n" + b"test_output", + "filename", + ) def test_inlinetostaticinline(self): patch = Patches.InlineToStaticInline.InlineToStaticInline(0) syntax = b"inline void FUNCTION() {}" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"static inline void FUNCTION() {}", - ) + self.check_patching_result( + patch, + syntax, + b"static inline void FUNCTION() {}", + ) def test_isoptionaldef(self): patch = Patches.IsOptionalDef.IsOptionalDef(0) syntax = b"OpInfo[i].isOptionalDef()" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"MCOperandInfo_isOptionalDef(&OpInfo[i])", - ) + self.check_patching_result( + patch, + syntax, + b"MCOperandInfo_isOptionalDef(&OpInfo[i])", + ) def test_ispredicate(self): patch = Patches.IsPredicate.IsPredicate(0) syntax = b"OpInfo[i].isPredicate()" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"MCOperandInfo_isPredicate(&OpInfo[i])", - ) + self.check_patching_result( + patch, + syntax, + b"MCOperandInfo_isPredicate(&OpInfo[i])", + ) def test_isregimm(self): patch = Patches.IsRegImm.IsOperandRegImm(0) syntax = b"OPERAND.isReg()" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"MCOperand_isReg(OPERAND)" - ) + self.check_patching_result(patch, syntax, b"MCOperand_isReg(OPERAND)") def test_llvmfallthrough(self): patch = Patches.LLVMFallThrough.LLVMFallThrough(0) syntax = b"LLVM_FALLTHROUGH;" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.check_patching_result(patch, syntax, b"") def test_llvmunreachable(self): patch = Patches.LLVMunreachable.LLVMUnreachable(0) syntax = b'llvm_unreachable("Error msg")' - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b'assert(0 && "Error msg")' - ) + self.check_patching_result(patch, syntax, b'assert(0 && "Error msg")') def test_methodtofunctions(self): patch = Patches.MethodToFunctions.MethodToFunction(0) syntax = b"void CLASS::METHOD_NAME(int a) {}" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"METHOD_NAME(int a)" - ) + self.check_patching_result(patch, syntax, b"METHOD_NAME(int a)") def test_methodtypequalifier(self): patch = Patches.MethodTypeQualifier.MethodTypeQualifier(0) syntax = b"void a_const_method() const {}" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"a_const_method()") + self.check_patching_result(patch, syntax, b"a_const_method()") def test_namespaceanon(self): patch = Patches.NamespaceAnon.NamespaceAnon(0) syntax = b"namespace { int a = 0; }" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b" int a = 0; ") + self.check_patching_result(patch, syntax, b" int a = 0; ") def test_namespacearch(self): patch = Patches.NamespaceArch.NamespaceArch(0) syntax = b"namespace ArchSpecificNamespace { int a = 0; }" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b"// CS namespace begin: ArchSpecificNamespace\n\n" - b"int a = 0;\n\n" - b"// CS namespace end: ArchSpecificNamespace\n\n" - ), - ) + self.check_patching_result( + patch, + syntax, + b"// CS namespace begin: ArchSpecificNamespace\n\n" + b"int a = 0;\n\n" + b"// CS namespace end: ArchSpecificNamespace\n\n", + ) def test_namespacellvm(self): patch = Patches.NamespaceLLVM.NamespaceLLVM(0) syntax = b"namespace llvm {int a = 0}" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"int a = 0") + self.check_patching_result(patch, syntax, b"int a = 0") def test_outstreamparam(self): patch = Patches.OutStreamParam.OutStreamParam(0) syntax = b"void function(int a, raw_ostream &OS);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"(int a, SStream *OS)" - ) + self.check_patching_result(patch, syntax, b"(int a, SStream *OS)") def test_predicateblockfunctions(self): patch = Patches.PredicateBlockFunctions.PredicateBlockFunctions(0) syntax = b"void function(MCInst *MI) { VPTBlock.instrInVPTBlock(); }" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"VPTBlock_instrInVPTBlock(&(MI->csh->VPTBlock))", - ) + self.check_patching_result( + patch, + syntax, + b"VPTBlock_instrInVPTBlock(&(MI->csh->VPTBlock))", + ) def test_predicateblockfunctions(self): patch = Patches.PrintAnnotation.PrintAnnotation(0) syntax = b"printAnnotation();" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"") + self.check_patching_result(patch, syntax, b"") def test_printregimmshift(self): patch = Patches.PrintRegImmShift.PrintRegImmShift(0) syntax = b"printRegImmShift(0)" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"printRegImmShift(Inst, 0)" - ) + self.check_patching_result(patch, syntax, b"printRegImmShift(Inst, 0)") def test_qualifiedidentifier(self): patch = Patches.QualifiedIdentifier.QualifiedIdentifier(0) syntax = b"NAMESPACE::ID" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"NAMESPACE_ID") + self.check_patching_result(patch, syntax, b"NAMESPACE_ID") def test_referencesdecl(self): patch = Patches.ReferencesDecl.ReferencesDecl(0) syntax = b"int &Param = 0;" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"*Param") + self.check_patching_result(patch, syntax, b"*Param") def test_regclasscontains(self): patch = Patches.RegClassContains.RegClassContains(0) syntax = b"if (MRI.getRegClass(AArch64::GPR32RegClassID).contains(Reg)) {}" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"MCRegisterClass_contains(MRI.getRegClass(AArch64::GPR32RegClassID), Reg)", - ) + self.check_patching_result( + patch, + syntax, + b"MCRegisterClass_contains(MRI.getRegClass(AArch64::GPR32RegClassID), Reg)", + ) def test_setopcode(self): patch = Patches.SetOpcode.SetOpcode(0) syntax = b"Inst.setOpcode(0)" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"MCInst_setOpcode(Inst, (0))" - ) + self.check_patching_result(patch, syntax, b"MCInst_setOpcode(Inst, (0))") def test_signextend(self): patch = Patches.SignExtend.SignExtend(0) syntax = b"SignExtend32(0)" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b"SignExtend32((0), A)" - ) + self.check_patching_result(patch, syntax, b"SignExtend32((0), A)") def test_sizeassignments(self): patch = Patches.SizeAssignments.SizeAssignment(0) syntax = b"void function(int &Size) { Size = 0; }" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"*Size = 0") + self.check_patching_result(patch, syntax, b"*Size = 0") def test_stiargument(self): patch = Patches.STIArgument.STIArgument(0) syntax = b"printSomeOperand(MI, NUM, STI, NUM)" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"(MI, NUM, NUM)") + self.check_patching_result(patch, syntax, b"(MI, NUM, NUM)") def test_stifeaturebits(self): patch = Patches.STIFeatureBits.STIFeatureBits(0, b"ARCH") syntax = b"STI.getFeatureBits()[ARCH::FLAG];" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"ARCH_getFeatureBits(Inst->csh->mode, ARCH::FLAG)", - ) + self.check_patching_result( + patch, + syntax, + b"ARCH_getFeatureBits(Inst->csh->mode, ARCH::FLAG)", + ) def test_stifeaturebits(self): patch = Patches.STParameter.SubtargetInfoParam(0) syntax = b"void function(MCSubtargetInfo &STI);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"()") + self.check_patching_result(patch, syntax, b"()") def test_streamoperation(self): patch = Patches.StreamOperation.StreamOperations(0) - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) syntax = b"{ OS << 'a'; }" - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), b'SStream_concat0(OS, "a");\n' - ) + self.check_patching_result(patch, syntax, b'SStream_concat0(OS, "a");\n') syntax = b'{ OS << "aaaa" << "bbbb" << "cccc"; }' - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b'SStream_concat(OS, "%s%s", "aaaa", "bbbb");\nSStream_concat0(OS, "cccc");' - ), - ) + self.check_patching_result( + patch, + syntax, + b'SStream_concat(OS, "%s%s", "aaaa", "bbbb");\nSStream_concat0(OS, "cccc");', + ) syntax = b'{ OS << "aaaa" << \'a\' << "cccc"; }' - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b'SStream_concat(OS, "%s", "aaaa");\n' - b"SStream_concat1(OS, 'a');\n" - b'SStream_concat0(OS, "cccc");' - ), - ) + self.check_patching_result( + patch, + syntax, + b'SStream_concat(OS, "%s", "aaaa");\n' + b"SStream_concat1(OS, 'a');\n" + b'SStream_concat0(OS, "cccc");', + ) def test_templatedeclaration(self): patch = Patches.TemplateDeclaration.TemplateDeclaration( 0, self.template_collector ) syntax = b"template void tfunction();" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b"#define DECLARE_tfunction(A, B) \\\n" - b" void CONCAT(tfunction, CONCAT(A, B))();\n" - b"DECLARE_tfunction(int, int);\n" - b"DECLARE_tfunction(int, char);\n" - ), - ) + self.check_patching_result( + patch, + syntax, + b"#define DECLARE_tfunction(A, B) \\\n" + b" void CONCAT(tfunction, CONCAT(A, B))();\n" + b"DECLARE_tfunction(int, int);\n" + b"DECLARE_tfunction(int, char);\n", + ) def test_templatedefinition(self): patch = Patches.TemplateDefinition.TemplateDefinition( 0, self.template_collector ) syntax = b"template void tfunction() {}" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - ( - b"#define DEFINE_tfunction(A, B) \\\n" - b" void CONCAT(tfunction, CONCAT(A, B))(){}\n" - b"DEFINE_tfunction(int, int);\n" - b"DEFINE_tfunction(int, char);\n" - ), - ) + self.check_patching_result( + patch, + syntax, + b"#define DEFINE_tfunction(A, B) \\\n" + b" void CONCAT(tfunction, CONCAT(A, B))(){}\n" + b"DEFINE_tfunction(int, int);\n" + b"DEFINE_tfunction(int, char);\n", + ) def test_templateparamdecl(self): patch = Patches.TemplateParamDecl.TemplateParamDecl(0) syntax = b"void function(ArrayRef x);" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual(patch.get_patch(cb, syntax, **kwargs), b"const uint8_t *x") + self.check_patching_result(patch, syntax, b"const uint8_t *x") def test_templaterefs(self): patch = Patches.TemplateRefs.TemplateRefs(0) syntax = b"TemplateFunction();" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - self.assertEqual( - patch.get_patch(cb, syntax, **kwargs), - b"CONCAT(TemplateFunction, CONCAT(A, B))", - ) + self.check_patching_result( + patch, + syntax, + b"CONCAT(TemplateFunction, CONCAT(A, B))", + ) def test_usemarkup(self): patch = Patches.UseMarkup.UseMarkup(0) syntax = b"UseMarkup()" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - assert patch.get_patch(cb, syntax, **kwargs) == b"getUseMarkup()" + self.check_patching_result(patch, syntax, b"getUseMarkup()") def test_usingdecl(self): patch = Patches.UsingDeclaration.UsingDeclaration(0) syntax = b"using namespace llvm;" - kwargs = self.translator.get_patch_kwargs(patch) - query: Query = self.ts_cpp_lang.query(patch.get_search_pattern()) - captures_bundle: [[(Node, str)]] = list() - for q in query.captures(self.parser.parse(syntax, keep_text=True).root_node): - if q[1] == patch.get_main_capture_name(): - captures_bundle.append([q]) - else: - captures_bundle[-1].append(q) - self.assertGreater(len(captures_bundle), 0) - for cb in captures_bundle: - assert patch.get_patch(cb, syntax, **kwargs) == b"" + self.check_patching_result(patch, syntax, b"") From da8d895b63606004d00f2eb8c8b001f1fe23110f Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 05:23:25 -0500 Subject: [PATCH 22/41] Import classes directly into test file --- .../cpptranslator/Tests/test_patches.py | 183 ++++++++++++------ 1 file changed, 120 insertions(+), 63 deletions(-) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index 163cdb247f..b93bdb2887 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -9,10 +9,71 @@ from tree_sitter import Node, Query -import autosync.cpptranslator.patches as Patches from autosync.cpptranslator import CppTranslator from autosync.cpptranslator.Configurator import Configurator +from autosync.cpptranslator.patches.AddCSDetail import AddCSDetail +from autosync.cpptranslator.patches.AddOperand import AddOperand +from autosync.cpptranslator.patches.Assert import Assert +from autosync.cpptranslator.patches.BitCastStdArray import BitCastStdArray +from autosync.cpptranslator.patches.CheckDecoderStatus import CheckDecoderStatus +from autosync.cpptranslator.patches.ClassesDef import ClassesDef +from autosync.cpptranslator.patches.ConstMCInstParameter import ConstMCInstParameter +from autosync.cpptranslator.patches.ConstMCOperand import ConstMCOperand +from autosync.cpptranslator.patches.CppInitCast import CppInitCast +from autosync.cpptranslator.patches.CreateOperand0 import CreateOperand0 +from autosync.cpptranslator.patches.CreateOperand1 import CreateOperand1 +from autosync.cpptranslator.patches.DeclarationInConditionClause import ( + DeclarationInConditionalClause, +) +from autosync.cpptranslator.patches.DecodeInstruction import DecodeInstruction +from autosync.cpptranslator.patches.DecoderCast import DecoderCast +from autosync.cpptranslator.patches.DecoderParameter import DecoderParameter +from autosync.cpptranslator.patches.FallThrough import FallThrough +from autosync.cpptranslator.patches.FeatureBits import FeatureBits +from autosync.cpptranslator.patches.FeatureBitsDecl import FeatureBitsDecl +from autosync.cpptranslator.patches.FieldFromInstr import FieldFromInstr +from autosync.cpptranslator.patches.GetNumOperands import GetNumOperands +from autosync.cpptranslator.patches.GetOpcode import GetOpcode +from autosync.cpptranslator.patches.GetOperand import GetOperand +from autosync.cpptranslator.patches.GetOperandRegImm import GetOperandRegImm +from autosync.cpptranslator.patches.GetRegClass import GetRegClass +from autosync.cpptranslator.patches.GetRegFromClass import GetRegFromClass +from autosync.cpptranslator.patches.GetSubReg import GetSubReg +from autosync.cpptranslator.patches.Includes import Includes +from autosync.cpptranslator.patches.InlineToStaticInline import InlineToStaticInline +from autosync.cpptranslator.patches.IsOptionalDef import IsOptionalDef +from autosync.cpptranslator.patches.IsPredicate import IsPredicate +from autosync.cpptranslator.patches.IsRegImm import IsOperandRegImm +from autosync.cpptranslator.patches.LLVMFallThrough import LLVMFallThrough +from autosync.cpptranslator.patches.LLVMunreachable import LLVMUnreachable +from autosync.cpptranslator.patches.MethodToFunctions import MethodToFunction +from autosync.cpptranslator.patches.MethodTypeQualifier import MethodTypeQualifier +from autosync.cpptranslator.patches.NamespaceAnon import NamespaceAnon +from autosync.cpptranslator.patches.NamespaceArch import NamespaceArch +from autosync.cpptranslator.patches.NamespaceLLVM import NamespaceLLVM +from autosync.cpptranslator.patches.OutStreamParam import OutStreamParam +from autosync.cpptranslator.patches.PredicateBlockFunctions import ( + PredicateBlockFunctions, +) +from autosync.cpptranslator.patches.PrintAnnotation import PrintAnnotation +from autosync.cpptranslator.patches.PrintRegImmShift import PrintRegImmShift +from autosync.cpptranslator.patches.QualifiedIdentifier import QualifiedIdentifier +from autosync.cpptranslator.patches.ReferencesDecl import ReferencesDecl +from autosync.cpptranslator.patches.RegClassContains import RegClassContains +from autosync.cpptranslator.patches.SetOpcode import SetOpcode +from autosync.cpptranslator.patches.SignExtend import SignExtend +from autosync.cpptranslator.patches.SizeAssignments import SizeAssignment +from autosync.cpptranslator.patches.STIArgument import STIArgument +from autosync.cpptranslator.patches.STIFeatureBits import STIFeatureBits +from autosync.cpptranslator.patches.STParameter import SubtargetInfoParam +from autosync.cpptranslator.patches.StreamOperation import StreamOperations +from autosync.cpptranslator.patches.TemplateDeclaration import TemplateDeclaration +from autosync.cpptranslator.patches.TemplateDefinition import TemplateDefinition +from autosync.cpptranslator.patches.TemplateParamDecl import TemplateParamDecl +from autosync.cpptranslator.patches.TemplateRefs import TemplateRefs +from autosync.cpptranslator.patches.UseMarkup import UseMarkup +from autosync.cpptranslator.patches.UsingDeclaration import UsingDeclaration from autosync.cpptranslator.TemplateCollector import TemplateCollector from autosync.Helper import get_path @@ -46,7 +107,7 @@ def check_patching_result(self, patch, syntax, expected, filename=""): self.assertEqual(patch.get_patch(cb, syntax, **kwargs), expected) def test_addcsdetail(self): - patch = Patches.AddCSDetail.AddCSDetail(0, "ARCH") + patch = AddCSDetail(0, "ARCH") syntax = b"int i = x; void printThumbLdrLabelOperand(MCInst *MI, unsigned OpNo, SStream *O) { int i = OpNo; }" self.check_patching_result( patch, @@ -58,7 +119,7 @@ def test_addcsdetail(self): ) def test_addoperand(self): - patch = Patches.AddOperand.AddOperand(0) + patch = AddOperand(0) syntax = b"MI.addOperand(OPERAND)" self.check_patching_result( patch, @@ -67,12 +128,12 @@ def test_addoperand(self): ) def test_assert(self): - patch = Patches.Assert.Assert(0) + patch = Assert(0) syntax = b"assert(0 == 0)" self.check_patching_result(patch, syntax, b"") def test_bitcaststdarray(self): - patch = Patches.BitCastStdArray.BitCastStdArray(0) + patch = BitCastStdArray(0) syntax = b"auto S = bit_cast>(Imm);" self.check_patching_result( patch, @@ -87,12 +148,12 @@ def test_bitcaststdarray(self): ) def test_checkdecoderstatus(self): - patch = Patches.CheckDecoderStatus.CheckDecoderStatus(0) + patch = CheckDecoderStatus(0) syntax = b"Check(S, functions())" self.check_patching_result(patch, syntax, b"Check(&S, functions())") def test_classesdef(self): - patch = Patches.ClassesDef.ClassesDef(0) + patch = ClassesDef(0) syntax = b"""class AArch64Disassembler : public MCDisassembler { std::unique_ptr const MCII; @@ -122,23 +183,23 @@ def test_classesdef(self): ) def test_constmcinstparameter(self): - patch = Patches.ConstMCInstParameter.ConstMCInstParameter(0) + patch = ConstMCInstParameter(0) syntax = b"void function(const MCInst *MI);" expected = b"MCInst *MI" self.check_patching_result(patch, syntax, expected) def test_constmcoperand(self): - patch = Patches.ConstMCOperand.ConstMCOperand(0) + patch = ConstMCOperand(0) syntax = b"const MCOperand op = { 0 };" self.check_patching_result(patch, syntax, b"MCOperand op = { 0 };") def test_cppinitcast(self): - patch = Patches.CppInitCast.CppInitCast(0) + patch = CppInitCast(0) syntax = b"int(0x0000)" self.check_patching_result(patch, syntax, b"((int)(0x0000))") def test_createoperand0(self): - patch = Patches.CreateOperand0.CreateOperand0(0) + patch = CreateOperand0(0) syntax = b"Inst.addOperand(MCOperand::createReg(REGISTER));" self.check_patching_result( patch, @@ -147,7 +208,7 @@ def test_createoperand0(self): ) def test_createoperand1(self): - patch = Patches.CreateOperand1.CreateOperand1(0) + patch = CreateOperand1(0) syntax = b"MI.insert(I, MCOperand::createReg(REGISTER));" self.check_patching_result( patch, @@ -156,12 +217,12 @@ def test_createoperand1(self): ) def test_declarationinconditionclause(self): - patch = Patches.DeclarationInConditionClause.DeclarationInConditionalClause(0) + patch = DeclarationInConditionalClause(0) syntax = b"if (int i = 0) {}" self.check_patching_result(patch, syntax, b"int i = 0;\nif (i)\n{}") def test_decodeinstruction(self): - patch = Patches.DecodeInstruction.DecodeInstruction(0) + patch = DecodeInstruction(0) syntax = ( b"decodeInstruction(DecoderTableThumb16, MI, Insn16, Address, this, STI);" ) @@ -179,29 +240,29 @@ def test_decodeinstruction(self): ) def test_decodercast(self): - patch = Patches.DecoderCast.DecoderCast(0) + patch = DecoderCast(0) syntax = ( b"const MCDisassembler *Dis = static_cast(Decoder);" ) self.check_patching_result(patch, syntax, b"") def test_decoderparameter(self): - patch = Patches.DecoderParameter.DecoderParameter(0) + patch = DecoderParameter(0) syntax = b"void function(const MCDisassembler *Decoder);" self.check_patching_result(patch, syntax, b"const void *Decoder") def test_fallthrough(self): - patch = Patches.FallThrough.FallThrough(0) + patch = FallThrough(0) syntax = b"[[fallthrough]]" self.check_patching_result(patch, syntax, b"// fall through") def test_featurebitsdecl(self): - patch = Patches.FeatureBitsDecl.FeatureBitsDecl(0) + patch = FeatureBitsDecl(0) syntax = b"const FeatureBitset &FeatureBits = ((const MCDisassembler*)Decoder)->getSubtargetInfo().getFeatureBits();" self.check_patching_result(patch, syntax, b"") def test_featurebits(self): - patch = Patches.FeatureBits.FeatureBits(0, b"ARCH") + patch = FeatureBits(0, b"ARCH") syntax = b"bool hasD32 = featureBits[ARCH::HasV8Ops];" self.check_patching_result( patch, @@ -210,7 +271,7 @@ def test_featurebits(self): ) def test_fieldfrominstr(self): - patch = Patches.FieldFromInstr.FieldFromInstr(0) + patch = FieldFromInstr(0) syntax = b"unsigned Rm = fieldFromInstruction(Inst16, 0, 4);" self.check_patching_result( patch, @@ -226,33 +287,33 @@ def test_fieldfrominstr(self): ) def test_getnumoperands(self): - patch = Patches.GetNumOperands.GetNumOperands(0) + patch = GetNumOperands(0) syntax = b"MI.getNumOperands();" self.check_patching_result(patch, syntax, b"MCInst_getNumOperands(MI)") def test_getopcode(self): - patch = Patches.GetOpcode.GetOpcode(0) + patch = GetOpcode(0) syntax = b"Inst.getOpcode();" self.check_patching_result(patch, syntax, b"MCInst_getOpcode(Inst)") def test_getoperand(self): - patch = Patches.GetOperand.GetOperand(0) + patch = GetOperand(0) syntax = b"MI.getOperand(0);" self.check_patching_result(patch, syntax, b"MCInst_getOperand(MI, (0))") def test_getoperandregimm(self): - patch = Patches.GetOperandRegImm.GetOperandRegImm(0) + patch = GetOperandRegImm(0) syntax = b"OPERAND.getReg()" self.check_patching_result(patch, syntax, b"MCOperand_getReg(OPERAND)") def test_getregclass(self): - patch = Patches.GetRegClass.GetRegClass(0) + patch = GetRegClass(0) syntax = b"MRI.getRegClass(RegClass);" expected = b"MCRegisterInfo_getRegClass(Inst->MRI, RegClass)" self.check_patching_result(patch, syntax, expected) def test_getregfromclass(self): - patch = Patches.GetRegFromClass.GetRegFromClass(0) + patch = GetRegFromClass(0) syntax = b"ARCHMCRegisterClasses[ARCH::FPR128RegClassID].getRegister(RegNo);" self.check_patching_result( patch, @@ -261,7 +322,7 @@ def test_getregfromclass(self): ) def test_getsubreg(self): - patch = Patches.GetSubReg.GetSubReg(0) + patch = GetSubReg(0) syntax = b"MRI.getSubReg(REGISTER);" self.check_patching_result( patch, @@ -270,7 +331,7 @@ def test_getsubreg(self): ) def test_includes(self): - patch = Patches.Includes.Includes(0, "TEST_ARCH") + patch = Includes(0, "TEST_ARCH") syntax = b'#include "some_llvm_header.h"' self.check_patching_result( patch, @@ -284,7 +345,7 @@ def test_includes(self): ) def test_inlinetostaticinline(self): - patch = Patches.InlineToStaticInline.InlineToStaticInline(0) + patch = InlineToStaticInline(0) syntax = b"inline void FUNCTION() {}" self.check_patching_result( patch, @@ -293,7 +354,7 @@ def test_inlinetostaticinline(self): ) def test_isoptionaldef(self): - patch = Patches.IsOptionalDef.IsOptionalDef(0) + patch = IsOptionalDef(0) syntax = b"OpInfo[i].isOptionalDef()" self.check_patching_result( patch, @@ -302,7 +363,7 @@ def test_isoptionaldef(self): ) def test_ispredicate(self): - patch = Patches.IsPredicate.IsPredicate(0) + patch = IsPredicate(0) syntax = b"OpInfo[i].isPredicate()" self.check_patching_result( patch, @@ -311,37 +372,37 @@ def test_ispredicate(self): ) def test_isregimm(self): - patch = Patches.IsRegImm.IsOperandRegImm(0) + patch = IsOperandRegImm(0) syntax = b"OPERAND.isReg()" self.check_patching_result(patch, syntax, b"MCOperand_isReg(OPERAND)") def test_llvmfallthrough(self): - patch = Patches.LLVMFallThrough.LLVMFallThrough(0) + patch = LLVMFallThrough(0) syntax = b"LLVM_FALLTHROUGH;" self.check_patching_result(patch, syntax, b"") def test_llvmunreachable(self): - patch = Patches.LLVMunreachable.LLVMUnreachable(0) + patch = LLVMUnreachable(0) syntax = b'llvm_unreachable("Error msg")' self.check_patching_result(patch, syntax, b'assert(0 && "Error msg")') def test_methodtofunctions(self): - patch = Patches.MethodToFunctions.MethodToFunction(0) + patch = MethodToFunction(0) syntax = b"void CLASS::METHOD_NAME(int a) {}" self.check_patching_result(patch, syntax, b"METHOD_NAME(int a)") def test_methodtypequalifier(self): - patch = Patches.MethodTypeQualifier.MethodTypeQualifier(0) + patch = MethodTypeQualifier(0) syntax = b"void a_const_method() const {}" self.check_patching_result(patch, syntax, b"a_const_method()") def test_namespaceanon(self): - patch = Patches.NamespaceAnon.NamespaceAnon(0) + patch = NamespaceAnon(0) syntax = b"namespace { int a = 0; }" self.check_patching_result(patch, syntax, b" int a = 0; ") def test_namespacearch(self): - patch = Patches.NamespaceArch.NamespaceArch(0) + patch = NamespaceArch(0) syntax = b"namespace ArchSpecificNamespace { int a = 0; }" self.check_patching_result( patch, @@ -352,17 +413,17 @@ def test_namespacearch(self): ) def test_namespacellvm(self): - patch = Patches.NamespaceLLVM.NamespaceLLVM(0) + patch = NamespaceLLVM(0) syntax = b"namespace llvm {int a = 0}" self.check_patching_result(patch, syntax, b"int a = 0") def test_outstreamparam(self): - patch = Patches.OutStreamParam.OutStreamParam(0) + patch = OutStreamParam(0) syntax = b"void function(int a, raw_ostream &OS);" self.check_patching_result(patch, syntax, b"(int a, SStream *OS)") def test_predicateblockfunctions(self): - patch = Patches.PredicateBlockFunctions.PredicateBlockFunctions(0) + patch = PredicateBlockFunctions(0) syntax = b"void function(MCInst *MI) { VPTBlock.instrInVPTBlock(); }" self.check_patching_result( patch, @@ -371,27 +432,27 @@ def test_predicateblockfunctions(self): ) def test_predicateblockfunctions(self): - patch = Patches.PrintAnnotation.PrintAnnotation(0) + patch = PrintAnnotation(0) syntax = b"printAnnotation();" self.check_patching_result(patch, syntax, b"") def test_printregimmshift(self): - patch = Patches.PrintRegImmShift.PrintRegImmShift(0) + patch = PrintRegImmShift(0) syntax = b"printRegImmShift(0)" self.check_patching_result(patch, syntax, b"printRegImmShift(Inst, 0)") def test_qualifiedidentifier(self): - patch = Patches.QualifiedIdentifier.QualifiedIdentifier(0) + patch = QualifiedIdentifier(0) syntax = b"NAMESPACE::ID" self.check_patching_result(patch, syntax, b"NAMESPACE_ID") def test_referencesdecl(self): - patch = Patches.ReferencesDecl.ReferencesDecl(0) + patch = ReferencesDecl(0) syntax = b"int &Param = 0;" self.check_patching_result(patch, syntax, b"*Param") def test_regclasscontains(self): - patch = Patches.RegClassContains.RegClassContains(0) + patch = RegClassContains(0) syntax = b"if (MRI.getRegClass(AArch64::GPR32RegClassID).contains(Reg)) {}" self.check_patching_result( patch, @@ -400,27 +461,27 @@ def test_regclasscontains(self): ) def test_setopcode(self): - patch = Patches.SetOpcode.SetOpcode(0) + patch = SetOpcode(0) syntax = b"Inst.setOpcode(0)" self.check_patching_result(patch, syntax, b"MCInst_setOpcode(Inst, (0))") def test_signextend(self): - patch = Patches.SignExtend.SignExtend(0) + patch = SignExtend(0) syntax = b"SignExtend32(0)" self.check_patching_result(patch, syntax, b"SignExtend32((0), A)") def test_sizeassignments(self): - patch = Patches.SizeAssignments.SizeAssignment(0) + patch = SizeAssignment(0) syntax = b"void function(int &Size) { Size = 0; }" self.check_patching_result(patch, syntax, b"*Size = 0") def test_stiargument(self): - patch = Patches.STIArgument.STIArgument(0) + patch = STIArgument(0) syntax = b"printSomeOperand(MI, NUM, STI, NUM)" self.check_patching_result(patch, syntax, b"(MI, NUM, NUM)") def test_stifeaturebits(self): - patch = Patches.STIFeatureBits.STIFeatureBits(0, b"ARCH") + patch = STIFeatureBits(0, b"ARCH") syntax = b"STI.getFeatureBits()[ARCH::FLAG];" self.check_patching_result( patch, @@ -429,12 +490,12 @@ def test_stifeaturebits(self): ) def test_stifeaturebits(self): - patch = Patches.STParameter.SubtargetInfoParam(0) + patch = SubtargetInfoParam(0) syntax = b"void function(MCSubtargetInfo &STI);" self.check_patching_result(patch, syntax, b"()") def test_streamoperation(self): - patch = Patches.StreamOperation.StreamOperations(0) + patch = StreamOperations(0) syntax = b"{ OS << 'a'; }" self.check_patching_result(patch, syntax, b'SStream_concat0(OS, "a");\n') @@ -455,9 +516,7 @@ def test_streamoperation(self): ) def test_templatedeclaration(self): - patch = Patches.TemplateDeclaration.TemplateDeclaration( - 0, self.template_collector - ) + patch = TemplateDeclaration(0, self.template_collector) syntax = b"template void tfunction();" self.check_patching_result( patch, @@ -469,9 +528,7 @@ def test_templatedeclaration(self): ) def test_templatedefinition(self): - patch = Patches.TemplateDefinition.TemplateDefinition( - 0, self.template_collector - ) + patch = TemplateDefinition(0, self.template_collector) syntax = b"template void tfunction() {}" self.check_patching_result( patch, @@ -483,12 +540,12 @@ def test_templatedefinition(self): ) def test_templateparamdecl(self): - patch = Patches.TemplateParamDecl.TemplateParamDecl(0) + patch = TemplateParamDecl(0) syntax = b"void function(ArrayRef x);" self.check_patching_result(patch, syntax, b"const uint8_t *x") def test_templaterefs(self): - patch = Patches.TemplateRefs.TemplateRefs(0) + patch = TemplateRefs(0) syntax = b"TemplateFunction();" self.check_patching_result( patch, @@ -497,11 +554,11 @@ def test_templaterefs(self): ) def test_usemarkup(self): - patch = Patches.UseMarkup.UseMarkup(0) + patch = UseMarkup(0) syntax = b"UseMarkup()" self.check_patching_result(patch, syntax, b"getUseMarkup()") def test_usingdecl(self): - patch = Patches.UsingDeclaration.UsingDeclaration(0) + patch = UsingDeclaration(0) syntax = b"using namespace llvm;" self.check_patching_result(patch, syntax, b"") From 5544e71e3b757c6890ce39930e926ee56b04835b Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 05:49:11 -0500 Subject: [PATCH 23/41] Let Github checkout action download the tree-sitter submodule --- .github/workflows/auto-sync.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 6d0a25aba7..c6406eb664 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -19,6 +19,8 @@ jobs: - name: Check out repository uses: actions/checkout@v4 + with: + submodules: true - name: Install auto-sync package run: | From ba08e5b1fede9cfb2499aaca69908d9748856c3b Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 06:06:52 -0500 Subject: [PATCH 24/41] Fixup .reuse dir --- .reuse/dep5 | 22 ++++++++++++++----- .reuse/reuse-bak/dep5 | 20 ----------------- .../templates/license-template.jinja2 | 0 3 files changed, 16 insertions(+), 26 deletions(-) delete mode 100644 .reuse/reuse-bak/dep5 rename .reuse/{reuse-bak => }/templates/license-template.jinja2 (100%) diff --git a/.reuse/dep5 b/.reuse/dep5 index fc755a7014..33b023fc42 100644 --- a/.reuse/dep5 +++ b/.reuse/dep5 @@ -1,10 +1,20 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: CapstoneEngine -Upstream-Contact: <> Source: https://github.com/capstone-engine/capstone -# Sample paragraph, commented out: -# -# Files: src/* -# Copyright: $YEAR $NAME <$CONTACT> -# License: ... +Files: src/autosync/cpptranslator/Tests/test_config.json +Copyright: 2022 Rot127 +License: BSD-3 + +Files: src/autosync/cpptranslator/arch_config.json +Copyright: 2022 Rot127 +License: BSD-3 + +Files: src/autosync/cpptranslator/saved_patches.json +Copyright: 2022 Rot127 +License: BSD-3 + +Files: src/autosync/path_vars.json +Copyright: 2022 Rot127 +License: BSD-3 + diff --git a/.reuse/reuse-bak/dep5 b/.reuse/reuse-bak/dep5 deleted file mode 100644 index 33b023fc42..0000000000 --- a/.reuse/reuse-bak/dep5 +++ /dev/null @@ -1,20 +0,0 @@ -Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ -Upstream-Name: CapstoneEngine -Source: https://github.com/capstone-engine/capstone - -Files: src/autosync/cpptranslator/Tests/test_config.json -Copyright: 2022 Rot127 -License: BSD-3 - -Files: src/autosync/cpptranslator/arch_config.json -Copyright: 2022 Rot127 -License: BSD-3 - -Files: src/autosync/cpptranslator/saved_patches.json -Copyright: 2022 Rot127 -License: BSD-3 - -Files: src/autosync/path_vars.json -Copyright: 2022 Rot127 -License: BSD-3 - diff --git a/.reuse/reuse-bak/templates/license-template.jinja2 b/.reuse/templates/license-template.jinja2 similarity index 100% rename from .reuse/reuse-bak/templates/license-template.jinja2 rename to .reuse/templates/license-template.jinja2 From aeb66e9445fdeb2d2b4e08fe703c7694a2328729 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 06:23:18 -0500 Subject: [PATCH 25/41] Fix sdist build by moving all license to LICENSES/ --- LICENSE.TXT => LICENSES/LICENSE.TXT | 0 LICENSES/{BSD-3-Clause.txt => LICENSE_BSD_3_CLAUSE.txt} | 0 LICENSE_LLVM.TXT => LICENSES/LICENSE_LLVM.TXT | 0 bindings/python/setup.py | 2 +- 4 files changed, 1 insertion(+), 1 deletion(-) rename LICENSE.TXT => LICENSES/LICENSE.TXT (100%) rename LICENSES/{BSD-3-Clause.txt => LICENSE_BSD_3_CLAUSE.txt} (100%) rename LICENSE_LLVM.TXT => LICENSES/LICENSE_LLVM.TXT (100%) diff --git a/LICENSE.TXT b/LICENSES/LICENSE.TXT similarity index 100% rename from LICENSE.TXT rename to LICENSES/LICENSE.TXT diff --git a/LICENSES/BSD-3-Clause.txt b/LICENSES/LICENSE_BSD_3_CLAUSE.txt similarity index 100% rename from LICENSES/BSD-3-Clause.txt rename to LICENSES/LICENSE_BSD_3_CLAUSE.txt diff --git a/LICENSE_LLVM.TXT b/LICENSES/LICENSE_LLVM.TXT similarity index 100% rename from LICENSE_LLVM.TXT rename to LICENSES/LICENSE_LLVM.TXT diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 92ebf2d337..9cbd35b8bd 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -96,7 +96,7 @@ def copy_sources(): src.extend(glob.glob(os.path.join(BUILD_DIR, "*.mk"))) src.extend(glob.glob(os.path.join(BUILD_DIR, "Makefile"))) - src.extend(glob.glob(os.path.join(BUILD_DIR, "LICENSE*"))) + src.extend(glob.glob(os.path.join(BUILD_DIR, "LICENSES/*"))) src.extend(glob.glob(os.path.join(BUILD_DIR, "README"))) src.extend(glob.glob(os.path.join(BUILD_DIR, "*.TXT"))) src.extend(glob.glob(os.path.join(BUILD_DIR, "RELEASE_NOTES"))) From d1f4b5daeeb7c12777c114f014d0773374b15816 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 06:46:54 -0500 Subject: [PATCH 26/41] Add printVectorIndex to templateswith argument deduction. --- suite/auto-sync/src/autosync/cpptranslator/arch_config.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/suite/auto-sync/src/autosync/cpptranslator/arch_config.json b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json index b33e9b1372..99da609f6b 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/arch_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json @@ -113,7 +113,8 @@ "printImmSVE", "printAMIndexedWB", "isSVECpyImm", - "isSVEAddSubImm" + "isSVEAddSubImm", + "printVectorIndex" ], "manually_edited_files": [] }, From e3441e52d5985350356445661aa66f6feab68a2c Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 06:47:09 -0500 Subject: [PATCH 27/41] Formatting of config files --- suite/auto-sync/src/autosync/path_vars.json | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/suite/auto-sync/src/autosync/path_vars.json b/suite/auto-sync/src/autosync/path_vars.json index 1a61077958..911111110b 100644 --- a/suite/auto-sync/src/autosync/path_vars.json +++ b/suite/auto-sync/src/autosync/path_vars.json @@ -1,6 +1,6 @@ { "paths": { - "{LLVM_ROOT}": "{AUTO_SYNC_ROOT}/vendor/llvm_root//", + "{LLVM_ROOT}": "{AUTO_SYNC_ROOT}/vendor/llvm_root/", "{LLVM_TARGET_DIR}": "{LLVM_ROOT}/llvm/lib/Target/", "{LLVM_TBLGEN_BIN}": "{LLVM_ROOT}/build/bin/llvm-tblgen", "{LLVM_INCLUDE_DIR}": "{LLVM_ROOT}/llvm/include/", @@ -20,6 +20,12 @@ "{CS_ARCH_MODULE_DIR}": "{CS_ROOT}/arch/", "{CS_CLANG_FORMAT_FILE}": "{CS_ROOT}/.clang-format" }, - "create_during_runtime": ["{BUILD_DIR}", "{C_INC_OUT_DIR}", "{CPP_INC_OUT_DIR}", "{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}", "{CPP_TRANSLATOR_DIFF_OUT_DIR}"] + "create_during_runtime": [ + "{BUILD_DIR}", + "{C_INC_OUT_DIR}", + "{CPP_INC_OUT_DIR}", + "{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}", + "{CPP_TRANSLATOR_DIFF_OUT_DIR}" + ] } From f26fe3ad38fde63b2103253acc4ac413a69857ef Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 07:08:32 -0500 Subject: [PATCH 28/41] Allow to fix none typedefed enums. --- .../src/autosync/cpptranslator/patches/Helper.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py b/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py index dface4ae22..45623d77ed 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py +++ b/suite/auto-sync/src/autosync/cpptranslator/patches/Helper.py @@ -105,18 +105,21 @@ def namespace_enum(src: bytes, ns_id: bytes, enum: Node) -> bytes: type_id = c primary_tid_set = True - if not (enumerator_list and type_id): + if not enumerator_list and not type_id: log.fatal("Could not find enumerator_list or enum type_identifier.") exit(1) - tid = get_text(src, type_id.start_byte, type_id.end_byte) + tid = get_text(src, type_id.start_byte, type_id.end_byte) if type_id else None elist = get_text(src, enumerator_list.start_byte, enumerator_list.end_byte) for e in enumerator_list.named_children: if e.type == "enumerator": enum_entry_text = get_text(src, e.start_byte, e.end_byte) elist = elist.replace(enum_entry_text, ns_id + b"_" + enum_entry_text) - new_enum = b"typedef enum " + tid + b" " + elist + b"\n " + ns_id + b"_" + tid + if tid: + new_enum = b"typedef enum " + tid + b" " + elist + b"\n " + ns_id + b"_" + tid + else: + new_enum = b"enum " + b" " + elist + b"\n" return new_enum From 190d5d208358cfc2ff284fd7b848ecd417a28001 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 07:15:51 -0500 Subject: [PATCH 29/41] Add test for full translation to AS workflow. --- .github/workflows/auto-sync.yml | 9 ++++++++- suite/auto-sync/src/autosync/ASUpdater.py | 11 ++++++++++- suite/auto-sync/src/autosync/Helper.py | 10 ++++++---- .../src/autosync/cpptranslator/CppTranslator.py | 5 +++-- .../src/autosync/cpptranslator/Tests/test_patches.py | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index c6406eb664..7e03c8dcd0 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -40,7 +40,7 @@ jobs: cmake --build . --target llvm-tblgen --config Debug cd ../../../ - - name: Test generationof inc files + - name: Test generation of inc files run: | ./src/autosync/ASUpdater.py -a AArch64 -s IncGen ./src/autosync/ASUpdater.py -a Alpha -s IncGen @@ -50,3 +50,10 @@ jobs: - name: CppTranslator - Patch tests run: | python -m unittest discover src/autosync/cpptranslator/Tests/ + + - name: Test translation + run: | + ./src/autosync/ASUpdater.py --ci -d -a AArch64 -s Translate + ./src/autosync/ASUpdater.py --ci -d -a ARM -s Translate + ./src/autosync/ASUpdater.py --ci -d -a PPC -s Translate + diff --git a/suite/auto-sync/src/autosync/ASUpdater.py b/suite/auto-sync/src/autosync/ASUpdater.py index 4f952c1082..aace638648 100755 --- a/suite/auto-sync/src/autosync/ASUpdater.py +++ b/suite/auto-sync/src/autosync/ASUpdater.py @@ -42,11 +42,13 @@ def __init__( no_clean: bool, refactor: bool, differ_no_auto_apply: bool, + wait_for_user: bool = True, ) -> None: self.arch = arch self.write = write self.no_clean_build = no_clean self.inc_list = inc_list + self.wait_for_user = wait_for_user if USteps.ALL in steps: self.steps = [USteps.INC_GEN, USteps.TRANS, USteps.DIFF] else: @@ -120,7 +122,7 @@ def translate(self) -> None: self.check_tree_sitter() translator_config = get_path("{CPP_TRANSLATOR_CONFIG}") configurator = Configurator(self.arch, translator_config) - translator = Translator(configurator) + translator = Translator(configurator, self.wait_for_user) translator.translate() translator.remark_manual_files() @@ -226,6 +228,12 @@ def parse_args() -> argparse.Namespace: help="Sets change update behavior to ease refacotring and new implementations.", action="store_true", ) + parser.add_argument( + "--ci", + dest="wait_for_user", + help="The translator will not wait for user input when printing important logs.", + action="store_false", + ) arguments = parser.parse_args() return arguments @@ -248,5 +256,6 @@ def parse_args() -> argparse.Namespace: args.no_clean, args.refactor, args.no_auto_apply, + args.wait_for_user, ) Updater.update() diff --git a/suite/auto-sync/src/autosync/Helper.py b/suite/auto-sync/src/autosync/Helper.py index 86eeef882c..6f7b352877 100644 --- a/suite/auto-sync/src/autosync/Helper.py +++ b/suite/auto-sync/src/autosync/Helper.py @@ -82,23 +82,25 @@ def find_id_by_type(node: Node, node_types: [str], type_must_match: bool) -> byt return b"" -def print_prominent_warning(msg: str) -> None: +def print_prominent_warning(msg: str, wait_for_user: bool = True) -> None: print("\n" + separator_line_1("yellow")) print(termcolor.colored("WARNING", "yellow", attrs=["bold"]) + "\n") print(msg) print(separator_line_1("yellow")) - input("Press enter to continue...\n") + if wait_for_user: + input("Press enter to continue...\n") def term_width() -> int: return shutil.get_terminal_size()[0] -def print_prominent_info(msg: str) -> None: +def print_prominent_info(msg: str, wait_for_user: bool = True) -> None: print("\n" + separator_line_1("blue")) print(msg) print(separator_line_1("blue")) - input("Press enter to continue...\n") + if wait_for_user: + input("Press enter to continue...\n") def bold(msg: str, color: str = None) -> str: diff --git a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py index c6cd7b87b2..c328295b7e 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py +++ b/suite/auto-sync/src/autosync/cpptranslator/CppTranslator.py @@ -174,8 +174,9 @@ class Translator: TemplateDefinition.__name__: 6, } - def __init__(self, configure: Configurator): + def __init__(self, configure: Configurator, wait_for_user: bool = False): self.configurator = configure + self.wait_for_user = wait_for_user self.arch = self.configurator.get_arch() self.conf = self.configurator.get_arch_config() self.conf_general = self.configurator.get_general_config() @@ -475,7 +476,7 @@ def remark_manual_files(self) -> None: return for f in manual_edited: msg += get_path(f).name + "\n" - print_prominent_warning(msg) + print_prominent_warning(msg, self.wait_for_user) def parse_args() -> argparse.Namespace: diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index b93bdb2887..1ce72a0054 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -82,7 +82,7 @@ class TestPatches(unittest.TestCase): @classmethod def setUpClass(cls): configurator = Configurator("ARCH", get_path("{CPP_TRANSLATOR_TEST_CONFIG}")) - cls.translator = CppTranslator.Translator(configurator) + cls.translator = CppTranslator.Translator(configurator, False) cls.ts_cpp_lang = configurator.get_cpp_lang() cls.parser = configurator.get_parser() cls.template_collector = TemplateCollector( From a95071be7ac0bcaac1f09bc6542ef786418d793f Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 07:20:12 -0500 Subject: [PATCH 30/41] Typo and better names --- .github/workflows/auto-sync.yml | 2 +- suite/auto-sync/src/autosync/ASUpdater.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 7e03c8dcd0..9d3b73f259 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -51,7 +51,7 @@ jobs: run: | python -m unittest discover src/autosync/cpptranslator/Tests/ - - name: Test translation + - name: CppTranslator - Test translation run: | ./src/autosync/ASUpdater.py --ci -d -a AArch64 -s Translate ./src/autosync/ASUpdater.py --ci -d -a ARM -s Translate diff --git a/suite/auto-sync/src/autosync/ASUpdater.py b/suite/auto-sync/src/autosync/ASUpdater.py index aace638648..3a15c9d66b 100755 --- a/suite/auto-sync/src/autosync/ASUpdater.py +++ b/suite/auto-sync/src/autosync/ASUpdater.py @@ -225,7 +225,7 @@ def parse_args() -> argparse.Namespace: parser.add_argument( "--refactor", dest="refactor", - help="Sets change update behavior to ease refacotring and new implementations.", + help="Sets change update behavior to ease refactoring and new implementations.", action="store_true", ) parser.add_argument( From b1e5dad91b1de97b1ee9f98f5a86c40f965be48e Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 07:40:36 -0500 Subject: [PATCH 31/41] Don't delete generated files for later translation --- .github/workflows/auto-sync.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 9d3b73f259..fdb419fa5b 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -42,10 +42,10 @@ jobs: - name: Test generation of inc files run: | - ./src/autosync/ASUpdater.py -a AArch64 -s IncGen - ./src/autosync/ASUpdater.py -a Alpha -s IncGen - ./src/autosync/ASUpdater.py -a ARM -s IncGen - ./src/autosync/ASUpdater.py -a PPC -s IncGen + ./src/autosync/ASUpdater.py -a -d AArch64 -s IncGen + ./src/autosync/ASUpdater.py -a -d Alpha -s IncGen + ./src/autosync/ASUpdater.py -a -d ARM -s IncGen + ./src/autosync/ASUpdater.py -a -d PPC -s IncGen - name: CppTranslator - Patch tests run: | From 4423b876d9061ad0aac9863025a95effd31df2b8 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 07:40:53 -0500 Subject: [PATCH 32/41] Delete present files before moving --- suite/auto-sync/src/autosync/IncGenerator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/suite/auto-sync/src/autosync/IncGenerator.py b/suite/auto-sync/src/autosync/IncGenerator.py index f81351d538..35c3f6cd43 100644 --- a/suite/auto-sync/src/autosync/IncGenerator.py +++ b/suite/auto-sync/src/autosync/IncGenerator.py @@ -110,6 +110,8 @@ def move_mapping_files(self) -> None: for file in Path.cwd().iterdir(): if re.search(rf"{self.arch}Gen.*\.inc", file.name): log.debug(f"Move {file} to {self.output_dir_c_inc}") + if self.output_dir_c_inc.joinpath(file.name).exists(): + os.remove(self.output_dir_c_inc.joinpath(file.name)) shutil.move(file, self.output_dir_c_inc) if self.arch == "AArch64": @@ -126,6 +128,8 @@ def move_mapping_files(self) -> None: fail_exit( f"{sys_ops_table_file} does not exist. But it should have been generated." ) + if new_sys_ops_file.exists(): + os.remove(new_sys_ops_file) shutil.move(sys_ops_table_file, new_sys_ops_file) def gen_incs(self) -> None: From fcee1876b23cbbb11f69febeb42614d73e13f4c4 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 07:41:33 -0500 Subject: [PATCH 33/41] Replace deprecated call. --- suite/auto-sync/src/autosync/IncGenerator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/suite/auto-sync/src/autosync/IncGenerator.py b/suite/auto-sync/src/autosync/IncGenerator.py index 35c3f6cd43..e29c22e2d7 100644 --- a/suite/auto-sync/src/autosync/IncGenerator.py +++ b/suite/auto-sync/src/autosync/IncGenerator.py @@ -192,6 +192,6 @@ def apply_patches(self) -> None: check=True, ) except subprocess.CalledProcessError as e: - log.warn(f"Patch {patch.name} did not apply correctly!") - log.warn(f"git apply returned: {e}") + log.warning(f"Patch {patch.name} did not apply correctly!") + log.warning(f"git apply returned: {e}") return From d84ccd298aef05f6fc226a70b212ed075d178d4e Mon Sep 17 00:00:00 2001 From: Rot127 Date: Fri, 22 Mar 2024 08:26:34 -0500 Subject: [PATCH 34/41] Fix CI --- .github/workflows/auto-sync.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index fdb419fa5b..09ad9b5ac1 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -42,10 +42,10 @@ jobs: - name: Test generation of inc files run: | - ./src/autosync/ASUpdater.py -a -d AArch64 -s IncGen - ./src/autosync/ASUpdater.py -a -d Alpha -s IncGen - ./src/autosync/ASUpdater.py -a -d ARM -s IncGen - ./src/autosync/ASUpdater.py -a -d PPC -s IncGen + ./src/autosync/ASUpdater.py -d -a AArch64 -s IncGen + ./src/autosync/ASUpdater.py -d -a Alpha -s IncGen + ./src/autosync/ASUpdater.py -d -a ARM -s IncGen + ./src/autosync/ASUpdater.py -d -a PPC -s IncGen - name: CppTranslator - Patch tests run: | From a69bc94e3cc72da95ce2c9d2bc874fec699b7667 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 23 Mar 2024 02:49:56 -0500 Subject: [PATCH 35/41] Replace LGPL-3 with BSD-3 --- suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c | 2 +- .../auto-sync/src/autosync/cpptranslator/Tests/test_patches.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c b/suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c index 4bc6f3f3f4..d36c96584a 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c @@ -1,5 +1,5 @@ // SPDX-FileCopyrightText: 2024 Rot127 -// SPDX-License-Identifier: LGPL-3.0-only +// SPDX-License-Identifier: BSD-3 int main() { tfunction(); diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index 1ce72a0054..4bdbb0f693 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -3,7 +3,6 @@ # Copyright © 2022 Rot127 # SPDX-FileCopyrightText: 2024 Rot127 # SPDX-License-Identifier: BSD-3 -# SPDX-License-Identifier: LGPL-3.0-only import unittest From e9caca785773c19ea73ca5a2503e57dfc8020e1c Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 23 Mar 2024 02:52:52 -0500 Subject: [PATCH 36/41] Add tests for header patcher. --- .github/workflows/auto-sync.yml | 3 ++ suite/auto-sync/src/autosync/HeaderPatcher.py | 15 ++++-- .../auto-sync/src/autosync/PathVarHandler.py | 1 - .../src/autosync/Tests/test_header.h | 12 +++++ .../src/autosync/Tests/test_header_patcher.py | 48 +++++++++++++++++++ .../src/autosync/Tests/test_include.inc | 11 +++++ suite/auto-sync/src/autosync/path_vars.json | 4 +- 7 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 suite/auto-sync/src/autosync/Tests/test_header.h create mode 100644 suite/auto-sync/src/autosync/Tests/test_header_patcher.py create mode 100644 suite/auto-sync/src/autosync/Tests/test_include.inc diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 09ad9b5ac1..893efde2de 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -57,3 +57,6 @@ jobs: ./src/autosync/ASUpdater.py --ci -d -a ARM -s Translate ./src/autosync/ASUpdater.py --ci -d -a PPC -s Translate + - name: Test Header patcher + run: | + python -m unittest src/autosync/Tests/test_header_patcher.py diff --git a/suite/auto-sync/src/autosync/HeaderPatcher.py b/suite/auto-sync/src/autosync/HeaderPatcher.py index d8f5da0581..502e389718 100755 --- a/suite/auto-sync/src/autosync/HeaderPatcher.py +++ b/suite/auto-sync/src/autosync/HeaderPatcher.py @@ -31,9 +31,13 @@ def error_exit(msg: str) -> None: class HeaderPatcher: - def __init__(self, header: Path, inc: Path) -> None: + def __init__(self, header: Path, inc: Path, write_file: bool = True) -> None: self.header = header self.inc = inc + self.inc_content: str = "" + self.write_file = write_file + # Gets set to the patched file content if writing to the file is disabled. + self.patched_header_content: str = "" def patch_header(self) -> bool: if not (self.header.exists() or self.header.is_file()): @@ -76,7 +80,7 @@ def patch_header(self) -> bool: header_enum_id = f":{ev_id}" if ev_id != "NOTGIVEN" else "" regex = ( rf"\s*// generated content <{self.inc.name}{header_enum_id}> begin.*(\n)" - rf"(.*\n)+" + rf"(.*\n)*" rf"\s*// generated content <{self.inc.name}{header_enum_id}> end.*(\n)" ) if not re.search(regex, header_content): @@ -91,8 +95,11 @@ def patch_header(self) -> bool: ) header_content = re.sub(regex, new_content, header_content) - with open(self.header, "w") as f: - f.write(header_content) + if self.write_file: + with open(self.header, "w") as f: + f.write(header_content) + else: + self.patched_header_content = header_content log.info(f"Patched {self.inc.name} into {self.header.name}") return True diff --git a/suite/auto-sync/src/autosync/PathVarHandler.py b/suite/auto-sync/src/autosync/PathVarHandler.py index ffe9256866..67b8d15f6d 100644 --- a/suite/auto-sync/src/autosync/PathVarHandler.py +++ b/suite/auto-sync/src/autosync/PathVarHandler.py @@ -19,7 +19,6 @@ def __call__(cls, *args, **kwargs): class PathVarHandler(metaclass=Singleton): - def __init__(self) -> None: try: res = subprocess.run( diff --git a/suite/auto-sync/src/autosync/Tests/test_header.h b/suite/auto-sync/src/autosync/Tests/test_header.h new file mode 100644 index 0000000000..f5cac5620a --- /dev/null +++ b/suite/auto-sync/src/autosync/Tests/test_header.h @@ -0,0 +1,12 @@ +// SPDX-FileCopyrightText: 2024 Rot127 +// SPDX-License-Identifier: BSD-3 + + + // Include the whole file + // generated content begin + // generated content end + + // Include only a part of the file. + // generated content begin + // generated content end + diff --git a/suite/auto-sync/src/autosync/Tests/test_header_patcher.py b/suite/auto-sync/src/autosync/Tests/test_header_patcher.py new file mode 100644 index 0000000000..110dd63ef3 --- /dev/null +++ b/suite/auto-sync/src/autosync/Tests/test_header_patcher.py @@ -0,0 +1,48 @@ +# SPDX-FileCopyrightText: 2024 Rot127 +# SPDX-License-Identifier: BSD-3 + +import unittest +from pathlib import Path + +from autosync.HeaderPatcher import HeaderPatcher +from autosync.Helper import get_path + + +class TestHeaderPatcher(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.hpatcher = HeaderPatcher( + get_path("{HEADER_PATCHER_TEST_HEADER_FILE}"), + get_path("{HEADER_PATCHER_TEST_INC_FILE}"), + write_file=False, + ) + + def test_header_patching(self): + self.hpatcher.patch_header() + self.assertEqual( + self.hpatcher.patched_header_content, + ( + "// SPDX-FileCopyrightText: 2024 Rot127 \n" + "// SPDX-License-Identifier: BSD-3\n" + "\n" + "\n" + " // Include the whole file\n" + " // generated content begin\n" + " // clang-format off\n" + "\n" + "This part should be included if the whole file is included.\n" + "\n" + " // clang-format on\n" + " // generated content end\n" + "\n" + " // Include only a part of the file.\n" + " // generated content begin\n" + " // clang-format off\n" + "\n" + " Partial include of something\n" + "\n" + " // clang-format on\n" + " // generated content end\n" + "\n" + ), + ) diff --git a/suite/auto-sync/src/autosync/Tests/test_include.inc b/suite/auto-sync/src/autosync/Tests/test_include.inc new file mode 100644 index 0000000000..a0288c9307 --- /dev/null +++ b/suite/auto-sync/src/autosync/Tests/test_include.inc @@ -0,0 +1,11 @@ +// SPDX-FileCopyrightText: 2024 Rot127 +// SPDX-License-Identifier: BSD-3 + +#ifdef GUARD +#undef GUARD + +Partial include of something + +#endif + +This part should be included if the whole file is included. diff --git a/suite/auto-sync/src/autosync/path_vars.json b/suite/auto-sync/src/autosync/path_vars.json index 911111110b..bfa4d0347d 100644 --- a/suite/auto-sync/src/autosync/path_vars.json +++ b/suite/auto-sync/src/autosync/path_vars.json @@ -18,7 +18,9 @@ "{INC_PATCH_DIR}": "{AUTO_SYNC_ROOT}/inc_patches/", "{CS_INCLUDE_DIR}": "{CS_ROOT}/include/capstone/", "{CS_ARCH_MODULE_DIR}": "{CS_ROOT}/arch/", - "{CS_CLANG_FORMAT_FILE}": "{CS_ROOT}/.clang-format" + "{CS_CLANG_FORMAT_FILE}": "{CS_ROOT}/.clang-format", + "{HEADER_PATCHER_TEST_HEADER_FILE}": "{AUTO_SYNC_SRC}/Tests/test_header.h", + "{HEADER_PATCHER_TEST_INC_FILE}": "{AUTO_SYNC_SRC}/Tests/test_include.inc" }, "create_during_runtime": [ "{BUILD_DIR}", From 417676562f0606cdd8984a407bd703ecc0ee3164 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 23 Mar 2024 03:47:14 -0500 Subject: [PATCH 37/41] Some cleanups in the Differ. --- .../src/autosync/cpptranslator/Differ.py | 91 +++++++++++++------ .../src/autosync/cpptranslator/README.md | 2 +- 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Differ.py b/suite/auto-sync/src/autosync/cpptranslator/Differ.py index 2877154856..60b31482c1 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/Differ.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Differ.py @@ -11,7 +11,6 @@ from enum import StrEnum from pathlib import Path from shutil import copy2 -from typing import Iterator from tree_sitter import Language, Node, Parser, Tree @@ -151,6 +150,38 @@ def __str__(self) -> str: class Differ: """ Diffs the newly translated C++ files against the old version. + + The general diffing works like this: + + The old and the new file get parsed with tree sitter into an AST. + Then, we extract all nodes of a specific type out of this AST. + Which nodes specifically is defined in "arch_config.json::General::nodes_to_diff". + + These nodes (old and new separately) are than sorted descending by their coordinates. + Meaning, nodes at the end in the file come first. + The identifiers of those nodes are saved in a single list. + Now we iterate over this list of identifiers. Now we make decisions: + + The node id is present as: + old node & new node => Text matches? + yes => Continue + no => Add new node as Patch (see below) + only old node => We save all consecutive old nodes, which have _no_ equivalent new node + and add them as single patch + only new node => Add patch + + Now we have the patch. We have a persistence file which saved previous decisions, on which patch to choose. + We take the node text of the old and new node (or only from a single one) and compare them to our previous decision. + If the text of the nodes didn't change since the last run, we auto-apply the patch. + Otherwise, the user decides: + - Choose the old node text + - Choose the new node text + - Open the editor to edit the patch and apply it. + - Use the stored previous decision. + - Select always the old nodes. + - Go back and decide on node before. + + Each decision is saved to the persistence file for later. """ ts_cpp_lang: Language = None @@ -166,8 +197,8 @@ class Differ: patches: list[Patch] current_patch: Patch - cur_old_node: Node = None - cur_new_node: Node = None + cur_old_node: Node | None = None + cur_new_node: Node | None = None cur_nid: str = None def __init__(self, configurator: Configurator, no_auto_apply: bool): @@ -337,7 +368,7 @@ def print_diff(self, diff_lines: list[str], node_id: str, current: int, total: i print(separator_line_2()) @staticmethod - def no_difference(diff_lines: Iterator[str]) -> bool: + def no_difference(diff_lines: list[str]) -> bool: for line in diff_lines: if line[0] != " ": return False @@ -478,7 +509,8 @@ def diff_nodes( """ # Sort list of nodes descending. # This is necessary because - # a) we need to apply the patches backwards (so the coordinates in the file don't change. + # a) we need to apply the patches backwards (starting from the end of the file, + # so the coordinates in the file don't change, when replace text). # b) If there is an old node, which is not present in the new file, we search for # a node which is adjacent (random node order wouldn't allow this). new_nodes = { @@ -502,23 +534,24 @@ def diff_nodes( # The initial patch coordinates point after the last node in the file. n0 = new_nodes[list(new_nodes.keys())[0]] - patch_coord = PatchCoord(n0.end_byte, n0.end_byte, n0.end_point, n0.end_point) + PatchCoord(n0.end_byte, n0.end_byte, n0.end_point, n0.end_point) node_ids = sorted(node_ids) self.patches = list() matching_nodes_count = 0 - # Counts the number of old nodes which have no equivalent new node. + # Counts the number of _consecutive_ old nodes which have no equivalent new node. + # They will be merged to a single patch later consec_old = 0 - choice: ApplyType = None - i = 0 - while i < len(node_ids): - self.cur_nid = node_ids[i] - self.cur_new_node = None - if self.cur_nid in new_nodes: - self.cur_new_node = new_nodes[self.cur_nid] - self.cur_old_node = None - if self.cur_nid in old_nodes: - self.cur_old_node = old_nodes[self.cur_nid] + choice: ApplyType | None = None + idx = 0 + while idx < len(node_ids): + self.cur_nid = node_ids[idx] + self.cur_new_node = ( + None if self.cur_nid not in new_nodes else new_nodes[self.cur_nid] + ) + self.cur_old_node = ( + None if self.cur_nid not in old_nodes else old_nodes[self.cur_nid] + ) n = ( self.cur_new_node.text.decode("utf8").splitlines() @@ -535,7 +568,7 @@ def diff_nodes( if self.no_difference(diff_lines): log.debug(f"Nodes {bold(self.cur_nid)} match.") matching_nodes_count += 1 - i += 1 + idx += 1 continue if self.cur_new_node: @@ -559,38 +592,38 @@ def diff_nodes( patch_coord = PatchCoord( ref_end_byte - 1, ref_end_byte - 1, - ref_end_byte, - ref_end_byte, + ref_new.start_point, + ref_new.start_point, ) save_exists = False - saved = None + saved: dict | None = None if ( old_filepath.name in self.saved_patches and self.cur_nid in self.saved_patches[old_filepath.name] ): - saved: dict = self.saved_patches[old_filepath.name][self.cur_nid] + saved = self.saved_patches[old_filepath.name][self.cur_nid] save_exists = True if self.saved_patch_matches(saved) and not self.no_auto_apply: apply_type = ApplyType(saved["apply_type"]) self.add_patch(apply_type, consec_old, old_filepath, patch_coord) log.info(f"Auto apply patch for {bold(self.cur_nid)}") - i += 1 + idx += 1 continue if choice == ApplyType.OLD_ALL: self.add_patch(ApplyType.OLD, consec_old, old_filepath, patch_coord) - i += 1 + idx += 1 continue - self.print_diff(diff_lines, self.cur_nid, i + 1, len(node_ids)) + self.print_diff(diff_lines, self.cur_nid, idx + 1, len(node_ids)) choice = self.get_user_choice( save_exists, None if not saved else saved["apply_type"] ) if choice == ApplyType.OLD: if not self.cur_old_node: # No data in old node. Skip - i += 1 + idx += 1 continue self.add_patch(ApplyType.OLD, consec_old, old_filepath, patch_coord) elif choice == ApplyType.NEW: @@ -609,13 +642,13 @@ def diff_nodes( print(f"{bold('Editing not yet implemented.', 'light_red')}") continue elif choice == ApplyType.PREVIOUS: - if i == 0: + if idx == 0: print(bold(f"There is no previous diff for {old_filepath.name}!")) input("Press enter...") continue - i -= 1 + idx -= 1 continue - i += 1 + idx += 1 log.info(f"Number of matching nodes = {matching_nodes_count}") return self.patches diff --git a/suite/auto-sync/src/autosync/cpptranslator/README.md b/suite/auto-sync/src/autosync/cpptranslator/README.md index bd4b8f44d4..20df2f93bc 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/README.md +++ b/suite/auto-sync/src/autosync/cpptranslator/README.md @@ -24,7 +24,7 @@ The config values have the following meaning: - `diff_color_edited`: Color in the `Differ` for edited content. - `nodes_to_diff`: List of parse tree nodes which get diffed - *Mind the note below*. - `node_type`: The `type` of the node to be diffed. - - `identifier_node_type`: Types of child nodes which identify the node during diffing (the identifier must be the same in the translated and the old file!). + - `identifier_node_type`: Types of child nodes which identify the node during diffing (the identifier must be the same in the translated and the old file!). Types can be of the form `/`. - ``: Settings valid for a specific architecture - `files_to_translate`: A list of file paths to translate. - `in`: *Path* to a specific source file. From a0bf99bf5f510b53529f8e99c5f5f3f339f5f148 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 23 Mar 2024 06:33:20 -0500 Subject: [PATCH 38/41] Add basic tests for Differ persistence. --- .github/workflows/auto-sync.yml | 6 +- suite/auto-sync/.gitignore | 1 + .../auto-sync/src/autosync/PathVarHandler.py | 1 + .../Tests/Differ/new_src/diff_test_file.c | 28 +++++ .../Tests/Differ/old_src/diff_test_file.c | 29 +++++ .../Tests/Differ/test_arch_config.json | 34 ++++++ .../cpptranslator/Tests/test_differ.py | 106 ++++++++++++++++++ suite/auto-sync/src/autosync/path_vars.json | 12 +- 8 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/new_src/diff_test_file.c create mode 100644 suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/old_src/diff_test_file.c create mode 100644 suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/test_arch_config.json create mode 100644 suite/auto-sync/src/autosync/cpptranslator/Tests/test_differ.py diff --git a/.github/workflows/auto-sync.yml b/.github/workflows/auto-sync.yml index 893efde2de..325d806c62 100644 --- a/.github/workflows/auto-sync.yml +++ b/.github/workflows/auto-sync.yml @@ -49,7 +49,11 @@ jobs: - name: CppTranslator - Patch tests run: | - python -m unittest discover src/autosync/cpptranslator/Tests/ + python -m unittest src/autosync/cpptranslator/Tests/test_patches.py + + - name: CppTranslator - Differ tests + run: | + python -m unittest src/autosync/cpptranslator/Tests/test_differ.py - name: CppTranslator - Test translation run: | diff --git a/suite/auto-sync/.gitignore b/suite/auto-sync/.gitignore index ac78135860..fca115d2e0 100644 --- a/suite/auto-sync/.gitignore +++ b/suite/auto-sync/.gitignore @@ -2,5 +2,6 @@ build/ vendor/llvm_root */.idea src/auto-sync/config.json +src/autosync/cpptranslator/Tests/Differ/test_saved_patches.json src/autosync.egg-info diff --git a/suite/auto-sync/src/autosync/PathVarHandler.py b/suite/auto-sync/src/autosync/PathVarHandler.py index 67b8d15f6d..554d7a30e8 100644 --- a/suite/auto-sync/src/autosync/PathVarHandler.py +++ b/suite/auto-sync/src/autosync/PathVarHandler.py @@ -59,6 +59,7 @@ def __init__(self) -> None: log.debug(f"Set {p_name} = {resolved}") if not Path(resolved).exists() and ( p_name not in create_during_runtime + and p_name not in vars["ignore_missing"] ): missing.append(resolved) elif var_id in create_during_runtime: diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/new_src/diff_test_file.c b/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/new_src/diff_test_file.c new file mode 100644 index 0000000000..3d56833594 --- /dev/null +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/new_src/diff_test_file.c @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: 2024 Rot127 +// SPDX-License-Identifier: BSD-3 + +#include "some_header_I.h" + +#include + +#define MACRO_A 0 +#define MACRO_B 0 + +#define FCN_MACRO_A(x) function_a(x) +#define FCN_MACRO_B(x) \ + function_b(x + 1) + +int main() { + int x = 10000 * 71; + return x; +} + +void function_a(int x) { + return; +} + +void function_b(unsigned x) { + return; +} + +void only_in_new() {} diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/old_src/diff_test_file.c b/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/old_src/diff_test_file.c new file mode 100644 index 0000000000..2613598f69 --- /dev/null +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/old_src/diff_test_file.c @@ -0,0 +1,29 @@ +// SPDX-FileCopyrightText: 2024 Rot127 +// SPDX-License-Identifier: BSD-3 + +#include "some_header_I.h" + +#include + +#define MACRO_A 0 +#define MACRO_B 0 + +#define FCN_MACRO_A(x) function_a(x) +#define FCN_MACRO_B(x) \ + function_b(x) + +int main() { + int x = 71; + return x; +} + +void function_a(int x) { + return; +} + +void function_b(int x) { + return; +} + +void only_in_old_I() {} +void only_in_old_II() {} diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/test_arch_config.json b/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/test_arch_config.json new file mode 100644 index 0000000000..2f39659778 --- /dev/null +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/test_arch_config.json @@ -0,0 +1,34 @@ +{ + "General": { + "diff_color_new": "green", + "diff_color_old": "light_blue", + "diff_color_saved": "yellow", + "diff_color_edited": "light_magenta", + "nodes_to_diff": [ + { + "node_type": "function_definition", + "identifier_node_type": ["function_declarator/identifier"] + },{ + "node_type": "preproc_function_def", + "identifier_node_type": ["identifier"] + },{ + "node_type": "preproc_include", + "identifier_node_type": ["string_literal", "system_lib_string"] + },{ + "node_type": "preproc_define", + "identifier_node_type": ["identifier"] + } + ] + }, + "ARCH": { + "files_to_translate": [ + { + "in": "{DIFFER_TEST_OLD_SRC_DIR}/diff_test_file.c", + "out": "diff_test_file.c" + } + ], + "files_for_template_search": [], + "templates_with_arg_deduction": [], + "manually_edited_files": [] + } +} diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_differ.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_differ.py new file mode 100644 index 0000000000..9adc1ab122 --- /dev/null +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_differ.py @@ -0,0 +1,106 @@ +# SPDX-FileCopyrightText: 2024 Rot127 +# SPDX-License-Identifier: BSD-3 + +import unittest + +from tree_sitter import Node + +from autosync.cpptranslator.Configurator import Configurator +from autosync.cpptranslator.Differ import ApplyType, Differ, Patch, PatchCoord +from autosync.cpptranslator.TemplateCollector import TemplateCollector + +from autosync.Helper import get_path + + +class TestHeaderPatcher(unittest.TestCase): + @classmethod + def setUpClass(cls): + configurator = Configurator("ARCH", get_path("{DIFFER_TEST_CONFIG_FILE}")) + cls.ts_cpp_lang = configurator.get_cpp_lang() + cls.parser = configurator.get_parser() + cls.template_collector = TemplateCollector( + configurator.get_parser(), configurator.get_cpp_lang(), [], [] + ) + cls.differ = Differ(configurator, testing=True, no_auto_apply=True) + + def check_persistence(self, nid, expected, apply_type, edited_text): + new_node: Node = self.new_nodes[nid] if nid in self.new_nodes else None + old_node: Node = self.old_nodes[nid] if nid in self.old_nodes else None + if not new_node: + before_old_node = old_node.start_byte - 1 + coord = PatchCoord( + before_old_node, + before_old_node, + (before_old_node, before_old_node), + (before_old_node, before_old_node), + ) + else: + coord = PatchCoord( + new_node.start_byte, + new_node.end_byte, + new_node.start_point, + new_node.end_point, + ) + patch = Patch( + node_id=nid, + old=old_node.text if old_node else b"", + new=new_node.text if new_node else b"", + coord=coord, + apply=apply_type, + edit=edited_text, + ) + self.assertEqual(patch.get_persist_info(), expected) + + def parse_files(self, filename: str): + self.old_nodes = self.differ.parse_file( + get_path("{DIFFER_TEST_OLD_SRC_DIR}").joinpath(filename) + ) + self.new_nodes = self.differ.parse_file( + get_path("{DIFFER_TEST_NEW_SRC_DIR}").joinpath(filename) + ) + + def test_patch_persistence(self): + self.parse_files("diff_test_file.c") + + nid = "function_b" + expected = { + f"{nid}": { + "apply_type": "OLD", + "edit": "aaaaaaa", + "new_hash": "e5b3e0e5c6fb1f5f39e5725e464e6dfa3c6a7f1a8a5d104801e1fc10b6f1cc2b", + "old_hash": "8fc2b2123209c37534bb60c8e38564ed773430b9fc5bca37a0ae73a64b2883ab", + } + } + edited_text: bytes = b"aaaaaaa" + self.check_persistence(nid, expected, ApplyType.OLD, edited_text) + + nid = "only_in_old_I" + expected = { + f"{nid}": { + "apply_type": "NEW", + "edit": "", + "new_hash": "", + "old_hash": "37431b6fe6707794a8e07902bef6510fc1d10b833db9b1dccc70b1530997b2b1", + } + } + self.check_persistence(nid, expected, ApplyType.NEW, b"") + self.assertRaises( + NotImplementedError, + self.check_persistence, + nid=nid, + expected=expected, + apply_type=ApplyType.SAVED, + edited_text=b"", + ) + + nid = "function_b" + expected = { + f"{nid}": { + "apply_type": "EDIT", + "edit": "aaaaaaa\n\n\n\n\n91928", + "new_hash": "e5b3e0e5c6fb1f5f39e5725e464e6dfa3c6a7f1a8a5d104801e1fc10b6f1cc2b", + "old_hash": "8fc2b2123209c37534bb60c8e38564ed773430b9fc5bca37a0ae73a64b2883ab", + } + } + edited_text: bytes = b"aaaaaaa\n\n\n\n\n91928" + self.check_persistence(nid, expected, ApplyType.EDIT, edited_text) diff --git a/suite/auto-sync/src/autosync/path_vars.json b/suite/auto-sync/src/autosync/path_vars.json index bfa4d0347d..fe0055ce74 100644 --- a/suite/auto-sync/src/autosync/path_vars.json +++ b/suite/auto-sync/src/autosync/path_vars.json @@ -12,7 +12,7 @@ "{CPP_TRANSLATOR_CONFIG}": "{CPP_TRANSLATOR_DIR}/arch_config.json", "{CPP_TRANSLATOR_TEST_DIR}": "{CPP_TRANSLATOR_DIR}/Tests/", "{CPP_TRANSLATOR_TEST_CONFIG}": "{CPP_TRANSLATOR_TEST_DIR}/test_config.json", - "{CPP_TRANSLATOR_PATH_PERSISTENCE_FILE}": "{CPP_TRANSLATOR_DIR}/saved_patches.json", + "{DIFFER_PERSISTENCE_FILE}": "{CPP_TRANSLATOR_DIR}/saved_patches.json", "{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}": "{BUILD_DIR}/translate_out/", "{CPP_TRANSLATOR_DIFF_OUT_DIR}": "{BUILD_DIR}/diff_out/", "{INC_PATCH_DIR}": "{AUTO_SYNC_ROOT}/inc_patches/", @@ -20,7 +20,12 @@ "{CS_ARCH_MODULE_DIR}": "{CS_ROOT}/arch/", "{CS_CLANG_FORMAT_FILE}": "{CS_ROOT}/.clang-format", "{HEADER_PATCHER_TEST_HEADER_FILE}": "{AUTO_SYNC_SRC}/Tests/test_header.h", - "{HEADER_PATCHER_TEST_INC_FILE}": "{AUTO_SYNC_SRC}/Tests/test_include.inc" + "{HEADER_PATCHER_TEST_INC_FILE}": "{AUTO_SYNC_SRC}/Tests/test_include.inc", + "{DIFFER_TEST_DIR}": "{CPP_TRANSLATOR_TEST_DIR}/Differ/", + "{DIFFER_TEST_CONFIG_FILE}": "{DIFFER_TEST_DIR}/test_arch_config.json", + "{DIFFER_TEST_OLD_SRC_DIR}": "{DIFFER_TEST_DIR}/old_src/", + "{DIFFER_TEST_NEW_SRC_DIR}": "{DIFFER_TEST_DIR}/new_src/", + "{DIFFER_TEST_PERSISTENCE_FILE}": "{DIFFER_TEST_DIR}/test_saved_patches.json" }, "create_during_runtime": [ "{BUILD_DIR}", @@ -28,6 +33,9 @@ "{CPP_INC_OUT_DIR}", "{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}", "{CPP_TRANSLATOR_DIFF_OUT_DIR}" + ], + "ignore_missing": [ + "{DIFFER_TEST_PERSISTENCE_FILE}" ] } From eb0cf5a2940f8bf7af0a67dbc93f32facf300f38 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 23 Mar 2024 07:37:26 -0500 Subject: [PATCH 39/41] Implement editing of diffs with an editor. --- .../src/autosync/Tests/test_header_patcher.py | 1 - .../src/autosync/cpptranslator/Differ.py | 171 ++++++++++++++---- .../src/autosync/cpptranslator/README.md | 1 + .../Tests/Differ/test_arch_config.json | 1 + .../cpptranslator/Tests/test_config.json | 1 + .../autosync/cpptranslator/arch_config.json | 1 + 6 files changed, 139 insertions(+), 37 deletions(-) diff --git a/suite/auto-sync/src/autosync/Tests/test_header_patcher.py b/suite/auto-sync/src/autosync/Tests/test_header_patcher.py index 110dd63ef3..6aef639ce4 100644 --- a/suite/auto-sync/src/autosync/Tests/test_header_patcher.py +++ b/suite/auto-sync/src/autosync/Tests/test_header_patcher.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: BSD-3 import unittest -from pathlib import Path from autosync.HeaderPatcher import HeaderPatcher from autosync.Helper import get_path diff --git a/suite/auto-sync/src/autosync/cpptranslator/Differ.py b/suite/auto-sync/src/autosync/cpptranslator/Differ.py index 60b31482c1..b7f6f33090 100755 --- a/suite/auto-sync/src/autosync/cpptranslator/Differ.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Differ.py @@ -7,7 +7,9 @@ import difflib as dl import json import logging as log +import subprocess import sys +import tempfile from enum import StrEnum from pathlib import Path from shutil import copy2 @@ -77,6 +79,7 @@ class ApplyType(StrEnum): NEW = "NEW" # Apply version from new file (leave unchanged) SAVED = "SAVED" # Use saved resolution EDIT = "EDIT" # Edit patch and apply + SHOW_EDIT = "SHOW_EDIT" # Show the saved edited text. OLD_ALL = "OLD_ALL" # Apply all versions from old file. PREVIOUS = "PREVIOUS" # Ignore diff and go to previous @@ -182,6 +185,9 @@ class Differ: - Go back and decide on node before. Each decision is saved to the persistence file for later. + + Last (optional) step is to write the patches to the new file. + Please note that we always write to the new file in the current version. """ ts_cpp_lang: Language = None @@ -201,7 +207,9 @@ class Differ: cur_new_node: Node | None = None cur_nid: str = None - def __init__(self, configurator: Configurator, no_auto_apply: bool): + def __init__( + self, configurator: Configurator, no_auto_apply: bool, testing: bool = False + ): self.configurator = configurator self.no_auto_apply = no_auto_apply self.arch = self.configurator.get_arch() @@ -210,23 +218,41 @@ def __init__(self, configurator: Configurator, no_auto_apply: bool): self.ts_cpp_lang = self.configurator.get_cpp_lang() self.parser = self.configurator.get_parser() self.differ = dl.Differ() - - t_out_dir: Path = get_path("{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}") - self.translated_files = [ - t_out_dir.joinpath(sp["out"]) for sp in self.conf_arch["files_to_translate"] - ] - cs_arch_src: Path = get_path("{CS_ARCH_MODULE_DIR}") - cs_arch_src = cs_arch_src.joinpath( - self.arch if self.arch != "PPC" else "PowerPC" - ) - self.old_files = [ - cs_arch_src.joinpath(f"{cs_arch_src}/" + sp["out"]) - for sp in self.conf_arch["files_to_translate"] - ] - self.load_persistence_file() + self.testing = testing + + self.diff_out_dir = get_path("{CPP_TRANSLATOR_DIFF_OUT_DIR}") + if self.testing: + t_out_dir: Path = get_path("{DIFFER_TEST_NEW_SRC_DIR}") + self.translated_files = [ + t_out_dir.joinpath(sp["out"]) + for sp in self.conf_arch["files_to_translate"] + ] + self.old_files = [ + get_path("{DIFFER_TEST_OLD_SRC_DIR}").joinpath(sp["out"]) + for sp in self.conf_arch["files_to_translate"] + ] + self.load_persistence_file() + else: + t_out_dir: Path = get_path("{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}") + self.translated_files = [ + t_out_dir.joinpath(sp["out"]) + for sp in self.conf_arch["files_to_translate"] + ] + cs_arch_src: Path = get_path("{CS_ARCH_MODULE_DIR}") + cs_arch_src = cs_arch_src.joinpath( + self.arch if self.arch != "PPC" else "PowerPC" + ) + self.old_files = [ + cs_arch_src.joinpath(f"{cs_arch_src}/" + sp["out"]) + for sp in self.conf_arch["files_to_translate"] + ] + self.load_persistence_file() def load_persistence_file(self) -> None: - self.persistence_filepath = get_path("{CPP_TRANSLATOR_PATH_PERSISTENCE_FILE}") + if self.testing: + self.persistence_filepath = get_path("{DIFFER_TEST_PERSISTENCE_FILE}") + else: + self.persistence_filepath = get_path("{DIFFER_PERSISTENCE_FILE}") if not self.persistence_filepath.exists(): self.saved_patches = dict() return @@ -247,6 +273,10 @@ def save_to_persistence_file(self) -> None: json.dump(self.saved_patches, f, indent=2) def persist_patch(self, filename: Path, patch: Patch) -> None: + """ + :param filename: The filename this patch is saved for. + :param patch: The patch to apply. + """ if filename.name not in self.saved_patches: self.saved_patches[filename.name] = dict() log.debug(f"Save: {patch.get_persist_info()}") @@ -257,7 +287,7 @@ def copy_files(self) -> None: Copy translated files to diff directory for editing. """ log.info("Copy files for editing") - diff_dir: Path = get_path("{CPP_TRANSLATOR_DIFF_OUT_DIR}") + diff_dir: Path = self.diff_out_dir for f in self.translated_files: dest = diff_dir.joinpath(f.name) copy2(f, dest) @@ -304,7 +334,7 @@ def get_diff_node_id(self, node: Node) -> bytes: exit(1) return identifier - def parse_file(self, file: Path) -> dict: + def parse_file(self, file: Path) -> dict[str:Node]: """ Parse a files and return all nodes which should be diffed. Nodes are indexed by a unique identifier. @@ -348,7 +378,7 @@ def parse_file(self, file: Path) -> dict: def print_diff(self, diff_lines: list[str], node_id: str, current: int, total: int): new_color = self.conf_general["diff_color_new"] old_color = self.conf_general["diff_color_old"] - print(separator_line_1()) + print(separator_line_2()) print(f"{bold('Patch:')} {current}/{total}\n") print(f"{bold('Node:')} {node_id}") print(f"{bold('Color:')} {colored('NEW FILE - (Just translated)', new_color)}") @@ -384,7 +414,7 @@ def print_prompt( choice = input( f"Choice: {colored('O', old_color)}, {bold('o', old_color)}, {bold('n', new_color)}, " - f"{saved_selection}, {colored('e', edited_color)}, p, q, ? > " + f"{saved_selection}, {colored('e', edited_color)}, {colored('E', edited_color)}, p, q, ? > " ) return choice @@ -432,7 +462,7 @@ def get_user_choice( ) -> ApplyType: while True: choice = self.print_prompt(saved_diff_present, saved_choice) - if choice not in ["O", "o", "n", "e", "s", "p", "q", "?", "help"]: + if choice not in ["O", "o", "n", "e", "E", "s", "p", "q", "?", "help"]: print(f"{bold(choice)} is not valid.") self.print_prompt_help(saved_diff_present, saved_choice) continue @@ -449,6 +479,8 @@ def get_user_choice( return ApplyType.OLD_ALL elif choice == "e": return ApplyType.EDIT + elif choice == "E": + return ApplyType.SHOW_EDIT elif choice == "s": return ApplyType.SAVED elif choice in ["?", "help"]: @@ -469,7 +501,11 @@ def saved_patch_matches(self, saved: dict) -> bool: return saved["old_hash"] == old_hash and saved["new_hash"] == new_hash def create_patch( - self, coord: PatchCoord, choice: ApplyType, saved_patch: dict = None + self, + coord: PatchCoord, + choice: ApplyType, + saved_patch: dict = None, + edited_text: bytes = None, ): old = self.cur_old_node.text if self.cur_old_node else b"" new = self.cur_new_node.text if self.cur_new_node else b"" @@ -479,6 +515,7 @@ def create_patch( new, coord, saved_patch["apply_type"] if saved_patch else choice, + edit=edited_text, ) def add_patch( @@ -487,8 +524,12 @@ def add_patch( consec_old: int, old_filepath: Path, patch_coord: PatchCoord, + saved_patch: dict | None = None, + edited_text: bytes | None = None, ) -> None: - self.current_patch = self.create_patch(patch_coord, apply_type) + self.current_patch = self.create_patch( + patch_coord, apply_type, saved_patch, edited_text + ) self.persist_patch(old_filepath, self.current_patch) if consec_old > 1: # Two or more old nodes are not present in the new file. @@ -566,13 +607,16 @@ def diff_nodes( diff_lines = list(self.differ.compare(o, n)) if self.no_difference(diff_lines): - log.debug(f"Nodes {bold(self.cur_nid)} match.") + log.info( + f"{bold('Patch:')} {idx + 1}/{len(node_ids)} - Nodes {bold(self.cur_nid)} match." + ) matching_nodes_count += 1 idx += 1 continue if self.cur_new_node: consec_old = 0 + # We always write to the new file. So we always take he coordinates form it. patch_coord = PatchCoord.get_coordinates_from_node(self.cur_new_node) else: consec_old += 1 @@ -589,6 +633,7 @@ def diff_nodes( else new_nodes[0] ) ref_end_byte = ref_new.start_byte + # We always write to the new file. So we always take he coordinates form it. patch_coord = PatchCoord( ref_end_byte - 1, ref_end_byte - 1, @@ -607,7 +652,9 @@ def diff_nodes( if self.saved_patch_matches(saved) and not self.no_auto_apply: apply_type = ApplyType(saved["apply_type"]) self.add_patch(apply_type, consec_old, old_filepath, patch_coord) - log.info(f"Auto apply patch for {bold(self.cur_nid)}") + log.info( + f"{bold('Patch:')} {idx + 1}/{len(node_ids)} - Auto apply patch for {bold(self.cur_nid)}" + ) idx += 1 continue @@ -634,13 +681,34 @@ def diff_nodes( print(bold("Save does not exist.")) continue self.add_patch( - saved["apply_type"], consec_old, old_filepath, patch_coord + saved["apply_type"], + consec_old, + old_filepath, + patch_coord, + saved_patch=saved, + edited_text=saved["edit"].encode(), + ) + elif choice == ApplyType.SHOW_EDIT: + if not saved or not saved["edit"]: + print(bold("No edited text was saved before.")) + input("Press enter to continue...\n") + continue + saved_edited_text = colored( + f'\n{saved["edit"]}\n', self.conf_general["diff_color_edited"] ) + print(saved_edited_text) + input("Press enter to continue...\n") + continue elif choice == ApplyType.OLD_ALL: self.add_patch(ApplyType.OLD, consec_old, old_filepath, patch_coord) elif choice == ApplyType.EDIT: - print(f"{bold('Editing not yet implemented.', 'light_red')}") - continue + edited_text = self.edit_patch(diff_lines) + if not edited_text: + continue + self.persist_patch( + old_filepath, + self.create_patch(patch_coord, choice, edited_text=edited_text), + ) elif choice == ApplyType.PREVIOUS: if idx == 0: print(bold(f"There is no previous diff for {old_filepath.name}!")) @@ -717,6 +785,38 @@ def patch_files(self, file_patches: dict[Path, list[Patch]]) -> None: run_clang_format(list(file_patches.keys())) return + def edit_patch(self, diff_lines: list[str]) -> bytes | None: + tmp_file = tempfile.NamedTemporaryFile(suffix="c", delete=False) + tmp_file_name = tmp_file.name + tmp_file.writelines([line.encode() + b"\n" for line in diff_lines]) + tmp_file.write(self.get_edit_explanation()) + tmp_file.close() + editor = self.conf_general["patch_editor"] + try: + subprocess.run([editor, tmp_file_name]) + except FileNotFoundError: + log.error(f"Could not find editor '{editor}'") + return None + edited_text = b"" + with open(tmp_file_name, "rb") as tmp_file: + for line in tmp_file.readlines(): + if self.get_separator_line() in line: + break + edited_text += line + tmp_file.close() + return edited_text + + @staticmethod + def get_separator_line() -> bytes: + return f"// {'=' * 50}".encode() + + def get_edit_explanation(self) -> bytes: + return ( + f"{self.get_separator_line().decode('utf8')}\n" + "// Everything below this line will be deleted\n" + "// Edit the file to your liking. The result will be written 'as is' to the source file.\n" + ).encode() + def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser( @@ -732,7 +832,7 @@ def parse_args() -> argparse.Namespace: parser.add_argument( "-a", dest="arch", - help="Name of target architecture.", + help="Name of target architecture (ignored with -t option)", choices=["ARM", "PPC, AArch64", "Alpha"], required=True, ) @@ -744,11 +844,7 @@ def parse_args() -> argparse.Namespace: default="info", ) parser.add_argument( - "-c", - dest="config_path", - help="Config file for architectures.", - default="arch_config.json", - type=Path, + "-t", dest="testing", help="Run with test configuration.", action="store_true" ) arguments = parser.parse_args() return arguments @@ -764,9 +860,12 @@ def parse_args() -> argparse.Namespace: stream=sys.stdout, format="%(levelname)-5s - %(message)s", ) - cfg = Configurator(args.arch, args.config_path) + if args.testing: + cfg = Configurator("ARCH", get_path("{DIFFER_TEST_CONFIG_FILE}")) + else: + cfg = Configurator(args.arch, get_path("{CPP_TRANSLATOR_CONFIG}")) - differ = Differ(cfg, args.no_auto_apply) + differ = Differ(cfg, args.no_auto_apply, testing=args.testing) try: differ.diff() except Exception as e: diff --git a/suite/auto-sync/src/autosync/cpptranslator/README.md b/suite/auto-sync/src/autosync/cpptranslator/README.md index 20df2f93bc..5d388dc962 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/README.md +++ b/suite/auto-sync/src/autosync/cpptranslator/README.md @@ -22,6 +22,7 @@ The config values have the following meaning: - `diff_color_old`: Color in the `Differ` for old/current Capstone content. - `diff_color_saved`: Color in the `Differ` for saved content. - `diff_color_edited`: Color in the `Differ` for edited content. + - `patch_editor`: Editor to open for patch editing. - `nodes_to_diff`: List of parse tree nodes which get diffed - *Mind the note below*. - `node_type`: The `type` of the node to be diffed. - `identifier_node_type`: Types of child nodes which identify the node during diffing (the identifier must be the same in the translated and the old file!). Types can be of the form `/`. diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/test_arch_config.json b/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/test_arch_config.json index 2f39659778..9f9992364d 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/test_arch_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/Differ/test_arch_config.json @@ -4,6 +4,7 @@ "diff_color_old": "light_blue", "diff_color_saved": "yellow", "diff_color_edited": "light_magenta", + "patch_editor": "vim", "nodes_to_diff": [ { "node_type": "function_definition", diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json index 558c0d9218..b7a9f68c93 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json @@ -4,6 +4,7 @@ "diff_color_old": "light_blue", "diff_color_saved": "yellow", "diff_color_edited": "light_magenta", + "patch_editor": "vim", "nodes_to_diff": [] }, "ARCH": { diff --git a/suite/auto-sync/src/autosync/cpptranslator/arch_config.json b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json index 99da609f6b..7b8680bd10 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/arch_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/arch_config.json @@ -4,6 +4,7 @@ "diff_color_old": "light_blue", "diff_color_saved": "yellow", "diff_color_edited": "light_magenta", + "patch_editor": "vim", "nodes_to_diff": [ { "node_type": "function_definition", From 2489fc0977818c88c023a00c18f63d7d28761d81 Mon Sep 17 00:00:00 2001 From: Rot127 Date: Sat, 23 Mar 2024 07:44:14 -0500 Subject: [PATCH 40/41] Move Patch test files into own directory --- .../autosync/cpptranslator/Tests/{ => Patches}/template_src.c | 0 .../Tests/{test_config.json => Patches/test_arch_config.json} | 2 +- .../auto-sync/src/autosync/cpptranslator/Tests/test_patches.py | 2 +- suite/auto-sync/src/autosync/path_vars.json | 3 ++- 4 files changed, 4 insertions(+), 3 deletions(-) rename suite/auto-sync/src/autosync/cpptranslator/Tests/{ => Patches}/template_src.c (100%) rename suite/auto-sync/src/autosync/cpptranslator/Tests/{test_config.json => Patches/test_arch_config.json} (80%) diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c b/suite/auto-sync/src/autosync/cpptranslator/Tests/Patches/template_src.c similarity index 100% rename from suite/auto-sync/src/autosync/cpptranslator/Tests/template_src.c rename to suite/auto-sync/src/autosync/cpptranslator/Tests/Patches/template_src.c diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json b/suite/auto-sync/src/autosync/cpptranslator/Tests/Patches/test_arch_config.json similarity index 80% rename from suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json rename to suite/auto-sync/src/autosync/cpptranslator/Tests/Patches/test_arch_config.json index b7a9f68c93..6fc12a6141 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_config.json +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/Patches/test_arch_config.json @@ -9,7 +9,7 @@ }, "ARCH": { "files_to_translate": [], - "files_for_template_search": ["{CPP_TRANSLATOR_TEST_DIR}/template_src.c"], + "files_for_template_search": ["{PATCHES_TEST_DIR}/template_src.c"], "templates_with_arg_deduction": [], "manually_edited_files": [] } diff --git a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py index 4bdbb0f693..4696df7956 100644 --- a/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py +++ b/suite/auto-sync/src/autosync/cpptranslator/Tests/test_patches.py @@ -80,7 +80,7 @@ class TestPatches(unittest.TestCase): @classmethod def setUpClass(cls): - configurator = Configurator("ARCH", get_path("{CPP_TRANSLATOR_TEST_CONFIG}")) + configurator = Configurator("ARCH", get_path("{PATCHES_TEST_CONFIG}")) cls.translator = CppTranslator.Translator(configurator, False) cls.ts_cpp_lang = configurator.get_cpp_lang() cls.parser = configurator.get_parser() diff --git a/suite/auto-sync/src/autosync/path_vars.json b/suite/auto-sync/src/autosync/path_vars.json index fe0055ce74..498f1e4518 100644 --- a/suite/auto-sync/src/autosync/path_vars.json +++ b/suite/auto-sync/src/autosync/path_vars.json @@ -11,7 +11,8 @@ "{CPP_TRANSLATOR_DIR}": "{AUTO_SYNC_SRC}/cpptranslator/", "{CPP_TRANSLATOR_CONFIG}": "{CPP_TRANSLATOR_DIR}/arch_config.json", "{CPP_TRANSLATOR_TEST_DIR}": "{CPP_TRANSLATOR_DIR}/Tests/", - "{CPP_TRANSLATOR_TEST_CONFIG}": "{CPP_TRANSLATOR_TEST_DIR}/test_config.json", + "{PATCHES_TEST_DIR}": "{CPP_TRANSLATOR_TEST_DIR}/Patches/", + "{PATCHES_TEST_CONFIG}": "{PATCHES_TEST_DIR}/test_arch_config.json", "{DIFFER_PERSISTENCE_FILE}": "{CPP_TRANSLATOR_DIR}/saved_patches.json", "{CPP_TRANSLATOR_TRANSLATION_OUT_DIR}": "{BUILD_DIR}/translate_out/", "{CPP_TRANSLATOR_DIFF_OUT_DIR}": "{BUILD_DIR}/diff_out/", From 5051f53323f904d23a9e1a865bf5a1e005e5679b Mon Sep 17 00:00:00 2001 From: Rot127 Date: Mon, 25 Mar 2024 05:43:24 -0500 Subject: [PATCH 41/41] Create paths if allowed by the Path handler. --- suite/auto-sync/src/autosync/PathVarHandler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/suite/auto-sync/src/autosync/PathVarHandler.py b/suite/auto-sync/src/autosync/PathVarHandler.py index 554d7a30e8..a973f84dcf 100644 --- a/suite/auto-sync/src/autosync/PathVarHandler.py +++ b/suite/auto-sync/src/autosync/PathVarHandler.py @@ -44,7 +44,7 @@ def __init__(self) -> None: vars = json.load(f) paths = vars["paths"] - create_during_runtime = vars["create_during_runtime"] + self.create_during_runtime = vars["create_during_runtime"] missing = list() for p_name, path in paths.items(): @@ -58,11 +58,11 @@ def __init__(self) -> None: resolved: str = re.sub(var_id, str(self.paths[var_id]), resolved) log.debug(f"Set {p_name} = {resolved}") if not Path(resolved).exists() and ( - p_name not in create_during_runtime + p_name not in self.create_during_runtime and p_name not in vars["ignore_missing"] ): missing.append(resolved) - elif var_id in create_during_runtime: + elif var_id in self.create_during_runtime: self.create_path(var_id, resolved) self.paths[p_name] = Path(resolved) if len(missing) > 0: @@ -74,6 +74,8 @@ def __init__(self) -> None: def get_path(self, name: str) -> Path: if name not in self.paths: raise ValueError(f"Path variable {name} has no path saved.") + if name in self.create_during_runtime: + self.create_path(name, self.paths[name]) return self.paths[name] def complete_path(self, path_str: str) -> Path: @@ -88,6 +90,7 @@ def create_path(var_id: str, path: str): if pp.exists(): return + log.debug(f"Create path {var_id} @ {path}") postfix = var_id.strip("}").split("_")[-1] if postfix == "FILE": if not pp.parent.exists():