How is character table processing done in LLVM compiler?

I read a tutorial to write a toy compiler using LLVM http://llvm.org/releases/3.1/docs/tutorial/ But there is not much about processing symbol tables. There is an llvm-nm command to display a character table that accepts a bitcode file as input. It returns only function names. How does the LLVM compiler handle local and loop variables without a character table? If not, how the character table is processed in

+4
source share
1 answer

The LLVM view in its IR memory does not use a character table. Instructions contain direct memory links to their operands (and their users), therefore, if you have an instruction and want to access its operand, just follow the link, you do not need to search in any character table.

There are several lists related to LLVM contexts, modules, functions, and basic blocks that allow you to access the contained elements, but basically they are just lists, not tables that associate a name with something.

Of course, if you want to parse a text IR file (ll), you probably need a character table (or something similar) to do this and create the above links; but there is no reason for this, since LLVM already contains such a parser (and this parser really uses some way to associate a "name" with a value - see the BitcodeReader implementation).

As for LLVM interfaces for generating IR, it is up to you. I would say that if you want to parse a C-like language, using a character table would be really useful.

+4
source

Source: https://habr.com/ru/post/1442328/


All Articles