|
Last change
on this file since 43 was 35, checked in by buchmann, 17 years ago |
|
Code cleanup.
Add --dynamiclink option to systemcass executable.
|
|
File size:
1.3 KB
|
| Rev | Line | |
|---|
| [35] | 1 | #include <systemc.h>
|
|---|
| [1] | 2 | #include <iostream>
|
|---|
| [18] | 3 | #include <cstring>
|
|---|
| [1] | 4 |
|
|---|
| 5 | #define ASSERT(x) \
|
|---|
| 6 | { errnum++; \
|
|---|
| 7 | if (!(x)) \
|
|---|
| 8 | { \
|
|---|
| 9 | cerr << "ASSERT : " #x "\n"; \
|
|---|
| 10 | exit (errnum); \
|
|---|
| 11 | } \
|
|---|
| 12 | }
|
|---|
| 13 |
|
|---|
| 14 | #ifdef DEBUG
|
|---|
| 15 | #define CERR(x) \
|
|---|
| 16 | { cerr << "" #x " = " << x << "\n"; }
|
|---|
| 17 | #else
|
|---|
| 18 | #define CERR(x)
|
|---|
| 19 | #endif
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | using namespace std;
|
|---|
| 23 |
|
|---|
| 24 | static int errnum = 0;
|
|---|
| 25 |
|
|---|
| 26 | void
|
|---|
| 27 | check_time (int i)
|
|---|
| 28 | {
|
|---|
| [23] | 29 | const sc_time &t = sc_time_stamp ();
|
|---|
| [1] | 30 | CERR(i);
|
|---|
| 31 | CERR(t.to_double());
|
|---|
| [23] | 32 | #ifdef SYSTEMCASS_SPECIFIC
|
|---|
| 33 | ASSERT((int) (t.to_double ()) == i);
|
|---|
| 34 | #else
|
|---|
| [1] | 35 | ASSERT((int) (t.to_double ()) == i * 1000);
|
|---|
| [23] | 36 | #endif
|
|---|
| [1] | 37 | CERR(t.to_seconds ());
|
|---|
| 38 | double seconds = t.to_seconds()*1000000000;
|
|---|
| 39 | CERR(seconds);
|
|---|
| 40 | ASSERT(((int)seconds) == i);
|
|---|
| 41 | char s[256];
|
|---|
| 42 | const char *unit;
|
|---|
| [23] | 43 | #ifdef SYSTEMCASS_SPECIFIC
|
|---|
| 44 | unit = "NS";
|
|---|
| 45 | #else
|
|---|
| [1] | 46 | if (i == 0)
|
|---|
| 47 | unit = "s";
|
|---|
| 48 | else if (i < 1000)
|
|---|
| 49 | unit = "ns";
|
|---|
| 50 | else
|
|---|
| 51 | unit = "ns";
|
|---|
| [23] | 52 | #endif
|
|---|
| [1] | 53 | sprintf (s, "%d %s", i,unit);
|
|---|
| 54 | CERR(s);
|
|---|
| 55 | CERR(t.to_string());
|
|---|
| 56 | ASSERT(strcmp (t.to_string ().c_str(), s)== 0);
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | int
|
|---|
| 60 | sc_main (int argc, char ** argv)
|
|---|
| 61 | {
|
|---|
| 62 | sc_clock clk ("clock");
|
|---|
| 63 |
|
|---|
| 64 | check_time (0);
|
|---|
| [23] | 65 | sc_start (0);
|
|---|
| [1] | 66 |
|
|---|
| 67 | check_time (0);
|
|---|
| [23] | 68 | sc_start (1);
|
|---|
| [1] | 69 | check_time (1);
|
|---|
| 70 |
|
|---|
| [23] | 71 | sc_start (15);
|
|---|
| [1] | 72 | check_time (16);
|
|---|
| 73 |
|
|---|
| [23] | 74 | sc_start (7);
|
|---|
| [1] | 75 | check_time (23);
|
|---|
| 76 |
|
|---|
| [23] | 77 | sc_start (100);
|
|---|
| [1] | 78 | check_time (123);
|
|---|
| 79 |
|
|---|
| [23] | 80 | sc_start (1000);
|
|---|
| [1] | 81 | check_time (1123);
|
|---|
| 82 | cerr << "Test OK.\n";
|
|---|
| 83 | return 0;
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.