Changeset e6512c8


Ignore:
Timestamp:
Feb 15, 2017, 8:42:12 AM (8 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
32b8144
Parents:
97f65d5
Message:

generate tuples by arity to reduce the number of generated structs

Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/Generate.cc

    r97f65d5 re6512c8  
    2222#include "SynTree/Declaration.h"
    2323#include "CodeGenerator.h"
     24#include "Tuples/Tuples.h"
    2425
    2526using namespace std;
     
    2829        void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty ) {
    2930                CodeGen::CodeGenerator cgv( os, pretty );
    30 
    31                 for ( std::list<Declaration *>::iterator i = translationUnit.begin(); i != translationUnit.end();  i++ ) {
    32                         if ( LinkageSpec::isGeneratable( (*i)->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( (*i)->get_linkage() ) ) ) {
    33                                 (*i)->accept(cgv);
    34                                 if ( doSemicolon( *i ) ) {
     31                for ( auto & dcl : translationUnit ) {
     32                        if ( LinkageSpec::isGeneratable( dcl->get_linkage() ) && (doIntrinsics || ! LinkageSpec::isBuiltin( dcl->get_linkage() ) ) ) {
     33                                dcl->accept(cgv);
     34                                if ( doSemicolon( dcl ) ) {
    3535                                        os << ";";
    3636                                } // if
  • src/Tuples/TupleExpansion.cc

    r97f65d5 re6512c8  
    7979                        }
    8080                  private:
    81                         ScopedMap< std::string, StructDecl * > typeMap;
     81                        ScopedMap< int, StructDecl * > typeMap;
    8282                };
    8383
     
    214214
    215215        Type * TupleTypeReplacer::mutate( TupleType * tupleType ) {
    216                 std::string mangleName = SymTab::Mangler::mangleType( tupleType );
    217216                tupleType = safe_dynamic_cast< TupleType * > ( Parent::mutate( tupleType ) );
    218                 if ( ! typeMap.count( mangleName ) ) {
    219                         // generate struct type to replace tuple type
    220                         // xxx - should fix this to only generate one tuple struct for each number of type parameters
    221                         StructDecl * decl = new StructDecl( "_tuple_type_" + mangleName );
     217                unsigned tupleSize = tupleType->size();
     218                if ( ! typeMap.count( tupleSize ) ) {
     219                        // generate struct type to replace tuple type based on the number of components in the tuple
     220                        StructDecl * decl = new StructDecl( toString( "_tuple_type_", tupleSize  ) );
    222221                        decl->set_body( true );
    223                         for ( size_t i = 0; i < tupleType->size(); ++i ) {
     222                        for ( size_t i = 0; i < tupleSize; ++i ) {
    224223                                TypeDecl * tyParam = new TypeDecl( toString("tuple_param_", i), DeclarationNode::NoStorageClass, nullptr, TypeDecl::Any );
    225224                                decl->get_members().push_back( new ObjectDecl( toString("field_", i), DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new TypeInstType( Type::Qualifiers(), tyParam->get_name(), tyParam ), nullptr ) );
    226225                                decl->get_parameters().push_back( tyParam );
    227226                        }
    228                         if ( tupleType->size() == 0 ) {
     227                        if ( tupleSize == 0 ) {
    229228                                // empty structs are not standard C. Add a dummy field to empty tuples to silence warnings when a compound literal Tuple0 is created.
    230229                                decl->get_members().push_back( new ObjectDecl( "dummy", DeclarationNode::NoStorageClass, LinkageSpec::C, nullptr, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), nullptr ) );
    231230                        }
    232                         typeMap[mangleName] = decl;
     231                        typeMap[tupleSize] = decl;
    233232                        addDeclaration( decl );
    234233                }
    235234                Type::Qualifiers qualifiers = tupleType->get_qualifiers();
    236235
    237                 StructDecl * decl = typeMap[mangleName];
     236                StructDecl * decl = typeMap[tupleSize];
    238237                StructInstType * newType = new StructInstType( qualifiers, decl );
    239238                for ( Type * t : *tupleType ) {
Note: See TracChangeset for help on using the changeset viewer.