This is an archive of the discontinued LLVM Phabricator instance.

Make readExpr return an Expr object instead of a vector of tokens.
ClosedPublic

Authored by ruiu on Jul 23 2016, 6:02 AM.

Details

Summary

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.

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu updated this revision to Diff 65226.Jul 23 2016, 6:02 AM
ruiu retitled this revision from to Make readExpr return an Expr object instead of a vector of tokens..
ruiu updated this object.
ruiu added reviewers: grimar, evgeny777.
ruiu added a subscriber: llvm-commits.
grimar edited edge metadata.Jul 24 2016, 12:58 AM

I debugged it a little and I think that it is really helpfull change.

I expect this should help to reduce the amount of changes in testcases of
patches like D22689, so I would probably land this first.

grimar accepted this revision.Jul 24 2016, 12:58 AM
grimar edited edge metadata.

LGTM

This revision is now accepted and ready to land.Jul 24 2016, 12:58 AM
This revision was automatically updated to reflect the committed changes.