[lld] [LLD] Improve linker script handing in LLD (PR #106334)

Hongyu Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 14:52:08 PDT 2024


================
@@ -131,6 +131,156 @@ uint64_t ExprValue::getSectionOffset() const {
   return getValue() - getSecAddr();
 }
 
+std::function<ExprValue()> ScriptExpr::getExpr() const {
+  switch (kind_) {
+  case ExprKind::Constant:
+    return static_cast<const ConstantExpr *>(this)->getConstantExpr();
+  case ExprKind::Dynamic: {
+    auto expr = static_cast<const DynamicExpr *>(this);
+    return expr->getImpl();
+  }
+  case ExprKind::Binary: {
+    auto expr = static_cast<const BinaryExpr *>(this);
+    return [=] { return expr->evaluateBinaryOperands(); };
+  }
+  default:
+    return [] { return ExprValue(0); };
+  };
+}
+
+ExprValue ScriptExpr::getExprValue() const {
+  switch (kind_) {
+  case ExprKind::Constant:
+    return static_cast<const ConstantExpr *>(this)->getConstantExprValue();
+  case ExprKind::Dynamic:
+    return static_cast<const DynamicExpr *>(this)->getImpl()();
+  case ExprKind::Binary:
+    return static_cast<const BinaryExpr *>(this)->evaluateBinaryOperands();
+  default:
+    return ExprValue(0);
+  }
+}
+
+BinaryExpr::Op BinaryExpr::stringToOp(const StringRef op) {
+  static const std::unordered_map<llvm::StringRef, Op> opMap = {
----------------
yugier wrote:

Fixed!

https://github.com/llvm/llvm-project/pull/106334


More information about the llvm-commits mailing list