MCParsedAsmOperand.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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/MC/MCInstrDesc.h"
  17. #include "llvm/Support/SMLoc.h"
  18. #include <string>
  19. namespace llvm {
  20. class raw_ostream;
  21. /// MCParsedAsmOperand - This abstract class represents a source-level assembly
  22. /// instruction operand. It should be subclassed by target-specific code. This
  23. /// base class is used by target-independent clients and is the interface
  24. /// between parsing an asm instruction and recognizing it.
  25. class MCParsedAsmOperand {
  26. /// MCOperandNum - The corresponding MCInst operand number. Only valid when
  27. /// parsing MS-style inline assembly.
  28. unsigned MCOperandNum;
  29. /// Constraint - The constraint on this operand. Only valid when parsing
  30. /// MS-style inline assembly.
  31. std::string Constraint;
  32. protected:
  33. // This only seems to need to be movable (by ARMOperand) but ARMOperand has
  34. // lots of members and MSVC doesn't support defaulted move ops, so to avoid
  35. // that verbosity, just rely on defaulted copy ops. It's only the Constraint
  36. // string member that would benefit from movement anyway.
  37. MCParsedAsmOperand() = default;
  38. MCParsedAsmOperand(const MCParsedAsmOperand &RHS) = default;
  39. MCParsedAsmOperand &operator=(const MCParsedAsmOperand &) = default;
  40. public:
  41. virtual ~MCParsedAsmOperand() = default;
  42. void setConstraint(StringRef C) { Constraint = C.str(); }
  43. StringRef getConstraint() { return Constraint; }
  44. void setMCOperandNum (unsigned OpNum) { MCOperandNum = OpNum; }
  45. unsigned getMCOperandNum() { return MCOperandNum; }
  46. virtual StringRef getSymName() { return StringRef(); }
  47. virtual void *getOpDecl() { return nullptr; }
  48. /// isToken - Is this a token operand?
  49. virtual bool isToken() const = 0;
  50. /// isImm - Is this an immediate operand?
  51. virtual bool isImm() const = 0;
  52. /// isReg - Is this a register operand?
  53. virtual bool isReg() const = 0;
  54. virtual unsigned getReg() const = 0;
  55. /// isMem - Is this a memory operand?
  56. virtual bool isMem() const = 0;
  57. /// getStartLoc - Get the location of the first token of this operand.
  58. virtual SMLoc getStartLoc() const = 0;
  59. /// getEndLoc - Get the location of the last token of this operand.
  60. virtual SMLoc getEndLoc() const = 0;
  61. /// needAddressOf - Do we need to emit code to get the address of the
  62. /// variable/label? Only valid when parsing MS-style inline assembly.
  63. virtual bool needAddressOf() const { return false; }
  64. /// isOffsetOfLocal - Do we need to emit code to get the offset of the local
  65. /// variable, rather than its value? Only valid when parsing MS-style inline
  66. /// assembly.
  67. virtual bool isOffsetOfLocal() const { return false; }
  68. /// isMemPlaceholder - Do we need to ignore the constraint, rather than emit
  69. /// code? Only valid when parsing MS-style inline assembly.
  70. virtual bool isMemPlaceholder(const MCInstrDesc &Desc) const { return false; }
  71. /// getOffsetOfLoc - Get the location of the offset operator.
  72. virtual SMLoc getOffsetOfLoc() const { return SMLoc(); }
  73. /// print - Print a debug representation of the operand to the given stream.
  74. virtual void print(raw_ostream &OS) const = 0;
  75. /// dump - Print to the debug stream.
  76. virtual void dump() const;
  77. };
  78. //===----------------------------------------------------------------------===//
  79. // Debugging Support
  80. inline raw_ostream& operator<<(raw_ostream &OS, const MCParsedAsmOperand &MO) {
  81. MO.print(OS);
  82. return OS;
  83. }
  84. } // end namespace llvm
  85. #endif // LLVM_MC_MCPARSER_MCPARSEDASMOPERAND_H
  86. #ifdef __GNUC__
  87. #pragma GCC diagnostic pop
  88. #endif