Ignore:
Timestamp:
May 16, 2015, 3:36:19 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
a32b204
Parents:
b8508a2
Message:

licencing: first groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/MakeLibCfa.cc

    rb8508a2 rb87a5ed  
    1 /*
    2  * This file is part of the Cforall project
    3  *
    4  * $Id: MakeLibCfa.cc,v 1.6 2005/08/29 20:14:14 rcbilson Exp $
    5  *
    6  */
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// MakeLibCfa.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Sat May 16 10:33:33 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat May 16 10:40:44 2015
     13// Update Count     : 13
     14//
    715
    816#include "MakeLibCfa.h"
     17#include "SynTree/Visitor.h"
    918#include "SynTree/Declaration.h"
    1019#include "SynTree/Type.h"
     
    1221#include "SynTree/Statement.h"
    1322#include "SynTree/Initializer.h"
    14 #include "SynTree/Visitor.h"
    1523#include "CodeGen/OperatorTable.h"
    1624#include "UniqueName.h"
    1725
     26namespace LibCfa {
     27        class MakeLibCfa : public Visitor {
     28          public:
     29                void visit( FunctionDecl* funcDecl );
     30                void visit( ObjectDecl* objDecl );
     31 
     32                std::list< Declaration* > &get_newDecls() { return newDecls; }
     33          private:
     34                std::list< Declaration* > newDecls;
     35        };
    1836
    19 namespace LibCfa {
     37        void makeLibCfa( std::list< Declaration* > &prelude ) {
     38                MakeLibCfa maker;
     39                acceptAll( prelude, maker );
     40                prelude.splice( prelude.end(), maker.get_newDecls() );
     41        }
    2042
    21 class MakeLibCfa : public Visitor
    22 {
    23 public:
    24   void visit( FunctionDecl* funcDecl );
    25   void visit( ObjectDecl* objDecl );
     43        void MakeLibCfa::visit( FunctionDecl* origFuncDecl ) {
     44                if ( origFuncDecl->get_linkage() != LinkageSpec::Intrinsic ) return;
    2645 
    27   std::list< Declaration* > &get_newDecls() { return newDecls; }
     46                FunctionDecl *funcDecl = origFuncDecl->clone();
     47                CodeGen::OperatorInfo opInfo;
     48                bool lookResult = CodeGen::operatorLookup( funcDecl->get_name(), opInfo );
     49                assert( lookResult );
     50                assert( !funcDecl->get_statements() );
     51                UntypedExpr *newExpr = new UntypedExpr( new NameExpr( funcDecl->get_name() ) );
     52                UniqueName paramNamer( "_p" );
     53                std::list< DeclarationWithType* >::iterator param = funcDecl->get_functionType()->get_parameters().begin();
     54                assert( param != funcDecl->get_functionType()->get_parameters().end() );
     55
     56                if ( (*param)->get_name() == "" ) {
     57                        (*param)->set_name( paramNamer.newName() );
     58                        (*param)->set_linkage( LinkageSpec::C );
     59                } // if
     60
     61                switch( opInfo.type ) {
     62                  case CodeGen::OT_INDEX:
     63                  case CodeGen::OT_CALL:
     64                  case CodeGen::OT_PREFIX:
     65                  case CodeGen::OT_POSTFIX:
     66                  case CodeGen::OT_INFIX:
     67                        newExpr->get_args().push_back( new VariableExpr( *param ) );
     68                        break;
     69                  case CodeGen::OT_PREFIXASSIGN:
     70                  case CodeGen::OT_POSTFIXASSIGN:
     71                  case CodeGen::OT_INFIXASSIGN:
     72                        {
     73                                newExpr->get_args().push_back( new VariableExpr( *param ) );
     74                                // UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
     75                                // deref->get_args().push_back( new VariableExpr( *param ) );
     76                                // newExpr->get_args().push_back( deref );
     77                                break;
     78                        }
     79                  case CodeGen::OT_CONSTANT:
     80                        assert( false );
     81                } // switch
     82
     83                for ( param++; param != funcDecl->get_functionType()->get_parameters().end(); ++param ) {
     84                        if ( (*param)->get_name() == "" ) {
     85                                (*param)->set_name( paramNamer.newName() );
     86                                (*param)->set_linkage( LinkageSpec::C );
     87                        }
     88                        newExpr->get_args().push_back( new VariableExpr( *param ) );
     89                } // for
     90                funcDecl->set_statements( new CompoundStmt( std::list< Label >() ) );
     91                funcDecl->get_statements()->get_kids().push_back( new ReturnStmt( std::list< Label >(), newExpr ) );
     92                newDecls.push_back( funcDecl );
     93        }
     94
     95        void MakeLibCfa::visit( ObjectDecl* origObjDecl ) {
     96                if ( origObjDecl->get_linkage() != LinkageSpec::Intrinsic ) return;
    2897 
    29 private:
    30   std::list< Declaration* > newDecls;
    31 };
     98                ObjectDecl *objDecl = origObjDecl->clone();
     99                assert( !objDecl->get_init() );
     100                std::list< Expression* > noDesignators;
     101                objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators ) );
     102                newDecls.push_back( objDecl );
     103        }
     104} // namespace LibCfa
    32105
    33 void
    34 makeLibCfa( std::list< Declaration* > &prelude )
    35 {
    36   MakeLibCfa maker;
    37   acceptAll( prelude, maker );
    38   prelude.splice( prelude.end(), maker.get_newDecls() );
    39 }
    40 
    41 void
    42 MakeLibCfa::visit( FunctionDecl* origFuncDecl )
    43 {
    44   if( origFuncDecl->get_linkage() != LinkageSpec::Intrinsic ) return;
    45  
    46   FunctionDecl *funcDecl = origFuncDecl->clone();
    47   CodeGen::OperatorInfo opInfo;
    48   bool lookResult = CodeGen::operatorLookup( funcDecl->get_name(), opInfo );
    49   assert( lookResult );
    50   assert( !funcDecl->get_statements() );
    51   UntypedExpr *newExpr = new UntypedExpr( new NameExpr( funcDecl->get_name() ) );
    52   UniqueName paramNamer( "_p" );
    53   std::list< DeclarationWithType* >::iterator param = funcDecl->get_functionType()->get_parameters().begin();
    54   assert( param != funcDecl->get_functionType()->get_parameters().end() );
    55   if( (*param)->get_name() == "" ) {
    56     (*param)->set_name( paramNamer.newName() );
    57     (*param)->set_linkage( LinkageSpec::C );
    58   }
    59   switch( opInfo.type ) {
    60   case CodeGen::OT_INDEX:
    61   case CodeGen::OT_CALL:
    62   case CodeGen::OT_PREFIX:
    63   case CodeGen::OT_POSTFIX:
    64   case CodeGen::OT_INFIX:
    65     newExpr->get_args().push_back( new VariableExpr( *param ) );
    66     break;
    67    
    68   case CodeGen::OT_PREFIXASSIGN:
    69   case CodeGen::OT_POSTFIXASSIGN:
    70   case CodeGen::OT_INFIXASSIGN:
    71   {
    72     newExpr->get_args().push_back( new VariableExpr( *param ) );
    73 ///     UntypedExpr *deref = new UntypedExpr( new NameExpr( "*?" ) );
    74 ///     deref->get_args().push_back( new VariableExpr( *param ) );
    75 ///     newExpr->get_args().push_back( deref );
    76     break;
    77   }
    78    
    79   case CodeGen::OT_CONSTANT:
    80     assert( false );
    81   }
    82   for( param++; param != funcDecl->get_functionType()->get_parameters().end(); ++param ) {
    83     if( (*param)->get_name() == "" ) {
    84       (*param)->set_name( paramNamer.newName() );
    85       (*param)->set_linkage( LinkageSpec::C );
    86     }
    87     newExpr->get_args().push_back( new VariableExpr( *param ) );
    88   }
    89   funcDecl->set_statements( new CompoundStmt( std::list< Label >() ) );
    90   funcDecl->get_statements()->get_kids().push_back( new ReturnStmt( std::list< Label >(), newExpr ) );
    91   newDecls.push_back( funcDecl );
    92 }
    93 
    94 void
    95 MakeLibCfa::visit( ObjectDecl* origObjDecl )
    96 {
    97   if( origObjDecl->get_linkage() != LinkageSpec::Intrinsic ) return;
    98  
    99   ObjectDecl *objDecl = origObjDecl->clone();
    100   assert( !objDecl->get_init() );
    101   std::list< Expression* > noDesignators;
    102   objDecl->set_init( new SingleInit( new NameExpr( objDecl->get_name() ), noDesignators ) );
    103   newDecls.push_back( objDecl );
    104 }
    105 
    106 } // namespace LibCfa
     106// Local Variables: //
     107// tab-width: 4 //
     108// mode: c++ //
     109// compile-command: "make install" //
     110// End: //
Note: See TracChangeset for help on using the changeset viewer.