Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace manually compile tree-sitter-cpp with their Python bindings. #2337

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions suite/auto-sync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ sudo apt install python3-venv
# Setup virtual environment in Capstone root dir
python3 -m venv ./.venv
source ./.venv/bin/activate
```

Clone C++ grammar

```
cd suite/auto-sync/
git submodule update --init --recursive ./vendor/
pip install -e .
```

Expand Down
3 changes: 2 additions & 1 deletion suite/auto-sync/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ name = "autosync"
version = "0.1.0"
dependencies = [
"termcolor >= 2.3.0",
"tree_sitter < 0.22.0",
"tree_sitter >= 0.21.3",
"tree-sitter-cpp >=0.22.0",
"black >= 24.3.0",
"usort >= 1.0.8",
"setuptools >= 69.2.0",
Expand Down
21 changes: 3 additions & 18 deletions suite/auto-sync/src/autosync/cpptranslator/Configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import logging as log
from pathlib import Path

import tree_sitter_cpp as ts_cpp
from tree_sitter import Language, Parser

from autosync.Helper import fail_exit, get_path
from autosync.Helper import fail_exit


class Configurator:
Expand All @@ -25,9 +26,7 @@ class Configurator:
def __init__(self, arch: str, config_path: Path) -> None:
self.arch = arch
self.config_path = config_path
self.ts_shared_object = get_path("{VENDOR_DIR}").joinpath("ts_cpp.so")
self.load_config()
self.ts_compile_cpp()
self.ts_set_cpp_language()
self.init_parser()

Expand Down Expand Up @@ -69,22 +68,8 @@ def load_config(self) -> None:
)
self.config = conf

def ts_compile_cpp(self) -> None:
log.info("Compile Cpp language")
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}'")
# 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(str(self.ts_shared_object), "cpp")
self.ts_cpp_lang = Language(ts_cpp.language(), "cpp")

def init_parser(self) -> None:
log.debug("Init parser")
Expand Down
1 change: 0 additions & 1 deletion suite/auto-sync/vendor/tree-sitter-cpp
Submodule tree-sitter-cpp deleted from e0c167
Loading