1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22  sc_main_main.cpp - Wrapper around user's toplevel routine `sc_main'.
23
24  Original Author: Andy Goodrich, Forte Design Systems
25
26 CHANGE LOG APPEARS AT THE END OF THE FILE
27 *****************************************************************************/
28
29
30#include "sysc/kernel/sc_cmnhdr.h"
31#include "sysc/kernel/sc_externs.h"
32#include "sysc/kernel/sc_except.h"
33#include "sysc/utils/sc_iostream.h"
34#include "sysc/utils/sc_report.h"
35#include "sysc/utils/sc_report_handler.h"
36#include "sysc/utils/sc_utils_ids.h"
37#include <vector>
38
39namespace sc_core {
40
41extern void pln();
42
43static int    argc_copy;	// Copy of argc value passed to sc_elab_and_sim.
44static char** argv_copy;	// Copy of argv value passed to sc_elab_and_sim.
45
46static
47inline
48void
49message_function( const char* s )
50{
51    ::std::cout << "\n" << s << ::std::endl;
52}
53
54bool sc_in_action = false;
55
56int sc_argc()
57{
58    return argc_copy;
59}
60
61const char* const* sc_argv()
62{
63    return argv_copy;
64}
65
66
67int
68sc_elab_and_sim( int argc, char* argv[] )
69{
70    int status = 1;
71    argc_copy = argc;
72    argv_copy = argv;
73    std::vector<char*> argv_call;
74    for ( int i = 0; i < argc; i++ )
75        argv_call.push_back(argv[i]);
76
77    try
78    {
79        pln();
80
81        // Perform initialization here
82        sc_in_action = true;
83
84        status = sc_main( argc, &argv_call[0] );
85
86        // Perform cleanup here
87        sc_in_action = false;
88    }
89    catch( const sc_report& x )
90    {
91	message_function( x.what() );
92    }
93    catch( ... )
94    {
95        // translate other escaping exceptions
96        sc_report*  err_p = sc_handle_exception();
97        if( err_p ) message_function( err_p->what() );
98        delete err_p;
99    }
100
101    // IF DEPRECATION WARNINGS WERE ISSUED TELL THE USER HOW TO TURN THEM OFF
102
103    if ( sc_report_handler::get_count( SC_ID_IEEE_1666_DEPRECATION_ ) > 0 )
104    {
105        std::stringstream ss;
106
107#       define MSGNL  "\n             "
108#       define CODENL "\n  "
109
110        ss <<
111          "You can turn off warnings about" MSGNL
112          "IEEE 1666 deprecated features by placing this method call" MSGNL
113          "as the first statement in your sc_main() function:\n" CODENL
114          "sc_core::sc_report_handler::set_actions( "
115          "\"" << SC_ID_IEEE_1666_DEPRECATION_ << "\"," CODENL
116          "                                         " /* indent param */
117          "sc_core::SC_DO_NOTHING );"
118          << std::endl;
119
120        SC_REPORT_INFO( SC_ID_IEEE_1666_DEPRECATION_, ss.str().c_str() );
121    }
122
123    return status;
124}
125
126} // namespace sc_core
127
128// $Log: sc_main_main.cpp,v $
129// Revision 1.9  2011/08/26 20:46:10  acg
130//  Andy Goodrich: moved the modification log to the end of the file to
131//  eliminate source line number skew when check-ins are done.
132//
133// Revision 1.8  2011/05/09 04:07:48  acg
134//  Philipp A. Hartmann:
135//    (1) Restore hierarchy in all phase callbacks.
136//    (2) Ensure calls to before_end_of_elaboration.
137//
138// Revision 1.7  2011/02/18 20:27:14  acg
139//  Andy Goodrich: Updated Copyrights.
140//
141// Revision 1.6  2011/02/13 21:47:37  acg
142//  Andy Goodrich: update copyright notice.
143//
144// Revision 1.5  2010/03/15 18:29:25  acg
145//  Andy Goodrich: Changed the default stack size to 128K from 64K.
146//
147// Revision 1.4  2009/10/14 19:06:48  acg
148//  Andy Goodrich: changed the way the "copy" of argv is handled. It is
149//  now passed to sc_main, and the original is referenced via argv_copy.
150//
151// Revision 1.3  2008/05/22 17:06:25  acg
152//  Andy Goodrich: updated copyright notice to include 2008.
153//
154// Revision 1.2  2008/04/11 20:41:28  acg
155//  Andy Goodrich: changed the return value in sc_elab_and_sim() to be 1
156//  when an exception occurs in sc_main() rather than 0.
157//
158// Revision 1.1.1.1  2006/12/15 20:20:05  acg
159// SystemC 2.3
160//
161// Revision 1.4  2006/01/25 00:31:19  acg
162//  Andy Goodrich: Changed over to use a standard message id of
163//  SC_ID_IEEE_1666_DEPRECATION for all deprecation messages.
164//
165// Revision 1.3  2006/01/13 18:44:29  acg
166// Added $Log to record CVS changes into the source.
167//
168