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


Golang llvm.ConstInt函数代码示例

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


在下文中一共展示了ConstInt函数的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: genArrayLiteral

// Allocates a literal array on the stack
func (v *Codegen) genArrayLiteral(n *parser.ArrayLiteral) llvm.Value {
	memberLLVMType := v.typeToLLVMType(n.Type.(parser.ArrayType).MemberType)

	// allocate backing array
	arrAlloca := v.builder.CreateArrayAlloca(llvm.ArrayType(memberLLVMType, len(n.Members)), llvm.ConstInt(llvm.IntType(32), uint64(len(n.Members)), false), "")

	// allocate the array object
	structAlloca := v.builder.CreateAlloca(v.typeToLLVMType(n.Type), "")

	// set the length of the array
	lenGEP := v.builder.CreateGEP(structAlloca, []llvm.Value{llvm.ConstInt(llvm.IntType(32), 0, false), llvm.ConstInt(llvm.IntType(32), 0, false)}, "")
	v.builder.CreateStore(llvm.ConstInt(llvm.IntType(32), uint64(len(n.Members)), false), lenGEP)

	// set the array pointer to the backing array we allocated
	arrGEP := v.builder.CreateGEP(structAlloca, []llvm.Value{llvm.ConstInt(llvm.IntType(32), 0, false), llvm.ConstInt(llvm.IntType(32), 1, false)}, "")
	v.builder.CreateStore(v.builder.CreateBitCast(arrAlloca, llvm.PointerType(llvm.ArrayType(memberLLVMType, 0), 0), ""), arrGEP)

	// copy the constant array to the backing array
	arrConstVals := make([]llvm.Value, 0, len(n.Members))
	for _, mem := range n.Members {
		arrConstVals = append(arrConstVals, v.genExpr(mem))
	}
	arrConst := llvm.ConstArray(llvm.ArrayType(memberLLVMType, len(n.Members)), arrConstVals)
	v.builder.CreateStore(arrConst, arrAlloca)

	return v.builder.CreateLoad(structAlloca, "")
}
开发者ID:PillaVamsiKrishna,项目名称:ark,代码行数:28,代码来源:codegen.go

示例3: generateExpression

func (c *Codegen) generateExpression(node parser.Node) llvm.Value {
	switch n := node.(type) {
	case *parser.BinaryExprNode:
		return c.generateBinaryExpression(n)
	case *parser.NumLitNode:
		if n.IsFloat {
			return llvm.ConstFloat(PRIMITIVE_TYPES["float"], n.FloatValue)
		} else {
			return llvm.ConstInt(PRIMITIVE_TYPES["int"], uint64(n.IntValue), false)
		}
	case *parser.BoolLitNode:
		i := 0
		if n.Value {
			i = 1
		}

		return llvm.ConstInt(PRIMITIVE_TYPES["boolean"], uint64(i), false)
	case *parser.CharLitNode:
		return llvm.ConstInt(PRIMITIVE_TYPES["char"], uint64(n.Value), false)
	case *parser.VarAccessNode, *parser.ObjectAccessNode, *parser.ArrayAccessNode, *parser.CallExprNode, *parser.StringLitNode, *parser.MakeExprNode:
		return c.generateAccess(n, true)
	}

	return null
}
开发者ID:furryfaust,项目名称:lyca,代码行数:25,代码来源:codegen.go

示例4: generateStringConcat

