1 //===-- AVRMCExpr.h - AVR specific MC expression classes --------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_AVR_MCEXPR_H
10 #define LLVM_AVR_MCEXPR_H
12 #include "llvm/MC/MCExpr.h"
14 #include "MCTargetDesc/AVRFixupKinds.h"
18 /// A expression in AVR machine code.
19 class AVRMCExpr
: public MCTargetExpr
{
21 /// Specifies the type of an expression.
25 VK_AVR_HI8
, ///< Corresponds to `hi8()`.
26 VK_AVR_LO8
, ///< Corresponds to `lo8()`.
27 VK_AVR_HH8
, ///< Corresponds to `hlo8() and hh8()`.
28 VK_AVR_HHI8
, ///< Corresponds to `hhi8()`.
30 VK_AVR_PM
, ///< Corresponds to `pm()`, reference to program memory.
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()`.
35 VK_AVR_LO8_GS
, ///< Corresponds to `lo8(gs())`.
36 VK_AVR_HI8_GS
, ///< Corresponds to `hi8(gs())`.
37 VK_AVR_GS
, ///< Corresponds to `gs()`.
41 /// Creates an AVR machine code expression.
42 static const AVRMCExpr
*create(VariantKind Kind
, const MCExpr
*Expr
,
43 bool isNegated
, MCContext
&Ctx
);
45 /// Gets the type of the expression.
46 VariantKind
getKind() const { return Kind
; }
47 /// Gets the name of the expression.
48 const char *getName() const;
49 const MCExpr
*getSubExpr() const { return SubExpr
; }
50 /// Gets the fixup which corresponds to the expression.
51 AVR::Fixups
getFixupKind() const;
52 /// Evaluates the fixup as a constant value.
53 bool evaluateAsConstant(int64_t &Result
) const;
55 bool isNegated() const { return Negated
; }
56 void setNegated(bool negated
= true) { Negated
= negated
; }
58 void printImpl(raw_ostream
&OS
, const MCAsmInfo
*MAI
) const override
;
59 bool evaluateAsRelocatableImpl(MCValue
&Res
, const MCAssembler
*Asm
,
60 const MCFixup
*Fixup
) const override
;
62 void visitUsedExpr(MCStreamer
&streamer
) const override
;
64 MCFragment
*findAssociatedFragment() const override
{
65 return getSubExpr()->findAssociatedFragment();
68 void fixELFSymbolsInTLSFixups(MCAssembler
&Asm
) const override
{}
70 static bool classof(const MCExpr
*E
) {
71 return E
->getKind() == MCExpr::Target
;
75 static VariantKind
getKindByName(StringRef Name
);
78 int64_t evaluateAsInt64(int64_t Value
) const;
80 const VariantKind Kind
;
81 const MCExpr
*SubExpr
;
85 explicit AVRMCExpr(VariantKind Kind
, const MCExpr
*Expr
, bool Negated
)
86 : Kind(Kind
), SubExpr(Expr
), Negated(Negated
) {}
87 ~AVRMCExpr() = default;
90 } // end namespace llvm
92 #endif // LLVM_AVR_MCEXPR_H