aboutsummaryrefslogtreecommitdiff
path: root/include/llvm/MC/MCExpr.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/MC/MCExpr.h')
-rw-r--r--include/llvm/MC/MCExpr.h142
1 files changed, 78 insertions, 64 deletions
diff --git a/include/llvm/MC/MCExpr.h b/include/llvm/MC/MCExpr.h
index bd9b2bc4751a..b38ad7daee3e 100644
--- a/include/llvm/MC/MCExpr.h
+++ b/include/llvm/MC/MCExpr.h
@@ -21,15 +21,14 @@ class MCAssembler;
class MCContext;
class MCFixup;
class MCSection;
-class MCSectionData;
class MCStreamer;
class MCSymbol;
class MCValue;
class raw_ostream;
class StringRef;
-typedef DenseMap<const MCSectionData*, uint64_t> SectionAddrMap;
+typedef DenseMap<const MCSection *, uint64_t> SectionAddrMap;
-/// MCExpr - Base class for the full range of assembler expressions which are
+/// \brief Base class for the full range of assembler expressions which are
/// needed for parsing.
class MCExpr {
public:
@@ -44,8 +43,8 @@ public:
private:
ExprKind Kind;
- MCExpr(const MCExpr&) LLVM_DELETED_FUNCTION;
- void operator=(const MCExpr&) LLVM_DELETED_FUNCTION;
+ MCExpr(const MCExpr&) = delete;
+ void operator=(const MCExpr&) = delete;
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
@@ -56,53 +55,52 @@ private:
const SectionAddrMap *Addrs, bool InSet) const;
protected:
- explicit MCExpr(ExprKind _Kind) : Kind(_Kind) {}
+ explicit MCExpr(ExprKind Kind) : Kind(Kind) {}
bool EvaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm,
const MCAsmLayout *Layout,
const MCFixup *Fixup,
- const SectionAddrMap *Addrs, bool InSet,
- bool ForceVarExpansion) const;
+ const SectionAddrMap *Addrs, bool InSet) const;
public:
- /// @name Accessors
+ /// \name Accessors
/// @{
ExprKind getKind() const { return Kind; }
/// @}
- /// @name Utility Methods
+ /// \name Utility Methods
/// @{
void print(raw_ostream &OS) const;
void dump() const;
/// @}
- /// @name Expression Evaluation
+ /// \name Expression Evaluation
/// @{
- /// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
+ /// \brief Try to evaluate the expression to an absolute value.
///
- /// @param Res - The absolute value, if evaluation succeeds.
- /// @param Layout - The assembler layout object to use for evaluating symbol
+ /// \param Res - The absolute value, if evaluation succeeds.
+ /// \param Layout - The assembler layout object to use for evaluating symbol
/// values. If not given, then only non-symbolic expressions will be
/// evaluated.
- /// @result - True on success.
+ /// \return - True on success.
bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout,
const SectionAddrMap &Addrs) const;
bool EvaluateAsAbsolute(int64_t &Res) const;
bool EvaluateAsAbsolute(int64_t &Res, const MCAssembler &Asm) const;
bool EvaluateAsAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
- int64_t evaluateKnownAbsolute(const MCAsmLayout &Layout) const;
+ bool evaluateKnownAbsolute(int64_t &Res, const MCAsmLayout &Layout) const;
- /// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
- /// value, i.e. an expression of the fixed form (a - b + constant).
+ /// \brief Try to evaluate the expression to a relocatable value, i.e. an
+ /// expression of the fixed form (a - b + constant).
///
- /// @param Res - The relocatable value, if evaluation succeeds.
- /// @param Layout - The assembler layout object to use for evaluating values.
- /// @param Fixup - The Fixup object if available.
- /// @result - True on success.
+ /// \param Res - The relocatable value, if evaluation succeeds.
+ /// \param Layout - The assembler layout object to use for evaluating values.
+ /// \param Fixup - The Fixup object if available.
+ /// \return - True on success.
bool EvaluateAsRelocatable(MCValue &Res, const MCAsmLayout *Layout,
const MCFixup *Fixup) const;
@@ -110,16 +108,14 @@ public:
/// neither a nor b are variables.
///
/// This is a more aggressive variant of EvaluateAsRelocatable. The intended
- /// use is for when relocations are not available, like the symbol value in
- /// the symbol table.
- bool EvaluateAsValue(MCValue &Res, const MCAsmLayout *Layout,
- const MCFixup *Fixup) const;
+ /// use is for when relocations are not available, like the .size directive.
+ bool evaluateAsValue(MCValue &Res, const MCAsmLayout &Layout) const;
- /// FindAssociatedSection - Find the "associated section" for this expression,
- /// which is currently defined as the absolute section for constants, or
+ /// \brief Find the "associated section" for this expression, which is
+ /// currently defined as the absolute section for constants, or
/// otherwise the section associated with the first defined symbol in the
/// expression.
- const MCSection *FindAssociatedSection() const;
+ MCSection *FindAssociatedSection() const;
/// @}
};
@@ -129,21 +125,21 @@ inline raw_ostream &operator<<(raw_ostream &OS, const MCExpr &E) {
return OS;
}
-//// MCConstantExpr - Represent a constant integer expression.
+//// \brief Represent a constant integer expression.
class MCConstantExpr : public MCExpr {
int64_t Value;
- explicit MCConstantExpr(int64_t _Value)
- : MCExpr(MCExpr::Constant), Value(_Value) {}
+ explicit MCConstantExpr(int64_t Value)
+ : MCExpr(MCExpr::Constant), Value(Value) {}
public:
- /// @name Construction
+ /// \name Construction
/// @{
static const MCConstantExpr *Create(int64_t Value, MCContext &Ctx);
/// @}
- /// @name Accessors
+ /// \name Accessors
/// @{
int64_t getValue() const { return Value; }
@@ -155,15 +151,14 @@ public:
}
};
-/// MCSymbolRefExpr - Represent a reference to a symbol from inside an
-/// expression.
+/// \brief Represent a reference to a symbol from inside an expression.
///
/// A symbol reference in an expression may be a use of a label, a use of an
/// assembler variable (defined constant), or constitute an implicit definition
/// of the symbol as external.
class MCSymbolRefExpr : public MCExpr {
public:
- enum VariantKind {
+ enum VariantKind : uint16_t {
VK_None,
VK_Invalid,
@@ -188,6 +183,7 @@ public:
VK_GOTPAGE,
VK_GOTPAGEOFF,
VK_SECREL,
+ VK_SIZE, // symbol@SIZE
VK_WEAKREF, // The link between the symbols in .weakref foo, bar
VK_ARM_NONE,
@@ -280,12 +276,25 @@ public:
VK_Mips_PCREL_HI16,
VK_Mips_PCREL_LO16,
- VK_COFF_IMGREL32 // symbol@imgrel (image-relative)
+ VK_COFF_IMGREL32, // symbol@imgrel (image-relative)
+
+ VK_Hexagon_PCREL,
+ VK_Hexagon_LO16,
+ VK_Hexagon_HI16,
+ VK_Hexagon_GPREL,
+ VK_Hexagon_GD_GOT,
+ VK_Hexagon_LD_GOT,
+ VK_Hexagon_GD_PLT,
+ VK_Hexagon_LD_PLT,
+ VK_Hexagon_IE,
+ VK_Hexagon_IE_GOT,
+ VK_TPREL,
+ VK_DTPREL
};
private:
/// The symbol reference modifier.
- const unsigned Kind : 16;
+ const VariantKind Kind;
/// Specifies how the variant kind should be printed.
const unsigned UseParensForSymbolVariant : 1;
@@ -300,7 +309,7 @@ private:
const MCAsmInfo *MAI);
public:
- /// @name Construction
+ /// \name Construction
/// @{
static const MCSymbolRefExpr *Create(const MCSymbol *Symbol, MCContext &Ctx) {
@@ -313,19 +322,19 @@ public:
MCContext &Ctx);
/// @}
- /// @name Accessors
+ /// \name Accessors
/// @{
const MCSymbol &getSymbol() const { return *Symbol; }
- VariantKind getKind() const { return static_cast<VariantKind>(Kind); }
+ VariantKind getKind() const { return Kind; }
void printVariantKind(raw_ostream &OS) const;
bool hasSubsectionsViaSymbols() const { return HasSubsectionsViaSymbols; }
/// @}
- /// @name Static Utility Functions
+ /// \name Static Utility Functions
/// @{
static StringRef getVariantKindName(VariantKind Kind);
@@ -339,7 +348,7 @@ public:
}
};
-/// MCUnaryExpr - Unary assembler expressions.
+/// \brief Unary assembler expressions.
class MCUnaryExpr : public MCExpr {
public:
enum Opcode {
@@ -353,11 +362,11 @@ private:
Opcode Op;
const MCExpr *Expr;
- MCUnaryExpr(Opcode _Op, const MCExpr *_Expr)
- : MCExpr(MCExpr::Unary), Op(_Op), Expr(_Expr) {}
+ MCUnaryExpr(Opcode Op, const MCExpr *Expr)
+ : MCExpr(MCExpr::Unary), Op(Op), Expr(Expr) {}
public:
- /// @name Construction
+ /// \name Construction
/// @{
static const MCUnaryExpr *Create(Opcode Op, const MCExpr *Expr,
@@ -376,13 +385,13 @@ public:
}
/// @}
- /// @name Accessors
+ /// \name Accessors
/// @{
- /// getOpcode - Get the kind of this unary expression.
+ /// \brief Get the kind of this unary expression.
Opcode getOpcode() const { return Op; }
- /// getSubExpr - Get the child of this unary expression.
+ /// \brief Get the child of this unary expression.
const MCExpr *getSubExpr() const { return Expr; }
/// @}
@@ -392,7 +401,7 @@ public:
}
};
-/// MCBinaryExpr - Binary assembler expressions.
+/// \brief Binary assembler expressions.
class MCBinaryExpr : public MCExpr {
public:
enum Opcode {
@@ -415,7 +424,8 @@ public:
NE, ///< Inequality comparison.
Or, ///< Bitwise or.
Shl, ///< Shift left.
- Shr, ///< Shift right (arithmetic or logical, depending on target)
+ AShr, ///< Arithmetic shift right.
+ LShr, ///< Logical shift right.
Sub, ///< Subtraction.
Xor ///< Bitwise exclusive or.
};
@@ -424,11 +434,11 @@ private:
Opcode Op;
const MCExpr *LHS, *RHS;
- MCBinaryExpr(Opcode _Op, const MCExpr *_LHS, const MCExpr *_RHS)
- : MCExpr(MCExpr::Binary), Op(_Op), LHS(_LHS), RHS(_RHS) {}
+ MCBinaryExpr(Opcode Op, const MCExpr *LHS, const MCExpr *RHS)
+ : MCExpr(MCExpr::Binary), Op(Op), LHS(LHS), RHS(RHS) {}
public:
- /// @name Construction
+ /// \name Construction
/// @{
static const MCBinaryExpr *Create(Opcode Op, const MCExpr *LHS,
@@ -493,9 +503,13 @@ public:
MCContext &Ctx) {
return Create(Shl, LHS, RHS, Ctx);
}
- static const MCBinaryExpr *CreateShr(const MCExpr *LHS, const MCExpr *RHS,
+ static const MCBinaryExpr *CreateAShr(const MCExpr *LHS, const MCExpr *RHS,
MCContext &Ctx) {
- return Create(Shr, LHS, RHS, Ctx);
+ return Create(AShr, LHS, RHS, Ctx);
+ }
+ static const MCBinaryExpr *CreateLShr(const MCExpr *LHS, const MCExpr *RHS,
+ MCContext &Ctx) {
+ return Create(LShr, LHS, RHS, Ctx);
}
static const MCBinaryExpr *CreateSub(const MCExpr *LHS, const MCExpr *RHS,
MCContext &Ctx) {
@@ -507,16 +521,16 @@ public:
}
/// @}
- /// @name Accessors
+ /// \name Accessors
/// @{
- /// getOpcode - Get the kind of this binary expression.
+ /// \brief Get the kind of this binary expression.
Opcode getOpcode() const { return Op; }
- /// getLHS - Get the left-hand side expression of the binary operator.
+ /// \brief Get the left-hand side expression of the binary operator.
const MCExpr *getLHS() const { return LHS; }
- /// getRHS - Get the right-hand side expression of the binary operator.
+ /// \brief Get the right-hand side expression of the binary operator.
const MCExpr *getRHS() const { return RHS; }
/// @}
@@ -526,8 +540,8 @@ public:
}
};
-/// MCTargetExpr - This is an extension point for target-specific MCExpr
-/// subclasses to implement.
+/// \brief This is an extension point for target-specific MCExpr subclasses to
+/// implement.
///
/// NOTE: All subclasses are required to have trivial destructors because
/// MCExprs are bump pointer allocated and not destructed.
@@ -543,7 +557,7 @@ public:
const MCAsmLayout *Layout,
const MCFixup *Fixup) const = 0;
virtual void visitUsedExpr(MCStreamer& Streamer) const = 0;
- virtual const MCSection *FindAssociatedSection() const = 0;
+ virtual MCSection *FindAssociatedSection() const = 0;
virtual void fixELFSymbolsInTLSFixups(MCAssembler &) const = 0;