What is the correct abstraction for a compilation unit in LLVM?

in LLVM, we have LLVMContext , which is the storage unit, and we have llvm::Module , in which new characters (functions and types) are built.

my question; what is the correct llvm abstraction for compilation? is Module ? or is it really intended for a larger volume, that is: the goal of a shared library

It seems to me that the compilation unit should satisfy the result "all or nothing"; either it compiles all its content without errors, or there are errors, and it needs to be fixed and created again before any characters in CU can be used. In my head, this is a definition of what a compilation unit should represent

if a module is the right abstraction for CU, how do you represent the characters in other (correctly compiled) Module objects for a new module that needs to be built so that it can find them? Do I need to add ads or is there any other way to do this?

a dot in the corresponding line in clang could be of great help

+3
c ++ compilation llvm llvm-clang incremental-compiler
Mar 23 2018-12-23T00:
source share
2 answers

A module is a proper abstraction for a compilation unit. You can link the modules together to do all the analysis of the programs from there.

+4
Mar 24 '12 at 19:24
source share

This is an attempt to progress in order to answer my own question:

The llvm::Linker has the ability to accept multiple modules and return one compound module back containing all the characters in the existing modules. After completing the layout and creating the composite module, I still do not understand what the rules for owning input modules are.

In any case, the class should allow you to use the incremental path to extend the module. Suppose you are trying to implement REPL, which means that you are adding new characters to the global namespace:

The REPL structure will work as follows:

  • write some function to REPL
  • compile the function as one module, name it "base"
  • write some more functions in REPL
  • compile new features in a new module
  • if the new function module compiles successfully, add the "base" link and the new module to the new module, name it "base.2"
  • rinse and repeat

    If you replace a character or function by name, you want older characters to display an overridden version of your character. Therefore, when you define a new function, you need to make sure that your getOrInsertFunction is called in the existing "base" module, as well as in the new one.

+2
Apr 01 '12 at 15:08
source share



All Articles