- Timestamp:
- Feb 3, 2025, 1:27:20 PM (8 weeks ago)
- Branches:
- master
- Children:
- dfe8f78
- Parents:
- 59fdd0d
- Location:
- src/CodeGen
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/CodeGen/CodeGenerator.cpp ¶
r59fdd0d r7959e56 130 130 // TODO: Which means the ast::Pass is just providing a default no visit? 131 131 visit_children = false; 132 changeState_ArgToIntrinsic(false); 132 133 } 133 134 … … 466 467 if ( var->var->linkage == ast::Linkage::Intrinsic && 467 468 ( opInfo = operatorLookup( var->var->name ) ) ) { 469 changeState_ArgToIntrinsic(true); 468 470 auto arg = expr->args.begin(); 469 471 switch ( opInfo->type ) { … … 558 560 if ( auto name = expr->func.as<ast::NameExpr>() ) { 559 561 if ( const OperatorInfo * opInfo = operatorLookup( name->name ) ) { 562 changeState_ArgToIntrinsic(true); 560 563 auto arg = expr->args.begin(); 561 564 switch ( opInfo->type ) { … … 743 746 extension( expr ); 744 747 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 746 756 && ( opInfo = operatorLookup( expr->var->name ) ) 747 757 && opInfo->type == OT_CONSTANT ) { -
TabularUnified src/CodeGen/CodeGenerator.hpp ¶
r59fdd0d r7959e56 181 181 void handleTypedef( ast::NamedTypeDecl const * type ); 182 182 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 } 183 190 }; 184 191 -
TabularUnified src/CodeGen/Generate.cpp ¶
r59fdd0d r7959e56 46 46 } 47 47 }; 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 }; 48 59 } // namespace 49 60 … … 52 63 erase_if( translationUnit.decls, shouldClean ); 53 64 ast::Pass<TreeCleaner>::run( translationUnit ); 65 ast::Pass<ZeroOneObjectHider>::run( translationUnit ); 54 66 55 67 ast::Pass<CodeGenerator> cgv( os,
Note: See TracChangeset
for help on using the changeset viewer.