ADT
        aaron-thesis
        arm-eh
        ast-experimental
        cleanup-dtors
        deferred_resn
        demangler
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        new-env
        no_list
        persistent-indexer
        pthread-emulation
        qualifiedEnum
        resolv-new
        with_gc
      
      
        
          | 
            Last change
 on this file since 6a0d1b1e was             13de47bc, checked in by Thierry Delisle <tdelisle@…>, 9 years ago           | 
        
        
          | 
             
Proper bootloader boilerplate implemented 
 
           | 
        
        
          
            
              - 
Property                 mode
 set to                 
100644
               
             
           | 
        
        
          | 
            File size:
            1.5 KB
           | 
        
      
      
| Line |   | 
|---|
| 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 | // FixMain.cc -- 
 | 
|---|
| 8 | //
 | 
|---|
| 9 | // Author           : Thierry Delisle
 | 
|---|
| 10 | // Created On       : Thr Jan 12 14:11:09 2017
 | 
|---|
| 11 | // Last Modified By : 
 | 
|---|
| 12 | // Last Modified On : 
 | 
|---|
| 13 | // Update Count     : 0
 | 
|---|
| 14 | //
 | 
|---|
| 15 | 
 | 
|---|
| 16 | 
 | 
|---|
| 17 | #include "FixMain.h"    
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include <fstream>
 | 
|---|
| 20 | #include <iostream>
 | 
|---|
| 21 | 
 | 
|---|
| 22 | #include "Common/SemanticError.h"
 | 
|---|
| 23 | #include "SynTree/Declaration.h"
 | 
|---|
| 24 | 
 | 
|---|
| 25 | namespace CodeGen {
 | 
|---|
| 26 |         bool FixMain::replace_main = false;
 | 
|---|
| 27 |         std::unique_ptr<FunctionDecl> FixMain::main_signature = nullptr;
 | 
|---|
| 28 |         
 | 
|---|
| 29 |         void FixMain::registerMain(FunctionDecl* functionDecl) 
 | 
|---|
| 30 |         {
 | 
|---|
| 31 |                 if(main_signature) { 
 | 
|---|
| 32 |                         throw SemanticError("Multiple definition of main routine\n", functionDecl); 
 | 
|---|
| 33 |                 }
 | 
|---|
| 34 |                 main_signature.reset( functionDecl->clone() );
 | 
|---|
| 35 |         }
 | 
|---|
| 36 | 
 | 
|---|
| 37 |         void FixMain::fix(std::ostream &os, const char* bootloader_filename) {
 | 
|---|
| 38 |                 if( main_signature ) {
 | 
|---|
| 39 |                         os << "static inline int invoke_main(int argc, char* argv[], char* envp[]) { (void)argc; (void)argv; (void)envp; return ";
 | 
|---|
| 40 | 
 | 
|---|
| 41 |                         os << main_signature->get_scopedMangleName() << "(";
 | 
|---|
| 42 |                         switch(main_signature->get_functionType()->get_parameters().size()) {
 | 
|---|
| 43 |                                 case 3: os << "argc, argv, envp"; break;
 | 
|---|
| 44 |                                 case 2: os << "argc, argv"; break;
 | 
|---|
| 45 |                                 case 0: break;
 | 
|---|
| 46 |                                 default : assert(false);
 | 
|---|
| 47 |                         }
 | 
|---|
| 48 |                         os << "); }\n";
 | 
|---|
| 49 | 
 | 
|---|
| 50 |                         std::ifstream bootloader(bootloader_filename, std::ios::in);
 | 
|---|
| 51 |                         assertf( bootloader.is_open(), "cannot open bootloader.c\n" );
 | 
|---|
| 52 |                         os << bootloader.rdbuf();
 | 
|---|
| 53 |                 }
 | 
|---|
| 54 |         }
 | 
|---|
| 55 | };
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.