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

using namespace parc;

r_signal<logic> Gnd;

module m2 {

public:
  r_signal<logic> *sig default &Gnd;

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

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

};

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

  r_signal<logic> *sig default new r_signal<logic>;

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

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

  m2.sub (sig=sig);
};

void test()
{
  top t;

  root()->StartAll();
}

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