14#ifndef ETISS_INCLUDE_MISC_H_
15#define ETISS_INCLUDE_MISC_H_
31#include "etiss/jit/types.h"
35typedef std::make_signed<size_t>::type ssize_t;
38#define ETISS_TOSTRING2(X) #X
39#define ETISS_TOSTRING(X) ETISS_TOSTRING2(X)
41#define etiss_log(LEVEL, MSG) \
42 etiss::log(etiss::LEVEL, \
43 std::string("On line " ETISS_TOSTRING(__LINE__) " in file " ETISS_TOSTRING(__FILE__) ": ") + (MSG));
45#define etiss_del_copy(CLASS) \
46 CLASS(const CLASS &) = delete; \
47 CLASS &operator=(const CLASS &) = delete;
48#define etiss_del_move(CLASS) \
49 CLASS &operator=(CLASS &&) = delete; \
50 CLASS(CLASS &&) = delete;
52#define etiss_del_como(CLASS) etiss_del_copy(CLASS) etiss_del_move(CLASS)
56#define ETISS_TEMPLATE_EXPRESSION_IS_VALID(STRUCT, EXPRESSION) \
62 template <typename T, typename Sfinae = void> \
63 struct STRUCT : std::false_type \
66 template <typename T> \
67 struct STRUCT<T, typename STRUCT##Void<decltype(EXPRESSION)>::type> : std::true_type \
106typename std::enable_if<std::is_base_of<etiss::ToString, T>::value, std::ostream &>::type
operator<<(std::ostream &os,
109 os << val.toString();
135 std::stringstream ss;
140std::list<std::string>
split(
141 const std::string &str,
142 std::function<
size_t(
const std::string & ,
size_t ,
size_t & )> findsplit);
143inline std::list<std::string>
split(
const std::string &str,
char splitchar)
146 [splitchar](
const std::string &str,
size_t from,
size_t &seperatorsize)
149 return str.find(splitchar, from);
153inline std::list<std::string>
split(
const std::string &str,
const std::string &splitstring)
156 [splitstring](
const std::string &str,
size_t from,
size_t &seperatorsize)
159 return str.find(splitstring, from);
167template <
typename T,
typename T2,
typename... O>
168std::string
toString(
const T &val,
const T2 &val2,
const O &...others)
202#define ETISS_SRCLOC etiss::SourceCodeLocation(__FILE__, __LINE__)
203#define ETISS_VARVAL(VAR) (std::string(ETISS_TOSTRING(VAR)) + "={" + toLogString(VAR) + "}")
215void logC(
Verbosity level, std::function<std::string(
void)> msgGen);
236template <
typename T1,
typename T2,
typename... O>
237std::string
toLogString(
const T1 &t1,
const T2 &t2,
const O &...os)
246template <
typename T,
typename... O>
247void log(
Verbosity level, std::string msg,
const T &t,
const O &...args)
255std::vector<std::string>
parseCommands(
const std::string &cmdline);
260Configuration &
cfg(
const std::string &cfgName);
305 std::map<std::string, std::string> &
config();
311 template <
typename T>
312 T
get(
const std::string &key, T default_,
bool *default_used = 0)
317 *default_used =
true;
334 template <
typename T>
335 bool set(
const std::string &key, T value)
358 size_t coreStart = key.find(
"core");
359 size_t coreEnd = key.find(
"::", coreStart + 1);
360 if (coreStart != std::string::npos && coreEnd != std::string::npos &&
361 key.substr(coreStart + 4, coreEnd - (coreStart + 4)).find_first_not_of(
"0123456789") == std::string::npos)
363 std::string newkey = key;
364 newkey.replace(coreStart, coreEnd - coreStart + 2,
"");
366 key.substr(coreStart, coreEnd - coreStart));
367 return etiss::cfg(key.substr(coreStart, coreEnd - coreStart)).
set<T>(newkey, value);
370 std::stringstream ss;
372 std::lock_guard<std::mutex> lock(
mu_);
379 cfg_[key] = (hlp->second)(ss.str());
383 cfg_[key] = ss.str();
391 bool isSet(std::string val);
396 void remove(
const std::string &key);
404 std::list<std::string>
set(
const std::list<std::string> &args);
422 void announce(std::string key, std::string type = std::string(), std::string values = std::string(),
423 std::string description = std::string());
428 std::map<std::string, std::tuple<std::string, std::string, std::string>>
getAnnounced()
const;
432 std::lock_guard<std::mutex> lock(other.mu_);
433 std::lock_guard<std::mutex> lock2(
mu_);
441 std::map<std::string, std::string>
cfg_;
443 std::map<std::string, std::function<std::string(std::string)>>
helpers_;
445 std::map<std::string, std::tuple<std::string, std::string, std::string>>
announced_;
450std::string Configuration::get<std::string>(
const std::string &key, std::string default_,
bool *default_used);
453bool Configuration::get<bool>(
const std::string &key,
bool default_,
bool *default_used);
456int Configuration::get<int>(
const std::string &key,
int default_,
bool *default_used);
459unsigned Configuration::get<unsigned>(
const std::string &key,
unsigned default_,
bool *default_used);
462uint64_t Configuration::get<uint64_t>(
const std::string &key,
uint64_t default_,
bool *default_used);
472 std::string values = std::string(), std::string description = std::string())
474 config.announce(key, type, values, description);
477 inline ConfigAnnouncer(std::string key, std::string type = std::string(), std::string values = std::string(),
478 std::string description = std::string())
499#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
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.
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...
endian_t getEndianness()
evaluates the endianness of the current build as a constexpr.
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.