ssa: add llvm debug info
This commit is contained in:
36
ssa/decl.go
36
ssa/decl.go
@@ -17,6 +17,7 @@
|
||||
package ssa
|
||||
|
||||
import (
|
||||
"go/token"
|
||||
"go/types"
|
||||
"log"
|
||||
"strconv"
|
||||
@@ -173,6 +174,8 @@ type aFunction struct {
|
||||
freeVars Expr
|
||||
base int // base = 1 if hasFreeVars; base = 0 otherwise
|
||||
hasVArg bool
|
||||
|
||||
diFunc DIFunction
|
||||
}
|
||||
|
||||
// Function represents a function or method.
|
||||
@@ -274,6 +277,10 @@ func (p Function) NewBuilder() Builder {
|
||||
return &aBuilder{b, nil, p, p.Pkg, prog}
|
||||
}
|
||||
|
||||
func (p Function) NewDIBuilder() *llvm.DIBuilder {
|
||||
return llvm.NewDIBuilder(p.Pkg.mod)
|
||||
}
|
||||
|
||||
// HasBody reports whether the function has a body.
|
||||
func (p Function) HasBody() bool {
|
||||
return len(p.blks) > 0
|
||||
@@ -324,4 +331,33 @@ func (p Function) SetRecover(blk BasicBlock) {
|
||||
p.recov = blk
|
||||
}
|
||||
|
||||
func (p Function) scopeMeta(b diBuilder, pos token.Position) DIScopeMeta {
|
||||
if p.diFunc == nil {
|
||||
paramTypes := make([]llvm.Metadata, len(p.params))
|
||||
for i, t := range p.params {
|
||||
paramTypes[i] = b.DIType(t, pos).ll
|
||||
}
|
||||
diFuncType := b.di.CreateSubroutineType(llvm.DISubroutineType{
|
||||
File: b.DIFile(pos.Filename).ll,
|
||||
Parameters: paramTypes,
|
||||
})
|
||||
p.diFunc = &aDIFunction{
|
||||
b.di.CreateFunction(
|
||||
p.Pkg.cu.ll,
|
||||
llvm.DIFunction{
|
||||
Type: diFuncType,
|
||||
Name: p.Name(),
|
||||
LinkageName: p.Name(),
|
||||
File: b.DIFile(pos.Filename).ll,
|
||||
Line: pos.Line,
|
||||
IsDefinition: true,
|
||||
Optimized: false,
|
||||
},
|
||||
),
|
||||
}
|
||||
p.impl.SetSubprogram(p.diFunc.ll)
|
||||
}
|
||||
return &aDIScopeMeta{p.diFunc.ll}
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user