Changeset b3f252a for src/CodeGen


Ignore:
Timestamp:
Sep 7, 2017, 10:36:35 AM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
e0886db
Parents:
871cdb4 (diff), 416cc86 (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.cc

    r871cdb4 rb3f252a  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug 18 15:34:00 2017
    13 // Update Count     : 488
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Sep  3 20:42:52 2017
     13// Update Count     : 490
    1414//
    1515#include "CodeGenerator.h"
     
    5959
    6060        void CodeGenerator::asmName( DeclarationWithType * decl ) {
    61                 if ( ConstantExpr * asmName = decl->get_asmName() ) {
     61                if ( ConstantExpr * asmName = dynamic_cast<ConstantExpr *>(decl->get_asmName()) ) {
    6262                        output << " asm ( " << asmName->get_constant()->get_value() << " )";
    6363                } // if
     
    195195                }
    196196
    197                 output << kind;
    198                 if ( aggDecl->get_name() != "" )
    199                         output << aggDecl->get_name();
     197                output << kind << aggDecl->get_name();
    200198
    201199                if ( aggDecl->has_body() ) {
     
    233231                genAttributes( enumDecl->get_attributes() );
    234232
    235                 if ( enumDecl->get_name() != "" )
    236                         output << enumDecl->get_name();
     233                output << enumDecl->get_name();
    237234
    238235                std::list< Declaration* > &memb = enumDecl->get_members();
     
    260257        }
    261258
    262         void CodeGenerator::visit( __attribute__((unused)) TraitDecl * traitDecl ) {}
     259        void CodeGenerator::visit( TraitDecl * traitDecl ) {
     260                assertf( ! genC, "TraitDecl nodes should not reach code generation." );
     261                extension( traitDecl );
     262                handleAggregate( traitDecl, "trait " );
     263        }
    263264
    264265        void CodeGenerator::visit( TypedefDecl * typeDecl ) {
     
    545546                extension( addressExpr );
    546547                output << "(&";
    547                 // this hack makes sure that we don't convert "constant_zero" to "0" if we're taking its address
    548                 if ( VariableExpr * variableExpr = dynamic_cast< VariableExpr* >( addressExpr->get_arg() ) ) {
    549                         output << mangleName( variableExpr->get_var() );
    550                 } else {
    551                         addressExpr->get_arg()->accept( *this );
    552                 } // if
     548                addressExpr->arg->accept( *this );
    553549                output << ")";
     550        }
     551
     552        void CodeGenerator::visit( LabelAddressExpr *addressExpr ) {
     553                extension( addressExpr );
     554                output << "(&&" << addressExpr->arg << ")";
    554555        }
    555556
     
    760761                for ( Statement * stmt : stmts ) {
    761762                        updateLocation( stmt );
    762                         output << printLabels( stmt->get_labels() );
     763                        output << indent << printLabels( stmt->get_labels() );
    763764                        if ( i+1 == numStmts ) {
    764765                                // last statement in a statement expression needs to be handled specially -
  • src/CodeGen/CodeGenerator.h

    r871cdb4 rb3f252a  
    5959                virtual void visit( NameExpr *nameExpr );
    6060                virtual void visit( AddressExpr *addressExpr );
     61                virtual void visit( LabelAddressExpr *addressExpr );
    6162                virtual void visit( CastExpr *castExpr );
    6263                virtual void visit( VirtualCastExpr *castExpr );
  • src/CodeGen/Generate.cc

    r871cdb4 rb3f252a  
    2121#include "CodeGenerator.h"           // for CodeGenerator, doSemicolon, oper...
    2222#include "GenType.h"                 // for genPrettyType
     23#include "Common/PassVisitor.h"      // for PassVisitor
    2324#include "Parser/LinkageSpec.h"      // for isBuiltin, isGeneratable
    2425#include "SynTree/BaseSyntaxNode.h"  // for BaseSyntaxNode
     
    2930
    3031namespace CodeGen {
     32        namespace {
     33                /// Removes misc. nodes that should not exist in CodeGen
     34                struct TreeCleaner {
     35                        void visit( CompoundStmt * stmt );
     36
     37                        static bool shouldClean( Declaration * );
     38                };
     39
     40                void cleanTree( std::list< Declaration * > & translationUnit ) {
     41                        PassVisitor<TreeCleaner> cleaner;
     42                        filter( translationUnit, [](Declaration * decl) { return TreeCleaner::shouldClean(decl); }, false );
     43                        acceptAll( translationUnit, cleaner );
     44                } // cleanTree
     45        } // namespace
     46
    3147        void generate( std::list< Declaration* > translationUnit, std::ostream &os, bool doIntrinsics, bool pretty, bool generateC, bool lineMarks ) {
     48                cleanTree( translationUnit );
     49
    3250                CodeGen::CodeGenerator cgv( os, pretty, generateC, lineMarks );
    3351                for ( auto & dcl : translationUnit ) {
     
    5270                os << std::endl;
    5371        }
     72
     73        namespace {
     74                void TreeCleaner::visit( CompoundStmt * cstmt ) {
     75                        filter( cstmt->kids, [](Statement * stmt) {
     76                                if ( DeclStmt * declStmt = dynamic_cast< DeclStmt * >( stmt ) ) {
     77                                        return shouldClean( declStmt->decl );
     78                                }
     79                                return false;
     80                        }, false );
     81                }
     82
     83                bool TreeCleaner::shouldClean( Declaration * decl ) {
     84                        return dynamic_cast< TraitDecl * >( decl );
     85                }
     86        } // namespace
    5487} // namespace CodeGen
    5588
  • src/CodeGen/OperatorTable.cc

    r871cdb4 rb3f252a  
    1919
    2020#include "OperatorTable.h"
     21#include "Common/utility.h"
    2122
    2223namespace CodeGen {
     
    6566                        {       "?^=?",         "^=",   "_operator_bitxorassign",               OT_INFIXASSIGN          },
    6667                        {       "?|=?",         "|=",   "_operator_bitorassign",                OT_INFIXASSIGN          },
    67                         {       "&&",           "&&",   "&&",                                                   OT_LABELADDRESS         },
    68                         {       "0",            "0",    "_constant_zero",                               OT_CONSTANT                     },
    69                         {       "1",            "1",    "_constant_one",                                OT_CONSTANT                     }
    7068                };
    7169
     
    8684                        initialize();
    8785                } // if
     86
    8887                std::map< std::string, OperatorInfo >::const_iterator i = table.find( funcName );
    8988                if ( i == table.end() ) {
     89                        if ( isPrefix( funcName, "?`" ) ) {
     90                                // handle literal suffixes, which are user-defined postfix operators
     91                                info.inputName = funcName;
     92                                info.symbol = funcName.substr(2);
     93                                info.outputName = toString( "__operator_literal_", info.symbol );
     94                                info.type = OT_POSTFIX;
     95                                return true;
     96                        }
    9097                        return false;
    9198                } else {
Note: See TracChangeset for help on using the changeset viewer.