LLVM API Documentation

MCParsedAsmOperand.h
Go to the documentation of this file.
00001 //===-- llvm/MC/MCParsedAsmOperand.h - Asm Parser Operand -------*- 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 #ifndef LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
00011 #define LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
00012 
00013 namespace llvm {
00014 class SMLoc;
00015 class raw_ostream;
00016 
00017 /// MCParsedAsmOperand - This abstract class represents a source-level assembly
00018 /// instruction operand.  It should be subclassed by target-specific code.  This
00019 /// base class is used by target-independent clients and is the interface
00020 /// between parsing an asm instruction and recognizing it.
00021 class MCParsedAsmOperand {
00022   /// MCOperandNum - The corresponding MCInst operand number.  Only valid when
00023   /// parsing MS-style inline assembly.
00024   unsigned MCOperandNum;
00025 
00026   /// Constraint - The constraint on this operand.  Only valid when parsing
00027   /// MS-style inline assembly.
00028   std::string Constraint;
00029 
00030 public:
00031   MCParsedAsmOperand() {}
00032   virtual ~MCParsedAsmOperand() {}
00033 
00034   void setConstraint(StringRef C) { Constraint = C.str(); }
00035   StringRef getConstraint() { return Constraint; }
00036 
00037   void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
00038   unsigned getMCOperandNum() { return MCOperandNum; }
00039 
00040   virtual StringRef getSymName() { return StringRef(); }
00041   virtual void *getOpDecl() { return nullptr; }
00042 
00043   /// isToken - Is this a token operand?
00044   virtual bool isToken() const = 0;
00045   /// isImm - Is this an immediate operand?
00046   virtual bool isImm() const = 0;
00047   /// isReg - Is this a register operand?
00048   virtual bool isReg() const = 0;
00049   virtual unsigned getReg() const = 0;
00050 
00051   /// isMem - Is this a memory operand?
00052   virtual bool isMem() const = 0;
00053 
00054   /// getStartLoc - Get the location of the first token of this operand.
00055   virtual SMLoc getStartLoc() const = 0;
00056   /// getEndLoc - Get the location of the last token of this operand.
00057   virtual SMLoc getEndLoc() const = 0;
00058 
00059   /// needAddressOf - Do we need to emit code to get the address of the
00060   /// variable/label?   Only valid when parsing MS-style inline assembly.
00061   virtual bool needAddressOf() const { return false; }
00062 
00063   /// isOffsetOf - Do we need to emit code to get the offset of the variable,
00064   /// rather then the value of the variable?   Only valid when parsing MS-style
00065   /// inline assembly.
00066   virtual bool isOffsetOf() const { return false; }
00067 
00068   /// getOffsetOfLoc - Get the location of the offset operator.
00069   virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
00070 
00071   /// print - Print a debug representation of the operand to the given stream.
00072   virtual void print(raw_ostream &OS) const = 0;
00073   /// dump - Print to the debug stream.
00074   virtual void dump() const;
00075 };
00076 
00077 //===----------------------------------------------------------------------===//
00078 // Debugging Support
00079 
00080 inline raw_ostream& operator<<(raw_ostream &OS, const MCParsedAsmOperand &MO) {
00081   MO.print(OS);
00082   return OS;
00083 }
00084 
00085 } // end namespace llvm.
00086 
00087 #endif