I am asking this question to see if it is possible or desirable to build a compilation/runtime system for C/C++ that can support the following:
- allow bc to call native (in dynamically loaded *.so)
- allow native to call bc (through JIT or interpreter)
- can compile/interpret C/C++ sources BASED on type info in precompiled bc
The class files produced by the java compiler carries sufficient information that another pass of compilation of java source can be done by including clas/jar files only:
A.java => A.class
B.java => B.class
C.java => C.class
[ABC].class => ABC.jar
Now compilation of any java class (X) that refs A/B/C can be done with:
javac -cp ABC.jar X.java
This makes it easy to build java scripting engines (beanshell, jython, groovy) that need to be able to compile java classes that refs existing compiled classes.
For C/C++ there are 2 tools that are close to fullfilling a similar goal: gcc+gdb and cint.
gdb: If an .so/.exe is compiled with gcc -g there is enough type info in the debugging symbols that gdb can later print fields of structs. Theoretically you can use gdb to ptype all the relevant types and reproduce all the headers for another pass of compilation.
cint: a C/C++ interpreter that interpret the .h.cxx files directly but also able to call funcs in native solibs. HOWEVER, to interpret code that refs funcs in the precompiled solibs, cint has to parse the relevant headers used by the precompiled solibs and cint has many limitations compared to gcc/g++ parser.
Given that llvm bytecode might become a viable distribution format ideally i would like to see a llvm object file format to carry similar kind of info for another pass of gcc/g++:
A.[h, cxx] => A.bc
B.[h, cxx] => B.bc
C.[h, cxx] => C.bc
[ABC].bc => ABC.bc
we can perform:
llvm-g++ X.cxx -I ABC.bc
without having to access the header files [ABC].h.
But since llvm’s type system is meant to be lang indep the best we can do is to make debugging info descriptive enough for future compilations, is this correct?
It would be nice to make bc files optionally carry type info useful for another compile pass (today bc files are only useful for linking).