52 #define _CRT_SECURE_NO_WARNINGS 1
62 #include <boost/algorithm/string/classification.hpp>
63 #include <boost/algorithm/string/split.hpp>
64 #include <boost/program_options/options_description.hpp>
65 #include <boost/program_options/parsers.hpp>
66 #include <boost/program_options/variables_map.hpp>
68 using namespace etiss;
87 return "INVALID_VERBOSITY_LEVEL";
92 const std::string &
str,
93 std::function<
size_t(
const std::string & ,
size_t ,
size_t & )> findsplit)
95 std::list<std::string> ret;
99 size_t sepsize = std::string::npos;
100 size_t tmpfind = findsplit(
str, find, sepsize);
101 if (tmpfind >= find && tmpfind != std::string::npos)
103 ret.push_back(
str.substr(find, tmpfind - find));
104 find = tmpfind + sepsize;
108 if (
str.size() > find)
110 ret.push_back(
str.substr(find));
129 std::cout <<
"ETISS: " <<
etiss::toString(level) <<
": " << msg << std::endl;
147 std::vector<std::string> ret;
151 for (
unsigned pos = 0; pos < cmdline.length(); pos++)
158 switch (cmdline[pos])
172 switch (cmdline[pos])
181 if (pos + 1 < cmdline.length())
184 tmp = tmp + cmdline[pos];
188 tmp = tmp + cmdline[pos];
193 switch (cmdline[pos])
202 if (pos + 1 < cmdline.length())
205 tmp = tmp + cmdline[pos];
209 tmp = tmp + cmdline[pos];
212 if (pos + 1 >= cmdline.length())
219 std::cerr <<
"ERROR: etiss::parseCommand(1) parser failed" << std::endl;
233 std::list<std::string> list;
234 list.insert(list.end(), vec.begin(), vec.end());
255 std::string Configuration::get<std::string>(
const std::string &key, std::string default_,
bool *default_used)
258 std::lock_guard<std::mutex> lock(mu_);
259 auto find = cfg_.find(key);
260 if (find != cfg_.end())
263 *default_used =
false;
271 return etiss::cfg().
get<std::string>(key, default_, default_used);
276 *default_used =
true;
282 bool Configuration::get<bool>(
const std::string &key,
bool default_,
bool *default_used)
284 std::string val = get<std::string>(key, default_ ?
"true" :
"false", default_used);
298 if (val ==
"true" || val ==
"1" || val ==
"on")
303 if (val ==
"false" || val ==
"0" || val ==
"off")
313 int Configuration::get<int>(
const std::string &key,
int default_,
bool *default_used)
315 std::string val = get<std::string>(key,
toString(default_), default_used);
318 return std::stoi(val, 0, 0);
323 *default_used =
true;
325 std::string(
"failed to parse value (") + val +
") of configuration key (" + key +
").");
331 unsigned Configuration::get<unsigned>(
const std::string &key,
unsigned default_,
bool *default_used)
333 std::string val = get<std::string>(key,
toString(default_), default_used);
336 return static_cast<unsigned>(std::stoull(val, 0, 0));
341 *default_used =
true;
344 std::string(
"failed to parse value (") + val +
") of configuration key (" + key +
").");
349 uint64_t Configuration::get<uint64_t>(
const std::string &key,
uint64_t default_,
bool *default_used)
351 std::string val = get<std::string>(key,
toString(default_), default_used);
354 return std::stoull(val, 0, 0);
359 *default_used =
true;
362 std::string(
"failed to parse value (") + val +
") of configuration key (" + key +
").");
371 return get<bool>(
"debug",
false);
376 std::lock_guard<std::mutex> lock(mu_);
377 if (final_.find(key) != final_.end())
384 std::lock_guard<std::mutex> lock(mu_);
385 return cfg_.find(key) != cfg_.end();
390 namespace po = boost::program_options;
394 if (
s.find(
"-f") == 0)
396 size_t epos =
s.find_first_of(
'=');
397 if (
s.length() > 5 &&
s.substr(2, 3) ==
"no-")
399 if (epos == std::string::npos)
401 std::string tmp =
s.substr(5);
406 return make_pair(tmp, std::string(
"false"));
410 std::string tmp =
s.substr(5, epos - 5);
413 return make_pair(std::string(), std::string());
418 if (epos == std::string::npos)
420 std::string tmp =
s.substr(2);
425 return make_pair(
s.substr(2), std::string(
"true"));
429 std::string tmp =
s.substr(2, epos - 2);
430 std::string tval =
s.substr(epos + 1);
434 return make_pair(
s.substr(2), tval);
436 return make_pair(std::string(), std::string());
440 return make_pair(std::string(), std::string());
446 std::list<std::string> ret;
447 for (
auto iter =
args.begin(); iter !=
args.end(); iter++)
449 const std::string &p = *iter;
453 if (p[0] ==
'-' && p[1] ==
'f')
457 size_t epos = p.find_first_of(
'=');
459 if (p.length() > 5 && p[2] ==
'n' && p[3] ==
'o' && p[4] ==
'-')
461 if (epos == std::string::npos)
463 std::string tmp = p.substr(5);
466 set<std::string>(tmp,
"false");
471 std::string tmp = p.substr(5, epos - 5);
478 if (epos == std::string::npos)
480 std::string tmp = p.substr(2);
483 set<std::string>(tmp,
"true");
488 std::string tmp = p.substr(2, epos - 2);
489 std::string tval = p.substr(epos + 1);
492 set<std::string>(tmp, tval);
497 if (p[0] ==
'-' && p[1] ==
'o')
500 std::string tmp = p.substr(2);
502 if (iter !=
args.end())
506 set<std::string>(tmp, *iter);
529 for (
auto iter = cfg_.begin(); iter != cfg_.end(); iter++)
531 ret[iter->first] = iter->second;
544 std::lock_guard<std::mutex> lock(mu_);
550 std::lock_guard<std::mutex> lock(mu_);
551 announced_[key] = std::tuple<std::string, std::string, std::string>(
type, values, description);
556 std::lock_guard<std::mutex> lock(mu_);
562 std::string cfgName_ = cfgName;
569 static std::map<std::string, etiss::Configuration>
cfg;
570 if (
cfg.find(cfgName_) ==
cfg.end())
575 return cfg[cfgName_];
579 std::string cfgName =
"global";
586 auto libPathLoc = etissLib.find_last_of(
"/\\");
587 auto libPath = etissLib.substr(0, libPathLoc);
588 auto etissPathLoc = libPath.find_last_of(
"/\\");
589 return libPath.substr(0, etissPathLoc);
598 std::vector<std::string>
x;
599 std::string range =
cfg().
get<std::string>(
"jit.external_headers",
"");
605 std::vector<std::string>
x;
606 std::string range =
cfg().
get<std::string>(
"jit.external_libs",
"");
612 std::vector<std::string>
x;
613 std::string range =
cfg().
get<std::string>(
"jit.external_header_paths",
"");
619 std::vector<std::string>
x;
620 std::string range =
cfg().
get<std::string>(
"jit.external_lib_paths",
"");
627 #if ETISS_USE_CONSTEXPR
630 "ETISS detected an invalid endianness configuartion of the floating point library. please change in the "
631 "file etiss/fpu/386-GCC.h the line #define LITTLEENDIAN (or similar) to #define BIGENDIAN");
635 "ETISS detected an invalid endianness configuartion of the floating point library. please change in the "
636 "file etiss/fpu/386-GCC.h the line #define BIGENDIAN (or similar) to #define LITTLEENDIAN");
639 #pragma message("ETISS cannot check if endianess is configured correctly due to missing constexpr support")
this file was derived from the 386-GCC.h file provided with John Hauser's Softfloat 2b library
#define static_assert(x, y)
Verbosity etiss_verbosity
static bool etiss_cfg_inConstructor
general configuration and logging
__device__ __2f16 float bool s
static __inline__ uint64_t
simple class to hold configuration options
std::map< std::string, std::string > & config()
access to the configuration key value map
void announce(std::string key, std::string type=std::string(), std::string values=std::string(), std::string description=std::string())
add a possible option to a list.
std::map< std::string, std::string > listFullConfiguration()
get a copy of the configuration as a map
static std::pair< std::string, std::string > set_cmd_line_boost(const std::string &s)
void makeFinal(const std::string &key)
makes an option final (option can no longer be changed)
std::map< std::string, std::tuple< std::string, std::string, std::string > > getAnnounced() const
get a map copy with announced options
bool isSet(std::string val)
return true if the value of an configuration key has been set
bool debug()
Get the value of the key "debug".
void remove(const std::string &key)
removes a key value mapping
bool set(const std::string &key, T value)
template function to set the value of a configuration key.
std::map< std::string, std::string > cfg_
T get(const std::string &key, T default_, bool *default_used=0)
template function to read the value of a configuration key.
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
std::vector< std::string > parseCommands(const std::string &cmdline)
std::list< std::string > split(const std::string &str, std::function< size_t(const std::string &, size_t, size_t &)> findsplit)
std::string jitFiles()
Get ETISS JIT files path.
void logC(Verbosity level, std::function< std::string(void)> msgGen)
write log message at the given level.
std::vector< std::string > jitExtLibPaths()
Get ETISS JIT external path.
std::string toString(const T &val)
conversion of type T to std::string.
std::string GetCurrentModulePath()
Returns the abolute path with filename to the own dynamic library.
std::string installDir()
Get ETISS installation directory.
std::vector< std::string > jitExtLibraries()
Get ETISS JIT external libraries.
std::vector< std::string > jitExtHeaders()
Get ETISS JIT external headers.
std::vector< std::string > jitExtHeaderPaths()
Get ETISS JIT external path.
Verbosity
Enumeration type for the log levels.
Configuration & cfg(const std::string &cfgName)
Get reference of the global ETISS configuration object.
endian_t getEndianness()
evaluates the endianness of the current build as a constexpr.
Verbosity & verbosity()
Get log level reference.
void log(Verbosity level, std::string msg)
write log message at the given level.