[Compbench-devel] CompBenchmarks++/compbenchmarks-plan cloptions.cpp, 1.1, 1.2
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-05-29 18:26:17
|
Update of /cvsroot/compbench/CompBenchmarks++/compbenchmarks-plan In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv4837 Modified Files: cloptions.cpp Log Message: Many new objects can be handled. Index: cloptions.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/compbenchmarks-plan/cloptions.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** cloptions.cpp 28 May 2007 17:49:46 -0000 1.1 --- cloptions.cpp 29 May 2007 18:26:11 -0000 1.2 *************** *** 10,13 **** --- 10,16 ---- #include <Base/Config.h> #include <Plan/Plan.h> + #include <Plan/Plan-Batch.h> + #include <Compiler/Compiler.h> + #include <Compiler/Compiler-OptionSet.h> #include <UI/UI.h> *************** *** 24,28 **** typedef enum { ! ActionUndef, ActionRegisterPlan, ActionUnregisterPlan } OptAction; --- 27,35 ---- typedef enum { ! ActionUndef, ! ActionRegisterPlan, ActionUnregisterPlan, ! ActionRegisterBatch, ActionUnregisterBatch, ActionListBatch, ! ActionRegisterCompiler, ActionUnregisterCompiler, ActionListCompiler, ! ActionRegisterOptionset, ActionUnregisterOptionset, ActionListOptionset } OptAction; *************** *** 57,60 **** --- 64,126 ---- } + int getPlanFileName(std::string& planFileName) + { + if (planFileName=="") { + planFileName=cbmSystem->Config()->getDefaultPlan(); + } + + if (planFileName!="") + return(1); + else { + std::cerr << "Can't find plan. Look at --plan-use option, or set a default plan (--default)" << std::endl; + return(0); + } + } + + CBM::Plan *restorePlan(std::string planFileName) + { + CBM::Plan *P = new CBM::Plan; + int r; + + r=P->restore(planFileName); + + if (r) + return(P); + else { + delete(P); + std::cerr << "Plan file " << planFileName << " not detected." << std::endl; + return(0); + } + } + + CBM::PlanBatch *restoreBatch(CBM::Plan **P, + std::string planFileName, + std::string batchId) + { + CBM::PlanBatch *B; + + (*P)=restorePlan(planFileName); + if (*P) { + B=(*P)->getBatch(batchId); + if (!B) { + std::cerr << "Batch " << batchId << " not found in " << planFileName << std::endl; + } + + return(B); + } else { + return(0); + } + } + + int storePlan(CBM::Plan *P, std::string planFileName) + { + parseExitValue=!(P->store(planFileName)); + if (parseExitValue) { + std::cerr << "Can't write in file " << planFileName << std::endl; + } + + return(!parseExitValue); + } + int cbmPlanOptionsParse(int argc, char *argv[]) { *************** *** 64,77 **** OptFilter filter = { 0 }; /* <empty>/all/installed */ int not_done = 1; std::string planFileName; ! CBM::Plan *P; static const struct option long_options[] = { {"help", no_argument, 0, 'h' }, - {"plan-register", required_argument, 0, 'r'}, - {"plan-unregister", required_argument, 0, 'u'}, - {"default", no_argument, 0, 1003}, {"version", no_argument, 0, 'v'}, ! { 0, 0, 0, 0} }; --- 130,170 ---- OptFilter filter = { 0 }; /* <empty>/all/installed */ int not_done = 1; + std::string planFileName; ! std::string batchName; ! std::string compilerName; ! std::string optionsetName; ! ! CBM::Plan *P = 0; ! CBM::PlanBatch *B = 0; ! CBM::CompilerSelector *CS = 0; ! CBM::Compiler *C = 0; ! CBM::CompilerOptionSet *OS = 0; ! ! int i, n; static const struct option long_options[] = { {"help", no_argument, 0, 'h' }, {"version", no_argument, 0, 'v'}, ! ! {"plan-register", required_argument, 0, 1001}, ! {"plan-unregister", required_argument, 0, 1002}, ! {"plan-use", required_argument, 0, 1003}, ! {"default", no_argument, 0, 1004}, ! ! {"batch-register", required_argument, 0, 2001}, ! {"batch-unregister", required_argument, 0, 2002}, ! {"batch-list", no_argument, 0, 2003}, ! {"batch-use", required_argument, 0, 2004}, ! ! {"compiler-register", required_argument, 0, 3001}, ! {"compiler-unregister", required_argument, 0, 3002}, ! {"compiler-list", no_argument, 0, 3003}, ! ! {"optionset-register", required_argument, 0, 4001}, ! {"optionset-unregister", required_argument, 0, 4002}, ! {"optionset-list", no_argument, 0, 4003}, ! ! { 0, 0, 0, 0 } }; *************** *** 82,86 **** break; ! c = getopt_long (argc, argv, "hr:u::", long_options, &option_index); if (c==-1) { --- 175,179 ---- break; ! c = getopt_long (argc, argv, "hv", long_options, &option_index); if (c==-1) { *************** *** 93,102 **** case 'h': break; ! case 'r': action=ActionRegisterPlan; planFileName=optarg; appendXML(planFileName); break; ! case 'u': action=ActionUnregisterPlan; planFileName=optarg; --- 186,195 ---- case 'h': break; ! case 1001: action=ActionRegisterPlan; planFileName=optarg; appendXML(planFileName); break; ! case 1002: action=ActionUnregisterPlan; planFileName=optarg; *************** *** 104,107 **** --- 197,204 ---- break; case 1003: + planFileName=optarg; + appendXML(planFileName); + break; + case 1004: filter.defaultPlan=1; if ((action!=ActionRegisterPlan) && *************** *** 110,113 **** --- 207,246 ---- } break; + case 2001: + action=ActionRegisterBatch; + batchName=optarg; + break; + case 2002: + action=ActionUnregisterBatch; + batchName=optarg; + break; + case 2003: + action=ActionListBatch; + break; + case 2004: + batchName=optarg; + break; + case 3001: + action=ActionRegisterCompiler; + compilerName=optarg; + break; + case 3002: + action=ActionUnregisterCompiler; + compilerName=optarg; + break; + case 3003: + action=ActionListCompiler; + break; + case 4001: + action=ActionRegisterOptionset; + optionsetName=optarg; + break; + case 4002: + action=ActionUnregisterOptionset; + optionsetName=optarg; + break; + case 4003: + action=ActionListOptionset; + break; default: case '?': *************** *** 115,118 **** --- 248,252 ---- } } + switch(action) { case ActionRegisterPlan: *************** *** 123,127 **** } P = new CBM::Plan; ! parseExitValue=!(P->store(planFileName)); if (filter.defaultPlan) { --- 257,261 ---- } P = new CBM::Plan; ! storePlan(P, planFileName); if (filter.defaultPlan) { *************** *** 145,158 **** break; } ! P=new CBM::Plan; ! if (P->restore(planFileName)) { parseExitValue=!(cbmSystem->unlink(planFileName)); if (!parseExitValue) { if (cbmSystem->Config()->getDefaultPlan()!="") { ! std::string abs = cbmSystem->Config()->Path(CBM::System::CurrentWD); ! ! abs+="/"; ! abs+=planFileName; if (abs==cbmSystem->Config()->getDefaultPlan()) { --- 279,289 ---- break; } ! P=restorePlan(planFileName); ! if (P) { parseExitValue=!(cbmSystem->unlink(planFileName)); if (!parseExitValue) { if (cbmSystem->Config()->getDefaultPlan()!="") { ! std::string abs = cbmSystem->fileAbsoluteName(planFileName); if (abs==cbmSystem->Config()->getDefaultPlan()) { *************** *** 165,174 **** } } } else { ! std::cerr << "Plan file not detected." << std::endl; } delete(P); break; default: printf("?\n"); --- 296,548 ---- } } + delete(P); + } + + break; + case ActionRegisterBatch: + if (!getPlanFileName(planFileName)) + break; + P=restorePlan(planFileName); + if (P) { + CBM::PlanBatch *B = new CBM::PlanBatch(batchName); + P->addBatch(B); + parseExitValue=!(P->store(planFileName)); + storePlan(P, planFileName); + if (!parseExitValue) { + std::cout << "Batch " << batchName << " added in " << planFileName << std::endl; + } + delete(P); + } + + break; + case ActionUnregisterBatch: + if (!getPlanFileName(planFileName)) + break; + P=restorePlan(planFileName); + + if (P) { + parseExitValue=!(P->removeBatch(batchName)); + if (!parseExitValue) { + std::cout << "Batch " << batchName << " removed from " << planFileName << std::endl; + storePlan(P, planFileName); + } else { + std::cerr << "Cant't find such batch in plan " << planFileName << std::endl; + } + } + break; + case ActionListBatch: + if (!getPlanFileName(planFileName)) + break; + P=restorePlan(planFileName); + + if (P) { + CBM::PlanBatch *B; + n = P->batchNumber(); + + parseExitValue=0; + if (!n) { + std::cout << "No batch registered." << std::endl; + } else { + printf("%d batch(s) found :\n", n); + for (i=0; i<n; i++) { + B=P->getBatch(i); + std::cout << " * " << B->Id() << std::endl; + } + } + delete(P); + } + break; + + case ActionRegisterCompiler: + if (!getPlanFileName(planFileName)) + break; + + B=restoreBatch(&P, + planFileName, + batchName); + + if (!P) + break; + + if (!B) { + delete(P); + break; + } + + CS = new CompilerSelector(cbmSystem); + C = CS->select(compilerName); + + if (C) { + if (B->add(C)) { + storePlan(P, planFileName); + if (!parseExitValue) { + std::cout << C->Name() << " added in batch " << batchName << std::endl; + } + } else { + std::cerr << compilerName << " has not been added (probably because it was already present in that plan)." << std::endl; + } + delete(C); } else { ! std::cerr << compilerName << " is not a supported compiler." << std::endl; ! } ! delete(CS); ! delete(P); ! break; ! ! case ActionUnregisterCompiler: ! if (!getPlanFileName(planFileName)) ! break; ! ! B=restoreBatch(&P, ! planFileName, ! batchName); ! ! if (!P) ! break; ! ! if (!B) { ! delete(P); ! break; ! } ! ! CS = new CompilerSelector(cbmSystem); ! C = CS->select(compilerName); ! ! if (C) { ! if (B->remove(C)) { ! storePlan(P, planFileName); ! if (!parseExitValue) { ! std::cout << C->Name() << " removed from batch " << batchName << std::endl; ! } ! } else { ! std::cerr << compilerName << " not found in that plan" << std::endl; ! } ! delete(C); ! } else { ! std::cerr << compilerName << " is not a supported compiler." << std::endl; ! } ! delete(CS); ! delete(P); ! break; ! ! case ActionListCompiler: ! if (!getPlanFileName(planFileName)) ! break; ! ! B=restoreBatch(&P, ! planFileName, ! batchName); ! ! if (!P) ! break; ! ! if (!B) { ! delete(P); ! break; ! } ! ! n = B->compilerNumber(); ! ! parseExitValue=0; ! if (!n) { ! std::cout << "No compiler registered." << std::endl; ! } else { ! printf("%d compiler(s) found :\n", n); ! for (i=0; i<n; i++) { ! C=B->getCompiler(i); ! std::cout << " * Binary : " << C->Binary() << " - Name : " ! << C->Name() << std::endl; ! } ! } ! delete(P); ! break; ! case ActionRegisterOptionset: ! if (!getPlanFileName(planFileName)) ! break; ! ! B=restoreBatch(&P, ! planFileName, ! batchName); ! ! if (!P) ! break; ! ! if (!B) { ! delete(P); ! break; ! } ! ! OS = new CompilerOptionSet(optionsetName); ! if (B->add(OS)) { ! storePlan(P, planFileName); ! if (!parseExitValue) { ! std::cout << OS->Id() << " added in batch " << batchName << std::endl; ! } ! } else { ! std::cerr << optionsetName << " has not been added." << std::endl; ! } ! delete(OS); ! delete(P); ! break; ! ! case ActionUnregisterOptionset: ! if (!getPlanFileName(planFileName)) ! break; ! ! B=restoreBatch(&P, ! planFileName, ! batchName); ! ! if (!P) ! break; ! ! if (!B) { ! delete(P); ! break; ! } ! ! OS = new CompilerOptionSet(optionsetName); ! if (B->remove(OS)) { ! storePlan(P, planFileName); ! if (!parseExitValue) { ! std::cout << OS->Id() << " removed from batch " << batchName << std::endl; ! } ! } else { ! std::cerr << optionsetName << " not found in batch." << std::endl; } + + delete(OS); delete(P); break; + case ActionListOptionset: + if (!getPlanFileName(planFileName)) + break; + + B=restoreBatch(&P, + planFileName, + batchName); + + if (!P) + break; + + if (!B) { + delete(P); + break; + } + + n=B->compilerOptionNumber(); + if (!n) { + std::cout << "No option set registered." << std::endl; + } else { + printf("%d option set(s) found :\n", n); + + for(i=0; i<n; i++) { + OS=B->getCompilerOptions(i); + std::cout << " * " << OS->Id() << std::endl; + } + } + break; + default: printf("?\n"); |