Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How symbol table handling is done in LLVM based compiler?

Tags:

llvm

I went through the tutorial to write a toy compiler using LLVM http://llvm.org/releases/3.1/docs/tutorial/ But there is not much about the symbol table handling. There is a command, llvm-nm to show the symbol table which takes the bitcode file as input. It returns only the function names. How the LLVM compiler handles the local variables and loop variables without a symbol table? If it is not so, how the symbol table is handled in

like image 730
ViG Avatar asked Oct 26 '12 14:10

ViG


1 Answers

The LLVM in-memory representation of its IR does not use a symbol table. Instructions contain direct memory links to their operands (and their users), so if you have an instruction and wants to access its operand, just follow the link, you do not have to perform a lookup in any symbol table.

There are some lists associated with LLVM contexts, modules, functions and basic blocks, which allow you to access the contained elements, but they are mostly just lists, not tables associating a name with anything.

Of course, if you want to parse a textual IR file (ll), you would probably need to a symbol table (or something similar) to do so and create the above-mentioned links; but there's little reason to do that seeing that LLVM already contains such a parser (and that parser indeed uses some way to associate a "name" with a value - see the implementation of BitcodeReader).

As for LLVM front-ends for generating IR - that is up to you. I'd say that if you want to parse a C-like language, using a symbol table would be really useful.

like image 162
Oak Avatar answered Oct 16 '22 17:10

Oak