当前位置: 首页>>代码示例>>Golang>>正文


Golang llvm.Int32Type函数代码示例

本文整理汇总了Golang中llvm/org/llvm/bindings/go/llvm.Int32Type函数的典型用法代码示例。如果您正苦于以下问题:Golang Int32Type函数的具体用法?Golang Int32Type怎么用?Golang Int32Type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Int32Type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: genAddressOfExpr

func (v *Codegen) genAddressOfExpr(n *parser.AddressOfExpr) llvm.Value {
	gep := v.builder.CreateGEP(v.variableLookup[n.Access.Accesses[0].Variable], []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false)}, "")

	for i := 0; i < len(n.Access.Accesses); i++ {

		switch n.Access.Accesses[i].AccessType {
		case parser.ACCESS_ARRAY:
			gepIndexes := []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), llvm.ConstInt(llvm.Int32Type(), 1, false)}
			gep = v.builder.CreateGEP(gep, gepIndexes, "")

			load := v.builder.CreateLoad(gep, "")

			// TODO check that access is in bounds!

			gepIndexes = []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), v.genExpr(n.Access.Accesses[i].Subscript)}
			gep = v.builder.CreateGEP(load, gepIndexes, "")

		case parser.ACCESS_VARIABLE:
			// nothing to do

		case parser.ACCESS_STRUCT:
			index := n.Access.Accesses[i].Variable.Type.(*parser.StructType).VariableIndex(n.Access.Accesses[i+1].Variable)
			gep = v.builder.CreateGEP(gep, []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), llvm.ConstInt(llvm.Int32Type(), uint64(index), false)}, "")

		default:
			panic("")
		}
	}

	return gep
}
开发者ID:PillaVamsiKrishna,项目名称:ark,代码行数:31,代码来源:codegen.go

示例2: chanSelect

func (fr *frame) chanSelect(sel *ssa.Select) (index, recvOk *govalue, recvElems []*govalue) {
	n := uint64(len(sel.States))
	if !sel.Blocking {
		// non-blocking means there's a default case
		n++
	}
	size := llvm.ConstInt(llvm.Int32Type(), n, false)
	selectp := fr.runtime.newSelect.call(fr, size)[0]

	// Allocate stack for the values to send and receive.
	ptrs := make([]llvm.Value, len(sel.States))
	for i, state := range sel.States {
		chantyp := state.Chan.Type().Underlying().(*types.Chan)
		elemtyp := fr.types.ToLLVM(chantyp.Elem())
		if state.Dir == types.SendOnly {
			ptrs[i] = fr.allocaBuilder.CreateAlloca(elemtyp, "")
			fr.builder.CreateStore(fr.llvmvalue(state.Send), ptrs[i])
		} else {
			// Only allocate stack space if the received value is used.
			used := chanSelectStateUsed(sel, len(recvElems))
			if used {
				ptrs[i] = fr.allocaBuilder.CreateAlloca(elemtyp, "")
			} else {
				ptrs[i] = llvm.ConstNull(llvm.PointerType(llvm.Int8Type(), 0))
			}
			recvElems = append(recvElems, newValue(ptrs[i], chantyp.Elem()))
		}
	}

	// Create select{send,recv2} calls.
	var receivedp llvm.Value
	if len(recvElems) > 0 {
		receivedp = fr.allocaBuilder.CreateAlloca(fr.types.ToLLVM(types.Typ[types.Bool]), "")
	}
	if !sel.Blocking {
		// If the default case is chosen, the index must be -1.
		fr.runtime.selectdefault.call(fr, selectp, llvm.ConstAllOnes(llvm.Int32Type()))
	}
	for i, state := range sel.States {
		ch := fr.llvmvalue(state.Chan)
		index := llvm.ConstInt(llvm.Int32Type(), uint64(i), false)
		if state.Dir == types.SendOnly {
			fr.runtime.selectsend.call(fr, selectp, ch, ptrs[i], index)
		} else {
			fr.runtime.selectrecv2.call(fr, selectp, ch, ptrs[i], receivedp, index)
		}
	}

	// Fire off the select.
	index = newValue(fr.runtime.selectgo.call(fr, selectp)[0], types.Typ[types.Int])
	if len(recvElems) > 0 {
		recvOk = newValue(fr.builder.CreateLoad(receivedp, ""), types.Typ[types.Bool])
		for _, recvElem := range recvElems {
			recvElem.value = fr.builder.CreateLoad(recvElem.value, "")
		}
	}
	return index, recvOk, recvElems
}
开发者ID:glycerine,项目名称:llgo,代码行数:58,代码来源:channels.go

示例3: genAccessGEP

