Changeset 56fcd77


Ignore:
Timestamp:
Dec 14, 2015, 4:06:26 PM (8 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
db0b3ce
Parents:
cdec5af
Message:

Roll back addition of layout struct because anonymous initializer can't be codegen'd now

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    rcdec5af r56fcd77  
    1414//
    1515
    16 #include <map>
    1716#include <set>
    18 #include <sstream>
    1917#include <stack>
    2018#include <string>
     
    2220#include <algorithm>
    2321#include <cassert>
    24 #include <utility>
    2522
    2623#include "Box.h"
     
    5451                FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
    5552
    56                 /// Cache for layout struct decls
    57                 class LayoutStructDecls {
    58                 public:
    59                         /// Gets the layout struct declaration for a given number of members (0 for non-generic); creates declarations as needed.
    60                         /// Declarations are allocated with "new", not freed on LayoutStructDecls destruction
    61                         StructDecl* get( int members );
    62                         /// adds all struct declarations to the translation unit
    63                         void addToTranslationUnit( std::list< Declaration* >& translationUnit );
    64                 private:
    65                         /// Layout struct declarations, indexed by number of members in the generic struct (0 for non-generic)
    66                         std::map< int, StructDecl* > decls;
    67                 };
    68 
    6953                /// Replaces polymorphic return types with out-parameters, replaces calls to polymorphic functions with adapter calls as needed, and adds appropriate type variables to the function call
    7054                class Pass1 : public PolyMutator {
    7155                  public:
    72                         Pass1( LayoutStructDecls &layoutDecls );
     56                        Pass1();
    7357                        virtual Expression *mutate( ApplicationExpr *appExpr );
    7458                        virtual Expression *mutate( AddressExpr *addrExpr );
     
    10488                        bool useRetval;
    10589                        UniqueName tempNamer;
    106                         LayoutStructDecls &layoutDecls;
    10790                };
    10891
     
    11093                class Pass2 : public PolyMutator {
    11194                  public:
    112                         Pass2( LayoutStructDecls &layoutDecls );
    11395                        template< typename DeclClass >
    11496                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    123105 
    124106                        std::map< UniqueId, std::string > adapterName;
    125                         LayoutStructDecls &layoutDecls;
    126107                };
    127108
     
    129110                class Pass3 : public PolyMutator {
    130111                  public:
    131                         Pass3( LayoutStructDecls &layoutDecls );
    132112                        template< typename DeclClass >
    133113                        DeclClass *handleDecl( DeclClass *decl, Type *type );
     
    140120                        virtual Type *mutate( FunctionType *funcType );
    141121                  private:
    142                         LayoutStructDecls &layoutDecls;
    143122                };
    144123
     
    155134
    156135        void box( std::list< Declaration *>& translationUnit ) {
    157                 LayoutStructDecls layoutStructs;
    158                 Pass1 pass1( layoutStructs );
    159                 Pass2 pass2( layoutStructs );
    160                 Pass3 pass3( layoutStructs );
     136                Pass1 pass1;
     137                Pass2 pass2;
     138                Pass3 pass3;
    161139                mutateAll( translationUnit, pass1 );
    162140                mutateAll( translationUnit, pass2 );
    163141                mutateAll( translationUnit, pass3 );
    164                 layoutStructs.addToTranslationUnit( translationUnit );
    165         }
    166 
    167         //////////////////////////////////// LayoutStructDecls //////////////////////////////////////////////
    168 
    169         namespace {
    170                 StructDecl* LayoutStructDecls::get( int members ) {
    171                         // Attempt to read declaration already in map
    172                         std::map< int, StructDecl* >::iterator decl = decls.find( members );
    173                         if ( decl != decls.end() ) return decl->second;
    174 
    175                         // Insert if not found
    176                         std::string member_str;
    177                         if ( members > 0 ) {
    178                                 std::stringstream ss;
    179                                 ss << members;
    180                                 member_str = ss.str();
    181                         }
    182                         StructDecl *newDecl = new StructDecl( std::string("_layout") + member_str );
    183 
    184                         newDecl->get_members().push_back(
    185                                         new ObjectDecl( "size", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 ) );
    186                         newDecl->get_members().push_back(
    187                                         new ObjectDecl( "align", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 ) );
    188                         if ( members > 0 ) {
    189                                 ArrayType *aType =
    190                                                 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ),
    191                                                                            new ConstantExpr( Constant( new BasicType( Type::Qualifiers(), BasicType::SignedInt ), member_str ) ), false, false );
    192                                 newDecl->get_members().push_back(
    193                                         new ObjectDecl( "offsets", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, aType, 0 ) );
    194                         }
    195 
    196                         decls.insert( std::make_pair( members, newDecl ) );
    197 
    198                         return newDecl;
    199                 }
    200 
    201                 void LayoutStructDecls::addToTranslationUnit( std::list< Declaration* >& translationUnit ) {
    202                         for ( std::map< int, StructDecl* >::reverse_iterator decl = decls.rbegin(); decl != decls.rend(); ++decl ) {
    203                                 translationUnit.push_front( decl->second );
    204                         }
    205                 }
    206142        }
    207143
     
    245181                }
    246182
    247                 Pass1::Pass1( LayoutStructDecls &layoutDecls )
    248                         : useRetval( false ), tempNamer( "_temp" ), layoutDecls( layoutDecls ) {
     183                Pass1::Pass1() : useRetval( false ), tempNamer( "_temp" ) {
    249184                        adapters.push(AdapterMap());
    250185                }
     
    374309                                        Type *concrete = env->lookup( tyParm->first );
    375310                                        if ( concrete ) {
     311                                                // TODO add alignment
    376312                                                arg = appExpr->get_args().insert( arg, new SizeofExpr( concrete->clone() ) );
    377313                                                arg++;
     
    1000936////////////////////////////////////////// Pass2 ////////////////////////////////////////////////////
    1001937
    1002                 Pass2::Pass2( LayoutStructDecls &layoutDecls ) : layoutDecls(layoutDecls) {}
    1003 
    1004938                void Pass2::addAdapters( FunctionType *functionType ) {
    1005939                        std::list< DeclarationWithType *> &paramList = functionType->get_parameters();
     
    10741008                        std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin();
    10751009                        std::list< DeclarationWithType *> inferredParams;
     1010                        // TODO add alignment
    10761011                        ObjectDecl *newObj = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );
    10771012//   ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 );
     
    11041039////////////////////////////////////////// Pass3 ////////////////////////////////////////////////////
    11051040
    1106                 Pass3::Pass3( LayoutStructDecls &layoutDecls ) : layoutDecls(layoutDecls) {}
    1107 
    11081041                template< typename DeclClass >
    11091042                DeclClass * Pass3::handleDecl( DeclClass *decl, Type *type ) {
Note: See TracChangeset for help on using the changeset viewer.