Example #1
0
File: irgen.go Project: mewmew/uc
// emitJmp emits to b an unconditional branch terminator to the target basic
// block.
func (b *BasicBlock) emitJmp(target value.NamedValue) {
	term, err := instruction.NewJmp(target)
	if err != nil {
		panic(fmt.Sprintf("unable to create unconditional br instruction; %v", err))
	}
	b.SetTerm(term)
}
Example #2
0
File: irx.go Project: llir/llvm
// NewJmpInst returns a new unconditional branch instruction based on the given
// target branch.
func NewJmpInst(ltarget interface{}) (*instruction.Jmp, error) {
	target, ok := ltarget.(*LocalDummy)
	if !ok {
		return nil, errutil.Newf("invalid target type; expected *LocalDummy, got %T", ltarget)
	}
	return instruction.NewJmp(target)
}
Example #3
0
File: fix.go Project: llir/llvm
// fixTerm replaces dummy values within the given terminator with their
// corresponding local variables.
func (m dummyMap) fixTerm(oldTerm instruction.Terminator) instruction.Terminator {
	switch oldTerm := oldTerm.(type) {
	case *instruction.Ret:
		oldVal := oldTerm.Value()
		var val value.Value
		if oldVal != nil {
			val = m.fixValue(oldVal)
		}
		term, err := instruction.NewRet(val)
		if err != nil {
			panic(errutil.Err(err))
		}
		return term
	case *instruction.Jmp:
		target := m.fixNamedValue(oldTerm.Target())
		term, err := instruction.NewJmp(target)
		if err != nil {
			panic(errutil.Err(err))
		}
		return term
	case *instruction.Br:
		cond := m.fixValue(oldTerm.Cond())
		trueBranch := m.fixNamedValue(oldTerm.TrueBranch())
		falseBranch := m.fixNamedValue(oldTerm.FalseBranch())
		term, err := instruction.NewBr(cond, trueBranch, falseBranch)
		if err != nil {
			panic(errutil.Err(err))
		}
		return term
	case *instruction.Switch:
		panic("irx.dummyMap.fixTerm: Switch not yet implemented")
	case *instruction.IndirectBr:
		panic("irx.dummyMap.fixTerm: IndirectBr not yet implemented")
	case *instruction.Invoke:
		panic("irx.dummyMap.fixTerm: Invoke not yet implemented")
	case *instruction.Resume:
		panic("irx.dummyMap.fixTerm: Resume not yet implemented")
	case *instruction.CatchSwitch:
		panic("irx.dummyMap.fixTerm: CatchSwitch not yet implemented")
	case *instruction.CatchRet:
		panic("irx.dummyMap.fixTerm: CatchRet not yet implemented")
	case *instruction.CleanupRet:
		panic("irx.dummyMap.fixTerm: CleanupRet not yet implemented")
	case *instruction.Unreachable:
		panic("irx.dummyMap.fixTerm: Unreachable not yet implemented")
	default:
		panic(fmt.Sprintf("support for terminator type %T not yet implemented", oldTerm))
	}
}