ICG exclude of class member variables now defines incorrect memory offsets in io_src #311

Added back the code that set the offset of variables with the offsetof function. This
code is running by default.  Any code that includes #ifndef TRICK_ICG in
classes/structures will want this on.

Added a flag to ICG that allows us to turn off writing of these lines.  If the flag
is present, ICG may write out io_src code for private/protected variables that it could
not reach if an offsetof function was required.  Code cannot have any #ifndef TRICK_ICG
present in classes/structures for this to work.
This commit is contained in:
Alex Lin
2016-09-16 08:39:37 -05:00
parent c4a32600cc
commit ae07b26243
8 changed files with 116 additions and 15 deletions

View File

@ -9,6 +9,8 @@
#include "EnumValues.hh"
#include "Utilities.hh"
extern llvm::cl::opt< bool > no_offset_of ;
PrintFileContents10::PrintFileContents10() {}
/** Prints the io_src header information */
@ -157,14 +159,63 @@ void PrintFileContents10::print_field_init_attr_stmts( std::ofstream & outfile ,
ClassValues * cv , unsigned int index ) {
// For static variables replace the offset field with the address of the static variable
if ( fdes->isStatic() ) {
outfile << " attr" ;
printNamespaces( outfile, cv , "__" ) ;
printContainerClasses( outfile, cv , "__" ) ;
outfile << cv->getMangledTypeName() << "[" << index << "].offset = (long)(void *)&" ;
printNamespaces( outfile, cv , "::" ) ;
printContainerClasses( outfile, cv , "::" ) ;
outfile << cv->getName() << "::" << fdes->getName() << " ;\n" ;
if ( no_offset_of ) {
if ( fdes->isStatic() ) {
outfile << " attr" ;
printNamespaces( outfile, cv , "__" ) ;
printContainerClasses( outfile, cv , "__" ) ;
outfile << cv->getMangledTypeName() << "[" << index << "].offset = (long)(void *)&" ;
printNamespaces( outfile, cv , "::" ) ;
printContainerClasses( outfile, cv , "::" ) ;
outfile << cv->getName() << "::" << fdes->getName() << " ;\n" ;
}
} else {
if ( fdes->isStatic() ) {
// print a special offsetof statement if this is a static
outfile << " attr" ;
printNamespaces( outfile, cv , "__" ) ;
printContainerClasses( outfile, cv , "__" ) ;
outfile << cv->getMangledTypeName() << "[" << index << "].offset = (long)(void *)&" ;
printNamespaces( outfile, cv , "::" ) ;
printContainerClasses( outfile, cv , "::" ) ;
outfile << cv->getName() << "::" << fdes->getName() << " ;\n" ;
} else if ( fdes->isBitField() ) {
// else if this is a bitfield
outfile << " attr" ;
printNamespaces( outfile, cv , "__" ) ;
printContainerClasses( outfile, cv , "__" ) ;
outfile << cv->getMangledTypeName() << "[" << index << "].offset = " ;
outfile << fdes->getBitFieldByteOffset() << " ;\n" ;
// All bitfield offsets are in terms of unsigned ints.
outfile << " attr" ;
printNamespaces( outfile, cv , "__" ) ;
printContainerClasses( outfile, cv , "__" ) ;
outfile << cv->getMangledTypeName() << "[" << index << "].size = sizeof(unsigned int) ;\n" ;
} else if ( fdes->isVirtualInherited() ) {
// else if we have a virtually inherited class.
outfile << " attr" ;
printNamespaces( outfile, cv , "__" ) ;
printContainerClasses( outfile, cv , "__" ) ;
outfile << cv->getMangledTypeName() << "[" << index << "].offset = " << fdes->getBaseClassOffset() ;
outfile << " + offsetof(" ;
outfile << fdes->getContainerClass() << "," << fdes->getName() << ") ;\n" ;
} else if ( cv->getMangledTypeName() != cv->getName() ) {
// else if we have a template type where mangled_type_name is different then name.
outfile << " attr" ;
printNamespaces( outfile, cv , "__" ) ;
printContainerClasses( outfile, cv , "__" ) ;
outfile << cv->getMangledTypeName() << "[" << index << "].offset = offsetof(" ;
outfile << cv->getMangledTypeName() << "," << fdes->getName() << ") ;\n" ;
} else {
// else print an offsetof statement if this is not a special case
outfile << " attr" ;
printNamespaces( outfile, cv , "__" ) ;
printContainerClasses( outfile, cv , "__" ) ;
outfile << cv->getMangledTypeName() << "[" << index << "].offset = offsetof(" ;
printNamespaces( outfile, cv , "::" ) ;
printContainerClasses( outfile, cv , "::" ) ;
outfile << cv->getMangledTypeName() << "," << fdes->getName() << ") ;\n" ;
}
}
if ( fdes->isSTL()) {