ETISS 0.8.0
Extendable Translating Instruction Set Simulator (version 0.8.0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ETISSInit.cpp
Go to the documentation of this file.
1
53#include "etiss/ETISS.h"
54#include "etiss/config.h"
55
56#include <cstdlib>
57#include <fstream>
58#include <sstream>
59#include <string>
60#include <vector>
61
62#include <boost/filesystem.hpp>
63
64namespace etiss
65{
66
67std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems)
68{
69 std::stringstream ss(s);
70 std::string item;
71 while (std::getline(ss, item, delim))
72 {
73 elems.push_back(item);
74 }
75 return elems;
76}
77
78} // namespace etiss
79
114static bool loadLibraryList(const std::string &path)
115{
116 std::string list_file = (path + "/list.txt");
117 std::ifstream lcfg(list_file.c_str());
118 if (!lcfg)
119 {
120 etiss::log(etiss::ERROR, std::string("Failed to open library list file: ") + list_file);
121 return false;
122 }
123
124 bool ret = false;
125 std::string line;
126 while (std::getline(lcfg, line))
127 {
128 if (line.find(',') == std::string::npos)
129 { // relative path
130 if (etiss::loadLibrary(path, line))
131 ret = true;
132 }
133 else
134 { // absolute path
135 std::vector<std::string> def;
136 etiss::split(line, ',', def);
137 if (def.size() == 3)
138 {
139 if (def[0] == def[2] && def[1].length() > 0 && def[2].length() > 0)
140 {
141 if (etiss::loadLibrary(def[1], def[2]))
142 ret = true;
143 }
144 else
145 {
146 etiss::log(etiss::ERROR, "Invalid line in plugin list file", line);
147 }
148 }
149 else
150 {
151 etiss::log(etiss::ERROR, "Invalid line in plugin list file", line);
152 }
153 }
154 }
155 return ret;
156}
157
169static void findLibs(const boost::filesystem::path &path, std::vector<std::string> &libs)
170{
171 if (boost::filesystem::exists(path) && boost::filesystem::is_directory(path))
172 {
173 boost::filesystem::recursive_directory_iterator end_itr;
174 for (boost::filesystem::recursive_directory_iterator itr(path); itr != end_itr; ++itr)
175 {
176 if (boost::filesystem::is_regular_file(itr->status()))
177 {
178 std::string name(itr->path().filename().string());
179 if (name.compare(0, 3, "lib") == 0 && name.compare(name.length() - 3, 3, ".so") == 0)
180 {
181 libs.push_back(itr->path().string());
182 }
183 }
184 }
185 }
186}
187
191
193{
194
195 // only allow to execute preloadLibraries() ones
197 {
198 return;
199 }
200 else
201 {
203 }
204
205 // load libraries
206 loadLibraryList(installDir() + "/lib/plugins");
207
208 // load libraries from user folder
209 std::string etiss_path = etiss::cfg().get<std::string>("etiss_wd", ".");
210 std::vector<std::string> lib_dirs{ std::string("ArchImpl"), std::string("JITImpl"), std::string("PluginImpl") };
211 if (!etiss_path.empty())
212 {
213 std::vector<std::string> libs;
214 for (auto itr = lib_dirs.begin(); itr != lib_dirs.end(); ++itr)
215 {
216 findLibs(boost::filesystem::path(etiss_path) / *itr, libs);
217 }
218 for (auto itr = libs.begin(); itr != libs.end(); ++itr)
219 {
220 size_t path_end = itr->rfind('/');
221 etiss::loadLibrary(itr->substr(0, path_end), itr->substr(path_end + 4, itr->length() - path_end - 7));
222 }
223 }
224}
bool etiss_preload_libraries
This flag indicate whether the preloading of the libraries has been executed or not.
static void findLibs(const boost::filesystem::path &path, std::vector< std::string > &libs)
Find all dynamically linked libraries in a folder and its subfolders.
static bool loadLibraryList(const std::string &path)
Load libraries specified in a list.txt file.
Header file of the ETISS library.
__device__ __2f16 float bool s
T get(const std::string &key, T default_, bool *default_used=0)
template function to read the value of a configuration key.
Definition Misc.h:349
contains defines to configure ETISS.
bool loadLibrary(std::string path, std::string name)
Load a library.
Definition ETISS.cpp:288
void preloadLibraries()
Search and try to load libraries.
Page Table Entry (PTE) defines the composition of Page Frame Number (PFN) and relavant flags.
Definition Benchmark.h:53
std::list< std::string > split(const std::string &str, std::function< size_t(const std::string &, size_t, size_t &)> findsplit)
Definition Misc.cpp:91
std::string installDir()
Get ETISS installation directory.
Definition Misc.cpp:583
@ ERROR
Definition Misc.h:127
Configuration & cfg()
Definition Misc.cpp:577
void log(Verbosity level, std::string msg)
write log message at the given level.
Definition Misc.cpp:125
float __ovld __cnfn length(float p)
Return the length of vector p, i.e., sqrt(p.x2 + p.y 2 + ...)