pelib
2.0.0
|
00001 /* 00002 Copyright 2015 Nicolas Melot 00003 00004 This file is part of Pelib. 00005 00006 Pelib is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 Pelib is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with Pelib. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 00021 #include <iostream> 00022 00023 #include <pelib/parser.h> 00024 #include <pelib/output.h> 00025 00026 #include <pelib/Set.hpp> 00027 #include <pelib/DummyCore.hpp> 00028 #include <pelib/AmplOutput.hpp> 00029 #include <pelib/Platform.hpp> 00030 00031 using namespace std; 00032 using namespace pelib; 00033 00034 #ifdef __cplusplus 00035 extern "C" { 00036 #endif 00037 00038 #ifndef debug 00039 #define debug(expr) cerr << "[" << __FILE__ << ":" << __FUNCTION__ << ":" << __LINE__ << "] " << #expr << " = \"" << expr << "\"." << endl; 00040 #endif 00041 00042 // /!\ the content of argv is freed after this function is run 00043 pelib::Record* 00044 pelib_parse(std::istream& cin, size_t argc, char **argv) 00045 { 00046 AmplOutput reader(AmplOutput::floatHandlers()); 00047 std::string line; 00048 Algebra alg_arch = reader.parse(cin); 00049 00050 const Scalar<float> *scalar_p = alg_arch.find<Scalar<float> >("p"); 00051 const Scalar<float> *f_unit = alg_arch.find<Scalar<float> >("Funit"); 00052 const Set<float> *set_F = alg_arch.find<Set<float> >("F"); 00053 00054 if(scalar_p == NULL || set_F == NULL) 00055 { 00056 throw ParseException(std::string("Missing core number scalar \"p\" or frequency set \"F\" in input.")); 00057 } 00058 00059 set<const Core*, Core::LessCorePtrByCoreId> cores; 00060 for(size_t i = 0; i < (size_t)scalar_p->getValue(); i++) 00061 { 00062 cores.insert(new DummyCore(set_F->getValues(), f_unit->getValue())); 00063 } 00064 00065 Platform *arch = new Platform(cores); 00066 00067 return arch; 00068 } 00069 00070 // /!\ the content of argv is freed after this function is run 00071 void 00072 pelib_dump(std::ostream& cout, std::map<const char*, Record*> records, size_t argc, char **argv) 00073 { 00074 const Platform *arch = (Platform*)records.find(typeid(Platform).name())->second; 00075 00076 AmplOutput output(AmplOutput::intFloatHandlers()); 00077 Algebra alg = arch->buildAlgebra(); 00078 output.dump(cout, alg); 00079 } 00080 00081 void 00082 pelib_delete(Record *obj) 00083 { 00084 delete obj; 00085 } 00086 00087 #ifdef __cplusplus 00088 } 00089 #endif 00090