-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add DIBuilder functions for OOP style (#125)
* Add some OOP style functions for DIBuilder. * pass pointers to avoid AccessViolation * Last functions * add test, remove erroneous &
- Loading branch information
1 parent
52b94ee
commit 729d58e
Showing
4 changed files
with
140 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.IO; | ||
using LLVMSharp.Interop; | ||
using NUnit.Framework; | ||
|
||
namespace LLVMSharp.UnitTests | ||
{ | ||
public class DIBuilder | ||
{ | ||
[Test(Description = "Exercises some DIBuilder functions, does not test the actual debug information is correct")] | ||
public void CreateDebugLocation() | ||
{ | ||
string fileName = Path.GetFileName("DIBuilder.c"); | ||
string directory = Path.GetDirectoryName("."); | ||
LLVMModuleRef module = LLVMModuleRef.CreateWithName("netscripten"); | ||
module.Target = "asmjs-unknown-emscripten"; | ||
var dIBuilder = module.CreateDIBuilder(); | ||
var builder = module.Context.CreateBuilder(); | ||
LLVMMetadataRef fileMetadata = dIBuilder.CreateFile(fileName, directory); | ||
|
||
LLVMMetadataRef compileUnitMetadata = dIBuilder.CreateCompileUnit( | ||
LLVMDWARFSourceLanguage.LLVMDWARFSourceLanguageC, | ||
fileMetadata, "ILC", 0 /* Optimized */, String.Empty, 1, String.Empty, | ||
LLVMDWARFEmissionKind.LLVMDWARFEmissionFull, 0, 0, 0); | ||
module.AddNamedMetadataOperand("llvm.dbg.cu", compileUnitMetadata); | ||
|
||
LLVMMetadataRef functionMetaType = dIBuilder.CreateSubroutineType(fileMetadata, | ||
ReadOnlySpan<LLVMMetadataRef>.Empty, LLVMDIFlags.LLVMDIFlagZero); | ||
|
||
uint lineNumber = 1; | ||
var debugFunction = dIBuilder.CreateFunction(fileMetadata, "CreateDebugLocation", "CreateDebugLocation", | ||
fileMetadata, | ||
lineNumber, functionMetaType, 1, 1, lineNumber, 0, 0); | ||
LLVMMetadataRef currentLine = | ||
module.Context.CreateDebugLocation(lineNumber, 0, debugFunction, default(LLVMMetadataRef)); | ||
|
||
LLVMTypeRef[] FooParamTys = {LLVMTypeRef.Int64, LLVMTypeRef.Int64,}; | ||
LLVMTypeRef FooFuncTy = LLVMTypeRef.CreateFunction(LLVMTypeRef.Int64, FooParamTys); | ||
LLVMValueRef FooFunction = module.AddFunction("foo", FooFuncTy); | ||
|
||
var funcBlock = module.Context.AppendBasicBlock(FooFunction, "foo"); | ||
builder.PositionAtEnd(funcBlock); | ||
builder.BuildRet(LLVMValueRef.CreateConstInt(LLVMTypeRef.Int64, 0)); | ||
builder.CurrentDebugLocation = module.Context.MetadataAsValue(currentLine); | ||
var dwarfVersion = LLVMValueRef.CreateMDNode(new[] | ||
{ | ||
LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, 2), module.Context.GetMDString("Dwarf Version", 13), | ||
LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, 4) | ||
}); | ||
var dwarfSchemaVersion = LLVMValueRef.CreateMDNode(new[] | ||
{ | ||
LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, 2), | ||
module.Context.GetMDString("Debug Info Version", 18), | ||
LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, 3) | ||
}); | ||
module.AddNamedMetadataOperand("llvm.module.flags", dwarfVersion); | ||
module.AddNamedMetadataOperand("llvm.module.flags", dwarfSchemaVersion); | ||
dIBuilder.DIBuilderFinalize(); | ||
|
||
module.TryVerify(LLVMVerifierFailureAction.LLVMPrintMessageAction, out string message); | ||
|
||
Assert.AreEqual("", message); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters