Hey,
>> I started playing with the Clang compiler. It has a nice library that can be called from C (libclang).
This is excellent! Though I am curious if the C interface is rich
enough for our needs. Another possibility would be binding clang's C++
API with cxxi using the old generator. It would be more work, but it
would help dogfood cxxi. Having rich managed bindings to clang's
parser could also help other projects-- like MonoDevelop's C/C++
support for example.
>>Another nice thing that Clang provides is name mangling, so we could just embed both the Itanium and Microsoft mangled name as metadata and there would be no need for all the complexity of mangling the names at runtime.
Most of the complexity is not actually in the name mangling
implementations. Yes, we need a lot of metadata to enable the name
mangling, but that metadata is also needed to inform the class
layouts, vtable layouts, calling conventions and a myriad of other
things that can differ between C++ ABIs.
> I'm talking about emitting the DLL. I know me and corrado talked about
> that and there was some work done, but I have no idea if it ever got
> in. That's the most important optimization, since once you have that,
> you're pretty much set.
I called this "static mode," and did devise a plan for it awhile back.
Here is my proposal:
In static mode, you would run the generator and create your bindings
like before. When you compiled it, you would get your bindings DLL
that would be linked with Mono.Cxxi.dll and use Reflection.Emit at
runtime. This is no different than before. However, we would add an
additional tool that would load the assembly and inspect the IL for
interfaces that extend ICppClass. You would also pass to this tool a
specific ABI implementation, and for each ICppClass interface that we
find, we would generate the implementation class for that interface
using the given ABI. A registrar would then keep track of the
implementations, either added statically by this tool, or at runtime
by the old Ref.Emit codepath. If, at runtime, the registrar didn't
find an impl for a call to CppLibrary.GetClass, we could either
generate it like we currently do, or throw an exception (for platforms
that don't allow JITing). This last part has already been started on
the "static-mode" branch
(
https://github.com/mono/cxxi/tree/static-mode).
-Alex