1 //===- AsmExpr.h - Assembly file expressions --------------------*- 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 //===----------------------------------------------------------------------===//
13 #include "llvm/Support/Casting.h"
14 #include "llvm/Support/DataTypes.h"
24 Binary, /// Binary expressions.
25 Constant, /// Constant expressions.
26 SymbolRef, /// References to labels and assigned expressions.
27 Unary /// Unary expressions.
34 AsmExpr(AsmExprKind _Kind) : Kind(_Kind) {}
39 AsmExprKind getKind() const { return Kind; }
41 /// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
43 /// @param Res - The absolute value, if evaluation succeeds.
44 /// @result - True on success.
45 bool EvaluateAsAbsolute(MCContext &Ctx, int64_t &Res) const;
47 /// EvaluateAsRelocatable - Try to evaluate the expression to a relocatable
50 /// @param Res - The relocatable value, if evaluation succeeds.
51 /// @result - True on success.
52 bool EvaluateAsRelocatable(MCContext &Ctx, MCValue &Res) const;
54 static bool classof(const AsmExpr *) { return true; }
57 class AsmConstantExpr : public AsmExpr {
61 AsmConstantExpr(int64_t _Value)
62 : AsmExpr(AsmExpr::Constant), Value(_Value) {}
64 int64_t getValue() const { return Value; }
66 static bool classof(const AsmExpr *E) {
67 return E->getKind() == AsmExpr::Constant;
69 static bool classof(const AsmConstantExpr *) { return true; }
72 class AsmSymbolRefExpr : public AsmExpr {
76 AsmSymbolRefExpr(MCSymbol *_Symbol)
77 : AsmExpr(AsmExpr::SymbolRef), Symbol(_Symbol) {}
79 MCSymbol *getSymbol() const { return Symbol; }
81 static bool classof(const AsmExpr *E) {
82 return E->getKind() == AsmExpr::SymbolRef;
84 static bool classof(const AsmSymbolRefExpr *) { return true; }
87 class AsmUnaryExpr : public AsmExpr {
90 LNot, /// Logical negation.
91 Minus, /// Unary minus.
92 Not, /// Bit-wise negation.
101 AsmUnaryExpr(Opcode _Op, AsmExpr *_Expr)
102 : AsmExpr(AsmExpr::Unary), Op(_Op), Expr(_Expr) {}
107 Opcode getOpcode() const { return Op; }
109 AsmExpr *getSubExpr() const { return Expr; }
111 static bool classof(const AsmExpr *E) {
112 return E->getKind() == AsmExpr::Unary;
114 static bool classof(const AsmUnaryExpr *) { return true; }
117 class AsmBinaryExpr : public AsmExpr {
121 And, /// Bitwise and.
123 EQ, /// Equality comparison.
124 GT, /// Greater than comparison.
125 GTE, /// Greater than or equal comparison.
126 LAnd, /// Logical and.
128 LT, /// Less than comparison.
129 LTE, /// Less than or equal comparison.
131 Mul, /// Multiplication.
132 NE, /// Inequality comparison.
134 Shl, /// Bitwise shift left.
135 Shr, /// Bitwise shift right.
136 Sub, /// Subtraction.
137 Xor /// Bitwise exclusive or.
145 AsmBinaryExpr(Opcode _Op, AsmExpr *_LHS, AsmExpr *_RHS)
146 : AsmExpr(AsmExpr::Binary), Op(_Op), LHS(_LHS), RHS(_RHS) {}
152 Opcode getOpcode() const { return Op; }
154 AsmExpr *getLHS() const { return LHS; }
155 AsmExpr *getRHS() const { return RHS; }
157 static bool classof(const AsmExpr *E) {
158 return E->getKind() == AsmExpr::Binary;
160 static bool classof(const AsmBinaryExpr *) { return true; }
163 } // end namespace llvm