[PATCH] D22728: Make readExpr return an Expr object instead of a vector of tokens.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 23 06:02:05 PDT 2016


ruiu created this revision.
ruiu added reviewers: grimar, evgeny777.
ruiu added a subscriber: llvm-commits.

Previously, we handled an expression as a vector of tokens. In other
words, an expression was a vector of uncooked raw StringRefs.
When we need a value of an expression, we used ExprParser to run
the expression.

The separation was needed essentially because parse time is too
early to evaluate an expression. In order to evaluate an expression,
we need to finalize section sizes. Because linker script parsing
is done at very early stage of the linking process, we can't
evaluate expressions while parsing.

The above mechanism worked fairly well, but there were a few
drawbacks.

One thing is that we sometimes have to parse the same expression
more than once in order to find the end of the expression.
In some contexts, linker script expressions have no clear end marker.
So, we needed to recognize balanced expressions and ternary operators.

The other is poor error reporting. Since expressions are parsed
basically twice, and some information that is available at the first
stage is lost in the second stage, it was hard to print out
apprpriate error messages.

This patch fixes the issues with a new approach.

Now the expression parsing is integrated into ScriptParser.
ExprParser class is removed. Expressions are represented as lambdas
instead of vectors of tokens. Lambdas captures information they
need to run themselves when they are created.

In this way, ends of expressions are naturally detected, and
errors are handled in the usual way. This patch also reduces
the amount of code.

https://reviews.llvm.org/D22728

Files:
  ELF/LinkerScript.cpp
  ELF/LinkerScript.h
  test/ELF/linkerscript-locationcounter.s

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22728.65226.patch
Type: text/x-patch
Size: 15073 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160723/a817b386/attachment.bin>


More information about the llvm-commits mailing list