Ignore:
Timestamp:
Oct 25, 2023, 6:33:25 PM (6 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
master
Children:
bef4f1a
Parents:
d22bf87
Message:

Direct translation of code generation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/Generate.cc

    rd22bf87 r8941b6b  
    1919#include <string>                    // for operator<<
    2020
     21#include "CodeGeneratorNew.hpp"      // for CodeGenerator_new, doSemicolon, ...
    2122#include "CodeGenerator.h"           // for CodeGenerator, doSemicolon, oper...
    2223#include "GenType.h"                 // for genPrettyType
     
    9394                }
    9495        } // namespace
     96
     97namespace {
     98        bool shouldClean( ast::Decl const * decl ) {
     99                return dynamic_cast<ast::TraitDecl const *>( decl );
     100        }
     101
     102        /// Removes various nodes that should not exist in CodeGen.
     103        struct TreeCleaner_new {
     104                ast::CompoundStmt const * previsit( ast::CompoundStmt const * stmt ) {
     105                        auto mutStmt = ast::mutate( stmt );
     106                        erase_if( mutStmt->kids, []( ast::Stmt const * stmt ){
     107                                auto declStmt = dynamic_cast<ast::DeclStmt const *>( stmt );
     108                                return ( declStmt ) ? shouldClean( declStmt->decl ) : false;
     109                        } );
     110                        return mutStmt;
     111                }
     112
     113                ast::Stmt const * postvisit( ast::ImplicitCtorDtorStmt const * stmt ) {
     114                        return stmt->callStmt;
     115                }
     116        };
     117} // namespace
     118
     119void generate( ast::TranslationUnit & translationUnit, std::ostream & os, bool doIntrinsics,
     120                bool pretty, bool generateC, bool lineMarks, bool printExprTypes ) {
     121        erase_if( translationUnit.decls, shouldClean );
     122        ast::Pass<TreeCleaner_new>::run( translationUnit );
     123
     124        ast::Pass<CodeGenerator_new> cgv( os,
     125                        Options( pretty, generateC, lineMarks, printExprTypes ) );
     126        for ( auto & decl : translationUnit.decls ) {
     127                if ( decl->linkage.is_generatable && (doIntrinsics || !decl->linkage.is_builtin ) ) {
     128                        cgv.core.updateLocation( decl );
     129                        decl->accept( cgv );
     130                        if ( doSemicolon( decl ) ) {
     131                                os << ";";
     132                        }
     133                        os << cgv.core.endl;
     134                }
     135        }
     136}
     137
    95138} // namespace CodeGen
    96139
Note: See TracChangeset for help on using the changeset viewer.