func (v *Codegen) genAccessGEP(n parser.Expr) llvm.Value {
	switch access := n.(type) {
	case *parser.VariableAccessExpr:
		varType := v.getVariable(access.Variable)
		log.Debugln("codegen", "%v => %v", access.Variable, varType)
		if varType.IsNil() {
			panic("varType was nil")
		}
		gep := v.builder().CreateGEP(varType, []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false)}, "")

		if _, ok := access.GetType().(parser.MutableReferenceType); ok {
			return v.builder().CreateLoad(gep, "")
		}

		if _, ok := access.GetType().(parser.ConstantReferenceType); ok {
			return v.builder().CreateLoad(gep, "")
		}

		return gep

	case *parser.StructAccessExpr:
		gep := v.genAccessGEP(access.Struct)

		typ := access.Struct.GetType().ActualType()

		index := typ.(parser.StructType).VariableIndex(access.Variable)
		return v.builder().CreateStructGEP(gep, index, "")

	case *parser.ArrayAccessExpr:
		gep := v.genAccessGEP(access.Array)
		subscriptExpr := v.genExpr(access.Subscript)

		v.genBoundsCheck(v.builder().CreateLoad(v.builder().CreateStructGEP(gep, 0, ""), ""),
			subscriptExpr, access.Subscript.GetType())

		gep = v.builder().CreateStructGEP(gep, 1, "")

		load := v.builder().CreateLoad(gep, "")

		gepIndexes := []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), subscriptExpr}
		return v.builder().CreateGEP(load, gepIndexes, "")

	case *parser.TupleAccessExpr:
		gep := v.genAccessGEP(access.Tuple)

		// TODO: Check overflow
		return v.builder().CreateStructGEP(gep, int(access.Index), "")

	case *parser.DerefAccessExpr:
		return v.genExpr(access.Expr)

	default:
		panic("unhandled access type")
	}
}
开发者ID:IanMurray,项目名称:ark,代码行数:55,代码来源:codegen.go

示例4: setBranchWeightMetadata

func (fr *frame) setBranchWeightMetadata(br llvm.Value, trueweight, falseweight uint64) {
	mdprof := llvm.MDKindID("prof")

	mdnode := llvm.MDNode([]llvm.Value{
		llvm.MDString("branch_weights"),
		llvm.ConstInt(llvm.Int32Type(), trueweight, false),
		llvm.ConstInt(llvm.Int32Type(), falseweight, false),
	})

	br.SetMetadata(mdprof, mdnode)
}
开发者ID:hinike,项目名称:llgo,代码行数:11,代码来源:errors.go

示例5: chanSelect

func (fr *frame) chanSelect(states []selectState, blocking bool) (index, recvOk *govalue, recvElems []*govalue) {
	n := uint64(len(states))
	if !blocking {
		// non-blocking means there's a default case
		n++
	}
	size := llvm.ConstInt(llvm.Int32Type(), n, false)
	selectp := fr.runtime.newSelect.call(fr, size)[0]

	// Allocate stack for the values to send and receive.
	//
	// TODO(axw) check if received elements have any users, and
	// elide stack allocation if not (pass nil to recv2 instead.)
	ptrs := make([]llvm.Value, len(states))
	for i, state := range states {
		chantyp := state.Chan.Type().Underlying().(*types.Chan)
		elemtyp := fr.types.ToLLVM(chantyp.Elem())
		ptrs[i] = fr.allocaBuilder.CreateAlloca(elemtyp, "")
		if state.Dir == types.SendOnly {
			fr.builder.CreateStore(state.Send.value, ptrs[i])
		} else {
			recvElems = append(recvElems, newValue(ptrs[i], chantyp.Elem()))
		}
	}

	// Create select{send,recv2} calls.
	var receivedp llvm.Value
	if len(recvElems) > 0 {
		receivedp = fr.allocaBuilder.CreateAlloca(fr.types.ToLLVM(types.Typ[types.Bool]), "")
	}
	if !blocking {
		// If the default case is chosen, the index must be -1.
		fr.runtime.selectdefault.call(fr, selectp, llvm.ConstAllOnes(llvm.Int32Type()))
	}
	for i, state := range states {
		ch := state.Chan.value
		index := llvm.ConstInt(llvm.Int32Type(), uint64(i), false)
		if state.Dir == types.SendOnly {
			fr.runtime.selectsend.call(fr, selectp, ch, ptrs[i], index)
		} else {
			fr.runtime.selectrecv2.call(fr, selectp, ch, ptrs[i], receivedp, index)
		}
	}

	// Fire off the select.
	index = newValue(fr.runtime.selectgo.call(fr, selectp)[0], types.Typ[types.Int])
	if len(recvElems) > 0 {
		recvOk = newValue(fr.builder.CreateLoad(receivedp, ""), types.Typ[types.Bool])
		for _, recvElem := range recvElems {
			recvElem.value = fr.builder.CreateLoad(recvElem.value, "")
		}
	}
	return index, recvOk, recvElems
}
开发者ID:hinike,项目名称:llgo,代码行数:54,代码来源:channels.go

