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