calculating binary layout of c++ classes for various compilers and operating systems

Hey All,

I need to take some sort of compiler-independent description of a c++
object and be able to interpret that object in memory or in a file,
including endian conversions and details around packing and such.

I don't need to reconstitute the vtable pointers myself, the compiler
can do that. I would like to be able to do something like this:

save out an object compiled with MS VC++ using fwrite( &object,
sizeof(object)) on Windows.

In a third-party program read the object in and write out an object.

On a PS3 (some odd version of gcc), fread the object into memory, then
apply a trivial constructor to build up correct vtable ptrs and go
merrily on my way.

This will mean swizzling member variables (endian conversion) and
could perhaps mean a lot more complex translation than that depending
on the differences among the compilers.

Does anyone have specific experience with the actual object binary
layouts of the different compilers? Where is the code that builds the
actual binary layouts in clang? I was told it was later, in the code
gen phase. I will probable want to use it as a template or reference.

Chris

The layout code is in AST, probably in ASTContext, because it's needed to determine the size of an object.

Sebastian