10b57cec5SDimitry Andric //===-- AVRMCExpr.h - AVR specific MC expression classes --------*- C++ -*-===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #ifndef LLVM_AVR_MCEXPR_H 100b57cec5SDimitry Andric #define LLVM_AVR_MCEXPR_H 110b57cec5SDimitry Andric 120b57cec5SDimitry Andric #include "llvm/MC/MCExpr.h" 130b57cec5SDimitry Andric 140b57cec5SDimitry Andric #include "MCTargetDesc/AVRFixupKinds.h" 150b57cec5SDimitry Andric 160b57cec5SDimitry Andric namespace llvm { 170b57cec5SDimitry Andric 180b57cec5SDimitry Andric /// A expression in AVR machine code. 190b57cec5SDimitry Andric class AVRMCExpr : public MCTargetExpr { 200b57cec5SDimitry Andric public: 210b57cec5SDimitry Andric /// Specifies the type of an expression. 220b57cec5SDimitry Andric enum VariantKind { 23fe6060f1SDimitry Andric VK_AVR_None = 0, 240b57cec5SDimitry Andric 250b57cec5SDimitry Andric VK_AVR_HI8, ///< Corresponds to `hi8()`. 260b57cec5SDimitry Andric VK_AVR_LO8, ///< Corresponds to `lo8()`. 270b57cec5SDimitry Andric VK_AVR_HH8, ///< Corresponds to `hlo8() and hh8()`. 280b57cec5SDimitry Andric VK_AVR_HHI8, ///< Corresponds to `hhi8()`. 290b57cec5SDimitry Andric 30fe6060f1SDimitry Andric VK_AVR_PM, ///< Corresponds to `pm()`, reference to program memory. 310b57cec5SDimitry Andric VK_AVR_PM_LO8, ///< Corresponds to `pm_lo8()`. 320b57cec5SDimitry Andric VK_AVR_PM_HI8, ///< Corresponds to `pm_hi8()`. 330b57cec5SDimitry Andric VK_AVR_PM_HH8, ///< Corresponds to `pm_hh8()`. 340b57cec5SDimitry Andric 350b57cec5SDimitry Andric VK_AVR_LO8_GS, ///< Corresponds to `lo8(gs())`. 360b57cec5SDimitry Andric VK_AVR_HI8_GS, ///< Corresponds to `hi8(gs())`. 370b57cec5SDimitry Andric VK_AVR_GS, ///< Corresponds to `gs()`. 380b57cec5SDimitry Andric }; 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric public: 410b57cec5SDimitry Andric /// Creates an AVR machine code expression. 420b57cec5SDimitry Andric static const AVRMCExpr *create(VariantKind Kind, const MCExpr *Expr, 430b57cec5SDimitry Andric bool isNegated, MCContext &Ctx); 440b57cec5SDimitry Andric 450b57cec5SDimitry Andric /// Gets the type of the expression. getKind()460b57cec5SDimitry Andric VariantKind getKind() const { return Kind; } 470b57cec5SDimitry Andric /// Gets the name of the expression. 480b57cec5SDimitry Andric const char *getName() const; getSubExpr()490b57cec5SDimitry Andric const MCExpr *getSubExpr() const { return SubExpr; } 500b57cec5SDimitry Andric /// Gets the fixup which corresponds to the expression. 510b57cec5SDimitry Andric AVR::Fixups getFixupKind() const; 520b57cec5SDimitry Andric /// Evaluates the fixup as a constant value. 530b57cec5SDimitry Andric bool evaluateAsConstant(int64_t &Result) const; 540b57cec5SDimitry Andric isNegated()550b57cec5SDimitry Andric bool isNegated() const { return Negated; } 560b57cec5SDimitry Andric void setNegated(bool negated = true) { Negated = negated; } 570b57cec5SDimitry Andric 580b57cec5SDimitry Andric void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override; 59*0fca6ea1SDimitry Andric bool evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, 600b57cec5SDimitry Andric const MCFixup *Fixup) const override; 610b57cec5SDimitry Andric 620b57cec5SDimitry Andric void visitUsedExpr(MCStreamer &streamer) const override; 630b57cec5SDimitry Andric findAssociatedFragment()640b57cec5SDimitry Andric MCFragment *findAssociatedFragment() const override { 650b57cec5SDimitry Andric return getSubExpr()->findAssociatedFragment(); 660b57cec5SDimitry Andric } 670b57cec5SDimitry Andric fixELFSymbolsInTLSFixups(MCAssembler & Asm)680b57cec5SDimitry Andric void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {} 690b57cec5SDimitry Andric classof(const MCExpr * E)700b57cec5SDimitry Andric static bool classof(const MCExpr *E) { 710b57cec5SDimitry Andric return E->getKind() == MCExpr::Target; 720b57cec5SDimitry Andric } 730b57cec5SDimitry Andric 740b57cec5SDimitry Andric public: 750b57cec5SDimitry Andric static VariantKind getKindByName(StringRef Name); 760b57cec5SDimitry Andric 770b57cec5SDimitry Andric private: 780b57cec5SDimitry Andric int64_t evaluateAsInt64(int64_t Value) const; 790b57cec5SDimitry Andric 800b57cec5SDimitry Andric const VariantKind Kind; 810b57cec5SDimitry Andric const MCExpr *SubExpr; 820b57cec5SDimitry Andric bool Negated; 830b57cec5SDimitry Andric 840b57cec5SDimitry Andric private: AVRMCExpr(VariantKind Kind,const MCExpr * Expr,bool Negated)850b57cec5SDimitry Andric explicit AVRMCExpr(VariantKind Kind, const MCExpr *Expr, bool Negated) 860b57cec5SDimitry Andric : Kind(Kind), SubExpr(Expr), Negated(Negated) {} 8781ad6265SDimitry Andric ~AVRMCExpr() = default; 880b57cec5SDimitry Andric }; 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric } // end namespace llvm 910b57cec5SDimitry Andric 920b57cec5SDimitry Andric #endif // LLVM_AVR_MCEXPR_H 93