Changeset 332e93a for src/CodeGen


Ignore:
Timestamp:
Feb 4, 2025, 9:18:54 PM (11 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
090b076
Parents:
985ff5f (diff), 1ee74df (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:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/CodeGen
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/CodeGenerator.cpp

    r985ff5f r332e93a  
    130130        // TODO: Which means the ast::Pass is just providing a default no visit?
    131131        visit_children = false;
     132        changeState_ArgToIntrinsic(false);
    132133}
    133134
     
    466467                if ( var->var->linkage == ast::Linkage::Intrinsic &&
    467468                                ( opInfo = operatorLookup( var->var->name ) ) ) {
     469                        changeState_ArgToIntrinsic(true);
    468470                        auto arg = expr->args.begin();
    469471                        switch ( opInfo->type ) {
     
    558560        if ( auto name = expr->func.as<ast::NameExpr>() ) {
    559561                if ( const OperatorInfo * opInfo = operatorLookup( name->name ) ) {
     562                        changeState_ArgToIntrinsic(true);
    560563                        auto arg = expr->args.begin();
    561564                        switch ( opInfo->type ) {
     
    743746        extension( expr );
    744747        const OperatorInfo * opInfo;
    745         if ( expr->var->linkage == ast::Linkage::Intrinsic
     748        if ( visitingArgToIntrinsic
     749                        && options.genC
     750                        && dynamic_cast<ast::ZeroType const *>( expr->var->get_type() ) ) {
     751                // int * p; p = 0;               ==>  ?=?( p, (zero_t){} );  ==>  p = 0;
     752                // void f( zero_t z ) { g(z); }  ==>  g(z);                  ==>  g(z);
     753                // (we are at the last '==>')
     754                output << "0";
     755        } else if ( expr->var->linkage == ast::Linkage::Intrinsic
    746756                        && ( opInfo = operatorLookup( expr->var->name ) )
    747757                        && opInfo->type == OT_CONSTANT ) {
  • src/CodeGen/CodeGenerator.hpp

    r985ff5f r332e93a  
    181181        void handleTypedef( ast::NamedTypeDecl const * type );
    182182        std::string mangleName( ast::DeclWithType const * decl );
     183
     184        bool nextVisitedNodeIsArgToIntrinsic = false;
     185        bool visitingArgToIntrinsic = false;
     186        void changeState_ArgToIntrinsic( bool newValue ) {
     187                GuardValue( visitingArgToIntrinsic ) = nextVisitedNodeIsArgToIntrinsic;
     188                GuardValue( nextVisitedNodeIsArgToIntrinsic ) = newValue;
     189        }
    183190};
    184191
  • src/CodeGen/GenType.cpp

    r985ff5f r332e93a  
    268268void GenType::postvisit( ast::ZeroType const * type ) {
    269269        // Ideally these wouldn't hit codegen at all, but should be safe to make them ints.
    270         result = (options.pretty ? "zero_t " : "long int ") + result;
     270        result = ( options.genC ? "long int /*zero_t*/ " : "zero_t " ) + result;
    271271        handleQualifiers( type );
    272272}
     
    274274void GenType::postvisit( ast::OneType const * type ) {
    275275        // Ideally these wouldn't hit codegen at all, but should be safe to make them ints.
    276         result = (options.pretty ? "one_t " : "long int ") + result;
     276        result = ( options.genC ? "long int /*one_t*/ " : "one_t " ) + result;
    277277        handleQualifiers( type );
    278278}
  • src/CodeGen/Generate.cpp

    r985ff5f r332e93a  
    4646                }
    4747        };
     48
     49        struct ZeroOneObjectHider final {
     50                ast::ObjectDecl const * postvisit( ast::ObjectDecl const * decl ) {
     51                        if ( decl->type.as<ast::ZeroType>() || decl->type.as<ast::OneType>() ) {
     52                                ast::ObjectDecl * mutDecl = ast::mutate( decl );
     53                                mutDecl->attributes.push_back( new ast::Attribute( "unused" ) );
     54                                return mutDecl;
     55                        }
     56                        return decl;
     57                }
     58        };
    4859} // namespace
    4960
     
    5263        erase_if( translationUnit.decls, shouldClean );
    5364        ast::Pass<TreeCleaner>::run( translationUnit );
     65        ast::Pass<ZeroOneObjectHider>::run( translationUnit );
    5466
    5567        ast::Pass<CodeGenerator> cgv( os,
Note: See TracChangeset for help on using the changeset viewer.