09caf314f1
We decided to get rid of the C FFI for libs. It was becoming too intricate and complicated. It was becoming a technical burden and expanding into too much extra code. It's unfortunate, but we'll have to give up on getting out-of-tree hot-loadable libraries the easy way. It's possible to still do it with cross compilation or by keeping track of the libstdc++ version that the running harikoff binary was compiled against. Then we can ensure that our loadable lib code is linked against that same libstdc++ code and this should ensure ABI stability.
70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
#include <iostream>
|
|
#include <fstream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <sstream>
|
|
#include <memory>
|
|
#include <cstdio>
|
|
#include <deviceManager/deviceManager.h>
|
|
#include "deviceSpecp.hh"
|
|
#include "deviceSpecl.hh"
|
|
|
|
namespace hk {
|
|
namespace device {
|
|
|
|
std::string DeviceManager::readDeviceFile(const std::string& filename)
|
|
{
|
|
std::ifstream file(filename);
|
|
if (!file.is_open()) {
|
|
throw std::runtime_error(
|
|
std::string(__func__) + ": Couldn't open deviceSpec file: "
|
|
+ filename);
|
|
}
|
|
|
|
std::string content(
|
|
(std::istreambuf_iterator<char>(file)),
|
|
std::istreambuf_iterator<char>());
|
|
|
|
return content;
|
|
}
|
|
|
|
void DeviceManager::collateAllDeviceSpecs(void)
|
|
{
|
|
OptionParser &options = OptionParser::getOptions();
|
|
allDeviceSpecs = options.deviceSpecs;
|
|
|
|
for (const auto& file : options.deviceSpecFiles)
|
|
{
|
|
std::string fileContent = readDeviceFile(file);
|
|
if (!allDeviceSpecs.empty()) {
|
|
allDeviceSpecs += "||";
|
|
}
|
|
allDeviceSpecs += fileContent;
|
|
}
|
|
}
|
|
|
|
void DeviceManager::parseAllDeviceSpecs(void)
|
|
{
|
|
std::unique_ptr<FILE, decltype(&fclose)> input(
|
|
fmemopen((void*)allDeviceSpecs.c_str(),
|
|
allDeviceSpecs.size(), "r"),
|
|
&fclose);
|
|
|
|
if (!input) {
|
|
throw std::runtime_error(
|
|
std::string(__func__) + ": Failed to fmemopen() a FILE* for "
|
|
"parsing device specs");
|
|
}
|
|
|
|
deviceSpeclin = input.get();
|
|
if (deviceSpecpparse()) {
|
|
throw std::runtime_error(
|
|
std::string(__func__) + ": Failed to parse device specs. "
|
|
"Check specs for errors");
|
|
}
|
|
}
|
|
|
|
} // namespace device
|
|
} // namespace hk
|