2020-01-19 18:17:01 +01:00
|
|
|
#include <fxos/library.h>
|
|
|
|
#include <fxos/load.h>
|
|
|
|
|
|
|
|
#include <fxos/errors.h>
|
|
|
|
#include <fxos/util.h>
|
|
|
|
#include <fxos/log.h>
|
|
|
|
|
|
|
|
#include <filesystem>
|
|
|
|
#include <ctime>
|
|
|
|
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
using namespace FxOS::Log;
|
|
|
|
|
|
|
|
namespace FxOS {
|
|
|
|
|
|
|
|
/* Add a new search path in the library. */
|
|
|
|
void Library::add_path(std::string path)
|
|
|
|
{
|
|
|
|
m_paths.push_back(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Recursively explore the fxos data file in a folder. */
|
|
|
|
void Library::explore(std::string path)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
fs::recursive_directory_iterator it(path);
|
2020-02-27 15:11:42 +01:00
|
|
|
for(auto &file: it)
|
|
|
|
{
|
2020-02-29 11:22:26 +01:00
|
|
|
if(!fs::is_directory(file)) try {
|
|
|
|
load(file.path());
|
|
|
|
}
|
|
|
|
catch(FxOS::SyntaxError &e) {
|
|
|
|
log(ERR "%s", e.str());
|
|
|
|
}
|
2020-02-27 15:11:42 +01:00
|
|
|
}
|
2020-01-19 18:17:01 +01:00
|
|
|
}
|
|
|
|
catch(fs::filesystem_error &e)
|
|
|
|
{
|
|
|
|
if(e.code().value() == ENOENT)
|
|
|
|
{
|
|
|
|
log(WRN "directory %s does not exist", path);
|
|
|
|
}
|
|
|
|
else throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Directly load an fxos data file into the library. */
|
|
|
|
void Library::load(std::string path)
|
|
|
|
{
|
|
|
|
Buffer file(path);
|
|
|
|
size_t offset;
|
|
|
|
int line;
|
|
|
|
|
|
|
|
log(LOG "Loading resource file '%s'...\\", path);
|
|
|
|
|
|
|
|
/* Time the loading */
|
|
|
|
auto start = timer_start();
|
|
|
|
|
|
|
|
Header h = load_header(file, offset, line);
|
|
|
|
if(h.find("type") == h.end())
|
|
|
|
{
|
|
|
|
log(ERR "no type set in the header of '%s'", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string type = h["type"];
|
|
|
|
|
|
|
|
if(type == "assembly")
|
|
|
|
{
|
2020-02-29 11:22:26 +01:00
|
|
|
int total = load_asm(file, offset, line);
|
|
|
|
m_asmtables.push_back(std::make_pair(h["name"],total));
|
2020-01-19 18:17:01 +01:00
|
|
|
}
|
|
|
|
else if(type == "target")
|
|
|
|
{
|
|
|
|
if(!h.count("name"))
|
|
|
|
{
|
|
|
|
log(ERR "no target name set in '%s'", path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-13 11:23:46 +02:00
|
|
|
TargetDescription t = load_target(file, offset, line);
|
|
|
|
t.mpu = h["mpu"];
|
|
|
|
m_targets[h["name"]] = t;
|
2020-01-19 18:17:01 +01:00
|
|
|
}
|
2020-02-15 18:42:14 +01:00
|
|
|
else if(type == "symbols")
|
|
|
|
{
|
2020-06-13 11:23:46 +02:00
|
|
|
SymbolTable st(h["os"], h["mpu"]);
|
|
|
|
load_symbols(file, offset, line, st);
|
|
|
|
|
2020-02-29 11:22:26 +01:00
|
|
|
m_symtables.push_back(st);
|
2020-02-15 18:42:14 +01:00
|
|
|
}
|
2020-01-19 18:17:01 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
log(ERR "unknown file type '%s' in '%s'", type, path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
long long ns = timer_end(start);
|
|
|
|
|
2020-02-12 07:53:00 +01:00
|
|
|
log(LOG "%s", timer_format(ns));
|
2020-01-19 18:17:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace FxOS */
|