本文整理汇总了Golang中code/google/com/p/go/tools/ssa.Instruction.Block方法的典型用法代码示例。如果您正苦于以下问题:Golang Instruction.Block方法的具体用法?Golang Instruction.Block怎么用?Golang Instruction.Block使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/google/com/p/go/tools/ssa.Instruction
的用法示例。
在下文中一共展示了Instruction.Block方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: instruction
//.........这里部分代码省略.........
fn = fr.indirectFunction(fn, args)
fr.createCall(fr.runtime.pushdefer, []*LLVMValue{fn})
case *ssa.Extract:
tuple := fr.value(instr.Tuple).LLVMValue()
elem := fr.builder.CreateExtractValue(tuple, instr.Index, instr.Name())
elemtyp := instr.Type()
fr.env[instr] = fr.NewValue(elem, elemtyp)
case *ssa.Field:
value := fr.value(instr.X).LLVMValue()
field := fr.builder.CreateExtractValue(value, instr.Field, instr.Name())
fieldtyp := instr.Type()
fr.env[instr] = fr.NewValue(field, fieldtyp)
case *ssa.FieldAddr:
// TODO: implement nil check and panic.
// TODO: combine a chain of {Field,Index}Addrs into a single GEP.
ptr := fr.value(instr.X).LLVMValue()
fieldptr := fr.builder.CreateStructGEP(ptr, instr.Field, instr.Name())
fieldptrtyp := instr.Type()
fr.env[instr] = fr.NewValue(fieldptr, fieldptrtyp)
case *ssa.Go:
fn, args, result := fr.prepareCall(instr)
if result != nil {
panic("illegal use of builtin in go statement")
}
fn = fr.indirectFunction(fn, args)
fr.createCall(fr.runtime.Go, []*LLVMValue{fn})
case *ssa.If:
cond := fr.value(instr.Cond).LLVMValue()
block := instr.Block()
trueBlock := fr.block(block.Succs[0])
falseBlock := fr.block(block.Succs[1])
fr.builder.CreateCondBr(cond, trueBlock, falseBlock)
case *ssa.Index:
// FIXME Surely we should be dealing with an
// *array, so we can do a GEP?
array := fr.value(instr.X).LLVMValue()
arrayptr := fr.builder.CreateAlloca(array.Type(), "")
fr.builder.CreateStore(array, arrayptr)
index := fr.value(instr.Index).LLVMValue()
zero := llvm.ConstNull(index.Type())
addr := fr.builder.CreateGEP(arrayptr, []llvm.Value{zero, index}, "")
fr.env[instr] = fr.NewValue(fr.builder.CreateLoad(addr, ""), instr.Type())
case *ssa.IndexAddr:
// TODO: implement nil-check and panic.
// TODO: combine a chain of {Field,Index}Addrs into a single GEP.
x := fr.value(instr.X).LLVMValue()
index := fr.value(instr.Index).LLVMValue()
var addr llvm.Value
var elemtyp types.Type
zero := llvm.ConstNull(index.Type())
switch typ := instr.X.Type().Underlying().(type) {
case *types.Slice:
elemtyp = typ.Elem()
x = fr.builder.CreateExtractValue(x, 0, "")
addr = fr.builder.CreateGEP(x, []llvm.Value{index}, "")
case *types.Pointer: // *array
elemtyp = typ.Elem().Underlying().(*types.Array).Elem()
addr = fr.builder.CreateGEP(x, []llvm.Value{zero, index}, "")
}
示例2: visitInstr
// visitInstr interprets a single ssa.Instruction within the activation
// record frame. It returns a continuation value indicating where to
// read the next instruction from.
func visitInstr(fr *frame, instr ssa.Instruction) continuation {
switch instr := instr.(type) {
case *ssa.DebugRef:
// no-op
case *ssa.UnOp:
fr.env[instr] = unop(instr, fr.get(instr.X))
case *ssa.BinOp:
fr.env[instr] = binop(instr.Op, instr.X.Type(), fr.get(instr.X), fr.get(instr.Y))
case *ssa.Call:
fn, args := prepareCall(fr, &instr.Call)
fr.env[instr] = call(fr.i, fr, instr.Pos(), fn, args)
case *ssa.ChangeInterface:
fr.env[instr] = fr.get(instr.X)
case *ssa.ChangeType:
fr.env[instr] = fr.get(instr.X) // (can't fail)
case *ssa.Convert:
fr.env[instr] = conv(instr.Type(), instr.X.Type(), fr.get(instr.X))
case *ssa.MakeInterface:
fr.env[instr] = iface{t: instr.X.Type(), v: fr.get(instr.X)}
case *ssa.Extract:
fr.env[instr] = fr.get(instr.Tuple).(tuple)[instr.Index]
case *ssa.Slice:
fr.env[instr] = slice(fr.get(instr.X), fr.get(instr.Low), fr.get(instr.High))
case *ssa.Return:
switch len(instr.Results) {
case 0:
case 1:
fr.result = fr.get(instr.Results[0])
default:
var res []value
for _, r := range instr.Results {
res = append(res, fr.get(r))
}
fr.result = tuple(res)
}
fr.block = nil
return kReturn
case *ssa.RunDefers:
fr.runDefers()
case *ssa.Panic:
panic(targetPanic{fr.get(instr.X)})
case *ssa.Send:
fr.get(instr.Chan).(chan value) <- copyVal(fr.get(instr.X))
case *ssa.Store:
*fr.get(instr.Addr).(*value) = copyVal(fr.get(instr.Val))
case *ssa.If:
succ := 1
if fr.get(instr.Cond).(bool) {
succ = 0
}
fr.prevBlock, fr.block = fr.block, fr.block.Succs[succ]
return kJump
case *ssa.Jump:
fr.prevBlock, fr.block = fr.block, fr.block.Succs[0]
return kJump
case *ssa.Defer:
fn, args := prepareCall(fr, &instr.Call)
fr.defers = &deferred{
fn: fn,
args: args,
instr: instr,
tail: fr.defers,
}
case *ssa.Go:
fn, args := prepareCall(fr, &instr.Call)
go call(fr.i, nil, instr.Pos(), fn, args)
case *ssa.MakeChan:
fr.env[instr] = make(chan value, asInt(fr.get(instr.Size)))
case *ssa.Alloc:
var addr *value
if instr.Heap {
// new
addr = new(value)
fr.env[instr] = addr
} else {
// local
addr = fr.env[instr].(*value)
//.........这里部分代码省略.........