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


Golang Value.Operand方法代码示例

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


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

示例1: parseBinOp

// parseBinOp converts the provided LLVM IR binary operation into an equivalent
// Go AST node (an assignment statement with a binary expression on the right-
// hand side).
//
// Syntax:
//    <result> add <type> <op1>, <op2>
//
// References:
//    http://llvm.org/docs/LangRef.html#binary-operations
func parseBinOp(inst llvm.Value, op token.Token) (ast.Stmt, error) {
	x, err := parseOperand(inst.Operand(0))
	if err != nil {
		return nil, err
	}
	y, err := parseOperand(inst.Operand(1))
	if err != nil {
		return nil, err
	}
	result, err := getResult(inst)
	if err != nil {
		return nil, errutil.Err(err)
	}
	lhs := []ast.Expr{result}
	rhs := []ast.Expr{&ast.BinaryExpr{X: x, Op: op, Y: y}}
	// TODO: Use "=" instead of ":=" and let go-post and grind handle the ":=" to
	// "=" propagation.
	return &ast.AssignStmt{Lhs: lhs, Tok: token.DEFINE, Rhs: rhs}, nil
}
开发者ID:decomp,项目名称:decomp,代码行数:28,代码来源:instruction.go

示例2: parseRetInst

// parseRetInst converts the provided LLVM IR ret instruction into an equivalent
// Go return statement.
//
// Syntax:
//    ret void
//    ret <type> <val>
func parseRetInst(inst llvm.Value) (*ast.ReturnStmt, error) {
	// TODO: Make more robust by using proper parsing instead of relying on
	// tokens. The current approach is used for a proof of concept and would fail
	// for composite literals. This TODO applies to the use of tokens in all
	// functions.

	// Parse and validate tokens.
	tokens, err := getTokens(inst)
	if err != nil {
		return nil, err
	}
	if len(tokens) < 4 {
		// TODO: Remove debug output.
		inst.Dump()
		return nil, errutil.Newf("unable to parse return instruction; expected >= 4 tokens, got %d", len(tokens))
	}
	typ := tokens[1]
	if typ.Kind != lltoken.Type {
		return nil, errutil.Newf(`invalid return instruction; expected type token, got %q`, typ)
	}

	// Create and return a void return statement.
	if typ.Val == "void" {
		return &ast.ReturnStmt{}, nil
	}

	// Create and return a return statement.
	val, err := parseOperand(inst.Operand(0))
	if err != nil {
		return nil, errutil.Err(err)
	}

	ret := &ast.ReturnStmt{
		Results: []ast.Expr{val},
	}
	return ret, nil
}
开发者ID:decomp,项目名称:decomp,代码行数:43,代码来源:instruction.go

示例3: parsePHIInst

// parsePHIInst converts the provided LLVM IR phi instruction into an equivalent
// variable definition mapping.
//
// Syntax:
//    %foo = phi i32 [ 42, %2 ], [ %bar, %3 ]
func parsePHIInst(inst llvm.Value) (ident string, defs []*definition, err error) {
	// Parse result.
	result, err := getResult(inst)
	if err != nil {
		return "", nil, errutil.Err(err)
	}
	ident = result.(*ast.Ident).Name

	// Parse and validate tokens.
	tokens, err := getTokens(inst)
	if err != nil {
		return "", nil, errutil.Err(err)
	}
	if len(tokens) < 10 {
		return "", nil, errutil.Newf("unable to parse PHI instruction; expected >= 10 tokens, got %d", len(tokens))
	}

	// Parse operands.
	for i := 0; i < inst.OperandsCount(); i++ {
		// Parse variable definition expression.
		expr, err := parseOperand(inst.Operand(i))
		if err != nil {
			return "", nil, errutil.Err(err)
		}

		// Parse source basic block.
		bbTok := tokens[7+i*6]
		if bbTok.Kind != lltoken.LocalID {
			return "", nil, errutil.Newf("invalid operand token, expected LocalID, got %v", bbTok.Kind)
		}
		def := &definition{bb: bbTok.Val, expr: expr}
		defs = append(defs, def)
	}

	return ident, defs, nil
}
开发者ID:decomp,项目名称:decomp,代码行数:41,代码来源:instruction.go

示例4: maybeStoreInInitializer

// If val is a constant and addr refers to a global variable which is defined in
// this module or an element thereof, simulate the effect of storing val at addr
// in the global variable's initializer and return true, otherwise return false.
// Precondition: we are compiling the init function.
func (fr *frame) maybeStoreInInitializer(val, addr llvm.Value) bool {
	if val.IsAConstant().IsNil() {
		return false
	}

	if !addr.IsAConstantExpr().IsNil() && addr.OperandsCount() >= 2 &&
		// TODO(pcc): Explicitly check that this is a constant GEP.
		// I don't think there are any other kinds of constantexpr which
		// satisfy the conditions we test for here, so this is probably safe.
		!addr.Operand(0).IsAGlobalVariable().IsNil() &&
		addr.Operand(1).IsNull() {
		gv := addr.Operand(0)
		globalInit, ok := fr.globalInits[gv]
		if !ok {
			return false
		}
		indices := make([]uint32, addr.OperandsCount()-2)
		for i := range indices {
			op := addr.Operand(i + 2)
			if op.IsAConstantInt().IsNil() {
				return false
			}
			indices[i] = uint32(op.ZExtValue())
		}
		globalInit.update(gv.Type().ElementType(), indices, val)
		return true
	} else if !addr.IsAGlobalVariable().IsNil() {
		if globalInit, ok := fr.globalInits[addr]; ok {
			globalInit.update(addr.Type().ElementType(), nil, val)
			return true
		}
		return false
	} else {
		return false
	}
}
开发者ID:hinike,项目名称:llgo,代码行数:40,代码来源:ssa.go


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