示例6: interfaceMethod

// interfaceMethod returns a function and receiver pointer for the specified
// interface and method pair.
func (fr *frame) interfaceMethod(lliface llvm.Value, ifacety types.Type, method *types.Func) (fn, recv *govalue) {
	llitab := fr.builder.CreateExtractValue(lliface, 0, "")
	recv = newValue(fr.builder.CreateExtractValue(lliface, 1, ""), types.Typ[types.UnsafePointer])
	methodset := fr.types.MethodSet(ifacety)
	// TODO(axw) cache ordered method index
	index := -1
	for i, m := range orderedMethodSet(methodset) {
		if m.Obj() == method {
			index = i
			break
		}
	}
	if index == -1 {
		panic("could not find method index")
	}
	llitab = fr.builder.CreateBitCast(llitab, llvm.PointerType(llvm.PointerType(llvm.Int8Type(), 0), 0), "")
	// Skip runtime type pointer.
	llifnptr := fr.builder.CreateGEP(llitab, []llvm.Value{
		llvm.ConstInt(llvm.Int32Type(), uint64(index+1), false),
	}, "")

	llifn := fr.builder.CreateLoad(llifnptr, "")
	// Replace receiver type with unsafe.Pointer.
	recvparam := types.NewParam(0, nil, "", types.Typ[types.UnsafePointer])
	sig := method.Type().(*types.Signature)
	sig = types.NewSignature(nil, recvparam, sig.Params(), sig.Results(), sig.Variadic())
	fn = newValue(llifn, sig)
	return
}
开发者ID:glycerine,项目名称:llgo,代码行数:31,代码来源:interfaces.go

示例7: condBrRuntimeError

func (fr *frame) condBrRuntimeError(cond llvm.Value, errcode uint64) {
	if cond.IsNull() {
		return
	}

	errorbb := fr.runtimeErrorBlocks[errcode]
	newbb := errorbb.C == nil
	if newbb {
		errorbb = llvm.AddBasicBlock(fr.function, "")
		fr.runtimeErrorBlocks[errcode] = errorbb
	}

	contbb := llvm.AddBasicBlock(fr.function, "")

	br := fr.builder.CreateCondBr(cond, errorbb, contbb)
	fr.setBranchWeightMetadata(br, 1, 1000)

	if newbb {
		fr.builder.SetInsertPointAtEnd(errorbb)
		fr.runtime.runtimeError.call(fr, llvm.ConstInt(llvm.Int32Type(), errcode, false))
		fr.builder.CreateUnreachable()
	}

	fr.builder.SetInsertPointAtEnd(contbb)
}
开发者ID:hinike,项目名称:llgo,代码行数:25,代码来源:errors.go

示例8: genAccessGEP

func (v *Codegen) genAccessGEP(n parser.Expr) llvm.Value {
	switch n.(type) {
	case *parser.VariableAccessExpr:
		vae := n.(*parser.VariableAccessExpr)
		return v.builder.CreateGEP(v.variableLookup[vae.Variable], []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false)}, "")

	case *parser.StructAccessExpr:
		sae := n.(*parser.StructAccessExpr)

		gep := v.genAccessGEP(sae.Struct)
		index := sae.Struct.GetType().(*parser.StructType).VariableIndex(sae.Variable)
		return v.builder.CreateGEP(gep, []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), llvm.ConstInt(llvm.Int32Type(), uint64(index), false)}, "")

	case *parser.ArrayAccessExpr:
		aae := n.(*parser.ArrayAccessExpr)

		gep := v.genAccessGEP(aae.Array)
		subscriptExpr := v.genExpr(aae.Subscript)

		sizeGepIndexes := []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), llvm.ConstInt(llvm.Int32Type(), 0, false)}
		v.genBoundsCheck(v.builder.CreateLoad(v.builder.CreateGEP(gep, sizeGepIndexes, ""), ""), subscriptExpr, aae.Subscript.GetType())

		gepIndexes := []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), llvm.ConstInt(llvm.Int32Type(), 1, false)}
		gep = v.builder.CreateGEP(gep, gepIndexes, "")

		load := v.builder.CreateLoad(gep, "")

		gepIndexes = []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), subscriptExpr}
		return v.builder.CreateGEP(load, gepIndexes, "")

	case *parser.TupleAccessExpr:
		tae := n.(*parser.TupleAccessExpr)

		gep := v.genAccessGEP(tae.Tuple)
		index := tae.Index

		return v.builder.CreateGEP(gep, []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 0, false), llvm.ConstInt(llvm.Int32Type(), index, false)}, "")

	case *parser.DerefAccessExpr:
		dae := n.(*parser.DerefAccessExpr)

		return v.genExpr(dae.Expr)

	default:
		panic("unhandled access type")
	}
}
开发者ID:gitter-badger,项目名称:ark,代码行数:47,代码来源:codegen.go

