System Verification with SCV

by George F. Frazier



Listing One



enum PROCESS_JPEG_EVENTS {RECEIVE, STORE, DECODE, MANIPULATE, ENCODE, SEND};



int jpeg_stream()

{

   scv_smart_ptr<PROCESS_JPEG_EVENTS> jpg;

   scv_bag<PROCESS_JPEG_EVENTS>       jpg_dist;

   jpg_dist.add(RECEIVE, 10);

   jpg_dist.add(STORE, 10);

   jpg_dist.add(DECODE, 20);

   jpg_dist.add(MANIPULATE, 40);

   jpg_dist.add(ENCODE, 10);

   jpg_dist.add(SEND, 10);

       

   jpg->set_mode(jpg_dist);



   while (1)

   {

       jpg->next();

       switch (jpg->read())

       {

           case RECEIVE:  jpg_receive(); break;

           case STORE: jpg_store(); break;

           case DECODE: jpg_decode(); break;

           case MANIPULATE: jpg_manipulate(); break;

           case ENCODE: jpg_encode(); break;

           case SEND: jpg_send(); break;

           default: return 1;

       }

   }

   return 1; // never return

}





Listing Two



// An SCV Constraint Base Class with 3 constraints



class boundary_constraint_class : public scv_constraint_base 

{

public:

    scv_smart_ptr<sc_uint> burst;

    scv_smart_ptr<uint> lower;

    scv_smart_ptr<uint> upper;



    SCV_CONSTRAINT_CTOR(boundary_constraint_class) 

    {

        SCV_CONSTRAINT (lower() > 100);

        SCV_CONSTRAINT (upper() < 500);

        SCV_CONSTRAINT (burst() >= lower() 

                        && burst() <= upper() );

    }

};

// using the boundary class

int use_boundary() 

{

    boundary_constraint_class bc ("boundary_constraint_instance"); 

    // The argument is a name string required by SystemC

    for(int i=0; i < DESIRED_NUMBER_OF_CONSTRAINED_RANDOM_VALUES; ++i) 

    {

        bc.next(); //generate values

        cout << "Value of burst: " << bc.burst() << endl;

    }

    return 0;

}





Listing Three



template <typename T> void fields(const T&obj)

{

    scv_extensions<T> ext = scv_extensions(obj);

    cout << "Our object has " << ext.get_num_fields() << " fields." << endl;

};

class aClass

{

public:

    long I;

    int t;

    char *p;

};

SCV_EXTENSIONS(aClass) {

public:

  scv_extensions<long> I;

  scv_extensions<int> t;

  scv_extensions<char*> p;

  SCV_EXTENSIONS_CTOR(aClass) {

    SCV_FIELD(I);

    SCV_FIELD(t);

    SCV_FIELD(p);

  }

};



void example()

{

  aClass ac;

  fields(ac);

}













2



