Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:12

0001 //===- llvm/MC/MCParsedAsmOperand.h - Asm Parser Operand --------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
0010 #define LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
0011 
0012 #include "llvm/ADT/StringRef.h"
0013 #include "llvm/Support/SMLoc.h"
0014 #include <string>
0015 
0016 namespace llvm {
0017 
0018 class MCRegister;
0019 class raw_ostream;
0020 
0021 /// MCParsedAsmOperand - This abstract class represents a source-level assembly
0022 /// instruction operand.  It should be subclassed by target-specific code.  This
0023 /// base class is used by target-independent clients and is the interface
0024 /// between parsing an asm instruction and recognizing it.
0025 class MCParsedAsmOperand {
0026   /// MCOperandNum - The corresponding MCInst operand number.  Only valid when
0027   /// parsing MS-style inline assembly.
0028   unsigned MCOperandNum = ~0u;
0029 
0030   /// Constraint - The constraint on this operand.  Only valid when parsing
0031   /// MS-style inline assembly.
0032   std::string Constraint;
0033 
0034 protected:
0035   // This only seems to need to be movable (by ARMOperand) but ARMOperand has
0036   // lots of members and MSVC doesn't support defaulted move ops, so to avoid
0037   // that verbosity, just rely on defaulted copy ops. It's only the Constraint
0038   // string member that would benefit from movement anyway.
0039   MCParsedAsmOperand() = default;
0040   MCParsedAsmOperand(const MCParsedAsmOperand &RHS) = default;
0041   MCParsedAsmOperand &operator=(const MCParsedAsmOperand &) = default;
0042 
0043 public:
0044   virtual ~MCParsedAsmOperand() = default;
0045 
0046   void setConstraint(StringRef C) { Constraint = C.str(); }
0047   StringRef getConstraint() { return Constraint; }
0048 
0049   void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
0050   unsigned getMCOperandNum() { return MCOperandNum; }
0051 
0052   virtual StringRef getSymName() { return StringRef(); }
0053   virtual void *getOpDecl() { return nullptr; }
0054 
0055   /// isToken - Is this a token operand?
0056   virtual bool isToken() const = 0;
0057   /// isImm - Is this an immediate operand?
0058   virtual bool isImm() const = 0;
0059   /// isReg - Is this a register operand?
0060   virtual bool isReg() const = 0;
0061   virtual MCRegister getReg() const = 0;
0062 
0063   /// isMem - Is this a memory operand?
0064   virtual bool isMem() const = 0;
0065 
0066   /// isMemUseUpRegs - Is memory operand use up regs, for example, intel MS
0067   /// inline asm may use ARR[baseReg + IndexReg + ...] which may use up regs
0068   /// in [...] expr, so ARR[baseReg + IndexReg + ...] can not use extra reg
0069   /// for ARR. For example, calculating ARR address to a reg or use another
0070   /// base reg in PIC model.
0071   virtual bool isMemUseUpRegs() const { return false; }
0072 
0073   /// getStartLoc - Get the location of the first token of this operand.
0074   virtual SMLoc getStartLoc() const = 0;
0075   /// getEndLoc - Get the location of the last token of this operand.
0076   virtual SMLoc getEndLoc() const = 0;
0077 
0078   /// needAddressOf - Do we need to emit code to get the address of the
0079   /// variable/label?   Only valid when parsing MS-style inline assembly.
0080   virtual bool needAddressOf() const { return false; }
0081 
0082   /// isOffsetOfLocal - Do we need to emit code to get the offset of the local
0083   /// variable, rather than its value?   Only valid when parsing MS-style inline
0084   /// assembly.
0085   virtual bool isOffsetOfLocal() const { return false; }
0086 
0087   /// getOffsetOfLoc - Get the location of the offset operator.
0088   virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
0089 
0090   /// print - Print a debug representation of the operand to the given stream.
0091   virtual void print(raw_ostream &OS) const = 0;
0092 
0093   /// dump - Print to the debug stream.
0094   virtual void dump() const;
0095 };
0096 
0097 //===----------------------------------------------------------------------===//
0098 // Debugging Support
0099 
0100 inline raw_ostream& operator<<(raw_ostream &OS, const MCParsedAsmOperand &MO) {
0101   MO.print(OS);
0102   return OS;
0103 }
0104 
0105 } // end namespace llvm
0106 
0107 #endif // LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H