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

using namespace parc;

template<int I>
module m2 {
  int data[I];
public:
  r_signal<logic> *sig;

  process p2 {
    char d;
  start:
    for (;;) { @(sig) 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) 
      printf("p3: v=%d,k=%d,s=%d @ %d\n",
             sig->Value().value,sig->Value().known,sig->Value().strength,
             Kern->Now().L()); 
    }
  } c;

};

template<int I>
module top {
public:
  char i;
  top() {
    i = 1;
  }

  r_signal<logic> sig;

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

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

  m2<I>.sub1(sig=&sig);
  m2<I>.sub2(
	     sig=&sig);
  m2<I>.
	sub3(sig=&sig);
};

void test()
{
  top<3> t;

  root()->StartAll();
}

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