diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2017-04-16 16:01:22 +0000 |
commit | 71d5a2540a98c81f5bcaeb48805e0e2881f530ef (patch) | |
tree | 5343938942df402b49ec7300a1c25a2d4ccd5821 /bindings/go | |
parent | 31bbf64f3a4974a2d6c8b3b27ad2f519caf74057 (diff) |
Diffstat (limited to 'bindings/go')
-rw-r--r-- | bindings/go/llvm/DIBuilderBindings.cpp | 3 | ||||
-rw-r--r-- | bindings/go/llvm/IRBindings.cpp | 13 | ||||
-rw-r--r-- | bindings/go/llvm/IRBindings.h | 8 | ||||
-rw-r--r-- | bindings/go/llvm/ir.go | 14 | ||||
-rw-r--r-- | bindings/go/llvm/ir_test.go | 39 | ||||
-rw-r--r-- | bindings/go/llvm/transforms_pmbuilder.go | 20 |
6 files changed, 96 insertions, 1 deletions
diff --git a/bindings/go/llvm/DIBuilderBindings.cpp b/bindings/go/llvm/DIBuilderBindings.cpp index 42aa819c7961..53e223d67b4e 100644 --- a/bindings/go/llvm/DIBuilderBindings.cpp +++ b/bindings/go/llvm/DIBuilderBindings.cpp @@ -119,7 +119,8 @@ LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Dref, const char *Name) { DIBuilder *D = unwrap(Dref); return wrap(D->createPointerType(unwrap<DIType>(PointeeType), SizeInBits, - AlignInBits, Name)); + AlignInBits, /* DWARFAddressSpace */ None, + Name)); } LLVMMetadataRef diff --git a/bindings/go/llvm/IRBindings.cpp b/bindings/go/llvm/IRBindings.cpp index 20cc05043f28..4bfa1bbaf0cc 100644 --- a/bindings/go/llvm/IRBindings.cpp +++ b/bindings/go/llvm/IRBindings.cpp @@ -14,6 +14,7 @@ #include "IRBindings.h" #include "llvm/IR/Attributes.h" #include "llvm/IR/DebugLoc.h" +#include "llvm/IR/DebugInfoMetadata.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" #include "llvm/IR/LLVMContext.h" @@ -71,6 +72,18 @@ void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line, InlinedAt ? unwrap<MDNode>(InlinedAt) : nullptr)); } +LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref) { + const auto& Loc = unwrap(Bref)->getCurrentDebugLocation(); + const auto* InlinedAt = Loc.getInlinedAt(); + const LLVMDebugLocMetadata md{ + Loc.getLine(), + Loc.getCol(), + wrap(Loc.getScope()), + InlinedAt == nullptr ? nullptr : wrap(InlinedAt->getRawInlinedAt()), + }; + return md; +} + void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) { unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP)); } diff --git a/bindings/go/llvm/IRBindings.h b/bindings/go/llvm/IRBindings.h index 21147712ed5b..f4f490391d4f 100644 --- a/bindings/go/llvm/IRBindings.h +++ b/bindings/go/llvm/IRBindings.h @@ -27,6 +27,12 @@ extern "C" { #endif typedef struct LLVMOpaqueMetadata *LLVMMetadataRef; +struct LLVMDebugLocMetadata{ + unsigned Line; + unsigned Col; + LLVMMetadataRef Scope; + LLVMMetadataRef InlinedAt; +}; LLVMMetadataRef LLVMConstantAsMetadata(LLVMValueRef Val); @@ -46,6 +52,8 @@ void LLVMSetCurrentDebugLocation2(LLVMBuilderRef Bref, unsigned Line, unsigned Col, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt); +struct LLVMDebugLocMetadata LLVMGetCurrentDebugLocation2(LLVMBuilderRef Bref); + void LLVMSetSubprogram(LLVMValueRef Fn, LLVMMetadataRef SP); #ifdef __cplusplus diff --git a/bindings/go/llvm/ir.go b/bindings/go/llvm/ir.go index b263c07c512d..fe191beb3813 100644 --- a/bindings/go/llvm/ir.go +++ b/bindings/go/llvm/ir.go @@ -1226,9 +1226,23 @@ func (b Builder) InsertWithName(instr Value, name string) { func (b Builder) Dispose() { C.LLVMDisposeBuilder(b.C) } // Metadata +type DebugLoc struct { + Line, Col uint + Scope Metadata + InlinedAt Metadata +} func (b Builder) SetCurrentDebugLocation(line, col uint, scope, inlinedAt Metadata) { C.LLVMSetCurrentDebugLocation2(b.C, C.unsigned(line), C.unsigned(col), scope.C, inlinedAt.C) } +// Get current debug location. Please do not call this function until setting debug location with SetCurrentDebugLocation() +func (b Builder) GetCurrentDebugLocation() (loc DebugLoc) { + md := C.LLVMGetCurrentDebugLocation2(b.C) + loc.Line = uint(md.Line) + loc.Col = uint(md.Col) + loc.Scope = Metadata{C: md.Scope} + loc.InlinedAt = Metadata{C: md.InlinedAt} + return +} func (b Builder) SetInstDebugLocation(v Value) { C.LLVMSetInstDebugLocation(b.C, v.C) } func (b Builder) InsertDeclare(module Module, storage Value, md Value) Value { f := module.NamedFunction("llvm.dbg.declare") diff --git a/bindings/go/llvm/ir_test.go b/bindings/go/llvm/ir_test.go index 13e113957b4d..c823615a4293 100644 --- a/bindings/go/llvm/ir_test.go +++ b/bindings/go/llvm/ir_test.go @@ -95,3 +95,42 @@ func TestAttributes(t *testing.T) { testAttribute(t, name) } } + +func TestDebugLoc(t *testing.T) { + mod := NewModule("") + defer mod.Dispose() + + ctx := mod.Context() + + b := ctx.NewBuilder() + defer b.Dispose() + + d := NewDIBuilder(mod) + defer func() { + d.Destroy() + }() + file := d.CreateFile("dummy_file", "dummy_dir") + voidInfo := d.CreateBasicType(DIBasicType{Name: "void"}) + typeInfo := d.CreateSubroutineType(DISubroutineType{file, []Metadata{voidInfo}}) + scope := d.CreateFunction(file, DIFunction{ + Name: "foo", + LinkageName: "foo", + Line: 10, + ScopeLine: 10, + Type: typeInfo, + File: file, + IsDefinition: true, + }) + + b.SetCurrentDebugLocation(10, 20, scope, Metadata{}) + loc := b.GetCurrentDebugLocation() + if loc.Line != 10 { + t.Errorf("Got line %d, though wanted 10", loc.Line) + } + if loc.Col != 20 { + t.Errorf("Got column %d, though wanted 20", loc.Col) + } + if loc.Scope.C != scope.C { + t.Errorf("Got metadata %v as scope, though wanted %v", loc.Scope.C, scope.C) + } +} diff --git a/bindings/go/llvm/transforms_pmbuilder.go b/bindings/go/llvm/transforms_pmbuilder.go index 3d79d6e2f327..b164e58812b1 100644 --- a/bindings/go/llvm/transforms_pmbuilder.go +++ b/bindings/go/llvm/transforms_pmbuilder.go @@ -43,6 +43,26 @@ func (pmb PassManagerBuilder) PopulateFunc(pm PassManager) { C.LLVMPassManagerBuilderPopulateFunctionPassManager(pmb.C, pm.C) } +func (pmb PassManagerBuilder) PopulateLTOPassManager(pm PassManager, internalize bool, runInliner bool) { + C.LLVMPassManagerBuilderPopulateLTOPassManager(pmb.C, pm.C, boolToLLVMBool(internalize), boolToLLVMBool(runInliner)) +} + func (pmb PassManagerBuilder) Dispose() { C.LLVMPassManagerBuilderDispose(pmb.C) } + +func (pmb PassManagerBuilder) SetDisableUnitAtATime(val bool) { + C.LLVMPassManagerBuilderSetDisableUnitAtATime(pmb.C, boolToLLVMBool(val)) +} + +func (pmb PassManagerBuilder) SetDisableUnrollLoops(val bool) { + C.LLVMPassManagerBuilderSetDisableUnrollLoops(pmb.C, boolToLLVMBool(val)) +} + +func (pmb PassManagerBuilder) SetDisableSimplifyLibCalls(val bool) { + C.LLVMPassManagerBuilderSetDisableSimplifyLibCalls(pmb.C, boolToLLVMBool(val)) +} + +func (pmb PassManagerBuilder) UseInlinerWithThreshold(threshold uint) { + C.LLVMPassManagerBuilderUseInlinerWithThreshold(pmb.C, C.uint(threshold)) +} |