LLVM API Documentation

MCInstBuilder.h
Go to the documentation of this file.
00001 //===-- llvm/MC/MCInstBuilder.h - Simplify creation of MCInsts --*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file contains the MCInstBuilder class for convenient creation of
00011 // MCInsts.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_MC_MCINSTBUILDER_H
00016 #define LLVM_MC_MCINSTBUILDER_H
00017 
00018 #include "llvm/MC/MCInst.h"
00019 
00020 namespace llvm {
00021 
00022 class MCInstBuilder {
00023   MCInst Inst;
00024 
00025 public:
00026   /// \brief Create a new MCInstBuilder for an MCInst with a specific opcode.
00027   MCInstBuilder(unsigned Opcode) {
00028     Inst.setOpcode(Opcode);
00029   }
00030 
00031   /// \brief Add a new register operand.
00032   MCInstBuilder &addReg(unsigned Reg) {
00033     Inst.addOperand(MCOperand::CreateReg(Reg));
00034     return *this;
00035   }
00036 
00037   /// \brief Add a new integer immediate operand.
00038   MCInstBuilder &addImm(int64_t Val) {
00039     Inst.addOperand(MCOperand::CreateImm(Val));
00040     return *this;
00041   }
00042 
00043   /// \brief Add a new floating point immediate operand.
00044   MCInstBuilder &addFPImm(double Val) {
00045     Inst.addOperand(MCOperand::CreateFPImm(Val));
00046     return *this;
00047   }
00048 
00049   /// \brief Add a new MCExpr operand.
00050   MCInstBuilder &addExpr(const MCExpr *Val) {
00051     Inst.addOperand(MCOperand::CreateExpr(Val));
00052     return *this;
00053   }
00054 
00055   /// \brief Add a new MCInst operand.
00056   MCInstBuilder &addInst(const MCInst *Val) {
00057     Inst.addOperand(MCOperand::CreateInst(Val));
00058     return *this;
00059   }
00060 
00061   operator MCInst&() {
00062     return Inst;
00063   }
00064 };
00065 
00066 } // end namespace llvm
00067 
00068 #endif