forked from dcblack/ModernSystemC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
109 lines (99 loc) · 2.82 KB
/
main.cpp
File metadata and controls
109 lines (99 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* @file main.cpp
*/
#include "top.hpp"
#include "report.hpp"
#include "fpsqrt.hpp"
#include <string>
#include <map>
#include <vector>
namespace {
char const * const MSGID{ "/Doulos/Example/Modern/main" };
}
/**
* Globals
*/
std::map<std::string,std::string> cmdline; ///< parsed from command-line
std::ostringstream mout; ///< Used by report.hpp
/**
* @brief Entry point for SystemC
*/
int sc_main( int argc, char* argv[] )
{
using namespace sc_core;
/**...........................................................................
* Scan command-line for options
*/
bool debugging { false };
std::string others;
for( int i=1; i<sc_argc(); ++i ) {
std::string arg(sc_argv()[i]);
if( arg == "--" ) {
// ignore
} else if( arg[0] == '-' and arg.find_first_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") == 1 ) {
size_t pos = arg.find_first_of( "=" );
if( pos == std::string::npos ) {
cmdline[ arg ] = "1";
} else {
cmdline[ arg.substr( 0, pos ) ] = arg.substr( pos+1 );
}
} else {
if( others.length() > 0 ) others += '\1';
others += arg;
}
}//endfor
if( others.length() > 0 ) cmdline[ "~" ] = others;
if( cmdline.size() > 0 ) {
MESSAGE( "Command-line options:" );
for( auto const& o: cmdline ) {
MESSAGE( "\n " << o.first << " = " << o.second );
}
MEND( ALWAYS );
}
/**...........................................................................
* @brief Test fpsqrt
*/
{
std::vector<FixedPt_t> sqrs = { 0, 1, 2, 4, 9.5, 6.4, 64.5, 100, 100.5, 95, 10000, 11200 };
for( auto v : sqrs ) {
INFO( ALWAYS, "FP::fpsqrt( " << v.to_double() << " ) = " << FP::fpsqrt( v ).to_double() );
}
}
if( cmdline.count("-x") > 0 ) {
exit( 0 );
}
/**...........................................................................
* Setup reporting
*/
if( cmdline.count("-d") > 0 ) {
sc_report_handler::set_verbosity_level( SC_DEBUG );
}
sc_report_handler::set_actions( SC_ERROR, SC_DISPLAY | SC_LOG );
/**...........................................................................
* Instantiate
*/
Top_module top{ "top" };
/**...........................................................................
* Simulate
*/
sc_start();
if ( not sc_end_of_simulation_invoked() )
{
SC_REPORT_ERROR( MSGID, "Simulation stopped without explicit sc_stop()");
sc_stop();
}
/**...........................................................................
* Report results
*/
if ( ( sc_report_handler::get_count( SC_ERROR )
+ sc_report_handler::get_count( SC_FATAL )
) == 0
)
{
SC_REPORT_INFO_VERB( MSGID, "PASSED", SC_NONE );
return 0;
} else {
SC_REPORT_INFO_VERB( MSGID, "FAILED", SC_NONE );
return 1;
}
}