Ignore:
Timestamp:
Jan 12, 2017, 3:28:29 PM (7 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:
aaa1a99a
Parents:
7cc2c8d
Message:

Proper bootloader boilerplate implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/CodeGen/FixMain.cc

    r7cc2c8d r13de47bc  
     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//
    115
     16
     17#include "FixMain.h"   
     18
     19#include <fstream>
     20#include <iostream>
     21
     22#include "Common/SemanticError.h"
     23#include "SynTree/Declaration.h"
     24
     25namespace 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 TracChangeset for help on using the changeset viewer.