gem5  v22.1.0.0
main.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 The Hewlett-Packard Development Company
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are
7  * met: redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer;
9  * redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution;
12  * neither the name of the copyright holders nor the names of its
13  * contributors may be used to endorse or promote products derived from
14  * this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include <Python.h>
30 
31 #include <iostream>
32 
33 #include "pybind11/embed.h"
34 #include "pybind11/pybind11.h"
35 
36 #include "python/embedded.hh"
37 #include "sim/init_signals.hh"
38 
39 using namespace gem5;
40 
41 namespace py = pybind11;
42 
43 // main() is now pretty stripped down and just sets up python and then
44 // calls EmbeddedPython::initAll which loads the various embedded python
45 // modules into the python environment and then starts things running by
46 // running python's m5.main().
47 int
48 main(int argc, char **argv)
49 {
50  // Initialize gem5 special signal handling.
51  initSignals();
52 
53  // Convert argv[0] to a wchar_t string, using python's locale and cleanup
54  // functions.
55  std::unique_ptr<wchar_t[], decltype(&PyMem_RawFree)> program(
56  Py_DecodeLocale(argv[0], nullptr),
57  &PyMem_RawFree);
58 
59  // This can help python find libraries at run time relative to this binary.
60  // It's probably not necessary, but is mostly harmless and might be useful.
61  Py_SetProgramName(program.get());
62 
63  py::scoped_interpreter guard(true, argc, argv);
64 
65  auto importer = py::module_::import("importer");
66  importer.attr("install")();
67 
68  try {
69  py::module_::import("m5").attr("main")();
70  } catch (py::error_already_set &e) {
71  if (e.matches(PyExc_SystemExit))
72  return e.value().attr("code").cast<int>();
73 
74  std::cerr << e.what();
75  return 1;
76  }
77 
78  return 0;
79 }
int main(int argc, char **argv)
Definition: main.cc:48
Bitfield< 9 > e
Definition: misc_types.hh:65
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
void initSignals()

Generated on Wed Dec 21 2022 10:22:39 for gem5 by doxygen 1.9.1