1 //===-- AVRMCExpr.h - AVR specific MC expression classes --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_AVR_MCEXPR_H
11 #define LLVM_AVR_MCEXPR_H
13 #include "llvm/MC/MCExpr.h"
15 #include "MCTargetDesc/AVRFixupKinds.h"
19 /// A expression in AVR machine code.
20 class AVRMCExpr : public MCTargetExpr {
22 /// Specifies the type of an expression.
26 VK_AVR_HI8, ///< Corresponds to `hi8()`.
27 VK_AVR_LO8, ///< Corresponds to `lo8()`.
28 VK_AVR_HH8, ///< Corresponds to `hlo8() and hh8()`.
29 VK_AVR_HHI8, ///< Corresponds to `hhi8()`.
31 VK_AVR_PM_LO8, ///< Corresponds to `pm_lo8()`.
32 VK_AVR_PM_HI8, ///< Corresponds to `pm_hi8()`.
33 VK_AVR_PM_HH8 ///< Corresponds to `pm_hh8()`.
37 /// Creates an AVR machine code expression.
38 static const AVRMCExpr *create(VariantKind Kind, const MCExpr *Expr,
39 bool isNegated, MCContext &Ctx);
41 /// Gets the type of the expression.
42 VariantKind getKind() const { return Kind; }
43 /// Gets the name of the expression.
44 const char *getName() const;
45 const MCExpr *getSubExpr() const { return SubExpr; }
46 /// Gets the fixup which corresponds to the expression.
47 AVR::Fixups getFixupKind() const;
48 /// Evaluates the fixup as a constant value.
49 bool evaluateAsConstant(int64_t &Result) const;
51 bool isNegated() const { return Negated; }
52 void setNegated(bool negated = true) { Negated = negated; }
54 void printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const override;
55 bool evaluateAsRelocatableImpl(MCValue &Res, const MCAsmLayout *Layout,
56 const MCFixup *Fixup) const override;
58 void visitUsedExpr(MCStreamer &streamer) const override;
60 MCFragment *findAssociatedFragment() const override {
61 return getSubExpr()->findAssociatedFragment();
64 void fixELFSymbolsInTLSFixups(MCAssembler &Asm) const override {}
66 static bool classof(const MCExpr *E) {
67 return E->getKind() == MCExpr::Target;
71 static VariantKind getKindByName(StringRef Name);
74 int64_t evaluateAsInt64(int64_t Value) const;
76 const VariantKind Kind;
77 const MCExpr *SubExpr;
81 explicit AVRMCExpr(VariantKind Kind, const MCExpr *Expr, bool Negated)
82 : Kind(Kind), SubExpr(Expr), Negated(Negated) {}
86 } // end namespace llvm
88 #endif // LLVM_AVR_MCEXPR_H