15522Snate@binkert.org/*
211988Sandreas.sandberg@arm.com * Copyright (c) 2017 ARM Limited
311988Sandreas.sandberg@arm.com * All rights reserved
411988Sandreas.sandberg@arm.com *
511988Sandreas.sandberg@arm.com * The license below extends only to copyright in the software and shall
611988Sandreas.sandberg@arm.com * not be construed as granting a license to any other intellectual
711988Sandreas.sandberg@arm.com * property including but not limited to intellectual property relating
811988Sandreas.sandberg@arm.com * to a hardware implementation of the functionality of the software
911988Sandreas.sandberg@arm.com * licensed hereunder.  You may use the software subject to the license
1011988Sandreas.sandberg@arm.com * terms below provided that you ensure that this notice is replicated
1111988Sandreas.sandberg@arm.com * unmodified and in its entirety in all distributions of the software,
1211988Sandreas.sandberg@arm.com * modified or unmodified, in source code or in binary form.
1311988Sandreas.sandberg@arm.com *
145522Snate@binkert.org * Copyright (c) 2008 The Hewlett-Packard Development Company
155522Snate@binkert.org * All rights reserved.
165522Snate@binkert.org *
175522Snate@binkert.org * Redistribution and use in source and binary forms, with or without
185522Snate@binkert.org * modification, are permitted provided that the following conditions are
195522Snate@binkert.org * met: redistributions of source code must retain the above copyright
205522Snate@binkert.org * notice, this list of conditions and the following disclaimer;
215522Snate@binkert.org * redistributions in binary form must reproduce the above copyright
225522Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
235522Snate@binkert.org * documentation and/or other materials provided with the distribution;
245522Snate@binkert.org * neither the name of the copyright holders nor the names of its
255522Snate@binkert.org * contributors may be used to endorse or promote products derived from
265522Snate@binkert.org * this software without specific prior written permission.
275522Snate@binkert.org *
285522Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
295522Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
305522Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
315522Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
325522Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
335522Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
345522Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
355522Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
365522Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
375522Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
385522Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
395522Snate@binkert.org *
405522Snate@binkert.org * Authors: Nathan Binkert
415522Snate@binkert.org */
425522Snate@binkert.org
435522Snate@binkert.org#ifndef __SIM_INIT_HH__
445522Snate@binkert.org#define __SIM_INIT_HH__
455522Snate@binkert.org
4611988Sandreas.sandberg@arm.com#include "pybind11/pybind11.h"
479554Sandreas.hansson@arm.com
487674Snate@binkert.org#include <list>
4911988Sandreas.sandberg@arm.com#include <map>
5011548Sandreas.hansson@arm.com#include <string>
517674Snate@binkert.org
528946Sandreas.hansson@arm.com#include <inttypes.h>
538946Sandreas.hansson@arm.com
547674Snate@binkert.org#ifndef PyObject_HEAD
557674Snate@binkert.orgstruct _object;
567674Snate@binkert.orgtypedef _object PyObject;
577674Snate@binkert.org#endif
587674Snate@binkert.org
5911548Sandreas.hansson@arm.com/*
6011548Sandreas.hansson@arm.com * Data structure describing an embedded python file.
6111548Sandreas.hansson@arm.com */
627674Snate@binkert.orgstruct EmbeddedPython
635522Snate@binkert.org{
645522Snate@binkert.org    const char *filename;
657502Snate@binkert.org    const char *abspath;
665522Snate@binkert.org    const char *modpath;
678946Sandreas.hansson@arm.com    const uint8_t *code;
685522Snate@binkert.org    int zlen;
697674Snate@binkert.org    int len;
707674Snate@binkert.org
717674Snate@binkert.org    EmbeddedPython(const char *filename, const char *abspath,
728946Sandreas.hansson@arm.com                   const char *modpath, const uint8_t *code, int zlen, int len);
737674Snate@binkert.org
747674Snate@binkert.org    PyObject *getCode() const;
757674Snate@binkert.org    bool addModule() const;
767674Snate@binkert.org
777674Snate@binkert.org    static EmbeddedPython *importer;
787674Snate@binkert.org    static PyObject *importerModule;
797674Snate@binkert.org    static std::list<EmbeddedPython *> &getList();
807674Snate@binkert.org    static int initAll();
815522Snate@binkert.org};
825522Snate@binkert.org
8311988Sandreas.sandberg@arm.comclass EmbeddedPyBind
8411988Sandreas.sandberg@arm.com{
8511988Sandreas.sandberg@arm.com  public:
8611988Sandreas.sandberg@arm.com    EmbeddedPyBind(const char *_name,
8711988Sandreas.sandberg@arm.com                   void (*init_func)(pybind11::module &),
8811988Sandreas.sandberg@arm.com                   const char *_base);
8911988Sandreas.sandberg@arm.com
9011988Sandreas.sandberg@arm.com    EmbeddedPyBind(const char *_name,
9111988Sandreas.sandberg@arm.com                   void (*init_func)(pybind11::module &));
9211988Sandreas.sandberg@arm.com
9313662Sandreas.sandberg@arm.com#if PY_MAJOR_VERSION >= 3
9413662Sandreas.sandberg@arm.com    static PyObject *initAll();
9513662Sandreas.sandberg@arm.com#else
9611988Sandreas.sandberg@arm.com    static void initAll();
9713662Sandreas.sandberg@arm.com#endif
9811988Sandreas.sandberg@arm.com
9911988Sandreas.sandberg@arm.com  private:
10011988Sandreas.sandberg@arm.com    void (*initFunc)(pybind11::module &);
10111988Sandreas.sandberg@arm.com
10211988Sandreas.sandberg@arm.com    bool depsReady() const;
10311988Sandreas.sandberg@arm.com    void init(pybind11::module &m);
10411988Sandreas.sandberg@arm.com
10511988Sandreas.sandberg@arm.com    bool registered;
10611988Sandreas.sandberg@arm.com    const std::string name;
10711988Sandreas.sandberg@arm.com    const std::string base;
10811988Sandreas.sandberg@arm.com
10911988Sandreas.sandberg@arm.com    static std::map<std::string, EmbeddedPyBind *> &getMap();
11011988Sandreas.sandberg@arm.com};
11111988Sandreas.sandberg@arm.com
11213662Sandreas.sandberg@arm.comvoid registerNativeModules();
11313662Sandreas.sandberg@arm.com
1145522Snate@binkert.orgint m5Main(int argc, char **argv);
1155522Snate@binkert.org
1165522Snate@binkert.org#endif // __SIM_INIT_HH__
117