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.
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_CONVERT | Generate a converter specialization of uvmc_convert<T> for the given transaction TYPE. |
UVMC_PRINT | Generate an operator<<(ostream&) implementation for use with cout and other output streams for the given transaction TYPE. |
UVMC_UTILS | Generate both a converter specialization and output stream operator<< for the given transaction TYPE. |
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.
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; } };
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.
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); }
Before using these macros, be sure the #include the appropriate headers that define ostream and other I/O utilities.
#include <iostream> #include <iomanp>
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.
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.