[lld] [LLD] Improve linker script handing in LLD (PR #106334)
Hongyu Chen via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 29 23:01:33 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 {
----------------
yugier wrote:
I agree that the name `DynamicExpr` is confusing since dynamic has a special meaning in the linker while what we have here has nothing to do with dynamic. I changed the name to `FallbackExpr` since we are temporarily using `FallbackExpr` to carry the lambdas that we cannot represent as `BinaryExpr`, `UnaryExpr`, and `ConstantExpr`. Yes potentially we can add more sub-classes to completely replace all lambda functions but we are still trying to figure out how to separate information and function calls in the lambda functions; `FallbackExpr` is more like a transition state for eventually removing all lambdas functions we have.
Hopefully I describe the motivation for `DynamicExpr` or `FallbackExpr` clearly here and please let me know if anything I can elaborate here. Any feedback or suggestions on extracting information we need in lambda functions out so we can remove them would be appreciated!
https://github.com/llvm/llvm-project/pull/106334
More information about the llvm-commits
mailing list