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"
23 Binary, /// Binary expressions.
24 Constant, /// Constant expressions.
25 SymbolRef, /// References to labels and assigned expressions.
26 Unary /// Unary expressions.
33 AsmExpr(AsmExprKind _Kind) : Kind(_Kind) {}
38 AsmExprKind getKind() const { return Kind; }
40 /// EvaluateAsAbsolute - Try to evaluate the expression to an absolute value.
42 /// @param Res - The absolute value if evaluation succeeds.
43 /// @result - True on success.
44 bool EvaluateAsAbsolute(MCContext &Ctx, int64_t &Res) const;
46 static bool classof(const AsmExpr *) { return true; }
49 class AsmConstantExpr : public AsmExpr {
53 AsmConstantExpr(int64_t _Value)
54 : AsmExpr(AsmExpr::Constant), Value(_Value) {}
56 int64_t getValue() const { return Value; }
58 static bool classof(const AsmExpr *E) {
59 return E->getKind() == AsmExpr::Constant;
61 static bool classof(const AsmConstantExpr *) { return true; }
64 class AsmSymbolRefExpr : public AsmExpr {
68 AsmSymbolRefExpr(MCSymbol *_Symbol)
69 : AsmExpr(AsmExpr::SymbolRef), Symbol(_Symbol) {}
71 MCSymbol *getSymbol() const { return Symbol; }
73 static bool classof(const AsmExpr *E) {
74 return E->getKind() == AsmExpr::SymbolRef;
76 static bool classof(const AsmSymbolRefExpr *) { return true; }
79 class AsmUnaryExpr : public AsmExpr {
82 LNot, /// Logical negation.
83 Minus, /// Unary minus.
84 Not, /// Bit-wise negation.
93 AsmUnaryExpr(Opcode _Op, AsmExpr *_Expr)
94 : AsmExpr(AsmExpr::Unary), Op(_Op), Expr(_Expr) {}
99 Opcode getOpcode() const { return Op; }
101 AsmExpr *getSubExpr() const { return Expr; }
103 static bool classof(const AsmExpr *E) {
104 return E->getKind() == AsmExpr::Unary;
106 static bool classof(const AsmUnaryExpr *) { return true; }
109 class AsmBinaryExpr : public AsmExpr {
113 And, /// Bitwise and.
115 EQ, /// Equality comparison.
116 GT, /// Greater than comparison.
117 GTE, /// Greater than or equal comparison.
118 LAnd, /// Logical and.
120 LT, /// Less than comparison.
121 LTE, /// Less than or equal comparison.
123 Mul, /// Multiplication.
124 NE, /// Inequality comparison.
126 Shl, /// Bitwise shift left.
127 Shr, /// Bitwise shift right.
128 Sub, /// Subtraction.
129 Xor /// Bitwise exclusive or.
137 AsmBinaryExpr(Opcode _Op, AsmExpr *_LHS, AsmExpr *_RHS)
138 : AsmExpr(AsmExpr::Binary), Op(_Op), LHS(_LHS), RHS(_RHS) {}
144 Opcode getOpcode() const { return Op; }
146 AsmExpr *getLHS() const { return LHS; }
147 AsmExpr *getRHS() const { return RHS; }
149 static bool classof(const AsmExpr *E) {
150 return E->getKind() == AsmExpr::Binary;
152 static bool classof(const AsmBinaryExpr *) { return true; }
155 } // end namespace llvm