@@ -200,4 +200,37 @@ def create_subroutine_type(self, return_type, param_types):
200200 type_array .append (param_types )
201201 return self .module .add_debug_info ("DISubroutineType" , {"types" : type_array })
202202
203+ def create_local_variable_debug_info (
204+ self , name : str , arg : int , var_type : Any
205+ ) -> Any :
206+ """
207+ Create debug info for a local variable (DILocalVariable) without scope.
208+ Example:
209+ !DILocalVariable(name: "ctx", arg: 1, file: !3, line: 20, type: !7)
210+ """
211+ return self .module .add_debug_info (
212+ "DILocalVariable" ,
213+ {
214+ "name" : name ,
215+ "arg" : arg ,
216+ "file" : self .module ._file_metadata ,
217+ "type" : var_type ,
218+ },
219+ )
203220
221+ def add_scope_to_local_variable (self , local_variable_debug_info , scope_value ):
222+ """
223+ Add scope information to an existing local variable debug info object.
224+ """
225+ #TODO: this is a workaround a flaw in the debug info generation. Fix this if possible in the future.
226+ # We should not be touching llvmlite's internals like this.
227+ if hasattr (local_variable_debug_info , 'operands' ):
228+ # LLVM metadata operands is a tuple, so we need to rebuild it
229+ existing_operands = local_variable_debug_info .operands
230+
231+ # Convert tuple to list, add scope, convert back to tuple
232+ operands_list = list (existing_operands )
233+ operands_list .append (('scope' , scope_value ))
234+
235+ # Reassign the new tuple
236+ local_variable_debug_info .operands = tuple (operands_list )
0 commit comments