[lld] [ELF] Added `struct Token` and changed `next()` and `peek()` to return Token (PR #100180)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 24 11:03:53 PDT 2024
================
@@ -1554,61 +1595,66 @@ Expr ScriptParser::readPrimary() {
return llvm::Log2_64_Ceil(std::max(a().getValue(), UINT64_C(1)));
};
}
- if (tok == "MAX" || tok == "MIN") {
+ case Tok::Max:
+ case Tok::Min: {
expect("(");
Expr a = readExpr();
expect(",");
Expr b = readExpr();
expect(")");
- if (tok == "MIN")
+ if (tok.kind == Tok::Min)
return [=] { return std::min(a().getValue(), b().getValue()); };
return [=] { return std::max(a().getValue(), b().getValue()); };
}
- if (tok == "ORIGIN") {
+ case Tok::Origin: {
StringRef name = readParenLiteral();
if (script->memoryRegions.count(name) == 0) {
setError("memory region not defined: " + name);
return [] { return 0; };
}
return script->memoryRegions[name]->origin;
}
- if (tok == "SEGMENT_START") {
+ case Tok::SegmentStart: {
expect("(");
skip();
expect(",");
Expr e = readExpr();
expect(")");
return [=] { return e(); };
}
- if (tok == "SIZEOF") {
+ case Tok::Sizeof: {
StringRef name = unquote(readParenLiteral());
OutputSection *cmd = &script->getOrCreateOutputSection(name)->osec;
// Linker script does not create an output section if its content is empty.
// We want to allow SIZEOF(.foo) where .foo is a section which happened to
// be empty.
return [=] { return cmd->size; };
}
- if (tok == "SIZEOF_HEADERS")
+ case Tok::SizeofHeaders:
return [=] { return elf::getHeaderSize(); };
- // Tok is the dot.
- if (tok == ".")
- return [=] { return script->getSymbolValue(tok, location); };
-
- // Tok is a literal number.
- if (std::optional<uint64_t> val = parseInt(tok))
- return [=] { return *val; };
-
- // Tok is a symbol name.
- if (tok.starts_with("\""))
- tok = unquote(tok);
- else if (!isValidSymbolName(tok))
- setError("malformed number: " + tok);
- if (activeProvideSym)
- script->provideMap[*activeProvideSym].push_back(tok);
- else
- script->referencedSymbols.push_back(tok);
- return [=] { return script->getSymbolValue(tok, location); };
+ default: {
+ // Tok is the dot.
+ if (tok == ".")
+ return [=] { return script->getSymbolValue(tok.val, location); };
+
+ // Tok is a literal number.
+ if (std::optional<uint64_t> val = parseInt(tok.val))
+ return [=] { return *val; };
+
+ // Tok is a symbol name.
+ StringRef tokVal = tok.val;
+ if (tokVal.starts_with("\""))
----------------
PiJoules wrote:
nit: `tokVal.starts_with('"')`
https://github.com/llvm/llvm-project/pull/100180
More information about the llvm-commits
mailing list