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

using namespace parc;

entity m2 {
public:
  rl_signal<logic> *sig;
};

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

  rl_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.sub=a0(sig=&sig);
};


architecture a0 : public m2 {
  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;

};

void test()
{
  top t;

  root()->StartAll();
}

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