Exemple #1
0
Fichier : fix.go Projet : llir/llvm
// fixStoreInst replaces dummy values within the given Store instruction with
// their corresponding local variables.
func (m dummyMap) fixStoreInst(oldInst *instruction.Store) *instruction.Store {
	src := m.fixValue(oldInst.Src())
	dstAddr := m.fixValue(oldInst.DstAddr())
	inst, err := instruction.NewStore(src, dstAddr)
	if err != nil {
		panic(errutil.Err(err))
	}
	return inst
}
Exemple #2
0
// indexExprDef lowers the given identifier expression definition to LLVM IR,
// emitting code to f.
func (m *Module) indexExprDef(f *Function, n *ast.IndexExpr, v value.Value) {
	addr := m.indexExpr(f, n)
	addrType, ok := addr.Type().(*irtypes.Pointer)
	if !ok {
		panic(fmt.Sprintf("invalid pointer type; expected *types.Pointer, got %T", addr.Type()))
	}
	v = m.convert(f, v, addrType.Elem())
	storeInst, err := instruction.NewStore(v, addr)
	if err != nil {
		panic(fmt.Sprintf("unable to create store instruction; %v", err))
	}
	f.curBlock.AppendInst(storeInst)
}
Exemple #3
0
Fichier : irx.go Projet : llir/llvm
// NewStoreInst returns a new store instruction based on the given value and
// address.
func NewStoreInst(srcType, src, dstAddrType, dstAddr interface{}) (*instruction.Store, error) {
	{
		src, err := NewValue(srcType, src)
		if err != nil {
			return nil, errutil.Err(err)
		}
		if dstAddrType, ok := dstAddrType.(types.Type); ok {
			dstAddr, err := NewValue(dstAddrType, dstAddr)
			if err != nil {
				return nil, errutil.Err(err)
			}
			return instruction.NewStore(src, dstAddr)
		}
	}
	return nil, errutil.Newf("invalid pointer type; expected types.Type, got %T", dstAddrType)
}
Exemple #4
0
// funcParam lowers the given function parameter to LLVM IR, emitting code to f.
func (m *Module) funcParam(f *Function, param *irtypes.Param) value.Value {
	// Input:
	//    void f(int a) {
	//    }
	// Output:
	//    %1 = alloca i32
	//    store i32 %a, i32* %1
	allocaInst, err := instruction.NewAlloca(param.Type(), 1)
	if err != nil {
		panic(fmt.Sprintf("unable to create alloca instruction; %v", err))
	}
	// Emit local variable definition for the given function parameter.
	addr := f.emitInst(allocaInst)
	storeInst, err := instruction.NewStore(param, addr)
	if err != nil {
		panic(fmt.Sprintf("unable to create store instruction; %v", err))
	}
	f.curBlock.AppendInst(storeInst)
	return addr
}