@@ -2694,8 +2694,10 @@ def __init__(
26942694 display_block_addrs = False ,
26952695 display_vvar_ids = False ,
26962696 min_data_addr : int = 0x400_000 ,
2697+ notes = None ,
2698+ display_notes : bool = True ,
26972699 ):
2698- super ().__init__ (flavor = flavor )
2700+ super ().__init__ (flavor = flavor , notes = notes )
26992701
27002702 self ._handlers = {
27012703 CodeNode : self ._handle_Code ,
@@ -2778,6 +2780,7 @@ def __init__(
27782780 self .map_addr_to_label : Dict [Tuple [int , Optional [int ]], RustLabel ] = {}
27792781 self .rust_func : Optional [RustFunction ] = None
27802782 self .cexterns : Optional [Set [RustVariable ]] = None
2783+ self .display_notes = display_notes
27812784
27822785 self ._analyze ()
27832786
@@ -2889,6 +2892,13 @@ def render_text(self, rust_func: RustFunction) -> RENDER_TYPE:
28892892 indent = self ._indent , pos_to_node = pos_to_node , pos_to_addr = pos_to_addr , addr_to_pos = addr_to_pos
28902893 )
28912894
2895+ if self .display_notes :
2896+ notes = self .render_notes ()
2897+ pos_to_node , pos_to_addr , addr_to_pos = self .adjust_mapping_positions (
2898+ len (notes ), pos_to_node , pos_to_addr , addr_to_pos
2899+ )
2900+ text = notes + text
2901+
28922902 for elem , node in pos_to_node .items ():
28932903 if isinstance (node .obj , RustConstant ):
28942904 ast_to_pos [node .obj .value ].add (elem )
@@ -2912,6 +2922,21 @@ def render_text(self, rust_func: RustFunction) -> RENDER_TYPE:
29122922
29132923 return text , pos_to_node , pos_to_addr , addr_to_pos , ast_to_pos
29142924
2925+ def render_notes (self ) -> str :
2926+ """
2927+ Render decompilation notes.
2928+
2929+ :return: A string containing all notes.
2930+ """
2931+ if not self .notes :
2932+ return ""
2933+
2934+ lines = []
2935+ for note in self .notes .values ():
2936+ note_lines = str (note ).split ("\n " )
2937+ lines += [f"// { line } " for line in note_lines ]
2938+ return "\n " .join (lines ) + "\n \n "
2939+
29152940 def _get_variable_type (self , var , is_global = False ):
29162941 if is_global :
29172942 return self ._variable_kb .variables ["global" ].get_variable_type (var )
0 commit comments