Skip to content

Commit

Permalink
Run ufmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 committed Mar 21, 2024
1 parent 1bd37cc commit 9526889
Show file tree
Hide file tree
Showing 73 changed files with 700 additions and 300 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,6 @@ android-ndk-*

# python virtual env
.venv/

# Auto-sync files
suite/auto-sync/src/autosync.egg-info
3 changes: 2 additions & 1 deletion suite/auto-sync/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
build/
vendor/llvm_root
*/.idea
Updater/config.json
src/auto-sync/config.json
src/autosync.egg-info

38 changes: 29 additions & 9 deletions suite/auto-sync/src/autosync/ASUpdater.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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/<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/<ARCH>/",
action="store_true",
)
parser.add_argument(
"-v",
Expand Down Expand Up @@ -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()
8 changes: 6 additions & 2 deletions suite/auto-sync/src/autosync/HeaderPatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 9 additions & 2 deletions suite/auto-sync/src/autosync/Helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 14 additions & 7 deletions suite/auto-sync/src/autosync/IncGenerator.py
Original file line number Diff line number Diff line change
@@ -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 = [
{
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 8 additions & 2 deletions suite/auto-sync/src/autosync/PathVarHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ 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)
repo_root = res.stdout.decode("utf8").strip("\n")
# 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
Expand Down
13 changes: 9 additions & 4 deletions suite/auto-sync/src/autosync/cpptranslator/Configurator.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Loading

0 comments on commit 9526889

Please sign in to comment.