#include <stdio.h>
#include "parc.h"

using namespace parc;

module m2 {
public:
  r_signal<logic> *sig;

  process p2 {
    char d;
  start:
    for (;;) { @(sig[0]) printf("p2: v=%d,k=%d,s=%d @ %d\n",
                             sig->Value().value,sig->Value().known,sig->Value().strength,
                             Kern->Now().L()); }
  } b;

  process p3 {
    char d; 
  start:
    for (;;) { 
      @(sig[1]) 
      printf("p3: v=%d,k=%d,s=%d @ %d\n",
             sig->Value().value,sig->Value().known,sig->Value().strength,
             Kern->Now().L()); 
    }
  } c;

};

module top {
public:
  char i;
  top() {
    i = 1;
  }

  signal<LOGIC_VEC(4)> sig;

  process p1 {
    driver<LOGIC_VEC_SLICE> drv0 = sig[1:1];
  start:
    for (; i < 40 ; i++) {
      printf("p1: %d\n",i);
      drv0 @= i & 1;
      wait(7);
    }
  } a;

  process px {
    driver<LOGIC_VEC_SLICE> drv1 = sig[2:2];
  start:
    for (; i < 40 ; i++) {
      printf("px: %d\n",i);
      drv1 @ 3 = i & 1;
      wait(11);
    }
  } x;

  m2.sub1(sig=sig[1:2]);
};

void test()
{
  top t;

  root()->StartAll();
}

int main(int argc,char **argv)
{
  test();
}