56 #ifndef ETISS_INCLUDE_MISC_H_
57 #define ETISS_INCLUDE_MISC_H_
73 #include "etiss/jit/types.h"
80 #define ETISS_TOSTRING2(X) #X
81 #define ETISS_TOSTRING(X) ETISS_TOSTRING2(X)
83 #define etiss_log(LEVEL, MSG) \
84 etiss::log(etiss::LEVEL, \
85 std::string("On line " ETISS_TOSTRING(__LINE__) " in file " ETISS_TOSTRING(__FILE__) ": ") + (MSG));
87 #define etiss_del_copy(CLASS) \
88 CLASS(const CLASS &) = delete; \
89 CLASS &operator=(const CLASS &) = delete;
90 #define etiss_del_move(CLASS) \
91 CLASS &operator=(CLASS &&) = delete; \
92 CLASS(CLASS &&) = delete;
94 #define etiss_del_como(CLASS) etiss_del_copy(CLASS) etiss_del_move(CLASS)
98 #define ETISS_TEMPLATE_EXPRESSION_IS_VALID(STRUCT, EXPRESSION) \
100 struct STRUCT##Void \
104 template <typename T, typename Sfinae = void> \
105 struct STRUCT : std::false_type \
108 template <typename T> \
109 struct STRUCT<T, typename STRUCT##Void<decltype(EXPRESSION)>::type> : std::true_type \
147 template <
typename T>
148 typename std::enable_if<std::is_base_of<etiss::ToString, T>::value, std::ostream &>
::type operator<<(std::ostream &os,
151 os << val.toString();
173 template <
typename T>
176 std::stringstream ss;
181 std::list<std::string>
split(
182 const std::string &
str,
183 std::function<
size_t(
const std::string & ,
size_t ,
size_t & )> findsplit);
184 inline std::list<std::string>
split(
const std::string &
str,
char splitchar)
186 return split(
str, [splitchar](
const std::string &
str,
size_t from,
size_t &seperatorsize) {
188 return str.find(splitchar, from);
192 inline std::list<std::string>
split(
const std::string &
str,
const std::string &splitstring)
194 return split(
str, [splitstring](
const std::string &
str,
size_t from,
size_t &seperatorsize) {
196 return str.find(splitstring, from);
204 template <
typename T,
typename T2,
typename... O>
205 std::string
toString(
const T &val,
const T2 &val2,
const O &... others)
239 #define ETISS_SRCLOC etiss::SourceCodeLocation(__FILE__, __LINE__)
240 #define ETISS_VARVAL(VAR) (std::string(ETISS_TOSTRING(VAR)) + "={" + toLogString(VAR) + "}")
252 void logC(
Verbosity level, std::function<std::string(
void)> msgGen);
260 template <
typename T>
273 template <
typename T1,
typename T2,
typename... O>
274 std::string
toLogString(
const T1 &t1,
const T2 &t2,
const O &... os)
283 template <
typename T,
typename... O>
292 std::vector<std::string>
parseCommands(
const std::string &cmdline);
297 Configuration &
cfg(
const std::string &cfgName);
298 Configuration &
cfg();
342 std::map<std::string, std::string> &
config();
348 template <
typename T>
349 T
get(
const std::string &key, T default_,
bool *default_used = 0)
354 *default_used =
true;
371 template <
typename T>
372 bool set(
const std::string &key, T value)
395 size_t coreStart = key.find(
"core");
396 size_t coreEnd = key.find(
"::", coreStart + 1);
397 if (coreStart != std::string::npos && coreEnd != std::string::npos &&
398 key.substr(coreStart + 4, coreEnd - (coreStart + 4)).find_first_not_of(
"0123456789") == std::string::npos)
400 std::string newkey = key;
401 newkey.replace(coreStart, coreEnd - coreStart + 2,
"");
403 key.substr(coreStart, coreEnd - coreStart));
404 return etiss::cfg(key.substr(coreStart, coreEnd - coreStart)).
set<T>(newkey, value);
407 std::stringstream ss;
409 std::lock_guard<std::mutex> lock(
mu_);
416 cfg_[key] = (hlp->second)(ss.str());
420 cfg_[key] = ss.str();
428 bool isSet(std::string val);
433 void remove(
const std::string &key);
441 std::list<std::string>
set(
const std::list<std::string> &
args);
459 void announce(std::string key, std::string
type = std::string(), std::string values = std::string(),
460 std::string description = std::string());
465 std::map<std::string, std::tuple<std::string, std::string, std::string>>
getAnnounced()
const;
469 std::lock_guard<std::mutex> lock(other.mu_);
470 std::lock_guard<std::mutex> lock2(
mu_);
478 std::map<std::string, std::string>
cfg_;
480 std::map<std::string, std::function<std::string(std::string)>>
helpers_;
482 std::map<std::string, std::tuple<std::string, std::string, std::string>>
announced_;
487 std::string Configuration::get<std::string>(
const std::string &key, std::string default_,
bool *default_used);
490 bool Configuration::get<bool>(
const std::string &key,
bool default_,
bool *default_used);
493 int Configuration::get<int>(
const std::string &key,
int default_,
bool *default_used);
496 unsigned Configuration::get<unsigned>(
const std::string &key,
unsigned default_,
bool *default_used);
499 uint64_t Configuration::get<uint64_t>(
const std::string &key,
uint64_t default_,
bool *default_used);
509 std::string values = std::string(), std::string description = std::string())
511 config.announce(key,
type, values, description);
514 inline ConfigAnnouncer(std::string key, std::string
type = std::string(), std::string values = std::string(),
515 std::string description = std::string())
536 #if ETISS_USE_CONSTEXPR
__device__ __2f16 float bool s
static __inline__ uint32_t
static __inline__ uint64_t
simple class to add a configuration option to the list of known options
ConfigAnnouncer(std::string key, std::string type=std::string(), std::string values=std::string(), std::string description=std::string())
ConfigAnnouncer(Configuration &config, std::string key, std::string type=std::string(), std::string values=std::string(), std::string description=std::string())
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
void operator=(Configuration &&other)
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".
std::map< std::string, std::tuple< std::string, std::string, std::string > > announced_
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_
std::set< std::string > final_
T get(const std::string &key, T default_, bool *default_used=0)
template function to read the value of a configuration key.
std::map< std::string, std::function< std::string(std::string)> > helpers_
simple class that store source location information.
SourceCodeLocation(const std::string &file, size_t line)
std::string toString() const
Marker interface for toString() support.
contains defines to configure ETISS.
#define ETISS_LITTLE_ENDIAN
#define ETISS_UNKNOWN_ENDIAN
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 installDir()
Get ETISS installation directory.
endian_t
Enumeration type for the endianness.
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.
std::enable_if< std::is_base_of< etiss::ToString, T >::value, std::ostream & >::type operator<<(std::ostream &os, const T &val)
Implementation of the write to stream operator for objects, that implement the etiss::ToString interf...
std::string toLogString(const T &t)
Format the string representation of a value for the log output.
Verbosity & verbosity()
Get log level reference.
void log(Verbosity level, std::string msg)
write log message at the given level.