private static InstructionBuilder CreateFunctionAndGetBuilder(BitcodeModule module, DebugBasicType doubleType, string name, string section, uint line) { DIFile file = module.DIBuilder.CreateFile(TestSrcFileName); DebugFunctionType signature = module.Context.CreateFunctionType(module.DIBuilder, doubleType, doubleType, doubleType); var func = module.CreateFunction(module.DICompileUnit !, name, name, file, line, signature, true, true, line + 1, DebugInfoFlags.None, false); func.Section = section; var entry = func.AppendBasicBlock("entry"); return(new InstructionBuilder(entry)); }
/// <summary>Creates a Function definition with Debug information</summary> /// <param name="scope">Containing scope for the function</param> /// <param name="name">Name of the function in source language form</param> /// <param name="linkageName">Mangled linker visible name of the function (may be same as <paramref name="name"/> if mangling not required by source language</param> /// <param name="file">File containing the function definition</param> /// <param name="line">Line number of the function definition</param> /// <param name="signature">LLVM Function type for the signature of the function</param> /// <param name="isLocalToUnit">Flag to indicate if this function is local to the compilation unit</param> /// <param name="isDefinition">Flag to indicate if this is a definition</param> /// <param name="scopeLine">First line of the function's outermost scope, this may not be the same as the first line of the function definition due to source formatting</param> /// <param name="debugFlags">Additional flags describing this function</param> /// <param name="isOptimized">Flag to indicate if this function is optimized</param> /// <param name="tParam">Parameter Metadata node</param> /// <param name="decl">Declaration Metadata node</param> /// <returns>Function described by the arguments</returns> public Function CreateFunction(DIScope scope , string name , string linkageName , DIFile file , uint line , DebugFunctionType signature , bool isLocalToUnit , bool isDefinition , uint scopeLine , DebugInfoFlags debugFlags , bool isOptimized , [CanBeNull] MDNode tParam = null , [CanBeNull] MDNode decl = null ) { ValidateHandle( ); scope.ValidateNotNull(nameof(scope)); name.ValidateNotNullOrWhiteSpace(nameof(name)); signature.ValidateNotNull(nameof(signature)); if (signature.DIType == null) { throw new ArgumentException("Signature requires debug type information", nameof(signature)); } var func = AddFunction(linkageName ?? name, signature); var diSignature = signature.DIType; var diFunc = DIBuilder.CreateFunction(scope: scope , name: name , mangledName: linkageName , file: file , line: line , signatureType: diSignature , isLocalToUnit: isLocalToUnit , isDefinition: isDefinition , scopeLine: scopeLine , debugFlags: debugFlags , isOptimized: isOptimized , function: func , typeParameter: tParam , declaration: decl ); Debug.Assert(diFunc.Describes(func), "Expected to get a debug function that describes the provided function"); func.DISubProgram = diFunc; return(func); }