Nirav Dave | 05b5891 | 2018-06-05 15:13:39 +0000 | [diff] [blame] | 1 | //=--- X86MCExpr.h - X86 specific MC expression classes ---*- 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 | // This file describes X86-specific MCExprs, i.e, registers used for |
| 11 | // extended variable assignments. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCEXPR_H |
| 16 | #define LLVM_LIB_TARGET_X86_MCTARGETDESC_X86MCEXPR_H |
| 17 | |
| 18 | #include "InstPrinter/X86ATTInstPrinter.h" |
| 19 | #include "llvm/MC/MCAsmInfo.h" |
| 20 | #include "llvm/MC/MCContext.h" |
| 21 | #include "llvm/MC/MCExpr.h" |
| 22 | #include "llvm/Support/ErrorHandling.h" |
| 23 | |
| 24 | namespace llvm { |
| 25 | |
| 26 | class X86MCExpr : public MCTargetExpr { |
| 27 | |
| 28 | private: |
| 29 | const int64_t RegNo; // All |
| 30 | |
| 31 | explicit X86MCExpr(int64_t R) : RegNo(R) {} |
| 32 | |
| 33 | public: |
| 34 | /// @name Construction |
| 35 | /// @{ |
| 36 | |
| 37 | static const X86MCExpr *create(int64_t RegNo, MCContext &Ctx) { |
| 38 | return new (Ctx) X86MCExpr(RegNo); |
| 39 | } |
| 40 | |
| 41 | /// @} |
| 42 | /// @name Accessors |
| 43 | /// @{ |
| 44 | |
| 45 | /// getSubExpr - Get the child of this expression. |
| 46 | int64_t getRegNo() const { return RegNo; } |
| 47 | |
| 48 | /// @} |
| 49 | |
| 50 | void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override { |
Nirav Dave | 7fd992a | 2018-08-16 16:31:14 +0000 | [diff] [blame] | 51 | if (!MAI || MAI->getAssemblerDialect() == 0) |
Nirav Dave | 05b5891 | 2018-06-05 15:13:39 +0000 | [diff] [blame] | 52 | OS << '%'; |
| 53 | OS << X86ATTInstPrinter::getRegisterName(RegNo); |
| 54 | } |
| 55 | |
| 56 | bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout, |
| 57 | const MCFixup *Fixup) const override { |
| 58 | return false; |
| 59 | } |
| 60 | // Register values should be inlined as they are not valid .set expressions. |
| 61 | bool inlineAssignedExpr() const override { return true; } |
Nirav Dave | 7fd992a | 2018-08-16 16:31:14 +0000 | [diff] [blame] | 62 | bool isEqualTo(const MCExpr *X) const override { |
| 63 | if (auto *E = dyn_cast<X86MCExpr>(X)) |
| 64 | return getRegNo() == E->getRegNo(); |
| 65 | return false; |
| 66 | } |
Nirav Dave | 05b5891 | 2018-06-05 15:13:39 +0000 | [diff] [blame] | 67 | void visitUsedExpr(MCStreamer &Streamer) const override{}; |
| 68 | MCFragment *findAssociatedFragment() const override { return nullptr; } |
| 69 | |
| 70 | // There are no TLS X86MCExprs at the moment. |
| 71 | void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {} |
| 72 | |
| 73 | static bool classof(const MCExpr *E) { |
| 74 | return E->getKind() == MCExpr::Target; |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | } // end namespace llvm |
| 79 | |
| 80 | #endif |