Changeset 2e9b59b for src/CodeGen


Ignore:
Timestamp:
Apr 19, 2022, 3:00:04 PM (4 years ago)
Author:
m3zulfiq <m3zulfiq@…>
Branches:
ADT, ast-experimental, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
5b84a321
Parents:
ba897d21 (diff), bb7c77d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

added benchmark and evaluations chapter to thesis

Location:
src/CodeGen
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cc

    rba897d21 r2e9b59b  
    274274        void CodeGenerator::postvisit( EnumDecl * enumDecl ) {
    275275                extension( enumDecl );
    276                 output << "enum ";
    277                 genAttributes( enumDecl->get_attributes() );
    278 
    279                 output << enumDecl->get_name();
    280 
    281276                std::list< Declaration* > &memb = enumDecl->get_members();
    282 
    283                 if ( ! memb.empty() ) {
    284                         output << " {" << endl;
    285 
    286                         ++indent;
     277                if (enumDecl->base && ! memb.empty()) {
     278                        unsigned long long last_val = -1;
    287279                        for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
    288280                                ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
    289281                                assert( obj );
    290                                 output << indent << mangleName( obj );
    291                                 if ( obj->get_init() ) {
    292                                         output << " = ";
    293                                         obj->get_init()->accept( *visitor );
    294                                 } // if
    295                                 output << "," << endl;
     282                                output << "static const ";
     283                                output << genType(enumDecl->base, "", options) << " ";
     284                                output << mangleName( obj ) << " ";
     285                                output << " = ";
     286                                output << "(" << genType(enumDecl->base, "", options) << ")";
     287                                if ( (BasicType *)(enumDecl->base) && ((BasicType *)(enumDecl->base))->isWholeNumber() ) {
     288                                        if ( obj->get_init() ) {
     289                                                obj->get_init()->accept( *visitor );
     290                                                last_val = ((ConstantExpr *)(((SingleInit *)(obj->init))->value))->constant.get_ival();
     291                                        } else {
     292                                                output << ++last_val;
     293                                        } // if
     294                                } else {
     295                                        if ( obj->get_init() ) {
     296                                                obj->get_init()->accept( *visitor );
     297                                        } else {
     298                                                // Should not reach here!
     299                                        }
     300                                }
     301                                output << ";" << endl;
    296302                        } // for
    297 
     303                } else {
     304                        output << "enum ";
     305                        genAttributes( enumDecl->get_attributes() );
     306
     307                        output << enumDecl->get_name();
     308
     309                        if ( ! memb.empty() ) {
     310                                output << " {" << endl;
     311
     312                                ++indent;
     313                                for ( std::list< Declaration* >::iterator i = memb.begin(); i != memb.end();  i++) {
     314                                        ObjectDecl * obj = dynamic_cast< ObjectDecl* >( *i );
     315                                        assert( obj );
     316                                        output << indent << mangleName( obj );
     317                                        if ( obj->get_init() ) {
     318                                                output << " = ";
     319                                                obj->get_init()->accept( *visitor );
     320                                        } // if
     321                                        output << "," << endl;
     322                                } // for
    298323                        --indent;
    299 
    300324                        output << indent << "}";
     325                        } // if
    301326                } // if
    302327        }
     
    347372                                des->accept( *visitor );
    348373                        } else {
    349                                 // otherwise, it has to be a ConstantExpr or CastExpr, initializing array eleemnt
     374                                // otherwise, it has to be a ConstantExpr or CastExpr, initializing array element
    350375                                output << "[";
    351376                                des->accept( *visitor );
     
    661686                        output << opInfo->symbol;
    662687                } else {
     688                        // if (dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())
     689                        // && dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base) {
     690                        //      output << '(' <<genType(dynamic_cast<EnumInstType *>(variableExpr->get_var()->get_type())->baseEnum->base, "", options) << ')';
     691                        // }
    663692                        output << mangleName( variableExpr->get_var() );
    664693                } // if
  • src/CodeGen/FixMain.cc

    rba897d21 r2e9b59b  
    9191}
    9292
    93 ObjectDecl * charStarObj() {
     93ObjectDecl * makeArgvObj() {
    9494        return new ObjectDecl(
    9595                "", Type::StorageClasses(), LinkageSpec::Cforall, 0,
     
    117117        main_type->get_returnVals().push_back( signedIntObj() );
    118118        main_type->get_parameters().push_back( signedIntObj() );
    119         main_type->get_parameters().push_back( charStarObj() );
     119        main_type->get_parameters().push_back( makeArgvObj() );
    120120        return create_mangled_main_function_name( main_type );
    121121}
  • src/CodeGen/GenType.cc

    rba897d21 r2e9b59b  
    253253
    254254        void GenType::postvisit( EnumInstType * enumInst ) {
    255                 typeString = enumInst->name + " " + typeString;
    256                 if ( options.genC ) typeString = "enum " + typeString;
     255                if ( enumInst->baseEnum->base ) {
     256                        typeString = genType(enumInst->baseEnum->base, "", options) + typeString;
     257                } else {
     258                        typeString = enumInst->name + " " + typeString;
     259                        if ( options.genC ) {
     260                                typeString = "enum " + typeString;
     261                        }
     262                }
    257263                handleQualifiers( enumInst );
    258264        }
Note: See TracChangeset for help on using the changeset viewer.