Home | History | Annotate | Download | only in MCParser
      1 //===-- llvm/MC/MCParsedAsmOperand.h - Asm Parser Operand -------*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 #ifndef LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
     11 #define LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
     12 
     13 namespace llvm {
     14 class SMLoc;
     15 class raw_ostream;
     16 
     17 /// MCParsedAsmOperand - This abstract class represents a source-level assembly
     18 /// instruction operand.  It should be subclassed by target-specific code.  This
     19 /// base class is used by target-independent clients and is the interface
     20 /// between parsing an asm instruction and recognizing it.
     21 class MCParsedAsmOperand {
     22   /// MCOperandNum - The corresponding MCInst operand number.  Only valid when
     23   /// parsing MS-style inline assembly.
     24   unsigned MCOperandNum;
     25 
     26   /// Constraint - The constraint on this operand.  Only valid when parsing
     27   /// MS-style inline assembly.
     28   std::string Constraint;
     29 
     30 public:
     31   MCParsedAsmOperand() {}
     32   virtual ~MCParsedAsmOperand() {}
     33 
     34   void setConstraint(StringRef C) { Constraint = C.str(); }
     35   StringRef getConstraint() { return Constraint; }
     36 
     37   void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
     38   unsigned getMCOperandNum() { return MCOperandNum; }
     39 
     40   unsigned getNameLen() {
     41     assert (getStartLoc().isValid() && "Invalid StartLoc!");
     42     assert (getEndLoc().isValid() && "Invalid EndLoc!");
     43     return getEndLoc().getPointer() - getStartLoc().getPointer();
     44   }
     45 
     46   StringRef getName() {
     47     return StringRef(getStartLoc().getPointer(), getNameLen());
     48   }
     49 
     50   /// isToken - Is this a token operand?
     51   virtual bool isToken() const = 0;
     52   /// isImm - Is this an immediate operand?
     53   virtual bool isImm() const = 0;
     54   /// isReg - Is this a register operand?
     55   virtual bool isReg() const = 0;
     56   virtual unsigned getReg() const = 0;
     57 
     58   /// isMem - Is this a memory operand?
     59   virtual bool isMem() const = 0;
     60   virtual unsigned getMemSize() const { return 0; }
     61 
     62   /// getStartLoc - Get the location of the first token of this operand.
     63   virtual SMLoc getStartLoc() const = 0;
     64   /// getEndLoc - Get the location of the last token of this operand.
     65   virtual SMLoc getEndLoc() const = 0;
     66 
     67   /// needAsmRewrite - AsmRewrites happen in both the target-independent and
     68   /// target-dependent parsers.  The target-independent parser calls this
     69   /// function to determine if the target-dependent parser has already taken
     70   /// care of the rewrites.  Only valid when parsing MS-style inline assembly.
     71   virtual bool needAsmRewrite() const { return true; }
     72 
     73   /// needAddressOf - Do we need to emit code to get the address of the
     74   /// variable/label?   Only valid when parsing MS-style inline assembly.
     75   virtual bool needAddressOf() const { return false; }
     76 
     77   /// isOffsetOf - Do we need to emit code to get the offset of the variable,
     78   /// rather then the value of the variable?   Only valid when parsing MS-style
     79   /// inline assembly.
     80   virtual bool isOffsetOf() const { return false; }
     81 
     82   /// getOffsetOfLoc - Get the location of the offset operator.
     83   virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
     84 
     85   /// needSizeDirective - Do we need to emit a sizing directive for this
     86   /// operand?  Only valid when parsing MS-style inline assembly.
     87   virtual bool needSizeDirective() const { return false; }
     88 
     89   /// print - Print a debug representation of the operand to the given stream.
     90   virtual void print(raw_ostream &OS) const = 0;
     91   /// dump - Print to the debug stream.
     92   virtual void dump() const;
     93 };
     94 
     95 //===----------------------------------------------------------------------===//
     96 // Debugging Support
     97 
     98 inline raw_ostream& operator<<(raw_ostream &OS, const MCParsedAsmOperand &MO) {
     99   MO.print(OS);
    100   return OS;
    101 }
    102 
    103 } // end namespace llvm.
    104 
    105 #endif
    106