summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
authorGeorge Rimar <grimar@accesssoftek.com>2016-04-22 10:35:34 +0000
committerGeorge Rimar <grimar@accesssoftek.com>2016-04-22 10:35:34 +0000
commit8c4acddebc47b2d6dbd8d05fc39bf2e007046e16 (patch)
treef041bf0668f201bbd4d638cfd3b118aa320fd86b /lld/ELF/LinkerScript.cpp
parentb530a2591b3d3f2d4c6f380468d710c677fe37be (diff)
downloadbcm5719-llvm-8c4acddebc47b2d6dbd8d05fc39bf2e007046e16.tar.gz
bcm5719-llvm-8c4acddebc47b2d6dbd8d05fc39bf2e007046e16.zip
[ELF] - implemented ternary operator for linkerscript expressions
Patch implements ternary operator for linkerscript expressions. Like: SECTIONS { . = 0x1 ? 0x2 : 0x3; ... } Differential revision: http://reviews.llvm.org/D19332 llvm-svn: 267132
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 9fcb2f61188..87743c60a46 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -97,6 +97,17 @@ uint64_t LinkerScript<ELFT>::parsePrimary(ArrayRef<StringRef> &Tokens) {
return getInteger(Tok);
}
+template <class ELFT>
+uint64_t LinkerScript<ELFT>::parseTernary(ArrayRef<StringRef> &Tokens,
+ uint64_t Cond) {
+ next(Tokens);
+ uint64_t V = parseExpr(Tokens, Dot);
+ if (!expect(Tokens, ":"))
+ return 0;
+ uint64_t W = parseExpr(Tokens, Dot);
+ return Cond ? V : W;
+}
+
static uint64_t apply(StringRef Op, uint64_t L, uint64_t R) {
if (Op == "+")
return L + R;
@@ -126,6 +137,9 @@ uint64_t LinkerScript<ELFT>::parseExpr1(ArrayRef<StringRef> &Tokens,
while (!Tokens.empty()) {
// Read an operator and an expression.
StringRef Op1 = Tokens.front();
+ if (Op1 == "?")
+ return parseTernary(Tokens, Lhs, Dot);
+
if (precedence(Op1) < MinPrec)
return Lhs;
next(Tokens);
OpenPOWER on IntegriCloud