[lld] [LLD] Improve linker script handing in LLD (PR #106334)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 15:01:02 PDT 2024
================
@@ -74,6 +75,106 @@ struct ExprValue {
// Later, we evaluate the expression by calling the function.
using Expr = std::function<ExprValue()>;
+class ScriptExpr {
+public:
+ enum class ExprKind : uint8_t { Constant, Dynamic, Unary, Binary };
+
+private:
+ ExprKind kind_;
+
+protected:
+ explicit ScriptExpr(ExprKind kind) : kind_(kind) {}
+
+public:
+ ExprKind getKind() const { return kind_; }
+ std::function<ExprValue()> getExpr() const;
+ ExprValue getExprValue() const;
+};
+
+class ConstantExpr : public ScriptExpr {
+public:
+ ConstantExpr(uint64_t val) : ScriptExpr(ExprKind::Constant), val_(val) {}
+ ExprValue getExprValue() const { return ExprValue(val_); }
+
+private:
+ uint64_t val_;
+};
+
+class DynamicExpr : public ScriptExpr {
+public:
+ DynamicExpr(std::function<ExprValue()> impl)
+ : ScriptExpr(ExprKind::Dynamic), impl_(impl) {}
+ ExprValue getExprValue() const { return impl_(); }
+
+private:
+ std::function<ExprValue()> impl_;
+};
+
+class UnaryExpr : public ScriptExpr {
+public:
+ static const UnaryExpr *create();
+
+private:
+ UnaryExpr(StringRef op, ScriptExpr *operand)
+ : ScriptExpr(ExprKind::Unary), op_(op), operand_(operand) {}
+ StringRef op_;
+ const ScriptExpr *operand_;
+};
+
+class BinaryExpr : public ScriptExpr {
+public:
+ enum class Op {
+ Add,
+ Sub,
+ Mul,
+ Div,
+ Mod,
+ Shl,
+ Shr,
+ And,
+ Or,
+ Xor,
+ LAnd,
+ LOr,
+ Eq,
+ Neq,
+ Lt,
+ Gt,
+ Leq,
+ Geq,
+ AddAssign,
+ SubAssign,
+ MulAssign,
+ DivAssign,
+ ShlAssign,
+ ShrAssign,
+ AndAssign,
+ OrAssign,
+ XorAssign,
+ Invalid
+ };
+ BinaryExpr(StringRef op, ScriptExpr *LHS, ScriptExpr *RHS,
+ const std::string loc)
+ : ScriptExpr(ExprKind::Binary), LHS(LHS), RHS(RHS), loc_(loc) {
+ opcode = stringToOp(op);
----------------
PiJoules wrote:
nit:
```
ScriptExpr(ExprKind::Binary), opcode(stringToOp(op)), LHS(LHS), RHS(RHS), loc_(loc) {}
```
https://github.com/llvm/llvm-project/pull/106334
More information about the llvm-commits
mailing list