1 | #include "cxxexecutor.h"
|
---|
2 |
|
---|
3 | #include <typeinfo>
|
---|
4 |
|
---|
5 | #include "strutilxx.h"
|
---|
6 | #include "dvlist.h"
|
---|
7 | #include "cxxcmplnk.h"
|
---|
8 |
|
---|
9 | #include "nomgadapter.h"
|
---|
10 | #include "pistdimgapp.h"
|
---|
11 |
|
---|
12 |
|
---|
13 | /* --Methode-- */
|
---|
14 | CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
|
---|
15 | : mUserCodeFn(""), mUserFctFn("")
|
---|
16 | , mCompOpt(""), mLinkOpt(""), mMyLibs("")
|
---|
17 | , mDefTmp(""), mDefRoot("cxx_spiapp"), mDefFunc("usercxx"), mPrtLevel(2)
|
---|
18 | {
|
---|
19 | mIncList.resize(0);
|
---|
20 | mCallArgs.resize(0);
|
---|
21 |
|
---|
22 | mIncImportList.resize(0);
|
---|
23 | mModuleImportList.resize(0);
|
---|
24 |
|
---|
25 | // La liste de tous les modules que l'on peut ajouter
|
---|
26 | mModuleImportDefaultList.resize(0);
|
---|
27 | mModuleImportDefaultList.push_back("Samba");
|
---|
28 | mModuleImportDefaultList.push_back("SkyMap");
|
---|
29 | mModuleImportDefaultList.push_back("PMixer");
|
---|
30 |
|
---|
31 | // Gestion des fichiers par default dans TmpDir
|
---|
32 | NamedObjMgr omg;
|
---|
33 | string tmpdir = omg.GetTmpDir();
|
---|
34 | if(tmpdir.size()>1) mDefTmp = tmpdir;
|
---|
35 |
|
---|
36 | // On enregistre les nouvelles commandes
|
---|
37 | string hgrp = "CxxExecutorCmd";
|
---|
38 | string usage,kw;
|
---|
39 |
|
---|
40 | kw = "c++exec";
|
---|
41 | usage = "c++exec: Execute the following c++ user code\n";
|
---|
42 | usage+= "Usage: c++exec c++ user code\n";
|
---|
43 | usage+= "Warning: c++ user code can be found in \"TmpDir/"+mDefRoot+".h\"\n";
|
---|
44 | usage+= " total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
|
---|
45 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
46 |
|
---|
47 | kw = "c++execfrf";
|
---|
48 | usage = "c++execfrf: Execute c++ user_code [user_function_code]\n";
|
---|
49 | usage+= "Usage: c++execfrf fileuser.cc [fileuserfct.cc]\n";
|
---|
50 | usage+= "Warning: total generated code can be found in \"TmpDir/"+mDefRoot+".cc\"";
|
---|
51 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
52 |
|
---|
53 | kw = "c++args";
|
---|
54 | usage = "c++args: Define user function arguments for c++exec and c++execfrf\n";
|
---|
55 | usage+= "Usage: c++args arg1 arg2 arg3 ...\n";
|
---|
56 | usage+= " c++args -? : give current arguments\n";
|
---|
57 | usage+= " c++args : reset current arguments";
|
---|
58 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
59 |
|
---|
60 | kw = "c++create";
|
---|
61 | usage = "c++create: create a file \"file.cc\" to be used by spiapp\n";
|
---|
62 | usage+= "Usage: c++create file.cc func c++ user code...\n";
|
---|
63 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
64 |
|
---|
65 | kw = "c++createfrf";
|
---|
66 | usage = "c++createfrf: create a file \"file.cc\" to be used by spiapp\n";
|
---|
67 | usage+= " with a user file code \"fileuser.cc\"\n";
|
---|
68 | usage+= " and an optional user function code \"fileuserfct.cc\"\n";
|
---|
69 | usage+= "Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]\n";
|
---|
70 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
71 |
|
---|
72 | kw = "c++compile";
|
---|
73 | usage = "c++compile: compile a file (file.cc -> file.so)\n";
|
---|
74 | usage+= "Usage: c++compile file\n";
|
---|
75 | usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n";
|
---|
76 | usage+= " : to be used before c++link";
|
---|
77 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
78 |
|
---|
79 | kw = "c++link";
|
---|
80 | usage = "c++link: link function \"func\" in file.so to spiapp\n";
|
---|
81 | usage+= "Usage: c++link file.so func";
|
---|
82 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
83 |
|
---|
84 | kw = "c++include";
|
---|
85 | usage = "c++include: add personnal includes to be used by executor\n";
|
---|
86 | usage+= "Usage: c++include myinc1.h myinc2.h ...\n";
|
---|
87 | usage+= " c++include -? : list current additionnal include files\n";
|
---|
88 | usage+= " c++include : reset to no additionnal include files\n";
|
---|
89 | usage+= "Warning: to be used before c++create c++compile c++exec...";
|
---|
90 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
91 |
|
---|
92 | kw = "c++compileopt";
|
---|
93 | usage = "c++compileopt: add personnal compile options\n";
|
---|
94 | usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n";
|
---|
95 | usage+= " c++compileopt -? : list current additionnal compile options\n";
|
---|
96 | usage+= " c++compileopt : reset to no additionnal compile options\n";
|
---|
97 | usage+= "Warning: to be used before c++create c++compile c++exec ...";
|
---|
98 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
99 |
|
---|
100 | kw = "c++linkopt";
|
---|
101 | usage = "c++linkopt: add personnal link options\n";
|
---|
102 | usage+= "Usage: c++linkopt -g -O5 ...\n";
|
---|
103 | usage+= " c++linkopt -? : list current additionnal link options\n";
|
---|
104 | usage+= " c++linkopt : reset to no additionnal link options\n";
|
---|
105 | usage+= "Warning: to be used before c++create c++compile c++exec ...";
|
---|
106 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
107 |
|
---|
108 | kw = "c++mylibs";
|
---|
109 | usage = "c++mylibs: add personnal libraries\n";
|
---|
110 | usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n";
|
---|
111 | usage+= " c++mylibs -? : list current additionnal libraries\n";
|
---|
112 | usage+= " c++mylibs : reset to no additionnal libraries\n";
|
---|
113 | usage+= "Warning: to be used before c++create c++compile c++exec ...";
|
---|
114 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
115 |
|
---|
116 | kw = "c++import";
|
---|
117 | usage = "c++import: Sophya additionnal modules to be use in C++ executor\n";
|
---|
118 | usage+= "Usage: c++import module1 ... : set list of modules to be used by executor\n";
|
---|
119 | usage+= " c++import all : set all modules known by executor\n";
|
---|
120 | usage+= " c++import : reset to no additionnal module\n";
|
---|
121 | usage+= " c++import -? : list modules currently used in executor\n";
|
---|
122 | usage+= " c++import -?? : list of available modules for executor\n";
|
---|
123 | usage+= "Warning: to be used before c++create c++compile c++exec ...";
|
---|
124 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
125 |
|
---|
126 | kw = "c++prtlevel";
|
---|
127 | usage = "c++prtlevel: Print level\n";
|
---|
128 | usage+= "Usage: c++prtlevel prtlevel\n";
|
---|
129 | usage+= " prtlevel=0 : minimum printing\n";
|
---|
130 | usage+= " prtlevel=1 : + compiler/linker output\n";
|
---|
131 | usage+= " prtlevel=2 : + full infos (default)";
|
---|
132 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
133 |
|
---|
134 | }
|
---|
135 |
|
---|
136 | /* --Methode-- */
|
---|
137 | CxxExecutor::~CxxExecutor()
|
---|
138 | {
|
---|
139 | }
|
---|
140 |
|
---|
141 | /* --Methode-- */
|
---|
142 | int CxxExecutor::Execute(string& kw, vector<string>& tokens, string& toks)
|
---|
143 | {
|
---|
144 | int rc=0;
|
---|
145 | if(kw == "c++exec") {
|
---|
146 | if(tokens.size()<1) {
|
---|
147 | cout<<"Usage: c++exec c++ user code"<<endl;
|
---|
148 | return(1);
|
---|
149 | }
|
---|
150 | rc = ExecuteCXX(toks); if(rc) return(1);
|
---|
151 |
|
---|
152 | } else if(kw == "c++execfrf") {
|
---|
153 | if(tokens.size()<1) {
|
---|
154 | cout<<"Usage: c++execfrf fileuser.cc [fileuserfct.cc]"<<endl;
|
---|
155 | return(1);
|
---|
156 | }
|
---|
157 | rc = FillUserCode(tokens[0]); if(rc) return(1);
|
---|
158 | if(tokens.size()>1) rc = FillUserFctFrF(tokens[1]);
|
---|
159 | else rc = FillUserFctFrF();
|
---|
160 | if(rc) return(1);
|
---|
161 | rc = CrFile(); if(rc) return(1);
|
---|
162 | rc = Compile(); if(rc) return(1);
|
---|
163 | rc = Link(); if(rc) return(1);
|
---|
164 | rc = Call(); if(rc) return(1);
|
---|
165 |
|
---|
166 | } else if(kw == "c++args") {
|
---|
167 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
168 | {cout<<"c++args "<<GetArgs()<<endl; return(0);}
|
---|
169 | FillArgs(tokens);
|
---|
170 |
|
---|
171 | } else if(kw == "c++create") {
|
---|
172 | if(tokens.size()<3) {
|
---|
173 | cout<<"Usage: c++create file.cc func c++ user code ..."<<endl;
|
---|
174 | return(1);
|
---|
175 | }
|
---|
176 | rc = FillUserCode(toks,2); if(rc) return(1);
|
---|
177 | rc = FillUserFctFrS(); if(rc) return(1);
|
---|
178 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
179 |
|
---|
180 | } else if(kw == "c++createfrf") {
|
---|
181 | if(tokens.size()<3) {
|
---|
182 | cout<<"Usage: c++createfrf file.cc func fileuser.cc [fileuserfct.cc]"<<endl;
|
---|
183 | return(1);
|
---|
184 | }
|
---|
185 | rc = FillUserCode(tokens[2]); if(rc) return(1);
|
---|
186 | if(tokens.size()>3) rc = FillUserFctFrF(tokens[3]);
|
---|
187 | else rc = FillUserFctFrF(tokens[3]);
|
---|
188 | if(rc) return(1);
|
---|
189 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
190 |
|
---|
191 | } else if(kw == "c++compile") {
|
---|
192 | if(tokens.size()>=1) rc = Compile(tokens[0]);
|
---|
193 | else rc = Compile();
|
---|
194 | if(rc) return(1);
|
---|
195 |
|
---|
196 | } else if(kw == "c++link") {
|
---|
197 | if(tokens.size()>=2) rc = Link(tokens[0],tokens[1]);
|
---|
198 | else if(tokens.size()>=1) rc = Link(tokens[0]);
|
---|
199 | else rc = Link();
|
---|
200 | if(rc) return(1);
|
---|
201 |
|
---|
202 | } else if(kw == "c++include") {
|
---|
203 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
204 | {cout<<"c++include "<<GetInclude()<<endl; return(0);}
|
---|
205 | FillInclude(tokens);
|
---|
206 |
|
---|
207 | } else if(kw == "c++compileopt") {
|
---|
208 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
209 | {cout<<"c++compileopt "<<GetCompileOpt()<<endl; return(0);}
|
---|
210 | FillCompileOpt(tokens);
|
---|
211 |
|
---|
212 | } else if(kw == "c++linkopt") {
|
---|
213 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
214 | {cout<<"c++linkopt "<<GetLinkOpt()<<endl; return(0);}
|
---|
215 | FillLinkOpt(tokens);
|
---|
216 |
|
---|
217 | } else if(kw == "c++mylibs") {
|
---|
218 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
219 | {cout<<"c++mylibs "<<GetLinkLibs()<<endl; return(0);}
|
---|
220 | FillLinkLibs(tokens);
|
---|
221 |
|
---|
222 | } else if(kw == "c++import") {
|
---|
223 | if(tokens.size()==1) {
|
---|
224 | if(tokens[0]=="-?")
|
---|
225 | {cout<<"c++import "<<GetModuleImport()<<endl; return(0);}
|
---|
226 | if(tokens[0]=="-??") {
|
---|
227 | cout<<"c++import possibilities :"<<endl;
|
---|
228 | if(mModuleImportDefaultList.size()>0) {
|
---|
229 | for(uint_4 i=0;i<mModuleImportDefaultList.size();i++)
|
---|
230 | cout<<" "<<mModuleImportDefaultList[i];
|
---|
231 | cout<<endl;
|
---|
232 | }
|
---|
233 | return(0);
|
---|
234 | }
|
---|
235 | }
|
---|
236 | FillModuleImport(tokens);
|
---|
237 |
|
---|
238 | } else if(kw == "c++prtlevel") {
|
---|
239 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
240 | {cout<<"c++prtlevel prtlevel = "<<mPrtLevel<<endl; return(0);}
|
---|
241 | if(tokens.size()>0) {
|
---|
242 | int lp=atoi(tokens[0].c_str()); if(lp<0) lp=0;
|
---|
243 | mPrtLevel=(uint_2) lp;
|
---|
244 | } else mPrtLevel=2;
|
---|
245 |
|
---|
246 | }
|
---|
247 |
|
---|
248 | return(0);
|
---|
249 | }
|
---|
250 |
|
---|
251 | /* --Methode-- */
|
---|
252 | int CxxExecutor::ExecuteCXX(string usercode,string userfct)
|
---|
253 | {
|
---|
254 | int rc=0;
|
---|
255 | rc = FillUserCode(usercode,0); if(rc) return(1);
|
---|
256 | rc = FillUserFctFrS(userfct); if(rc) return(1);
|
---|
257 | rc = CrFile(); if(rc) return(1);
|
---|
258 | rc = Compile(); if(rc) return(1);
|
---|
259 | rc = Link(); if(rc) return(1);
|
---|
260 | rc = Call(); if(rc) return(1);
|
---|
261 | return 0;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /* --Methode-- */
|
---|
265 | int CxxExecutor::CrFile(string cfilename,string func)
|
---|
266 | // Si un nom n'est pas precise alors TmpDir/cxx_spiapp.cc
|
---|
267 | {
|
---|
268 | if(cfilename.size()<1) cfilename = mDefTmp + mDefRoot + ".cc";
|
---|
269 |
|
---|
270 | if(func.size()<1) func = mDefFunc;
|
---|
271 |
|
---|
272 | ofstream os(cfilename.c_str(),ios::out);
|
---|
273 | if(!os)
|
---|
274 | {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl;
|
---|
275 | return 1;}
|
---|
276 |
|
---|
277 | PutInclude(os);
|
---|
278 | os<<endl;
|
---|
279 |
|
---|
280 | PutIncludeUser(os);
|
---|
281 | os<<endl;
|
---|
282 |
|
---|
283 | os<<"//-------------------------------------------------//"<<endl;
|
---|
284 | os<<"//----------------- User Functions ----------------//"<<endl;
|
---|
285 | os<<"//-------------------------------------------------//"<<endl;
|
---|
286 | if(mUserFctFn.size()>0) os<<"#include \""<<mUserFctFn<<"\""<<endl;
|
---|
287 | os<<endl;
|
---|
288 |
|
---|
289 |
|
---|
290 | os<<"extern \"C\" {"<<endl;
|
---|
291 | os<<" int "<<func<<"( vector<string>& args );"<<endl;
|
---|
292 | os<<"}"<<endl<<endl;
|
---|
293 | os<<"int "<<func<<"( vector<string>& args )"<<endl;
|
---|
294 | os<<"{"<<endl;
|
---|
295 | os<<"// Some definitions to help using spiapp;"<<endl;
|
---|
296 | os<<"NamedObjMgr omg;"<<endl;
|
---|
297 | os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl;
|
---|
298 | os<<endl;
|
---|
299 |
|
---|
300 | PutObject(os);
|
---|
301 | os<<endl;
|
---|
302 |
|
---|
303 | PutVar(os);
|
---|
304 | os<<endl;
|
---|
305 |
|
---|
306 | os<<"//--------------------------------------------//"<<endl;
|
---|
307 | os<<"//----------------- User Code ----------------//"<<endl;
|
---|
308 | os<<"//--------------------------------------------//"<<endl;
|
---|
309 | if(mUserCodeFn.size()>0) os<<"#include \""<<mUserCodeFn<<"\""<<endl;
|
---|
310 | os<<endl;
|
---|
311 |
|
---|
312 | os<<"return 0;"<<endl;
|
---|
313 | os<<"}"<<endl;
|
---|
314 |
|
---|
315 | if(mPrtLevel>1)
|
---|
316 | cout<<"File "<<cfilename<<" for function "<<func<<" created :"<<endl;
|
---|
317 | if(mPrtLevel>1 && mUserCodeFn.size()>0)
|
---|
318 | cout<<" User code was in file "<<mUserCodeFn<<endl;
|
---|
319 | if(mPrtLevel>1 && mUserFctFn.size()>0)
|
---|
320 | cout<<" User function code was in file "<<mUserFctFn<<endl;
|
---|
321 | return 0;
|
---|
322 | }
|
---|
323 |
|
---|
324 | /* --Methode-- */
|
---|
325 | void CxxExecutor::PutInclude(ofstream& os)
|
---|
326 | {
|
---|
327 | os<<"#include \"machdefs.h\""<<endl<<endl;
|
---|
328 |
|
---|
329 | os<<"//---- System et stdc++ include files"<<endl
|
---|
330 | <<"#include <stdio.h>"<<endl
|
---|
331 | <<"#include <stdlib.h>"<<endl
|
---|
332 | <<"#include <math.h>"<<endl
|
---|
333 | <<"#include <ctype.h>"<<endl
|
---|
334 | <<"#include <string.h>"<<endl
|
---|
335 | <<"#include <iostream.h>"<<endl
|
---|
336 | <<"#include <fstream.h>"<<endl
|
---|
337 | <<"#include <complex>"<<endl
|
---|
338 | <<endl
|
---|
339 |
|
---|
340 | <<"#include <typeinfo>"<<endl
|
---|
341 | <<"#include <string>"<<endl
|
---|
342 | <<"#include <vector>"<<endl
|
---|
343 | <<"#include <map>"<<endl
|
---|
344 | <<"#include <functional>"<<endl
|
---|
345 | <<"#include <list>"<<endl
|
---|
346 | <<endl
|
---|
347 |
|
---|
348 | <<"//---- Sophya include files"<<endl
|
---|
349 | <<"#include \"systools.h\""<<endl
|
---|
350 | <<"#include \"ntools.h\""<<endl
|
---|
351 | <<"#include \"array.h\""<<endl
|
---|
352 | <<"#include \"histats.h\""<<endl
|
---|
353 | <<endl
|
---|
354 |
|
---|
355 | <<"//---- Spiapp include files"<<endl
|
---|
356 | <<"#include \"nobjmgr.h\""<<endl
|
---|
357 | <<"#include \"servnobjm.h\""<<endl
|
---|
358 | <<endl;
|
---|
359 |
|
---|
360 | os<<"//---- Include files from additionnal modules"<<endl;
|
---|
361 | if(mIncImportList.size()>0)
|
---|
362 | for(uint_4 i=0;i<mIncImportList.size();i++)
|
---|
363 | os<<"#include \""<<mIncImportList[i]<<"\""<<endl;
|
---|
364 | os<<endl;
|
---|
365 |
|
---|
366 | os<<"//---- Objects and variables saving"<<endl
|
---|
367 | <<"#define KeepObj(obj) ___nomobj = #obj; omg.AddObj(obj,___nomobj);"<<endl
|
---|
368 | <<"#define KeepVar(var) ___nomobj = #var; omg.GetVarList().Get(___nomobj) = var ;"<<endl
|
---|
369 | <<endl;
|
---|
370 |
|
---|
371 | return;
|
---|
372 | }
|
---|
373 |
|
---|
374 | /* --Methode-- */
|
---|
375 | void CxxExecutor::PutIncludeUser(ofstream& os)
|
---|
376 | {
|
---|
377 | if(mIncList.size()<1) return;
|
---|
378 | for(uint_4 i=0;i<mIncList.size();i++)
|
---|
379 | os<<"#include \""<<mIncList[i]<<"\""<<endl;
|
---|
380 | }
|
---|
381 |
|
---|
382 | /* --Methode-- */
|
---|
383 | void CxxExecutor::PutObject(ofstream& os)
|
---|
384 | {
|
---|
385 | NamedObjMgr omg;
|
---|
386 | NObjMgrAdapter* objmgrad;
|
---|
387 | vector<string> objlist;
|
---|
388 | string patt = "*";
|
---|
389 | omg.GetObjList(patt,objlist);
|
---|
390 | int nobjs = objlist.size();
|
---|
391 |
|
---|
392 | os<<"//-------------- Object List --------------"<<endl;
|
---|
393 | os<<"//Number of objects = "<<nobjs<<endl;
|
---|
394 | os<<"string ___nomobj;"<<endl<<endl;
|
---|
395 | if(nobjs<=0) return;
|
---|
396 |
|
---|
397 | string dir,nobj,stmp,obtype;
|
---|
398 | for(int i=0;i<nobjs;i++) {
|
---|
399 | objmgrad = omg.GetObjAdapter(objlist[i]);
|
---|
400 | omg.ParseObjectName(objlist[i],dir,nobj);
|
---|
401 | obtype = objmgrad->GetDataObjType();
|
---|
402 | stmp = "___" + nobj;
|
---|
403 |
|
---|
404 | os<<"___nomobj = \""<<nobj<<"\";"<<endl;
|
---|
405 | os<<obtype<<"* "<<stmp
|
---|
406 | <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl;
|
---|
407 | os<<"if("<<stmp<<"==NULL) throw NullPtrError"
|
---|
408 | <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj
|
---|
409 | <<"... please update file\");"<<endl;
|
---|
410 | os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl;
|
---|
411 | }
|
---|
412 |
|
---|
413 | return;
|
---|
414 | }
|
---|
415 |
|
---|
416 | /* --Methode-- */
|
---|
417 | void CxxExecutor::PutVar(ofstream& os)
|
---|
418 | {
|
---|
419 | os<<"//-------------- Variable List --------------"<<endl;
|
---|
420 | NamedObjMgr omg;
|
---|
421 | DVList& varlist = omg.GetVarList();
|
---|
422 | // varlist.Show(); varlist.Print();
|
---|
423 | DVList::ValList::const_iterator it;
|
---|
424 | for(it=varlist.Begin(); it!=varlist.End(); it++) {
|
---|
425 | string key = (*it).first;
|
---|
426 | if (isalpha(key[0]) ) {
|
---|
427 | os<<"___nomobj = \""<<key<<"\";"<<endl;
|
---|
428 | os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl;
|
---|
429 | }
|
---|
430 | }
|
---|
431 |
|
---|
432 | return;
|
---|
433 | }
|
---|
434 |
|
---|
435 | /* --Methode-- */
|
---|
436 | int CxxExecutor::FillUserCode(string& usercode,uint_4 first)
|
---|
437 | // User code is read from input.
|
---|
438 | // - first is the first position in the "string" where the code starts
|
---|
439 | // - Code is put into file "TmpDir/cxx_spiapp.h".
|
---|
440 | {
|
---|
441 | mUserCodeFn = "";
|
---|
442 |
|
---|
443 | // get the string part which is after word "first"
|
---|
444 | string code = usercode;
|
---|
445 | if(code.size()<=0) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
|
---|
446 | return 1;}
|
---|
447 | size_t q;
|
---|
448 | for(uint_4 i=0;i<=first;i++) {
|
---|
449 | q = code.find_first_not_of(" \t");
|
---|
450 | if(q>=code.size()) {code=""; break;}
|
---|
451 | code = code.substr(q);
|
---|
452 | if(i==first) break;
|
---|
453 | q = code.find_first_of(" \t");
|
---|
454 | if(q>=code.size()) {code=""; break;}
|
---|
455 | code = code.substr(q);
|
---|
456 | }
|
---|
457 | if(code.size()<=0)
|
---|
458 | {cout<<"CxxExecutor::FillUserCode: no user code after "<<first<<endl;
|
---|
459 | return 1;}
|
---|
460 |
|
---|
461 | // Fill the file with user code
|
---|
462 | mUserCodeFn = mDefTmp + mDefRoot + ".h";
|
---|
463 | ofstream os(mUserCodeFn.c_str(),ios::out);
|
---|
464 | if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open "
|
---|
465 | <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;}
|
---|
466 | os<<code<<endl;
|
---|
467 | if(mPrtLevel>1)
|
---|
468 | cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
|
---|
469 | return 0;
|
---|
470 | }
|
---|
471 |
|
---|
472 | /* --Methode-- */
|
---|
473 | int CxxExecutor::FillUserFctFrS(string userfctcode)
|
---|
474 | // - Fill user Fonction code from string "userfct"
|
---|
475 | // - Code is put into file "TmpDir/cxx_spiapp_fct.h".
|
---|
476 | {
|
---|
477 | mUserFctFn = "";
|
---|
478 | if(userfctcode.size()<1) return 0;
|
---|
479 | mUserFctFn = mDefTmp + mDefRoot + "_fct.h";
|
---|
480 | ofstream os(mUserFctFn.c_str(),ios::out);
|
---|
481 | if(!os) {cout<<"CxxExecutor::FillUserFctFrS: unable to open "
|
---|
482 | <<mUserFctFn<<endl; mUserFctFn = ""; return 1;}
|
---|
483 | os<<userfctcode<<endl;
|
---|
484 | if(mPrtLevel>1)
|
---|
485 | cout<<"User Function code filled from standard input into "<<mUserFctFn<<endl;
|
---|
486 | return 0;
|
---|
487 | }
|
---|
488 |
|
---|
489 | /* --Methode-- */
|
---|
490 | int CxxExecutor::FillUserCode(string filename)
|
---|
491 | // User code is read from "filename".
|
---|
492 | {
|
---|
493 | mUserCodeFn = filename;
|
---|
494 | if(mPrtLevel>1 && mUserCodeFn.size()>0)
|
---|
495 | cout<<"User code filled from file "<<mUserCodeFn<<endl;
|
---|
496 | return 0;
|
---|
497 | }
|
---|
498 |
|
---|
499 | /* --Methode-- */
|
---|
500 | int CxxExecutor::FillUserFctFrF(string filefctname)
|
---|
501 | // User function code is read from "filefctname".
|
---|
502 | {
|
---|
503 | mUserFctFn = filefctname;
|
---|
504 | if(mPrtLevel>1 && mUserFctFn.size()>0)
|
---|
505 | cout<<"User Function code filled from file "<<mUserFctFn<<endl;
|
---|
506 | return 0;
|
---|
507 | }
|
---|
508 |
|
---|
509 | /* --Methode-- */
|
---|
510 | int CxxExecutor::Compile(string rootfilename)
|
---|
511 | //--------------------------------------------------------//
|
---|
512 | // rootfilename = | name | "" ou (default) //
|
---|
513 | //--------------------------------------------------------//
|
---|
514 | // fichier .cc | name.cc | TmpDir/cxx_spiapp.cc //
|
---|
515 | // | ../dir/name.cc | //
|
---|
516 | // fichier .o | TmpDir/name.o | TmpDir/cxx_spiapp.o //
|
---|
517 | // fichier .so | TmpDir/name.so | TmpDir/cxx_spiapp.so //
|
---|
518 | //--------------------------------------------------------//
|
---|
519 | {
|
---|
520 | if(rootfilename.size()<1) rootfilename = mDefTmp + mDefRoot;
|
---|
521 | if(mPrtLevel>1) cout<<"Compile "<<rootfilename<<endl;
|
---|
522 |
|
---|
523 | int rc;
|
---|
524 | CxxCompilerLinker cxx;
|
---|
525 | if(mDefTmp.size()>0) cxx.SetTmpDir(mDefTmp);
|
---|
526 | if(mPrtLevel>0) cxx.SetVerbose(true);
|
---|
527 | else cxx.SetVerbose(false);
|
---|
528 |
|
---|
529 | // Compilation
|
---|
530 | string fcc = rootfilename + ".cc";
|
---|
531 | string fo = "";
|
---|
532 | cxx.AddCompileOptions(mCompOpt);
|
---|
533 | rc = cxx.Compile(fcc,fo);
|
---|
534 | if(mPrtLevel>1) cout << "Compilation rc = "<<rc<< endl;
|
---|
535 | if(rc) return 1;
|
---|
536 |
|
---|
537 | // Fabrication Shared Lib.
|
---|
538 | string fso = "";
|
---|
539 | cxx.AddLinkOptions(mLinkOpt);
|
---|
540 | #ifdef SANS_EVOLPLANCK
|
---|
541 | string sophlib = "-lPIE";
|
---|
542 | #else
|
---|
543 | string sophlib = "-lPI";
|
---|
544 | #endif
|
---|
545 | cxx.AddLinkOptions(sophlib);
|
---|
546 | cxx.AddLinkOptions(mMyLibs);
|
---|
547 | rc = cxx.BuildSO(fo,fso);
|
---|
548 | if(mPrtLevel>1) cout << "Shared Library rc = "<<rc<< endl;
|
---|
549 | if(rc) return 2;
|
---|
550 |
|
---|
551 | return 0;
|
---|
552 | }
|
---|
553 |
|
---|
554 | /* --Methode-- */
|
---|
555 | //int CxxExecutor::Compile(string rootfilename)
|
---|
556 | // Ne marche pas si TmpDir != ""
|
---|
557 | //{
|
---|
558 | //if(rootfilename.size()<1) rootfilename = mDefRoot;
|
---|
559 | //if(mPrtLevel>1) cout<<"Compile: "<<rootfilename<<endl;
|
---|
560 | //int rc = 0;
|
---|
561 | //rc = CrMakefile();
|
---|
562 | //if(rc) return(1);
|
---|
563 | //string make = "";
|
---|
564 | //make += "make -f " + mDefRoot + "_Makefile";
|
---|
565 | //make += " CXXFLAGS=\"" + mCompOpt + "\"";
|
---|
566 | //make += " LDFLAGS=\"" + mLinkOpt + "\"";
|
---|
567 | //make += " MYLIBS=\"" + mMyLibs + "\"";
|
---|
568 | //make += " " + rootfilename;
|
---|
569 | //rc = system(make.c_str());
|
---|
570 | //if(rc)
|
---|
571 | // {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
|
---|
572 | // return 1000+rc;}
|
---|
573 | //return 0;
|
---|
574 | //}
|
---|
575 |
|
---|
576 | /* --Methode-- */
|
---|
577 | //int CxxExecutor::CrMakefile(void)
|
---|
578 | // Ne marche pas si TmpDir != ""
|
---|
579 | //{
|
---|
580 | //string makename = mDefTmp + mDefRoot + "_Makefile";
|
---|
581 | //ofstream os(makename.c_str(),ios::out);
|
---|
582 | //if(!os)
|
---|
583 | // {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
|
---|
584 | // return 1;}
|
---|
585 | //---------------------------------------------------------------------
|
---|
586 | //os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
|
---|
587 | //os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
|
---|
588 | //os<<"MYLIBS ="<<endl;
|
---|
589 | //os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
|
---|
590 | //os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
|
---|
591 | //os<<"LIBS := $(LIBS) -lfor"<<endl;
|
---|
592 | //os<<"endif"<<endl;
|
---|
593 | //os<<"ifeq ($(MACHEROS),Linux)"<<endl;
|
---|
594 | //os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
|
---|
595 | //os<<"endif"<<endl;
|
---|
596 | //os<<"%.so:%.o"<<endl;
|
---|
597 | //os<<"%:%.cc"<<endl;
|
---|
598 | //os<<"%:%.o"<<endl;
|
---|
599 | //os<<"%.o:%.cc"<<endl;
|
---|
600 | //os<<"%.o:%.c"<<endl;
|
---|
601 | //os<<"%:%.c"<<endl;
|
---|
602 | //os<<endl;
|
---|
603 | //os<<".PRECIOUS: %.so"<<endl;
|
---|
604 | //os<<endl;
|
---|
605 | //os<<"%:%.so"<<endl;
|
---|
606 | //os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
|
---|
607 | //os<<"%.so:%.o"<<endl;
|
---|
608 | //os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
|
---|
609 | //os<<"%.o:%.cc"<<endl;
|
---|
610 | //os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
|
---|
611 | //os<<"%.o:%.c"<<endl;
|
---|
612 | //os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
|
---|
613 | //---------------------------------------------------------------------
|
---|
614 | //return 0;
|
---|
615 | //}
|
---|
616 |
|
---|
617 | /* --Methode-- */
|
---|
618 | int CxxExecutor::Link(string libname,string func)
|
---|
619 | {
|
---|
620 | if(libname.size()<1) libname = mDefTmp + mDefRoot + ".so";
|
---|
621 | else libname = mDefTmp + libname;
|
---|
622 | if(func.size()<1) func = mDefFunc;
|
---|
623 |
|
---|
624 | NamedObjMgr omg;
|
---|
625 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
626 |
|
---|
627 | string key("linkff2");
|
---|
628 | vector<string> arg; arg.push_back(libname); arg.push_back(func);
|
---|
629 | string toks = libname + " " + func;
|
---|
630 | int rc = mpiac->ExecuteCommand(key,arg,toks);
|
---|
631 | if(mPrtLevel>1) cout<<"Link from "<<libname<<" for function "<<func
|
---|
632 | <<" (rc="<<rc<<")"<<endl;
|
---|
633 | return 0;
|
---|
634 | }
|
---|
635 |
|
---|
636 | /* --Methode-- */
|
---|
637 | int CxxExecutor::Call(string func)
|
---|
638 | {
|
---|
639 | if(func.size()<1) func = mDefFunc;
|
---|
640 |
|
---|
641 | NamedObjMgr omg;
|
---|
642 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
643 |
|
---|
644 | string key("call");
|
---|
645 | vector<string> arg; arg.push_back(func);
|
---|
646 | string toks = func;
|
---|
647 | if(mCallArgs.size()>0)
|
---|
648 | for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);
|
---|
649 | mpiac->ExecuteCommand(key,arg,toks);
|
---|
650 | return 0;
|
---|
651 | }
|
---|
652 |
|
---|
653 | /* --Methode-- */
|
---|
654 | void CxxExecutor::FillArgs(vector<string>& args)
|
---|
655 | {
|
---|
656 | mCallArgs.resize(0);
|
---|
657 | if(args.size()<1) return;
|
---|
658 | for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]);
|
---|
659 | }
|
---|
660 |
|
---|
661 | void CxxExecutor::FillArgs(string& args)
|
---|
662 | {
|
---|
663 | mCallArgs.resize(0);
|
---|
664 | FillVStringFrString(args,mCallArgs,' ');
|
---|
665 | }
|
---|
666 |
|
---|
667 | string CxxExecutor::GetArgs(void)
|
---|
668 | {
|
---|
669 | string dum = "";
|
---|
670 | if(mCallArgs.size()<1) return dum;
|
---|
671 | for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " ";
|
---|
672 | return dum;
|
---|
673 | }
|
---|
674 |
|
---|
675 | /* --Methode-- */
|
---|
676 | void CxxExecutor::FillInclude(vector<string>& inc)
|
---|
677 | {
|
---|
678 | mIncList.resize(0);
|
---|
679 | if(inc.size()<1) return;
|
---|
680 | for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]);
|
---|
681 | }
|
---|
682 |
|
---|
683 | void CxxExecutor::FillInclude(string& inc)
|
---|
684 | {
|
---|
685 | mIncList.resize(0);
|
---|
686 | FillVStringFrString(inc,mIncList,' ');
|
---|
687 | }
|
---|
688 |
|
---|
689 | string CxxExecutor::GetInclude(void)
|
---|
690 | {
|
---|
691 | string dum = "";
|
---|
692 | if(mIncList.size()<1) return dum;
|
---|
693 | for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " ";
|
---|
694 | return dum;
|
---|
695 | }
|
---|
696 |
|
---|
697 | /* --Methode-- */
|
---|
698 | void CxxExecutor::FillCompileOpt(vector<string>& copt)
|
---|
699 | {
|
---|
700 | mCompOpt = "";
|
---|
701 | if(copt.size()<1) return;
|
---|
702 | for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " ";
|
---|
703 | }
|
---|
704 |
|
---|
705 | void CxxExecutor::FillCompileOpt(string& copt)
|
---|
706 | {
|
---|
707 | mCompOpt = copt;
|
---|
708 | }
|
---|
709 |
|
---|
710 | string CxxExecutor::GetCompileOpt(void)
|
---|
711 | {
|
---|
712 | return mCompOpt;
|
---|
713 | }
|
---|
714 |
|
---|
715 | /* --Methode-- */
|
---|
716 | void CxxExecutor::FillLinkOpt(vector<string>& lopt)
|
---|
717 | {
|
---|
718 | mLinkOpt = "";
|
---|
719 | if(lopt.size()<1) return;
|
---|
720 | for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " ";
|
---|
721 | }
|
---|
722 |
|
---|
723 | void CxxExecutor::FillLinkOpt(string& lopt)
|
---|
724 | {
|
---|
725 | mLinkOpt = lopt;
|
---|
726 | }
|
---|
727 |
|
---|
728 | string CxxExecutor::GetLinkOpt(void)
|
---|
729 | {
|
---|
730 | return mLinkOpt;
|
---|
731 | }
|
---|
732 |
|
---|
733 | /* --Methode-- */
|
---|
734 | void CxxExecutor::FillLinkLibs(vector<string>& llibs)
|
---|
735 | {
|
---|
736 | mMyLibs = "";
|
---|
737 | if(llibs.size()<1) return;
|
---|
738 | for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " ";
|
---|
739 | }
|
---|
740 |
|
---|
741 | void CxxExecutor::FillLinkLibs(string& llibs)
|
---|
742 | {
|
---|
743 | mMyLibs = llibs;
|
---|
744 | }
|
---|
745 |
|
---|
746 | string CxxExecutor::GetLinkLibs(void)
|
---|
747 | {
|
---|
748 | return mMyLibs;
|
---|
749 | }
|
---|
750 |
|
---|
751 | /* --Methode-- */
|
---|
752 | void CxxExecutor::FillModuleImport(vector<string>& import)
|
---|
753 | {
|
---|
754 | mModuleImportList.resize(0);
|
---|
755 | mIncImportList.resize(0);
|
---|
756 | if(import.size()<1) return;
|
---|
757 |
|
---|
758 | if(import[0]=="all" || import[0]=="All" || import[0]=="ALL") {
|
---|
759 | mModuleImportList = mModuleImportDefaultList;
|
---|
760 | } else {
|
---|
761 | for(uint_4 i=0;i<import.size();i++) mModuleImportList.push_back(import[i]);
|
---|
762 | }
|
---|
763 |
|
---|
764 | // Set additionnal Includes
|
---|
765 | if(mModuleImportList.size()>0)
|
---|
766 | for(uint_4 i=0;i<mModuleImportList.size();i++) {
|
---|
767 | if( mModuleImportList[i]=="Samba") mIncImportList.push_back("samba.h");
|
---|
768 | else if(mModuleImportList[i]=="SkyMap") mIncImportList.push_back("skymap.h");
|
---|
769 | else if(mModuleImportList[i]=="PMixer") mIncImportList.push_back("pmixer.h");
|
---|
770 | }
|
---|
771 |
|
---|
772 | return;
|
---|
773 | }
|
---|
774 |
|
---|
775 | void CxxExecutor::FillModuleImport(string& import)
|
---|
776 | {
|
---|
777 | mModuleImportList.resize(0);
|
---|
778 | vector<string> vsimport;
|
---|
779 | FillVStringFrString(import,vsimport,' ');
|
---|
780 | FillModuleImport(vsimport);
|
---|
781 | }
|
---|
782 |
|
---|
783 | string CxxExecutor::GetModuleImport(void)
|
---|
784 | {
|
---|
785 | string dum = "";
|
---|
786 | if(mModuleImportList.size()<1) return dum;
|
---|
787 | for(uint_4 i=0;i<mModuleImportList.size();i++) dum += mModuleImportList[i] + " ";
|
---|
788 | return dum;
|
---|
789 | }
|
---|