main.cc revision 13620:e0d9b09788f6
17199Sgblack@eecs.umich.edu/*
27199Sgblack@eecs.umich.edu * Copyright (c) 2008 The Hewlett-Packard Development Company
37199Sgblack@eecs.umich.edu * All rights reserved.
47199Sgblack@eecs.umich.edu *
57199Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
67199Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
77199Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
87199Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
97199Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
107199Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
117199Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
127199Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
137199Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
147199Sgblack@eecs.umich.edu * this software without specific prior written permission.
157199Sgblack@eecs.umich.edu *
167199Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
177199Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
187199Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
197199Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
207199Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217199Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227199Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237199Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247199Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257199Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
267199Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
277199Sgblack@eecs.umich.edu *
287199Sgblack@eecs.umich.edu * Authors: Nathan Binkert
297199Sgblack@eecs.umich.edu */
307199Sgblack@eecs.umich.edu
317199Sgblack@eecs.umich.edu#include <Python.h>
327199Sgblack@eecs.umich.edu
337199Sgblack@eecs.umich.edu#include "sim/init.hh"
347199Sgblack@eecs.umich.edu#include "sim/init_signals.hh"
357199Sgblack@eecs.umich.edu
367199Sgblack@eecs.umich.edu// main() is now pretty stripped down and just sets up python and then
377199Sgblack@eecs.umich.edu// calls initM5Python which loads the various embedded python modules
387199Sgblack@eecs.umich.edu// into the python environment and then starts things running by
397199Sgblack@eecs.umich.edu// calling m5Main.
407199Sgblack@eecs.umich.eduint
417199Sgblack@eecs.umich.edumain(int argc, char **argv)
427199Sgblack@eecs.umich.edu{
437199Sgblack@eecs.umich.edu    int ret;
447199Sgblack@eecs.umich.edu
457199Sgblack@eecs.umich.edu    // Initialize m5 special signal handling.
467199Sgblack@eecs.umich.edu    initSignals();
477199Sgblack@eecs.umich.edu
487199Sgblack@eecs.umich.edu#if PY_MAJOR_VERSION >= 3
497199Sgblack@eecs.umich.edu    std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> program(
507199Sgblack@eecs.umich.edu        Py_DecodeLocale(argv[0], NULL),
517199Sgblack@eecs.umich.edu        &PyMem_RawFree);
527199Sgblack@eecs.umich.edu    Py_SetProgramName(program.get());
537199Sgblack@eecs.umich.edu#else
547199Sgblack@eecs.umich.edu    Py_SetProgramName(argv[0]);
557199Sgblack@eecs.umich.edu#endif
567199Sgblack@eecs.umich.edu
577199Sgblack@eecs.umich.edu    // initialize embedded Python interpreter
58    Py_Initialize();
59
60    // Initialize the embedded m5 python library
61    ret = initM5Python();
62
63    if (ret == 0) {
64        // start m5
65        ret = m5Main(argc, argv);
66    }
67
68    // clean up Python intepreter.
69    Py_Finalize();
70
71    return ret;
72}
73