MCParsedAsmOperand.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/MC/MCParsedAsmOperand.h - Asm Parser Operand --------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
  14. #define LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
  15. #include "llvm/ADT/StringRef.h"
  16. #include "llvm/Support/SMLoc.h"
  17. #include <string>
  18. namespace llvm {
  19. class raw_ostream;
  20. /// MCParsedAsmOperand - This abstract class represents a source-level assembly
  21. /// instruction operand. It should be subclassed by target-specific code. This
  22. /// base class is used by target-independent clients and is the interface
  23. /// between parsing an asm instruction and recognizing it.
  24. class MCParsedAsmOperand {
  25. /// MCOperandNum - The corresponding MCInst operand number. Only valid when
  26. /// parsing MS-style inline assembly.
  27. unsigned MCOperandNum;
  28. /// Constraint - The constraint on this operand. Only valid when parsing
  29. /// MS-style inline assembly.
  30. std::string Constraint;
  31. protected:
  32. // This only seems to need to be movable (by ARMOperand) but ARMOperand has
  33. // lots of members and MSVC doesn't support defaulted move ops, so to avoid
  34. // that verbosity, just rely on defaulted copy ops. It's only the Constraint
  35. // string member that would benefit from movement anyway.
  36. MCParsedAsmOperand() = default;
  37. MCParsedAsmOperand(const MCParsedAsmOperand &RHS) = default;
  38. MCParsedAsmOperand &operator=(const MCParsedAsmOperand &) = default;
  39. public:
  40. virtual ~MCParsedAsmOperand() = default;
  41. void setConstraint(StringRef C) { Constraint = C.str(); }
  42. StringRef getConstraint() { return Constraint; }
  43. void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
  44. unsigned getMCOperandNum() { return MCOperandNum; }
  45. virtual StringRef getSymName() { return StringRef(); }
  46. virtual void *getOpDecl() { return nullptr; }
  47. /// isToken - Is this a token operand?
  48. virtual bool isToken() const = 0;
  49. /// isImm - Is this an immediate operand?
  50. virtual bool isImm() const = 0;
  51. /// isReg - Is this a register operand?
  52. virtual bool isReg() const = 0;
  53. virtual unsigned getReg() const = 0;
  54. /// isMem - Is this a memory operand?
  55. virtual bool isMem() const = 0;
  56. /// isMemUseUpRegs - Is memory operand use up regs, for example, intel MS
  57. /// inline asm may use ARR[baseReg + IndexReg + ...] which may use up regs
  58. /// in [...] expr, so ARR[baseReg + IndexReg + ...] can not use extra reg
  59. /// for ARR. For example, calculating ARR address to a reg or use another
  60. /// base reg in PIC model.
  61. virtual bool isMemUseUpRegs() const { return false; }
  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. /// needAddressOf - Do we need to emit code to get the address of the
  67. /// variable/label? Only valid when parsing MS-style inline assembly.
  68. virtual bool needAddressOf() const { return false; }
  69. /// isOffsetOfLocal - Do we need to emit code to get the offset of the local
  70. /// variable, rather than its value? Only valid when parsing MS-style inline
  71. /// assembly.
  72. virtual bool isOffsetOfLocal() const { return false; }
  73. /// getOffsetOfLoc - Get the location of the offset operator.
  74. virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
  75. /// print - Print a debug representation of the operand to the given stream.
  76. virtual void print(raw_ostream &OS) const = 0;
  77. /// dump - Print to the debug stream.
  78. virtual void dump() const;
  79. };
  80. //===----------------------------------------------------------------------===//
  81. // Debugging Support
  82. inline raw_ostream& operator<<(raw_ostream &OS, const MCParsedAsmOperand &MO) {
  83. MO.print(OS);
  84. return OS;
  85. }
  86. } // end namespace llvm
  87. #endif // LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
  88. #ifdef __GNUC__
  89. #pragma GCC diagnostic pop
  90. #endif