OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / main / dynamic / mainDynamic.cxx
1 // mainDynamic.cxx - One possible mainline.  -*- C++ -*-
2
3 // Copyright (C) 1999, 2000 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
6
7 #include "config.h"
8
9 #include <sidcomp.h>
10 #include <sidso.h>
11 #include <sidpinutil.h>
12 #include <sidcomputil.h>
13
14 #include <unistd.h>
15 #ifdef HAVE_GETOPT_H
16 #include <getopt.h>
17 #endif
18
19
20 using namespace std;
21 using namespace sid;
22 using namespace sidutil;
23
24
25 // Link to compConfig component directly.
26 extern component_library /* *not* DLLIMPORT */ config_component_library;
27
28
29 // Stub functions to set breakpoints on
30 static void sid_pre_configure () {}
31 static void sid_post_configure () {}
32 static void sid_pre_run () {}
33 static void sid_post_run () {}
34
35
36
37 void
38 usage ()
39 {
40   cout << "Usage: sid OPTIONS [FILE] ..." << endl;
41   cout << "OPTIONS:" << endl;
42   cout << "-h        print this help" << endl;
43   cout << "-n        load/check configuration but do not run simulation" << endl;
44   cout << "-f FILE   also read configuration FILE" << endl;
45   cout << "-e LINE   also do configuration LINE" << endl;
46   cout << endl;
47   cout << "All -f/-e options are performed first, in sequence." << endl;
48   cout << "FILE names supplied without -f are done last, in sequence." << endl;
49 }
50
51
52 // main line
53 int
54 main(int argc, char* argv[])
55 {
56   vector< pair<bool,string> > config_items;
57   bool dry_run_p = false;
58   string config_file;
59
60   if (argc == 1)
61     {
62       usage();
63       return 1;
64     }
65
66   while (true)
67     {
68       int c = getopt (argc, argv, "hne:f:");
69       if (c == EOF)
70         break;
71
72       switch (c)
73         {
74         case 'h':
75           usage ();
76           return 0;
77           
78         case 'n':
79           dry_run_p = true;
80           break;
81
82         case 'e':
83           config_items.push_back (make_pair (false, string(optarg)));
84           break;
85
86         case 'f':
87           config_items.push_back (make_pair (true, string(optarg)));
88           break;
89
90         default:
91           usage ();
92           return 1;
93         }
94     }
95
96
97   // Treat remaining arguments as file names
98   for (unsigned j=optind; j<argc; j++)
99     {
100       config_items.push_back (make_pair (true, string(argv[j])));
101     }
102
103   component* main_component = 
104     config_component_library.create_component("sid-control-cfgroot");
105   if(main_component == 0)
106     {
107       cerr << "Cannot instantiate configuration root component." << endl;
108       return 2;
109     }
110
111   sid_pre_configure ();
112   // select & load the config file
113   bool config_ok = true;
114
115
116   // NB: There is no problem if config_items is empty.  cfgroot will
117   // abort a run if there are no other configured components.
118
119   for (unsigned k=0; k < config_items.size(); k++)
120     {
121       const pair<bool,string>& item = config_items[k];
122       sid::component::status s;
123
124       if (item.first == true)
125         s = main_component->set_attribute_value ("config-file!", item.second);
126       else
127         s = main_component->set_attribute_value ("config-line!", item.second);
128
129       if(s != sid::component::ok)
130         config_ok = false;
131     }
132
133   if (! config_ok)
134     {
135       cerr << "Configuration error.  Aborting." << endl;
136       return 3;
137     }
138
139   sid_post_configure ();
140
141
142   if (! dry_run_p)
143     {
144       // drive the root's "run" pin.
145       sid_pre_run ();
146       sid::pin* run_pin = main_component->find_pin ("run!");
147       if (! run_pin)
148         {
149           cerr << "Cannot find root run pin." << endl;
150           return 4;
151         }
152       
153       // run the simulation
154       run_pin->driven (0);
155       // the simulation has ended.
156       sid_post_run ();
157     }
158
159   // delete cfgroot and the rest of the world
160   config_component_library.delete_component (main_component);
161 }
162
163
164 #ifndef SID_STATIC
165 // Define a stub lt_preloaded_symbols[], as if libtool's
166 // "--dlpreopen libnull.la" linker option was given (for an empty libnull.la).
167 // This must agree with ltmain.sh & libltdl.
168 struct symbols {
169   const char *name;
170   void* address;
171 };
172 extern struct symbols lt_preloaded_symbols[];
173 struct symbols lt_preloaded_symbols[] = { 0, 0 };
174 #endif // !SID_STATIC
175