func (c *Codegen) generateStringConcat(str1, str2 llvm.Value) llvm.Value {
	//    one := llvm.ConstInt(PRIMITIVE_TYPES["int"], 1, false)

	len1 := c.builder.CreateCall(c.module.NamedFunction("-string-len"), []llvm.Value{str1}, "")
	len2 := c.builder.CreateLoad(c.builder.CreateStructGEP(str2, 1, ""), "")
	len_sum := c.builder.CreateAdd(len1, len2, "")

	chars := c.builder.CreateCall(c.module.NamedFunction("malloc"), []llvm.Value{len_sum}, "")
	c.builder.CreateCall(c.module.NamedFunction("llvm.memcpy.p0i8.p0i8.i32"), []llvm.Value{
		chars, c.unbox(str1), len1,
		llvm.ConstInt(PRIMITIVE_TYPES["int"], 0, false),
		llvm.ConstInt(PRIMITIVE_TYPES["boolean"], 0, false),
	}, "")
	c.builder.CreateCall(c.module.NamedFunction("llvm.memcpy.p0i8.p0i8.i32"), []llvm.Value{
		c.builder.CreateGEP(chars, []llvm.Value{len1}, ""), c.unbox(str2), len2,
		llvm.ConstInt(PRIMITIVE_TYPES["int"], 0, false),
		llvm.ConstInt(PRIMITIVE_TYPES["boolean"], 0, false),
	}, "")

	str := c.builder.CreateMalloc(c.templates["string"].Type, "")
	c.builder.CreateStore(chars, c.builder.CreateStructGEP(str, 0, ""))
	c.builder.CreateStore(len_sum, c.builder.CreateStructGEP(str, 1, ""))
	c.builder.CreateStore(len_sum, c.builder.CreateStructGEP(str, 2, ""))

	return str
}
开发者ID:furryfaust,项目名称:lyca,代码行数:26,代码来源:stdlib.go

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: genArrayLiteral

// Allocates a literal array on the stack
func (v *Codegen) genArrayLiteral(n *parser.ArrayLiteral) llvm.Value {
	arrayLLVMType := v.typeToLLVMType(n.Type)
	memberLLVMType := v.typeToLLVMType(n.Type.(parser.ArrayType).MemberType)

	if v.inFunction {
		// allocate backing array
		arrAlloca := v.builder.CreateAlloca(llvm.ArrayType(memberLLVMType, len(n.Members)), "")

		// copy the constant array to the backing array
		for idx, value := range n.Members {
			gep := v.builder.CreateGEP(arrAlloca, []llvm.Value{llvm.ConstInt(llvm.IntType(32), 0, false), llvm.ConstInt(llvm.IntType(32), uint64(idx), false)}, "")
			value := v.genExpr(value)
			v.builder.CreateStore(value, gep)
		}

		// allocate struct
		structAlloca := v.builder.CreateAlloca(arrayLLVMType, "")

		// set the length of the array
		lenGEP := v.builder.CreateGEP(structAlloca, []llvm.Value{llvm.ConstInt(llvm.IntType(32), 0, false), llvm.ConstInt(llvm.IntType(32), 0, false)}, "")
		v.builder.CreateStore(llvm.ConstInt(llvm.IntType(32), uint64(len(n.Members)), false), lenGEP)

		// set the array pointer to the backing array we allocated
		arrGEP := v.builder.CreateGEP(structAlloca, []llvm.Value{llvm.ConstInt(llvm.IntType(32), 0, false), llvm.ConstInt(llvm.IntType(32), 1, false)}, "")
		v.builder.CreateStore(v.builder.CreateBitCast(arrAlloca, llvm.PointerType(llvm.ArrayType(memberLLVMType, 0), 0), ""), arrGEP)

		return v.builder.CreateLoad(structAlloca, "")
	} else {
		backName := fmt.Sprintf("_globarr_back_%d", v.arrayIndex)
		v.arrayIndex++

		backGlob := llvm.AddGlobal(v.curFile.Module, llvm.ArrayType(memberLLVMType, len(n.Members)), backName)
		backGlob.SetLinkage(llvm.InternalLinkage)
		backGlob.SetGlobalConstant(false)

		arrConstVals := make([]llvm.Value, len(n.Members))
		for idx, mem := range n.Members {
			value := v.genExpr(mem)
			if !value.IsConstant() {
				v.err("Encountered non-constant value in global array")
			}
			arrConstVals[idx] = v.genExpr(mem)
		}
		backGlob.SetInitializer(llvm.ConstArray(memberLLVMType, arrConstVals))

		lengthVal := llvm.ConstInt(llvm.IntType(32), uint64(len(n.Members)), false)
		backRef := llvm.ConstBitCast(backGlob, llvm.PointerType(llvm.ArrayType(memberLLVMType, 0), 0))

		return llvm.ConstStruct([]llvm.Value{lengthVal, backRef}, false)
	}
}
开发者ID:gitter-badger,项目名称:ark,代码行数:52,代码来源:codegen.go