示例9: memcpy

func (fr *frame) memcpy(dest llvm.Value, src llvm.Value, size llvm.Value) {
	memcpy := fr.runtime.memcpy
	dest = fr.builder.CreateBitCast(dest, llvm.PointerType(llvm.Int8Type(), 0), "")
	src = fr.builder.CreateBitCast(src, llvm.PointerType(llvm.Int8Type(), 0), "")
	size = fr.createZExtOrTrunc(size, fr.target.IntPtrType(), "")
	align := llvm.ConstInt(llvm.Int32Type(), 1, false)
	isvolatile := llvm.ConstNull(llvm.Int1Type())
	fr.builder.CreateCall(memcpy, []llvm.Value{dest, src, size, align, isvolatile}, "")
}
开发者ID:glycerine,项目名称:llgo,代码行数:9,代码来源:runtime.go

示例10: memsetZero

func (fr *frame) memsetZero(ptr llvm.Value, size llvm.Value) {
	memset := fr.runtime.memset
	ptr = fr.builder.CreateBitCast(ptr, llvm.PointerType(llvm.Int8Type(), 0), "")
	fill := llvm.ConstNull(llvm.Int8Type())
	size = fr.createZExtOrTrunc(size, fr.target.IntPtrType(), "")
	align := llvm.ConstInt(llvm.Int32Type(), 1, false)
	isvolatile := llvm.ConstNull(llvm.Int1Type())
	fr.builder.CreateCall(memset, []llvm.Value{ptr, fill, size, align, isvolatile}, "")
}
开发者ID:glycerine,项目名称:llgo,代码行数:9,代码来源:runtime.go

示例11: SetLocation

// SetLocation sets the current debug location.
func (d *DIBuilder) SetLocation(b llvm.Builder, pos token.Pos) {
	if !pos.IsValid() {
		return
	}
	position := d.fset.Position(pos)
	d.lb = llvm.Value{nil}
	if position.Filename != d.fnFile && position.Filename != "" {
		// This can happen rarely, e.g. in init functions.
		diFile := d.builder.CreateFile(d.remapFilePath(position.Filename), "")
		d.lb = d.builder.CreateLexicalBlockFile(d.scope(), diFile, 0)
	}
	b.SetCurrentDebugLocation(llvm.MDNode([]llvm.Value{
		llvm.ConstInt(llvm.Int32Type(), uint64(position.Line), false),
		llvm.ConstInt(llvm.Int32Type(), uint64(position.Column), false),
		d.scope(),
		llvm.Value{},
	}))
}
开发者ID:hinike,项目名称:llgo,代码行数:19,代码来源:debug.go

示例12: Finalize

// Finalize must be called after all compilation units are translated,
// generating the final debug metadata for the module.
func (d *DIBuilder) Finalize() {
	d.module.AddNamedMetadataOperand(
		"llvm.module.flags",
		llvm.GlobalContext().MDNode([]llvm.Metadata{
			llvm.ConstInt(llvm.Int32Type(), 2, false).ConstantAsMetadata(), // Warn on mismatch
			llvm.GlobalContext().MDString("Dwarf Version"),
			llvm.ConstInt(llvm.Int32Type(), 4, false).ConstantAsMetadata(),
		}),
	)
	d.module.AddNamedMetadataOperand(
		"llvm.module.flags",
		llvm.GlobalContext().MDNode([]llvm.Metadata{
			llvm.ConstInt(llvm.Int32Type(), 1, false).ConstantAsMetadata(), // Error on mismatch
			llvm.GlobalContext().MDString("Debug Info Version"),
			llvm.ConstInt(llvm.Int32Type(), 2, false).ConstantAsMetadata(),
		}),
	)
	d.builder.Finalize()
}
开发者ID:glycerine,项目名称:llgo,代码行数:21,代码来源:debug.go

示例13: returnAddress

