main.cc revision 13662
12SN/A/* 21762SN/A * Copyright (c) 2008 The Hewlett-Packard Development Company 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Nathan Binkert 292665Ssaidi@eecs.umich.edu */ 302665Ssaidi@eecs.umich.edu 312SN/A#include <Python.h> 322SN/A 332SN/A#include "sim/init.hh" 342SN/A#include "sim/init_signals.hh" 352SN/A 362655Sstever@eecs.umich.edu// main() is now pretty stripped down and just sets up python and then 372655Sstever@eecs.umich.edu// calls initM5Python which loads the various embedded python modules 382SN/A// into the python environment and then starts things running by 392SN/A// calling m5Main. 401399SN/Aint 411396SN/Amain(int argc, char **argv) 422SN/A{ 432SN/A int ret; 442729Ssaidi@eecs.umich.edu 452SN/A // Initialize m5 special signal handling. 461310SN/A initSignals(); 472SN/A 482SN/A#if PY_MAJOR_VERSION >= 3 492SN/A std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> program( 502667Sstever@eecs.umich.edu Py_DecodeLocale(argv[0], NULL), 5156SN/A &PyMem_RawFree); 52146SN/A Py_SetProgramName(program.get()); 531388SN/A#else 5456SN/A Py_SetProgramName(argv[0]); 5556SN/A#endif 561311SN/A 57400SN/A // Register native modules with Python's init system before 583356Sbinkertn@umich.edu // initializing the interpreter. 591717SN/A registerNativeModules(); 601717SN/A 612738Sstever@eecs.umich.edu // initialize embedded Python interpreter 622738Sstever@eecs.umich.edu Py_Initialize(); 63146SN/A 64146SN/A // Initialize the embedded m5 python library 65146SN/A ret = EmbeddedPython::initAll(); 662797Sktlim@umich.edu 6756SN/A if (ret == 0) { 6856SN/A // start m5 6956SN/A ret = m5Main(argc, argv); 703202Shsul@eecs.umich.edu } 71695SN/A 72695SN/A // clean up Python intepreter. 731696SN/A Py_Finalize(); 742SN/A 752SN/A return ret; 762SN/A} 772SN/A