This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Implemented basic set of arithmetic operations on location counter.
AbandonedPublic

Authored by grimar on Apr 18 2016, 6:23 AM.

Details

Reviewers
ruiu
rafael
Summary

Patch implements set of basic arithmetic operations
that are commonly used in linkerscripts, they
are: +,-,*,/,&,().

At first for expression Reverse Polish Notation (RPN) is built
using shunting-yard algorithm by Edsger Dijkstra.
Then RPN is used to calculate the expression.

Approach and algorithm should be extremely fast.
To analyze the running time complexity of this algorithm, one
has only to note that each token will be read once, each function,
operator, or parenthesis will be pushed onto the stack and popped
off the stack once – therefore, there are at most a constant number
of operations executed per token, and the running time is
thus O(n) – linear in the size of the input.

Also this approach is easy to extend to support functions,
ternary operator and other operators which we might want to add
in future.

Diff Detail

Event Timeline

grimar updated this revision to Diff 54052.Apr 18 2016, 6:23 AM
grimar retitled this revision from to [ELF] - Implemented basic set of arithmetic operations on location counter..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
grimar updated this revision to Diff 54055.Apr 18 2016, 6:26 AM
  • Removed redundant forward declaration.
emaste added a subscriber: emaste.Apr 18 2016, 6:39 AM

How feasible is it to connect errors from here to the line/column error reporting?

How feasible is it to connect errors from here to the line/column error reporting?

I`ll look what can I do for it.

grimar updated this revision to Diff 54057.Apr 18 2016, 6:58 AM
  • Added few testcases
  • Minor changes.
ruiu edited edge metadata.Apr 18 2016, 2:04 PM

In this patch, an intermediate parse tree is constructed and then evaluated,
but you don't actually need to do that. You can just evaluate the expression
as you parse the token strings. Please take a look at
http://reviews.llvm.org/D19237.

grimar abandoned this revision.Apr 20 2016, 4:51 AM

D19237 was landed instead.