2013年2月12日 星期二

python + SystemC = pySystemC

Wrapper SystemC TLM models in Python

  • How to install SystemC TLM models in MAC
    • download SystemC2.3
    • cd $
    • %mkdir build
    • %cd  build
    • %../configure
    • %make install
    • %export SYSTEMC_HOME=$
    • cd $/examples/tlm/build-unix
    • replace Makefile.config TARGET_ARCH ?= macosx64
    • make install

  • embedded SystemC to python env

    • advantages
      • script language easy to extend
      • more libraries support
      • more easily to reuse and rebuild(no compiler knowledge)
    • swig
  • how to do it?
    • wrapper SystemC thread/method to python call back
      • void sc_module_swig::method (PyObject * f){
        sc_python_callback * callback =
        new sc_python_callback (f);
        PyObject* name = PyObject_GetAttrString (f,"__name__");
        if(name == NULL || !PyString_Check(name)){
        std::cerr << "python name error\n";
        return;
        }
        sc_method_handle handle = simcontext()->
        register_method_process(
        PyString_AsString (name), callback,this );
        sc_module::sensitive << handle;
        sc_module::sensitive_pos << handle;
        sc_module::sensitive_neg << handle;
        }

    • wrapper SystemC start/end simulation

      • class sc_module_swig : public sc_module {
        public:sc_module_swig (const char * nm): sc_module ((sc_module_name)nm){}

        virtual void beforeEndOfElaboration(){}
        virtual void endOfElaboration(){}
        virtual void startOfSimulation(){}
        virtual void endOfSimulation (){}

        inline void dontInitialize ()
        {sc_module::dont_initialize ();}

        inline sc_sensitive & getSensitive (){return sensitive;}
        ...
        protected:
        inline void before_end_of_elaboration()
        {this->beforeEndOfElaboration ();}
        inline void end_of_elaboration()
        {this->endOfElaboration ();}
        inline void start_of_simulation()
        {this->startOfSimulation ();}
        inline void end_of_simulation()
        {this->endOfSimulation ();}
        ...
        };
    • wrapper SystemC module
      •                                                                                                                                                                  
    • set up SystemC map table "*.i"
      • %module sc_module_swig
        %{
        #include "systemc.h"
        #include "sc_module_swig.h"
        %}

        %include "sc_module_swig.h"
    • swig -c++ -I" -python *.i
  • ref

GreenScript User Manual - GreenSocs

沒有留言:

張貼留言