summaryrefslogtreecommitdiffstats
path: root/lld/ELF/ScriptLexer.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-03-09 19:23:00 +0000
committerRui Ueyama <ruiu@google.com>2017-03-09 19:23:00 +0000
commitf5fce486797d49b82660fef841b57d49c007dab1 (patch)
tree0276436a6638320e31093b02477bee82cedd8368 /lld/ELF/ScriptLexer.cpp
parentfe267a37f49a0614e2710be91468942a75102313 (diff)
downloadbcm5719-llvm-f5fce486797d49b82660fef841b57d49c007dab1.tar.gz
bcm5719-llvm-f5fce486797d49b82660fef841b57d49c007dab1.zip
Handle ":" as a regular token character in linker scripts.
This is an alternative to https://reviews.llvm.org/D30500 to simplify the version definition parser and allow ":" in symbol names. Differential Revision: https://reviews.llvm.org/D30722 llvm-svn: 297402
Diffstat (limited to 'lld/ELF/ScriptLexer.cpp')
-rw-r--r--lld/ELF/ScriptLexer.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/lld/ELF/ScriptLexer.cpp b/lld/ELF/ScriptLexer.cpp
index fa77df59583..86720de3527 100644
--- a/lld/ELF/ScriptLexer.cpp
+++ b/lld/ELF/ScriptLexer.cpp
@@ -124,7 +124,7 @@ void ScriptLexer::tokenize(MemoryBufferRef MB) {
// so that you can write "file-name.cpp" as one bare token, for example.
size_t Pos = S.find_first_not_of(
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
- "0123456789_.$/\\~=+[]*?-!<>^");
+ "0123456789_.$/\\~=+[]*?-!<>^:");
// A character that cannot start a word (which is usually a
// punctuation) forms a single character token.
@@ -169,7 +169,7 @@ bool ScriptLexer::atEOF() { return Error || Tokens.size() == Pos; }
// Split a given string as an expression.
// This function returns "3", "*" and "5" for "3*5" for example.
static std::vector<StringRef> tokenizeExpr(StringRef S) {
- StringRef Ops = "+-*/"; // List of operators
+ StringRef Ops = "+-*/:"; // List of operators
// Quoted strings are literal strings, so we don't want to split it.
if (S.startswith("\""))
@@ -229,14 +229,11 @@ StringRef ScriptLexer::next() {
return Tokens[Pos++];
}
-StringRef ScriptLexer::peek(unsigned N) {
- StringRef Tok;
- for (unsigned I = 0; I <= N; ++I) {
- Tok = next();
- if (Error)
- return "";
- }
- Pos = Pos - N - 1;
+StringRef ScriptLexer::peek() {
+ StringRef Tok = next();
+ if (Error)
+ return "";
+ Pos = Pos - 1;
return Tok;
}
@@ -248,6 +245,18 @@ bool ScriptLexer::consume(StringRef Tok) {
return false;
}
+// Consumes Tok followed by ":". Space is allowed between Tok and ":".
+bool ScriptLexer::consumeLabel(StringRef Tok) {
+ if (consume((Tok + ":").str()))
+ return true;
+ if (Tokens.size() >= Pos + 2 && Tokens[Pos] == Tok &&
+ Tokens[Pos + 1] == ":") {
+ Pos += 2;
+ return true;
+ }
+ return false;
+}
+
void ScriptLexer::skip() { (void)next(); }
void ScriptLexer::expect(StringRef Expect) {
OpenPOWER on IntegriCloud