1 | #include "cxxexecutor.h"
|
---|
2 |
|
---|
3 | #include <typeinfo>
|
---|
4 |
|
---|
5 | #include "strutilxx.h"
|
---|
6 | #include "dvlist.h"
|
---|
7 |
|
---|
8 | #include "nomgadapter.h"
|
---|
9 | #include "pistdimgapp.h"
|
---|
10 |
|
---|
11 |
|
---|
12 | /* --Methode-- */
|
---|
13 | CxxExecutor::CxxExecutor(PIACmd *mpiac, PIStdImgApp* /* app */)
|
---|
14 | : mUserCodeFn(""), mCompOpt(""), mLinkOpt(""), mMyLibs("")
|
---|
15 | {
|
---|
16 | mIncList.resize(0);
|
---|
17 | mCallArgs.resize(0);
|
---|
18 |
|
---|
19 | // On enregistre les nouvelles commandes
|
---|
20 | string hgrp = "CxxExecutorCmd";
|
---|
21 | string usage,kw;
|
---|
22 |
|
---|
23 | kw = "c++exec";
|
---|
24 | usage = "c++exec: Execute the following c++ user code\n";
|
---|
25 | usage+= "Usage: c++exec c++ user code\n";
|
---|
26 | usage+= "Warning: c++ user code can be found in \"cxx_spiapp.h\"\n";
|
---|
27 | usage+= " total generated code can be found in \"cxx_spiapp.cc\"";
|
---|
28 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
29 |
|
---|
30 | kw = "c++execfrf";
|
---|
31 | usage = "c++execfrf: Execute c++ user code contained in a file\n";
|
---|
32 | usage+= "Usage: c++execfrf fileuser.cc\n";
|
---|
33 | usage+= "Warning: total generated code can be found in \"cxx_spiapp.cc\"";
|
---|
34 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
35 |
|
---|
36 | kw = "c++args";
|
---|
37 | usage = "c++args: Define user function arguments for c++exec and c++execfrf\n";
|
---|
38 | usage+= "Usage: c++args arg1 arg2 arg3 ...\n";
|
---|
39 | usage+= " c++args -? : give current arguments\n";
|
---|
40 | usage+= " c++args : reset current arguments";
|
---|
41 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
42 |
|
---|
43 | kw = "c++create";
|
---|
44 | usage = "c++create: create a file to be used by spiapp\n";
|
---|
45 | usage+= "Usage: c++create file.cc func c++ user code...\n";
|
---|
46 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
47 |
|
---|
48 | kw = "c++createfrf";
|
---|
49 | usage = "c++createfrf: create a file \"file.cc\"to be used by spiapp\n";
|
---|
50 | usage+= " with a user file \"fileuser.cc\"\n";
|
---|
51 | usage+= "Usage: c++createfrf file.cc func fileuser.cc\n";
|
---|
52 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
53 |
|
---|
54 | kw = "c++compile";
|
---|
55 | usage = "c++compile: compile a file (file.cc -> file.so)\n";
|
---|
56 | usage+= "Usage: c++compile file\n";
|
---|
57 | usage+= "Warning: give \"file\" or \"file.so\" to create \"file.so\" from \"file.cc\"\n";
|
---|
58 | usage+= " : to be used before c++link";
|
---|
59 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
60 |
|
---|
61 | kw = "c++link";
|
---|
62 | usage = "c++link: link function \"func\" in file.so to spiapp\n";
|
---|
63 | usage+= "Usage: c++link file.so func";
|
---|
64 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
65 |
|
---|
66 | kw = "c++include";
|
---|
67 | usage = "c++include: give personnal includes to be used\n";
|
---|
68 | usage+= "Usage: c++include myinc1.h myinc2.h ...\n";
|
---|
69 | usage+= " c++include -? : give current include files\n";
|
---|
70 | usage+= " c++include : reset current include files\n";
|
---|
71 | usage+= "Warning: to be used before c++create... c++exec...";
|
---|
72 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
73 |
|
---|
74 | kw = "c++compileopt";
|
---|
75 | usage = "c++compileopt: give additionnal compile options\n";
|
---|
76 | usage+= "Usage: c++compileopt -g -O5 -IMy_Inc_Dir ...\n";
|
---|
77 | usage+= " c++compileopt -? : give current compile options\n";
|
---|
78 | usage+= " c++compileopt : reset current compile options\n";
|
---|
79 | usage+= "Warning: to be used before c++compile";
|
---|
80 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
81 |
|
---|
82 | kw = "c++linkopt";
|
---|
83 | usage = "c++linkopt: give additionnal link options\n";
|
---|
84 | usage+= "Usage: c++linkopt -g -O5 ...\n";
|
---|
85 | usage+= " c++linkopt -? : give current link options\n";
|
---|
86 | usage+= " c++linkopt : reset current link options\n";
|
---|
87 | usage+= "Warning: to be used before c++compile";
|
---|
88 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
89 |
|
---|
90 | kw = "c++mylibs";
|
---|
91 | usage = "c++mylibs: give additionnal libraries\n";
|
---|
92 | usage+= "Usage: c++mylibs -LMy_Lib_Dir -lmylib1 -lmylib2 ...\n";
|
---|
93 | usage+= " c++mylibs -? : give current additionnal libraries\n";
|
---|
94 | usage+= " c++mylibs : reset current additionnal libraries\n";
|
---|
95 | usage+= "Warning: to be used before c++compile";
|
---|
96 | mpiac->RegisterCommand(kw, usage, this, hgrp);
|
---|
97 |
|
---|
98 |
|
---|
99 | }
|
---|
100 |
|
---|
101 | /* --Methode-- */
|
---|
102 | CxxExecutor::~CxxExecutor()
|
---|
103 | {
|
---|
104 | }
|
---|
105 |
|
---|
106 | /* --Methode-- */
|
---|
107 | int CxxExecutor::Execute(string& kw, vector<string>& tokens)
|
---|
108 | {
|
---|
109 | int rc=0;
|
---|
110 | if(kw == "c++exec" || kw == "c++execfrf") {
|
---|
111 | if(tokens.size()<1) {
|
---|
112 | cout<<"Usage: c++exec c++ user code"<<endl;
|
---|
113 | cout<<"Usage: c++execfrf fileuser.cc"<<endl;
|
---|
114 | return(1);
|
---|
115 | }
|
---|
116 | if(kw == "c++exec") rc = FillUserCode(tokens,0);
|
---|
117 | if(kw == "c++execfrf") rc = FillUserCode(tokens[0]);
|
---|
118 | if(rc) return(1);
|
---|
119 | rc = CrFile(); if(rc) return(1);
|
---|
120 | rc = Compile(); if(rc) return(1);
|
---|
121 | rc = Link(); if(rc) return(1);
|
---|
122 | rc = Call(); if(rc) return(1);
|
---|
123 |
|
---|
124 | } else if(kw == "c++args") {
|
---|
125 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
126 | {cout<<"c++args "<<GetArgs()<<endl; return(0);}
|
---|
127 | FillArgs(tokens);
|
---|
128 |
|
---|
129 | } else if(kw == "c++create") {
|
---|
130 | if(tokens.size()<3) {
|
---|
131 | cout<<"Usage: c++create file.cc func c++ user code ..."<<endl;
|
---|
132 | return(1);
|
---|
133 | }
|
---|
134 | rc = FillUserCode(tokens,2); if(rc) return(1);
|
---|
135 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
136 |
|
---|
137 | } else if(kw == "c++createfrf") {
|
---|
138 | if(tokens.size()<3) {
|
---|
139 | cout<<"Usage: c++createfrf file.cc func fileuser.cc"<<endl;
|
---|
140 | return(1);
|
---|
141 | }
|
---|
142 | rc = FillUserCode(tokens[2]); if(rc) return(1);
|
---|
143 | rc = CrFile(tokens[0],tokens[1]); if(rc) return(1);
|
---|
144 |
|
---|
145 | } else if(kw == "c++compile") {
|
---|
146 | if(tokens.size()>=1) rc = Compile(tokens[0]);
|
---|
147 | else rc = Compile();
|
---|
148 | if(rc) return(1);
|
---|
149 |
|
---|
150 | } else if(kw == "c++link") {
|
---|
151 | if(tokens.size()>=2) rc = Link(tokens[0],tokens[1]);
|
---|
152 | else if(tokens.size()>=1) rc = Link(tokens[0]);
|
---|
153 | else rc = Link();
|
---|
154 | if(rc) return(1);
|
---|
155 |
|
---|
156 | } else if(kw == "c++include") {
|
---|
157 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
158 | {cout<<"c++include "<<GetInclude()<<endl; return(0);}
|
---|
159 | FillInclude(tokens);
|
---|
160 |
|
---|
161 | } else if(kw == "c++compileopt") {
|
---|
162 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
163 | {cout<<"c++compileopt "<<GetCompileOpt()<<endl; return(0);}
|
---|
164 | FillCompileOpt(tokens);
|
---|
165 |
|
---|
166 | } else if(kw == "c++linkopt") {
|
---|
167 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
168 | {cout<<"c++linkopt "<<GetLinkOpt()<<endl; return(0);}
|
---|
169 | FillLinkOpt(tokens);
|
---|
170 |
|
---|
171 | } else if(kw == "c++mylibs") {
|
---|
172 | if(tokens.size()==1) if(tokens[0]=="-?")
|
---|
173 | {cout<<"c++mylibs "<<GetLinkLibs()<<endl; return(0);}
|
---|
174 | FillLinkLibs(tokens);
|
---|
175 |
|
---|
176 |
|
---|
177 | //// A VIRER quand variable de objmanager OK --> Pour Reza
|
---|
178 | } else if(kw == "c++setvar") {
|
---|
179 | if(tokens.size()<2) {
|
---|
180 | cout<<" Usage: c++setvar varname varcontent "<<endl;
|
---|
181 | return(1);
|
---|
182 | }
|
---|
183 | string varcont = tokens[1];
|
---|
184 | if(tokens.size()>2)
|
---|
185 | for(uint_4 i=2;i<tokens.size();i++) varcont += " " + tokens[i] ;
|
---|
186 | NamedObjMgr omg;
|
---|
187 | omg.SetVar(tokens[0], varcont);
|
---|
188 | } else if(kw == "c++getvar") {
|
---|
189 | if(tokens.size()<1) {
|
---|
190 | cout<<" Usage: c++getvar varname "<<endl;
|
---|
191 | return(1);
|
---|
192 | }
|
---|
193 | NamedObjMgr omg;
|
---|
194 | cout<<"c++getvar("<<tokens[0]<<")="<<omg.GetVar(tokens[0])<<endl;
|
---|
195 | } else if(kw == "c++varlist") {
|
---|
196 | NamedObjMgr omg;
|
---|
197 | cout<<omg.GetVarList();
|
---|
198 | }
|
---|
199 | //// A VIRER quand variable de objmanager OK --> Pour Reza
|
---|
200 |
|
---|
201 |
|
---|
202 | return(0);
|
---|
203 | }
|
---|
204 |
|
---|
205 | /* --Methode-- */
|
---|
206 | int CxxExecutor::ExecuteCxx(string const & code)
|
---|
207 | {
|
---|
208 | int rc;
|
---|
209 |
|
---|
210 | mUserCodeFn = "";
|
---|
211 | mUserCodeFn = "cxx_spiapp.h";
|
---|
212 | ofstream os(mUserCodeFn.c_str(),ios::out);
|
---|
213 | if(!os) {cout<<"CxxExecutor::ExecuteCxx(): unable to open "
|
---|
214 | <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;}
|
---|
215 |
|
---|
216 | os << code ;
|
---|
217 | os << endl ;
|
---|
218 |
|
---|
219 | cout<<"CxxExecutor: User code filled from standard input into "
|
---|
220 | <<mUserCodeFn<<endl;
|
---|
221 |
|
---|
222 | rc = CrFile(); if(rc) return(1);
|
---|
223 | rc = Compile(); if(rc) return(1);
|
---|
224 | rc = Link(); if(rc) return(1);
|
---|
225 | rc = Call(); if(rc) return(1);
|
---|
226 | return(rc);
|
---|
227 | }
|
---|
228 |
|
---|
229 | /* --Methode-- */
|
---|
230 | int CxxExecutor::CrFile(string cfilename,string func)
|
---|
231 | {
|
---|
232 | ofstream os(cfilename.c_str(),ios::out);
|
---|
233 | if(!os)
|
---|
234 | {cout<<"CxxExecutor::CrFile: unable to open "<<cfilename<<endl;
|
---|
235 | return 1;}
|
---|
236 |
|
---|
237 | PutInclude(os);
|
---|
238 | os<<endl;
|
---|
239 |
|
---|
240 | PutIncludeUser(os);
|
---|
241 | os<<endl;
|
---|
242 |
|
---|
243 | os<<"extern \"C\" {"<<endl;
|
---|
244 | os<<" int "<<func<<"( vector<string>& args );"<<endl;
|
---|
245 | os<<"}"<<endl<<endl;
|
---|
246 | os<<"int "<<func<<"( vector<string>& args )"<<endl;
|
---|
247 | os<<"{"<<endl;
|
---|
248 | os<<"// Some definitions to help using spiapp;"<<endl;
|
---|
249 | os<<"NamedObjMgr omg;"<<endl;
|
---|
250 | os<<"Services2NObjMgr& srvo = *omg.GetServiceObj();"<<endl;
|
---|
251 | os<<endl;
|
---|
252 |
|
---|
253 | PutObject(os);
|
---|
254 | os<<endl;
|
---|
255 |
|
---|
256 | PutVar(os);
|
---|
257 | os<<endl;
|
---|
258 |
|
---|
259 | os<<"//--------------------------------------------//"<<endl;
|
---|
260 | os<<"//------------- Code utilisateur -------------//"<<endl;
|
---|
261 | os<<"//--------------------------------------------//"<<endl;
|
---|
262 | os<<endl;
|
---|
263 | os<<"#include \""<<mUserCodeFn<<"\""<<endl;
|
---|
264 | os<<endl;
|
---|
265 |
|
---|
266 | os<<"return 0;"<<endl;
|
---|
267 | os<<"}"<<endl;
|
---|
268 |
|
---|
269 | cout<<"File "<<cfilename<<" for function "<<func<<" created"<<endl;
|
---|
270 | cout<<"User code is in file "<<mUserCodeFn<<" included in "<<cfilename<<endl;
|
---|
271 | return 0;
|
---|
272 | }
|
---|
273 |
|
---|
274 | /* --Methode-- */
|
---|
275 | void CxxExecutor::PutInclude(ofstream& os)
|
---|
276 | {
|
---|
277 | os<<"#include \"machdefs.h\""<<endl
|
---|
278 | <<endl
|
---|
279 |
|
---|
280 | <<"//---- System et stdc++ include files"<<endl
|
---|
281 | <<"#include <stdio.h>"<<endl
|
---|
282 | <<"#include <stdlib.h>"<<endl
|
---|
283 | <<"#include <math.h>"<<endl
|
---|
284 | <<"#include <ctype.h>"<<endl
|
---|
285 | <<"#include <string.h>"<<endl
|
---|
286 | <<"#include <iostream.h>"<<endl
|
---|
287 | <<"#include <fstream.h>"<<endl
|
---|
288 | <<"#include <complex>"<<endl
|
---|
289 | <<endl
|
---|
290 |
|
---|
291 | <<"#include <typeinfo>"<<endl
|
---|
292 | <<"#include <string>"<<endl
|
---|
293 | <<"#include <vector>"<<endl
|
---|
294 | <<"#include <map>"<<endl
|
---|
295 | <<"#include <functional>"<<endl
|
---|
296 | <<"#include <list>"<<endl
|
---|
297 | <<endl
|
---|
298 |
|
---|
299 | <<"//---- Sophya include files"<<endl
|
---|
300 | <<"#include \"systools.h\""<<endl
|
---|
301 | <<"#include \"ntools.h\""<<endl
|
---|
302 | <<"#include \"array.h\""<<endl
|
---|
303 | <<"#include \"histats.h\""<<endl
|
---|
304 | <<endl
|
---|
305 |
|
---|
306 | <<"//---- Spiapp include files"<<endl
|
---|
307 | <<"#include \"nobjmgr.h\""<<endl
|
---|
308 | <<"#include \"servnobjm.h\""<<endl
|
---|
309 | <<endl
|
---|
310 |
|
---|
311 | <<"#define KeepObj(obj) ___nomobj = #obj; omg.AddObj(obj,___nomobj);"<<endl
|
---|
312 | <<"#define KeepVar(var) ___nomobj = #var; omg.GetVarList().Get(___nomobj) = var ;"<<endl
|
---|
313 | <<endl;
|
---|
314 |
|
---|
315 | return;
|
---|
316 | }
|
---|
317 |
|
---|
318 | /* --Methode-- */
|
---|
319 | void CxxExecutor::PutIncludeUser(ofstream& os)
|
---|
320 | {
|
---|
321 | if(mIncList.size()<1) return;
|
---|
322 | for(uint_4 i=0;i<mIncList.size();i++)
|
---|
323 | os<<"#include \""<<mIncList[i]<<"\""<<endl;
|
---|
324 | }
|
---|
325 |
|
---|
326 | /* --Methode-- */
|
---|
327 | void CxxExecutor::PutObject(ofstream& os)
|
---|
328 | {
|
---|
329 | NamedObjMgr omg;
|
---|
330 | NObjMgrAdapter* objmgrad;
|
---|
331 | vector<string> objlist;
|
---|
332 | string patt = "*";
|
---|
333 | omg.GetObjList(patt,objlist);
|
---|
334 | int nobjs = objlist.size();
|
---|
335 |
|
---|
336 | os<<"//-------------- Object List --------------"<<endl;
|
---|
337 | os<<"//Number of objects = "<<nobjs<<endl;
|
---|
338 | os<<"string ___nomobj;"<<endl<<endl;
|
---|
339 | if(nobjs<=0) return;
|
---|
340 |
|
---|
341 | string dir,nobj,stmp,obtype;
|
---|
342 | for(int i=0;i<nobjs;i++) {
|
---|
343 | objmgrad = omg.GetObjAdapter(objlist[i]);
|
---|
344 | omg.ParseObjectName(objlist[i],dir,nobj);
|
---|
345 | obtype = objmgrad->GetDataObjType();
|
---|
346 | stmp = "___" + nobj;
|
---|
347 |
|
---|
348 | os<<"___nomobj = \""<<nobj<<"\";"<<endl;
|
---|
349 | os<<obtype<<"* "<<stmp
|
---|
350 | <<" = dynamic_cast< "<<obtype<<" * >(omg.GetObj(___nomobj));"<<endl;
|
---|
351 | os<<"if("<<stmp<<"==NULL) throw NullPtrError"
|
---|
352 | <<"(\"CxxExecutor::PutObject: Non existing object "<<nobj
|
---|
353 | <<"... please update file\");"<<endl;
|
---|
354 | os<<obtype<<"& "<<nobj<<" = (*"<<stmp<<");"<<endl<<endl;
|
---|
355 | }
|
---|
356 |
|
---|
357 | return;
|
---|
358 | }
|
---|
359 |
|
---|
360 | /* --Methode-- */
|
---|
361 | void CxxExecutor::PutVar(ofstream& os)
|
---|
362 | {
|
---|
363 | os<<"//-------------- Variable List --------------"<<endl;
|
---|
364 | NamedObjMgr omg;
|
---|
365 | DVList& varlist = omg.GetVarList();
|
---|
366 | // varlist.Show(); varlist.Print();
|
---|
367 | DVList::ValList::const_iterator it;
|
---|
368 | for(it=varlist.Begin(); it!=varlist.End(); it++) {
|
---|
369 | string key = (*it).first;
|
---|
370 | if (isalpha(key[0]) ) {
|
---|
371 | os<<"___nomobj = \""<<key<<"\";"<<endl;
|
---|
372 | os<<"MuTyV & $"<<key<<" = omg.GetVarList().Get(___nomobj);"<<endl;
|
---|
373 | }
|
---|
374 | }
|
---|
375 |
|
---|
376 | return;
|
---|
377 | }
|
---|
378 |
|
---|
379 | /* --Methode-- */
|
---|
380 | int CxxExecutor::FillUserCode(vector<string>& usercode,uint_4 first)
|
---|
381 | // - first is the first position in the vector<> where the code starts
|
---|
382 | // User code is read from input. It is put into file "cxx_spiapp.h".
|
---|
383 | {
|
---|
384 | mUserCodeFn = "";
|
---|
385 | uint_4 nus = usercode.size();
|
---|
386 | if(nus<=first) {cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
|
---|
387 | return 1;}
|
---|
388 | mUserCodeFn = "cxx_spiapp.h";
|
---|
389 | ofstream os(mUserCodeFn.c_str(),ios::out);
|
---|
390 | if(!os) {cout<<"CxxExecutor::FillUserCode: unable to open "
|
---|
391 | <<mUserCodeFn<<endl; mUserCodeFn = ""; return 1;}
|
---|
392 | // On ajoute un blanc pour les chaines de caracteres contenant des blancs
|
---|
393 | for(uint_4 i=first;i<nus;i++) os<<" "<<usercode[i];
|
---|
394 | os<<endl;
|
---|
395 | cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
|
---|
396 | return 0;
|
---|
397 | }
|
---|
398 |
|
---|
399 | /* --Methode-- */
|
---|
400 | int CxxExecutor::FillUserCode(string filename)
|
---|
401 | // User code is read from "filename".
|
---|
402 | {
|
---|
403 | mUserCodeFn = filename;
|
---|
404 | cout<<"User code filled from file "<<filename<<endl;
|
---|
405 | return 0;
|
---|
406 | }
|
---|
407 |
|
---|
408 | /* --Methode-- */
|
---|
409 | int CxxExecutor::Compile(string rootfilename)
|
---|
410 | {
|
---|
411 | string fc = rootfilename + ".cc";
|
---|
412 | string fl = rootfilename + ".so";
|
---|
413 | cout<<"Compile: "<<rootfilename<<endl;
|
---|
414 | int rc = 0;
|
---|
415 | rc = CrMakefile();
|
---|
416 | if(rc) return(1);
|
---|
417 | string make = "make -f cxx_spiapp_Makefile";
|
---|
418 | make += " CXXFLAGS=\"" + mCompOpt + "\"";
|
---|
419 | make += " LDFLAGS=\"" + mLinkOpt + "\"";
|
---|
420 | make += " MYLIBS=\"" + mMyLibs + "\"";
|
---|
421 | make += " " + rootfilename;
|
---|
422 | rc = system(make.c_str());
|
---|
423 | if(rc)
|
---|
424 | {cout<<"CxxExecutor::Compile : \n"<<make<<" Failed"<<endl;
|
---|
425 | return 1000+rc;}
|
---|
426 | return 0;
|
---|
427 | }
|
---|
428 |
|
---|
429 | /* --Methode-- */
|
---|
430 | int CxxExecutor::CrMakefile(void)
|
---|
431 | {
|
---|
432 | ofstream os("cxx_spiapp_Makefile",ios::out);
|
---|
433 | if(!os)
|
---|
434 | {cout<<"CxxExecutor::CrMakefile: unable to open file for Makefile"<<endl;
|
---|
435 | return 1;}
|
---|
436 | //---------------------------------------------------------------------
|
---|
437 | os<<"MODULEDECCXXFLAGS := -msg_quiet"<<endl;
|
---|
438 | os<<"include $(DPCBASEREP)/Include/MakefileUser.h"<<endl;
|
---|
439 | os<<"MYLIBS ="<<endl;
|
---|
440 | os<<"LIBS = -L$(SLB) -lPI -lextsophya -lsophya -lm"<<endl;
|
---|
441 | os<<"ifeq ($(MACHEROS),OSF1)"<<endl;
|
---|
442 | os<<"LIBS := $(LIBS) -lfor"<<endl;
|
---|
443 | os<<"endif"<<endl;
|
---|
444 | os<<"ifeq ($(MACHEROS),Linux)"<<endl;
|
---|
445 | os<<"LIBS := $(LIBS) -ldl -lf2c"<<endl;
|
---|
446 | os<<"endif"<<endl;
|
---|
447 | os<<"%.so:$(OBJ)%.o"<<endl;
|
---|
448 | os<<"%:%.cc"<<endl;
|
---|
449 | os<<"%:%.o"<<endl;
|
---|
450 | os<<"%.o:%.cc"<<endl;
|
---|
451 | os<<"%.o:%.c"<<endl;
|
---|
452 | os<<"%:%.c"<<endl;
|
---|
453 | os<<endl;
|
---|
454 | os<<".PRECIOUS: %.so"<<endl;
|
---|
455 | os<<endl;
|
---|
456 | os<<"%:%.so"<<endl;
|
---|
457 | os<<"\t"<<"echo $@ \" made (.so) \""<<endl;
|
---|
458 | os<<"%.so:$(OBJ)%.o"<<endl;
|
---|
459 | os<<"\t"<<"$(LINK.cc) -shared -o $@ $< $(LIBS) $(MYLIBS)"<<endl;
|
---|
460 | os<<"$(OBJ)%.o:%.cc"<<endl;
|
---|
461 | os<<"\t"<<"$(COMPILE.cc) -o $@ $<"<<endl;
|
---|
462 | os<<"$(OBJ)%.o:%.c"<<endl;
|
---|
463 | os<<"\t"<<"$(COMPILE.c) -c $(CFLAGS) $(USERFLAGS) -o $@ $<"<<endl;
|
---|
464 | //---------------------------------------------------------------------
|
---|
465 | return 0;
|
---|
466 | }
|
---|
467 |
|
---|
468 | /* --Methode-- */
|
---|
469 | int CxxExecutor::Link(string libname,string func)
|
---|
470 | {
|
---|
471 | NamedObjMgr omg;
|
---|
472 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
473 | string key("link");
|
---|
474 | vector<string> arg; arg.push_back(libname); arg.push_back(func);
|
---|
475 | int rc = mpiac->ExecuteCommand(key,arg);
|
---|
476 | cout<<"Link from "<<libname<<" for function "<<func
|
---|
477 | <<" (rc="<<rc<<")"<<endl;
|
---|
478 | return 0;
|
---|
479 | }
|
---|
480 |
|
---|
481 | /* --Methode-- */
|
---|
482 | int CxxExecutor::Call(string func)
|
---|
483 | {
|
---|
484 | NamedObjMgr omg;
|
---|
485 | PIACmd* mpiac = omg.GetImgApp()->CmdInterpreter();
|
---|
486 | string key("call");
|
---|
487 | vector<string> arg; arg.push_back(func);
|
---|
488 | if(mCallArgs.size()>0)
|
---|
489 | for(uint_4 i=0;i<mCallArgs.size();i++) arg.push_back(mCallArgs[i]);
|
---|
490 | mpiac->ExecuteCommand(key,arg);
|
---|
491 | return 0;
|
---|
492 | }
|
---|
493 |
|
---|
494 | /* --Methode-- */
|
---|
495 | void CxxExecutor::FillArgs(vector<string>& args)
|
---|
496 | {
|
---|
497 | mCallArgs.resize(0);
|
---|
498 | if(args.size()<1) return;
|
---|
499 | for(uint_4 i=0;i<args.size();i++) mCallArgs.push_back(args[i]);
|
---|
500 | }
|
---|
501 |
|
---|
502 | void CxxExecutor::FillArgs(string& args)
|
---|
503 | {
|
---|
504 | mCallArgs.resize(0);
|
---|
505 | FillVStringFrString(args,mCallArgs,' ');
|
---|
506 | }
|
---|
507 |
|
---|
508 | string CxxExecutor::GetArgs(void)
|
---|
509 | {
|
---|
510 | string dum = "";
|
---|
511 | if(mCallArgs.size()<1) return dum;
|
---|
512 | for(uint_4 i=0;i<mCallArgs.size();i++) dum += mCallArgs[i] + " ";
|
---|
513 | return dum;
|
---|
514 | }
|
---|
515 |
|
---|
516 | /* --Methode-- */
|
---|
517 | void CxxExecutor::FillInclude(vector<string>& inc)
|
---|
518 | {
|
---|
519 | mIncList.resize(0);
|
---|
520 | if(inc.size()<1) return;
|
---|
521 | for(uint_4 i=0;i<inc.size();i++) mIncList.push_back(inc[i]);
|
---|
522 | }
|
---|
523 |
|
---|
524 | void CxxExecutor::FillInclude(string& inc)
|
---|
525 | {
|
---|
526 | mIncList.resize(0);
|
---|
527 | FillVStringFrString(inc,mIncList,' ');
|
---|
528 | }
|
---|
529 |
|
---|
530 | string CxxExecutor::GetInclude(void)
|
---|
531 | {
|
---|
532 | string dum = "";
|
---|
533 | if(mIncList.size()<1) return dum;
|
---|
534 | for(uint_4 i=0;i<mIncList.size();i++) dum += mIncList[i] + " ";
|
---|
535 | return dum;
|
---|
536 | }
|
---|
537 |
|
---|
538 | /* --Methode-- */
|
---|
539 | void CxxExecutor::FillCompileOpt(vector<string>& copt)
|
---|
540 | {
|
---|
541 | mCompOpt = "";
|
---|
542 | if(copt.size()<1) return;
|
---|
543 | for(uint_4 i=0;i<copt.size();i++) mCompOpt += copt[i] + " ";
|
---|
544 | }
|
---|
545 |
|
---|
546 | void CxxExecutor::FillCompileOpt(string& copt)
|
---|
547 | {
|
---|
548 | mCompOpt = copt;
|
---|
549 | }
|
---|
550 |
|
---|
551 | string CxxExecutor::GetCompileOpt(void)
|
---|
552 | {
|
---|
553 | return mCompOpt;
|
---|
554 | }
|
---|
555 |
|
---|
556 | /* --Methode-- */
|
---|
557 | void CxxExecutor::FillLinkOpt(vector<string>& lopt)
|
---|
558 | {
|
---|
559 | mLinkOpt = "";
|
---|
560 | if(lopt.size()<1) return;
|
---|
561 | for(uint_4 i=0;i<lopt.size();i++) mLinkOpt += lopt[i] + " ";
|
---|
562 | }
|
---|
563 |
|
---|
564 | void CxxExecutor::FillLinkOpt(string& lopt)
|
---|
565 | {
|
---|
566 | mLinkOpt = lopt;
|
---|
567 | }
|
---|
568 |
|
---|
569 | string CxxExecutor::GetLinkOpt(void)
|
---|
570 | {
|
---|
571 | return mLinkOpt;
|
---|
572 | }
|
---|
573 |
|
---|
574 | /* --Methode-- */
|
---|
575 | void CxxExecutor::FillLinkLibs(vector<string>& llibs)
|
---|
576 | {
|
---|
577 | mMyLibs = "";
|
---|
578 | if(llibs.size()<1) return;
|
---|
579 | for(uint_4 i=0;i<llibs.size();i++) mMyLibs += llibs[i] + " ";
|
---|
580 | }
|
---|
581 |
|
---|
582 | void CxxExecutor::FillLinkLibs(string& llibs)
|
---|
583 | {
|
---|
584 | mMyLibs = llibs;
|
---|
585 | }
|
---|
586 |
|
---|
587 | string CxxExecutor::GetLinkLibs(void)
|
---|
588 | {
|
---|
589 | return mMyLibs;
|
---|
590 | }
|
---|
591 |
|
---|
592 |
|
---|
593 |
|
---|
594 |
|
---|
595 | /* --Methode-- DO NOT DELETE.... cmv property !!!
|
---|
596 | int CxxExecutor::FillUserCode(vector<string>& usercode,uint_4 first)
|
---|
597 | {
|
---|
598 | mUserCodeFn = "";
|
---|
599 | uint_4 nus = usercode.size();
|
---|
600 | if(nus<=first) {
|
---|
601 | cout<<"CxxExecutor::FillUserCode: no user code"<<endl;
|
---|
602 | return 1;
|
---|
603 | }
|
---|
604 | mUserCodeFn = "cxx_spiapp.h";
|
---|
605 | ofstream os(mUserCodeFn.c_str(),ios::out);
|
---|
606 | if(!os)
|
---|
607 | {cout<<"CxxExecutor::FillUserCode: unable to open "<<mUserCodeFn<<endl;
|
---|
608 | mUserCodeFn = ""; return 1;}
|
---|
609 | // **** 1er probleme ****
|
---|
610 | // - Pour la lisibilite et eviter les bugs avec les chaines de caracteres
|
---|
611 | // contenant des blancs, on ne casse les lignes qu'apres un ";" a condition
|
---|
612 | // qu'il ne soit pas dans une chaine de caracteres c'est a dire
|
---|
613 | // entoure de "....;....".
|
---|
614 | // - Attention aux " dans les chaines de caracteres: "...\"..."
|
---|
615 | // - Bugs non-gere pour les tortures: ".....\\" suivi par une autre
|
---|
616 | // chaine de caracteres qui contient un ';'
|
---|
617 | // ex: cout<<"aaa\\"; cout<<"blabla;blabla";
|
---|
618 | // **** 2ieme probleme ****
|
---|
619 | // - Le decodeur de ligne va couper les commentaires qui contiennent des blancs:
|
---|
620 | // "salut ca va" --> tokens[0]="salut tokens[1]=ca tokens[2]=va" --> "salutcava"
|
---|
621 | // - On contourne partiellement le pb en ajoutant un blanc en debut des tokens[]
|
---|
622 | // identifies comme etant dans une chaine de caracteres (mais impossible de gerer
|
---|
623 | // si il y a plusieurs blancs!): "salut ca va" -> "salut ca va"
|
---|
624 | // **** Conclusion ****
|
---|
625 | // Pour ecrire du code sophistique, le faire dans un fichier
|
---|
626 | string dum = "";
|
---|
627 | bool lastchar = false;
|
---|
628 | bool comment = false;
|
---|
629 | for(uint_4 i=first;i<nus;i++) {
|
---|
630 | const char* str = usercode[i].c_str();
|
---|
631 | size_t lstr= strlen(str);
|
---|
632 | for(uint_4 j=0;j<lstr;j++) {
|
---|
633 | // debut de mot dans un commentaire -> ajouter un blanc
|
---|
634 | if(j==0 && comment) dum += " ";
|
---|
635 | // on arrive sur un " : debut ou fin commentaire? inactif (\")?
|
---|
636 | if(str[j]=='"') {
|
---|
637 | if(j==0) comment = (comment) ? false: true;
|
---|
638 | else {if(str[j-1]!='\\') comment = (comment) ? false: true;}
|
---|
639 | }
|
---|
640 | dum += str[j];
|
---|
641 | if( i==nus-1 && j==lstr-1 ) lastchar = true;
|
---|
642 | // On charge la string "dum" si : 1-/ on a un ";"
|
---|
643 | // 2-/ c'est le dernier charactere
|
---|
644 | if((str[j]==';' && !comment) || lastchar)
|
---|
645 | {os<<dum<<endl; dum = "";}
|
---|
646 | }
|
---|
647 | }
|
---|
648 | cout<<"User code filled from standard input into "<<mUserCodeFn<<endl;
|
---|
649 | return 0;
|
---|
650 | }
|
---|
651 | */
|
---|