1 //===-- llvm/MC/MCInstBuilder.h - Simplify creation of MCInsts --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the MCInstBuilder class for convenient creation of
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_MC_MCINSTBUILDER_H
16 #define LLVM_MC_MCINSTBUILDER_H
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCStreamer.h"
27 /// \brief Create a new MCInstBuilder for an MCInst with a specific opcode.
28 MCInstBuilder(unsigned Opcode) {
29 Inst.setOpcode(Opcode);
32 /// \brief Add a new register operand.
33 MCInstBuilder &addReg(unsigned Reg) {
34 Inst.addOperand(MCOperand::CreateReg(Reg));
38 /// \brief Add a new integer immediate operand.
39 MCInstBuilder &addImm(int64_t Val) {
40 Inst.addOperand(MCOperand::CreateImm(Val));
44 /// \brief Add a new floating point immediate operand.
45 MCInstBuilder &addFPImm(double Val) {
46 Inst.addOperand(MCOperand::CreateFPImm(Val));
50 /// \brief Add a new MCExpr operand.
51 MCInstBuilder &addExpr(const MCExpr *Val) {
52 Inst.addOperand(MCOperand::CreateExpr(Val));
56 /// \brief Add a new MCInst operand.
57 MCInstBuilder &addInst(const MCInst *Val) {
58 Inst.addOperand(MCOperand::CreateInst(Val));
62 /// \brief Emit the built instruction to an MCStreamer.
63 void emit(MCStreamer &OutStreamer) {
64 OutStreamer.EmitInstruction(Inst);
68 } // end namespace llvm