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


Golang Value.InstructionOpcode方法代码示例

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


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

示例1: parseInst

// parseInst converts the provided LLVM IR instruction into an equivalent Go AST
// node (a statement).
func parseInst(inst llvm.Value) (ast.Stmt, error) {
	// TODO: Remove debug output.
	if flagVerbose {
		fmt.Println("parseInst:")
		fmt.Println("   nops:", inst.OperandsCount())
		inst.Dump()
		fmt.Println()
	}

	// Assignment operation.
	//    %foo = ...
	opcode := inst.InstructionOpcode()
	if _, err := getResult(inst); err == nil {
		// Binary Operations
		switch opcode {
		case llvm.Add, llvm.FAdd:
			return parseBinOp(inst, token.ADD)
		case llvm.Sub, llvm.FSub:
			return parseBinOp(inst, token.SUB)
		case llvm.Mul, llvm.FMul:
			return parseBinOp(inst, token.MUL)
		case llvm.UDiv, llvm.SDiv, llvm.FDiv:
			// TODO: Handle signed and unsigned div separately.
			return parseBinOp(inst, token.QUO)
		case llvm.URem, llvm.SRem, llvm.FRem:
			// TODO: Handle signed and unsigned mod separately.
			return parseBinOp(inst, token.REM)

		// Bitwise Binary Operations
		case llvm.Shl:
			return parseBinOp(inst, token.SHL)
		case llvm.LShr, llvm.AShr:
			// TODO: Handle logical and arithmetic shift right separately.
			return parseBinOp(inst, token.SHR)
		case llvm.And:
			return parseBinOp(inst, token.AND)
		case llvm.Or:
			return parseBinOp(inst, token.OR)
		case llvm.Xor:
			return parseBinOp(inst, token.XOR)

		// Other Operators
		case llvm.ICmp, llvm.FCmp:
			pred, err := getCmpPred(inst)
			if err != nil {
				return nil, errutil.Err(err)
			}
			return parseBinOp(inst, pred)
		}
	}

	return nil, errutil.Newf("support for LLVM IR instruction %q not yet implemented", prettyOpcode(opcode))
}
开发者ID:decomp,项目名称:decomp,代码行数:55,代码来源:instruction.go

示例2: addTerm

// addTerm adds the provided terminator instruction to the basic block. If the
// terminator instruction doesn't have a target basic block (e.g. ret) it is
// parsed and added to the statements list of the basic block instead.
func (bb *basicBlock) addTerm(term llvm.Value) error {
	// TODO: Check why there is no opcode in the llvm library for the resume
	// terminator instruction.
	switch opcode := term.InstructionOpcode(); opcode {
	case llvm.Ret:
		// The return instruction doesn't have any target basic blocks so treat it
		// like a regular instruction and append it to the list of statements.
		ret, err := parseRetInst(term)
		if err != nil {
			return err
		}
		bb.stmts = append(bb.stmts, ret)
	case llvm.Br, llvm.Switch, llvm.IndirectBr, llvm.Invoke, llvm.Unreachable:
		// Parse the terminator instruction during the control flow analysis.
		bb.term = term
	default:
		return errutil.Newf("non-terminator instruction %q at end of basic block", prettyOpcode(opcode))
	}
	return nil
}
开发者ID:decomp,项目名称:decomp,代码行数:23,代码来源:basicblock.go


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