@@ -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
0 commit comments