1249259Sdim//===-- llvm/MC/MCInstBuilder.h - Simplify creation of MCInsts --*- C++ -*-===// 2249259Sdim// 3249259Sdim// The LLVM Compiler Infrastructure 4249259Sdim// 5249259Sdim// This file is distributed under the University of Illinois Open Source 6249259Sdim// License. See LICENSE.TXT for details. 7249259Sdim// 8249259Sdim//===----------------------------------------------------------------------===// 9249259Sdim// 10249259Sdim// This file contains the MCInstBuilder class for convenient creation of 11249259Sdim// MCInsts. 12249259Sdim// 13249259Sdim//===----------------------------------------------------------------------===// 14249259Sdim 15249259Sdim#ifndef LLVM_MC_MCINSTBUILDER_H 16249259Sdim#define LLVM_MC_MCINSTBUILDER_H 17249259Sdim 18249259Sdim#include "llvm/MC/MCInst.h" 19249259Sdim 20249259Sdimnamespace llvm { 21249259Sdim 22249259Sdimclass MCInstBuilder { 23249259Sdim MCInst Inst; 24249259Sdim 25249259Sdimpublic: 26249259Sdim /// \brief Create a new MCInstBuilder for an MCInst with a specific opcode. 27249259Sdim MCInstBuilder(unsigned Opcode) { 28249259Sdim Inst.setOpcode(Opcode); 29249259Sdim } 30249259Sdim 31249259Sdim /// \brief Add a new register operand. 32249259Sdim MCInstBuilder &addReg(unsigned Reg) { 33249259Sdim Inst.addOperand(MCOperand::CreateReg(Reg)); 34249259Sdim return *this; 35249259Sdim } 36249259Sdim 37249259Sdim /// \brief Add a new integer immediate operand. 38249259Sdim MCInstBuilder &addImm(int64_t Val) { 39249259Sdim Inst.addOperand(MCOperand::CreateImm(Val)); 40249259Sdim return *this; 41249259Sdim } 42249259Sdim 43249259Sdim /// \brief Add a new floating point immediate operand. 44249259Sdim MCInstBuilder &addFPImm(double Val) { 45249259Sdim Inst.addOperand(MCOperand::CreateFPImm(Val)); 46249259Sdim return *this; 47249259Sdim } 48249259Sdim 49249259Sdim /// \brief Add a new MCExpr operand. 50249259Sdim MCInstBuilder &addExpr(const MCExpr *Val) { 51249259Sdim Inst.addOperand(MCOperand::CreateExpr(Val)); 52249259Sdim return *this; 53249259Sdim } 54249259Sdim 55249259Sdim /// \brief Add a new MCInst operand. 56249259Sdim MCInstBuilder &addInst(const MCInst *Val) { 57249259Sdim Inst.addOperand(MCOperand::CreateInst(Val)); 58249259Sdim return *this; 59249259Sdim } 60249259Sdim 61249259Sdim operator MCInst&() { 62249259Sdim return Inst; 63249259Sdim } 64249259Sdim}; 65249259Sdim 66249259Sdim} // end namespace llvm 67249259Sdim 68249259Sdim#endif 69