Skip to content

Commit 259cf22

Browse files
update
1 parent f7668f1 commit 259cf22

File tree

6 files changed

+6
-112
lines changed

6 files changed

+6
-112
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Note that you should collect **both the data dependencies and control dependenci
4242
```
4343

4444
4. Ensure you have the Tree-sitter library and language bindings installed:
45+
4546
```sh
4647
cd lib
4748
python build.py

src/memory/IR/IR.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,7 @@
44

55
class IR(ABC):
66
"""Abstract base class for intermediate representations used in code analysis.
7-
8-
This class provides an interface for loading and saving intermediate representations for abstraction
97
"""
108

119
def __init__(self, code_in_files: Dict[str, str]) -> None:
12-
self.code_in_files = code_in_files
13-
14-
@abstractmethod
15-
def load(self) -> None:
16-
"""Load and parse the intermediate representation."""
17-
pass
18-
19-
@abstractmethod
20-
def save(self) -> None:
21-
"""Save the intermediate representation"""
22-
pass
10+
self.code_in_files = code_in_files

src/memory/IR/U6IR.py

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,14 @@ class U6IR(IR):
7070
- Various locks for concurrent access protection
7171
"""
7272

73-
def __init__(self, code_in_files: Dict[str, str], persist_dir: str) -> None:
73+
def __init__(self, code_in_files: Dict[str, str]) -> None:
7474
"""Initialize U6IR with source code and optional persistence directory.
7575
7676
Args:
7777
code_in_files: Dictionary mapping file paths to their source code content
78-
persist_dir: Optional directory path for persisting IR data to disk
7978
"""
8079
super().__init__(code_in_files)
8180

82-
# Persist directory and file path
83-
self.persist_dir = persist_dir
84-
if not Path(persist_dir).exists():
85-
os.makedirs(persist_dir)
86-
self.persist_json_path = os.path.join(persist_dir, "u6ir.json")
87-
8881
# ====================================================================
8982
# RAW PARSING DATA
9083
# Data structures populated during initial AST parsing phase
@@ -472,75 +465,4 @@ def find_nodes_by_type(self, root_node: Node, node_type: str, k=0) -> List[Node]
472465
nodes.append(root_node)
473466
for child_node in root_node.children:
474467
nodes.extend(self.find_nodes_by_type(child_node, node_type, k + 1))
475-
return nodes
476-
477-
# ====================================================================
478-
# PERSISTENCE FUNCTIONS
479-
# Load and save IR data
480-
# ====================================================================
481-
482-
# @Hanxi: This function is to be implemented.
483-
def load(self) -> None:
484-
"""Load previously persisted U6IR data from disk.
485-
486-
If persist_dir was specified during initialization, attempts to load
487-
all analysis data from the persistence directory. This enables
488-
resuming analysis from a previous state without re-parsing.
489-
490-
Note:
491-
Currently not implemented - serves as placeholder for future
492-
persistence functionality.
493-
"""
494-
pass
495-
496-
# @Hanxi: This function is to be carefully designed.
497-
def save(self) -> None:
498-
"""Save current U6IR data to disk for persistence.
499-
500-
Serializes all analysis data structures to JSON format and saves to
501-
the persistence directory specified during initialization.
502-
503-
The following data is persisted:
504-
- Raw function metadata (functionRawDataDic)
505-
- Function name mappings (functionNameToId)
506-
- Function file locations (functionToFile)
507-
- Global variables/macros (glb_var_map)
508-
- Function analysis results (function_env)
509-
- API analysis results (api_env)
510-
- Call graph relationships
511-
512-
Attention: AST nodes are not serializable, so we only persist the function name and location.
513-
"""
514-
515-
# Build dictionary of data to persist
516-
persist_data = {
517-
"functionRawDataDic": {
518-
str(k): (None, v[1], v[2], v[3])
519-
for k, v in self.functionRawDataDic.items()
520-
},
521-
"functionNameToId": {k: list(v) for k, v in self.functionNameToId.items()},
522-
"functionToFile": {str(k): v for k, v in self.functionToFile.items()},
523-
"glb_var_map": self.glb_var_map,
524-
"function_env": {str(k): v.to_dict() for k, v in self.function_env.items()},
525-
"api_env": {str(k): v.to_dict() for k, v in self.api_env.items()},
526-
"function_caller_callee_map": {
527-
str(k): {str(site_id): list(callees) for site_id, callees in v.items()}
528-
for k, v in self.function_caller_callee_map.items()
529-
},
530-
"function_callee_caller_map": {
531-
str(k): [(site_id, caller_id) for site_id, caller_id in v]
532-
for k, v in self.function_callee_caller_map.items()
533-
},
534-
"function_caller_api_callee_map": {
535-
str(k): {str(site_id): list(apis) for site_id, apis in v.items()}
536-
for k, v in self.function_caller_api_callee_map.items()
537-
},
538-
"api_callee_function_caller_map": {
539-
str(k): [(site_id, caller_id) for site_id, caller_id in v]
540-
for k, v in self.api_callee_function_caller_map.items()
541-
},
542-
}
543-
544-
# Write to JSON file
545-
with open(self.persist_json_path, "w") as f:
546-
json.dump(persist_data, f, indent=2)
468+
return nodes

src/reposlice.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,10 @@ def __init__(
5555
suffixs = ["cpp", "cc", "hpp", "c", "h"]
5656
self.traverse_files(self.project_path, suffixs)
5757

58-
self.result_dir = f"{BASE_PATH}/IRDB/{self.language}/U6IR/{self.project_name}"
59-
os.makedirs(self.result_dir, exist_ok=True)
60-
6158
# Build the U6IR of the project
6259
self.ts_analyzer = Cpp_TSAnalyzer(
6360
self.code_in_files,
6461
self.language,
65-
self.result_dir,
6662
self.max_symbolic_workers,
6763
)
6864

src/tstool/analyzer/Cpp_TS_analyzer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ def __init__(
1919
self,
2020
code_in_files: Dict[str, str],
2121
language_name: str,
22-
persist_dir: str,
2322
max_symbolic_workers_num=10,
2423
) -> None:
2524
super().__init__(
26-
code_in_files, language_name, persist_dir, max_symbolic_workers_num
25+
code_in_files, language_name, max_symbolic_workers_num
2726
)
2827

2928
def _extract_function_raw_info(

src/tstool/analyzer/TS_analyzer.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ def __init__(
3030
self,
3131
code_in_files: Dict[str, str],
3232
language_name: str,
33-
persist_dir: str,
3433
max_symbolic_workers_num=10,
3534
) -> None:
3635
"""
@@ -39,17 +38,14 @@ def __init__(
3938
Args:
4039
code_in_files: Dict mapping file paths to source contents
4140
language_name: Programming language name
42-
persist_dir: Directory to persist the analysis results
4341
max_symbolic_workers_num: Max parallel workers for analysis
4442
"""
4543
self.code_in_files = code_in_files
46-
self.persist_dir = persist_dir
4744
cwd = Path(__file__).resolve().parent.absolute()
4845
TSPATH = cwd / "../../../lib/build/"
4946
language_path = TSPATH / "my-languages.so"
5047
self.max_symbolic_workers_num = max_symbolic_workers_num
51-
52-
self.u6ir = U6IR(code_in_files, persist_dir)
48+
self.u6ir = U6IR(code_in_files)
5349

5450
# Initialize tree-sitter parser
5551
self.parser = Parser()
@@ -79,14 +75,6 @@ def run(self) -> U6IR:
7975
self._analyze_call_graph()
8076
return self.u6ir
8177

82-
def incremental_run(
83-
self, old_u6ir: U6IR, code_in_changed_files: Dict[str, str]
84-
) -> U6IR:
85-
"""
86-
Run the analyzer incrementally.
87-
"""
88-
return self.u6ir
89-
9078
##################################################
9179
# Wrapper functions for project AST parsing #
9280
# (Only used by the TSAnalyzer class/subclasses) #

0 commit comments

Comments
 (0)