cl: LLGO_TRACE
This commit is contained in:
@@ -49,6 +49,7 @@ var (
|
||||
debugInstr bool
|
||||
debugGoSSA bool
|
||||
debugSymbols bool
|
||||
debugTrace bool
|
||||
)
|
||||
|
||||
// SetDebug sets debug flags.
|
||||
@@ -61,6 +62,10 @@ func EnableDebugSymbols(b bool) {
|
||||
debugSymbols = b
|
||||
}
|
||||
|
||||
func EnableTrace(b bool) {
|
||||
debugTrace = b
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
type instrOrValue interface {
|
||||
@@ -380,6 +385,9 @@ func (p *context) compileBlock(b llssa.Builder, block *ssa.BasicBlock, n int, do
|
||||
var instrs = block.Instrs[n:]
|
||||
var ret = fn.Block(block.Index)
|
||||
b.SetBlock(ret)
|
||||
if block.Index == 0 && debugTrace && !strings.HasPrefix(fn.Name(), "github.com/goplus/llgo/runtime/internal/runtime.Print") {
|
||||
b.Printf("call " + fn.Name() + "\n\x00")
|
||||
}
|
||||
// place here to avoid wrong current-block
|
||||
if debugSymbols && block.Index == 0 {
|
||||
p.debugParams(b, block.Parent())
|
||||
|
||||
@@ -142,6 +142,7 @@ func Do(args []string, conf *Config) ([]Package, error) {
|
||||
}
|
||||
|
||||
cl.EnableDebugSymbols(IsDebugEnabled())
|
||||
cl.EnableTrace(IsTraceEnabled())
|
||||
llssa.Initialize(llssa.InitAll)
|
||||
|
||||
target := &llssa.Target{
|
||||
@@ -731,6 +732,7 @@ var (
|
||||
)
|
||||
|
||||
const llgoDebug = "LLGO_DEBUG"
|
||||
const llgoTrace = "LLGO_TRACE"
|
||||
const llgoOptimize = "LLGO_OPTIMIZE"
|
||||
const llgoCheck = "LLGO_CHECK"
|
||||
|
||||
@@ -742,6 +744,10 @@ func isEnvOn(env string, defVal bool) bool {
|
||||
return envVal == "1" || envVal == "true" || envVal == "on"
|
||||
}
|
||||
|
||||
func IsTraceEnabled() bool {
|
||||
return isEnvOn(llgoTrace, false)
|
||||
}
|
||||
|
||||
func IsDebugEnabled() bool {
|
||||
return isEnvOn(llgoDebug, false)
|
||||
}
|
||||
|
||||
@@ -1254,6 +1254,21 @@ func (b Builder) BuiltinCall(fn string, args ...Expr) (ret Expr) {
|
||||
panic("todo: " + fn)
|
||||
}
|
||||
|
||||
func (p Program) tyPrintf() *types.Signature {
|
||||
if p.printfTy == nil {
|
||||
pchar := types.NewPointer(types.Typ[types.Int8])
|
||||
params := types.NewTuple(types.NewVar(0, nil, "format", pchar), VArg())
|
||||
rets := types.NewTuple(types.NewVar(0, nil, "", types.Typ[types.Int32]))
|
||||
p.printfTy = types.NewSignatureType(nil, nil, nil, params, rets, true)
|
||||
}
|
||||
return p.printfTy
|
||||
}
|
||||
|
||||
func (b Builder) Printf(fmt string, args ...Expr) Expr {
|
||||
fn := b.Pkg.cFunc("printf", b.Prog.tyPrintf())
|
||||
return b.Call(fn, append([]Expr{b.CStr(fmt)}, args...)...)
|
||||
}
|
||||
|
||||
// Println prints the arguments to stderr, followed by a newline.
|
||||
func (b Builder) Println(args ...Expr) (ret Expr) {
|
||||
return b.PrintEx(true, args...)
|
||||
|
||||
@@ -197,6 +197,8 @@ type aProgram struct {
|
||||
sigsetjmpTy *types.Signature
|
||||
sigljmpTy *types.Signature
|
||||
|
||||
printfTy *types.Signature
|
||||
|
||||
paramObjPtr_ *types.Var
|
||||
linkname map[string]string // pkgPath.nameInPkg => linkname
|
||||
|
||||
|
||||
Reference in New Issue
Block a user