func (fr *frame) returnAddress(level uint64) llvm.Value {
	returnaddress := fr.runtime.returnaddress
	levelValue := llvm.ConstInt(llvm.Int32Type(), level, false)
	return fr.builder.CreateCall(returnaddress, []llvm.Value{levelValue}, "")
}
开发者ID:glycerine,项目名称:llgo,代码行数:5,代码来源:runtime.go

示例14: newRuntimeInterface


//.........这里部分代码省略.........
		},
		{
			name: "__go_string_plus",
			rfi:  &ri.stringPlus,
			args: []types.Type{String, String},
			res:  []types.Type{String},
		},
		{
			name: "__go_string_slice",
			rfi:  &ri.stringSlice,
			args: []types.Type{String, Int, Int},
			res:  []types.Type{String},
		},
		{
			name: "__go_string_to_int_array",
			rfi:  &ri.stringToIntArray,
			args: []types.Type{String},
			res:  []types.Type{IntSlice},
		},
		{
			name: "runtime.stringiter2",
			rfi:  &ri.stringiter2,
			args: []types.Type{String, Int},
			res:  []types.Type{Int, Rune},
		},
		{
			name: "__go_type_descriptors_equal",
			rfi:  &ri.typeDescriptorsEqual,
			args: []types.Type{UnsafePointer, UnsafePointer},
			res:  []types.Type{Bool},
		},
		{
			name: "__go_undefer",
			rfi:  &ri.undefer,
			args: []types.Type{UnsafePointer},
		},
	} {
		rt.rfi.init(tm, module, rt.name, rt.args, rt.res)
		for _, attr := range rt.attrs {
			rt.rfi.fn.AddFunctionAttr(attr)
		}
	}

	memsetName := "llvm.memset.p0i8.i" + strconv.Itoa(tm.target.IntPtrType().IntTypeWidth())
	memsetType := llvm.FunctionType(
		llvm.VoidType(),
		[]llvm.Type{
			llvm.PointerType(llvm.Int8Type(), 0),
			llvm.Int8Type(),
			tm.target.IntPtrType(),
			llvm.Int32Type(),
			llvm.Int1Type(),
		},
		false,
	)
	ri.memset = llvm.AddFunction(module, memsetName, memsetType)

	memcpyName := "llvm.memcpy.p0i8.p0i8.i" + strconv.Itoa(tm.target.IntPtrType().IntTypeWidth())
	memcpyType := llvm.FunctionType(
		llvm.VoidType(),
		[]llvm.Type{
			llvm.PointerType(llvm.Int8Type(), 0),
			llvm.PointerType(llvm.Int8Type(), 0),
			tm.target.IntPtrType(),
			llvm.Int32Type(),
			llvm.Int1Type(),
		},
		false,
	)
	ri.memcpy = llvm.AddFunction(module, memcpyName, memcpyType)

	returnaddressType := llvm.FunctionType(
		llvm.PointerType(llvm.Int8Type(), 0),
		[]llvm.Type{llvm.Int32Type()},
		false,
	)
	ri.returnaddress = llvm.AddFunction(module, "llvm.returnaddress", returnaddressType)

	gccgoPersonalityType := llvm.FunctionType(
		llvm.Int32Type(),
		[]llvm.Type{
			llvm.Int32Type(),
			llvm.Int64Type(),
			llvm.PointerType(llvm.Int8Type(), 0),
			llvm.PointerType(llvm.Int8Type(), 0),
		},
		false,
	)
	ri.gccgoPersonality = llvm.AddFunction(module, "__gccgo_personality_v0", gccgoPersonalityType)

	ri.gccgoExceptionType = llvm.StructType(
		[]llvm.Type{
			llvm.PointerType(llvm.Int8Type(), 0),
			llvm.Int32Type(),
		},
		false,
	)

	return &ri, nil
}
开发者ID:glycerine,项目名称:llgo,代码行数:101,代码来源:runtime.go

示例15: genSizeofExpr

func (v *Codegen) genSizeofExpr(n *parser.SizeofExpr) llvm.Value {
	if n.Expr != nil {
		gep := v.builder.CreateGEP(llvm.ConstNull(llvm.PointerType(v.typeToLLVMType(n.Expr.GetType()), 0)), []llvm.Value{llvm.ConstInt(llvm.Int32Type(), 1, false)}, "")
		return v.builder.CreatePtrToInt(gep, v.typeToLLVMType(n.GetType()), "sizeof")
	} else {
		// we have a type
		panic("can't do this yet")
	}
}
开发者ID:PillaVamsiKrishna,项目名称:ark,代码行数:9,代码来源:codegen.go


注:本文中的llvm/org/llvm/bindings/go/llvm.Int32Type函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。