SC Macros

UVMC defines simple convenience macros for generating converter definitions and output stream operator (operator<<(ostream&)) so that you may use cout to print the contents of your SC transactions.  These macros do not present any performance or debug difficulties beyond the very nature of their being macros.  The code they expand into would be identical to code you would write yourself.

These macros are completely optional.  You are encouraged to learn how to write converters and operator<<, perhaps using the macro definitions as templates to get you started.

Summary
SC Macros
UVMC defines simple convenience macros for generating converter definitions and output stream operator (operator<<(ostream&)) so that you may use cout to print the contents of your SC transactions.
UVMC_CONVERTGenerate a converter specialization of uvmc_convert<T> for the given transaction TYPE.
UVMC_PRINTGenerate an operator<<(ostream&) implementation for use with cout and other output streams for the given transaction TYPE.
UVMC_UTILSGenerate both a converter specialization and output stream operator<< for the given transaction TYPE.

UVMC_CONVERT

Generate a converter specialization of uvmc_convert<T> for the given transaction TYPE.

UVMC_CONVERT_N (TYPE, <list of N variables> )
UVMC_CONVERT_EXT_N (TYPE, BASE, <list of N variables> )

For the second form, the generated converter will pack/unpack the members in the provided BASE class before those in TYPE.

Invoke the macro whose numeric suffix equals the number of field members you wish to include in the pack, unpack, and print operations.  These must all appear in the list of macro arguments in the order you want them streamed.

Example

UVMC_CONVERT_3( bus_trans, cmd, addr, data)
UVMC_CONVERT_EXT_1 (bus_error, bus_trans, crc)

The first macro generates a converter for the bus_trans class.  Three member variables of bus_trans are included in the pack and unpack operations, in the order given: cmd, addr, and data.  If there were other members in bus_trans, they will not be included in the converter implementations.

The second macro generates a converter and operator<< for the bus_error class.  Packing, unpacking, and output streaming for the base type, bus_trans is performed first, followed by the crc field in bus_error.

The macros above generate the following code

template <>
class uvmc_converter<bus_trans> {
  public:
  static void do_pack(const bus_trans &t, uvmc_packer &packer) {
    packer << cmd << addr << data;
  }
  static void do_unpack(bus_trans &t, uvmc_packer &packer) {
    packer >> cmd >> addr >> data;
  }
};
template <>
class uvmc_converter<bus_error> {
  public:
  static void do_pack(const bus_error &t, uvmc_packer &packer) {
    uvmc_converter<base_trans>::do_pack(t,packer);
    packer << crc;
  }
  static void do_unpack(bus_error &t, uvmc_packer &packer) {
    uvmc_converter<base_trans>::do_unpack(t,packer);
    packer >> crc;
  }
};

Usage notes

  • The default converter delegates to T.do_pack and T.do_unpack.  For transactions that do not possess these member functions (likely most), use one of these macros to generate a simple converter class that packs and unpacks your transaction from outside your transaction class.
  • All class members given in the list must be public members.
  • The uvmc_packer must provide operator>> and operator<< for all the types passed in the list.  See UVMC Type Support for a list of supported types.
  • These macros define a simple converter that does bit-by-bit packing and unpacking in the order provided.  Any customized conversions would require you write your own converter.  See Converter Specialization for details.
  • The macros support up to 20 member variables, i.e. up through UVM_UTILS_20 and UVM_UTILS_EXT_20.

UVMC_PRINT

Generate an operator<<(ostream&) implementation for use with cout and other output streams for the given transaction TYPE.

UVMC_PRINT_<N> (TYPE, <list of N variables> )
UVMC_PRINT_EXT_<N> (TYPE, BASE, <list of N variables> )

For the second form, the generated output stream operator will stream the contents of the provided BASE class before streaming those of TYPE.

Invoke the macro whose numeric suffix equals the number of field members you wish to include in the pack, unpack, and print operations.  These must all appear in the list of macro arguments in the order you want them streamed.

Example

UVMC_PRINT_3( bus_trans, cmd, addr, data)
UVMC_PRINT_EXT_1 (bus_error, bus_trans, crc)

The first macro generates an operator<< for the bus_trans class.  Three member variables of bus_trans are included in the output stream operation, in the order given: cmd, addr, and data.  If there were other members in bus_trans, they will not be included in the operator<< implementations.

The second macro generates an operator<< for the bus_error class.  Output streaming for the base type, bus_trans is performed first, followed by the crc field in bus_error.

The macros above generate the following code

template <>
class uvmc_print<bus_trans> {
  public:
  static void do_print(const bus_trans& t, ostream& os=cout) {
    os << hex << "cmd"  ":" << t.cmd << " "
                 "addr" ":" << t.addr << " "
                 "data" ":" << t.data << dec;
  }
  static void print(const bus_trans& t, ostream& os=cout) {
    os << "'{";
    do_print(t,os);
    os << " }";
  }
};
ostream& operator << (ostream& os, const bus_trans& v) {
  uvmc_print<bus_trans>::print(v,os);
}
template <>
class uvmc_print<bus_error> {
  public:
  static void do_print(const bus_error& t, ostream& os=cout) {
    uvmc_print<bus_trans>::do_print(t,os);
    os << " ";
    os << hex << "crc" ":" << t.cmd << " "
  }
  static void print(const bus_error& t, ostream& os=cout) {
    os << "'{";
    do_print(t,os);
    os << " }";
  }
};
ostream& operator << (ostream& os, const bus_error& v) {
  uvmc_print<bus_error>::print(v,os);
}

Usage notes

  • All class members given in the list must be public members
  • An operator<<(ostream) must be defined for each class member type listed.  This is true for integral, string, and SystemC data types.  UVMC also defines operator<<(ostream&) for STL vector<T>, map<KEY,T>, and list<T> types.
  • The macros support up to 20 member variables, i.e.  UVM_UTILS_20 and UVM_UTILS_EXT_20.

Before using these macros, be sure the #include the appropriate headers that define ostream and other I/O utilities.

#include <iostream>
#include <iomanp>

UVMC_UTILS

Generate both a converter specialization and output stream operator<< for the given transaction TYPE.

UVMC_UTILS_<N> (TYPE, <list of N variables> )
UVMC_UTILS_EXT_<N> (TYPE, BASE, <list of N variables> )

For the second form, the generated converter and output stream operator will perform the operation in BASE before doing the same in TYPE.

Invoke the macro whose numeric suffix equals the number of field members you wish to include in the pack, unpack, and print operations.

The UVMC_UTILS macro simply calls the corresponding UVMC_CONVERT and UVMC_PRINT macros.  See UVMC_CONVERT and UVMC_PRINT for detailed usage information.

Example

UVMC_UTILS_3( bus_trans, cmd, addr, data)
UVMC_UTILS_EXT_1 (bus_error, bus_trans, crc)

The first macro generates converter and output stream implementions for bus_trans.  Three member variables are included in the pack, unpack, and output stream operations, in the order given: cmd, addr, and data.  If there were other members in bus_trans, they will not be included in the converter or operator<< implementations.

The second macro generates a converter and operator<< for the bus_error class.  Packing, unpacking, and output streaming for the base type, bus_trans is performed first, followed by the crc field in bus_error.

The code that these macros expand into are provided in the descriptions of UVMC_CONVERT and UVMC_PRINT.

The members of your transaction definitions may be any collection of the following types, which have direct support in UVMC.
Define a separate class for converting your transaction type.
Generate a converter specialization of uvmc_convert<T> for the given transaction TYPE.
Generate an operator<<(ostream&) implementation for use with cout and other output streams for the given transaction TYPE.