예제 #1
0
파일: debug.go 프로젝트: hinike/llgo
// Declare creates an llvm.dbg.declare call for the specified function
// parameter or local variable.
func (d *DIBuilder) Declare(b llvm.Builder, v ssa.Value, llv llvm.Value, paramIndex int) {
	tag := tagAutoVariable
	if paramIndex >= 0 {
		tag = tagArgVariable
	}
	var diFile llvm.Value
	var line int
	if file := d.fset.File(v.Pos()); file != nil {
		line = file.Line(v.Pos())
		diFile = d.getFile(file)
	}
	localVar := d.builder.CreateLocalVariable(d.scope(), llvm.DILocalVariable{
		Tag:   tag,
		Name:  llv.Name(),
		File:  diFile,
		Line:  line,
		ArgNo: paramIndex + 1,
		Type:  d.DIType(v.Type()),
	})
	expr := d.builder.CreateExpression(nil)
	d.builder.InsertDeclareAtEnd(llv, localVar, expr, b.GetInsertBlock())
}
예제 #2
0
// isCondFair returns true if an if condition (bool expression) is constant.
func (fa *FairnessAnalysis) isCondFair(cond ssa.Value) bool {
	switch cond := cond.(type) {
	case *ssa.Const:
		fa.logger.Println(color.YellowString("Warning: loop condition is constant"))
		return false
	case *ssa.BinOp: // <, <=, !=, ==
		if _, xConst := cond.X.(*ssa.Const); xConst {
			if _, yConst := cond.Y.(*ssa.Const); yConst {
				fa.logger.Println(color.YellowString("Warning: loop condition is constant"))
				return false
			} else {
				fa.logger.Println(color.YellowString("Try to trace back on Y"))
			}
		} else {
			fa.logger.Println(color.YellowString("Try to trace back on X"))
		}
	case *ssa.UnOp:
		if _, con := cond.X.(*ssa.Const); con {
			fa.logger.Println(color.YellowString("Warning: loop condition is constant"))
			return false
		}
	case *ssa.Call:
		fa.logger.Println(color.YellowString("Warning:%s: condition is function call --> unsure", fa.info.FSet.Position(cond.Pos()).String()))
		return false
	}
	return true // Assume fair by default
}