systemc-clang icon indicating copy to clipboard operation
systemc-clang copied to clipboard

Duplicate processes in child class

Open zhuanhao-wu opened this issue 3 years ago • 0 comments

https://github.com/intel/systemc-compiler/blob/main/tests/method/test_virtual_cast.cpp

The original C++ code

#include "systemc.h"

using namespace sc_core;

// Virtual and non-virtual unction call with cast to base module type

struct A : public sc_module
{
    A(const sc_module_name& name) : sc_module(name)
    {}
    
    void f() {
        char m = 1;
    }
};


class C : public A 
{
public:
    sc_signal<bool> dummy{"dummy"};

    SC_HAS_PROCESS(C);
    C(const sc_module_name& name) : A(name) {
        SC_METHOD(proc_func); sensitive << dummy;
    }
    
    void f() {
        short m = 2;
    }

    void proc_func() {
        f();
        C::f();
        A::f();
    }
};

class D : public C 
{
public:
    sc_signal<bool> dummy{"dummy"};

    SC_HAS_PROCESS(D);
    D(const sc_module_name& name) : C(name) {
        SC_METHOD(proc_func); sensitive << dummy;
    }

    void f() {
        int m = 3;
    }

    void proc_func() {
        f();
        D::f();
        C::f();
        A::f();
    }
};
// ...

Generated code for module D, notice how proc_func is repeated:

hModule D_sc_module_2 [
    hPortsigvarlist  NONAME [
      hSigdecl dummy_scclang_global_0 [
        hTypeinfo  NONAME [
          hType sc_signal [
            hType _Bool NOLIST
          ]
        ]
      ]
      hSigdecl dummy_scclang_global_1 [
        hTypeinfo  NONAME [
          hType sc_signal [
            hType _Bool NOLIST
          ]
        ]
      ]
    ]
    hProcesses  NONAME [
      hProcess proc_func [
        hMethod proc_func [
          hCStmt  NONAME [
            hMethodCall D__f_func_0 NOLIST
            hMethodCall D__f_func_0 NOLIST
            hMethodCall C__f_func_1 NOLIST
            hMethodCall A__f_func_2 NOLIST
          ]
        ]
      ]
      hProcess proc_func [
        hMethod proc_func [
          hCStmt  NONAME [
            hMethodCall C__f_func_1 NOLIST
            hMethodCall C__f_func_1 NOLIST
            hMethodCall A__f_func_2 NOLIST
          ]
        ]
      ]
...

zhuanhao-wu avatar Aug 22 '22 17:08 zhuanhao-wu