示例10: callCap

func (fr *frame) callCap(arg *govalue) *govalue {
	var v llvm.Value
	switch typ := arg.Type().Underlying().(type) {
	case *types.Array:
		v = llvm.ConstInt(fr.llvmtypes.inttype, uint64(typ.Len()), false)
	case *types.Pointer:
		atyp := typ.Elem().Underlying().(*types.Array)
		v = llvm.ConstInt(fr.llvmtypes.inttype, uint64(atyp.Len()), false)
	case *types.Slice:
		v = fr.builder.CreateExtractValue(arg.value, 2, "")
	case *types.Chan:
		v = fr.runtime.chanCap.call(fr, arg.value)[0]
	}
	return newValue(v, types.Typ[types.Int])
}
开发者ID:glycerine,项目名称:llgo,代码行数:15,代码来源:builtins.go

示例11: 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)

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

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

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

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

		v.genBoundsCheck(v.builder.CreateLoad(v.builder.CreateStructGEP(gep, 0, ""), ""), subscriptExpr, aae.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:
		tae := n.(*parser.TupleAccessExpr)

		gep := v.genAccessGEP(tae.Tuple)

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

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

		return v.genExpr(dae.Expr)

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

示例12: genNumericLiteral

func (v *Codegen) genNumericLiteral(n *parser.NumericLiteral) llvm.Value {
	if n.Type.IsFloatingType() {
		return llvm.ConstFloat(v.typeToLLVMType(n.Type), n.AsFloat())
	} else {
		return llvm.ConstInt(v.typeToLLVMType(n.Type), n.AsInt(), false)
	}
}
开发者ID:vnev,项目名称:ark,代码行数:7,代码来源:codegen.go

示例13: genBoundsCheck

func (v *Codegen) genBoundsCheck(limit llvm.Value, index llvm.Value, indexType parser.Type) {
	segvBlock := llvm.AddBasicBlock(v.currentLLVMFunction(), "boundscheck_segv")
	endBlock := llvm.AddBasicBlock(v.currentLLVMFunction(), "boundscheck_end")
	upperCheckBlock := llvm.AddBasicBlock(v.currentLLVMFunction(), "boundscheck_upper_block")

	tooLow := v.builder().CreateICmp(llvm.IntSGT, llvm.ConstInt(index.Type(), 0, false), index, "boundscheck_lower")
	v.builder().CreateCondBr(tooLow, segvBlock, upperCheckBlock)

	v.builder().SetInsertPointAtEnd(upperCheckBlock)

	// make sure limit and index have same width
	castedLimit := limit
	castedIndex := index
	if index.Type().IntTypeWidth() < limit.Type().IntTypeWidth() {
		if indexType.IsSigned() {
			castedIndex = v.builder().CreateSExt(index, limit.Type(), "")
		} else {
			castedIndex = v.builder().CreateZExt(index, limit.Type(), "")
		}
	} else if index.Type().IntTypeWidth() > limit.Type().IntTypeWidth() {
		castedLimit = v.builder().CreateZExt(limit, index.Type(), "")
	}

	tooHigh := v.builder().CreateICmp(llvm.IntSLE, castedLimit, castedIndex, "boundscheck_upper")
	v.builder().CreateCondBr(tooHigh, segvBlock, endBlock)

	v.builder().SetInsertPointAtEnd(segvBlock)
	v.genRaiseSegfault()
	v.builder().CreateUnreachable()

	v.builder().SetInsertPointAtEnd(endBlock)
}
开发者ID:vnev,项目名称:ark,代码行数:32,代码来源:codegen.go

示例14: 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

示例15: 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


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