Use settings for json and pcf
This commit is contained in:
parent
b326b03a52
commit
61bce47f3c
@ -26,19 +26,53 @@
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
boost::filesystem::path make_relative(boost::filesystem::path child, boost::filesystem::path parent)
|
||||||
|
{
|
||||||
|
boost::filesystem::path::const_iterator parentIter = parent.begin();
|
||||||
|
boost::filesystem::path::const_iterator childIter = child.begin();
|
||||||
|
|
||||||
|
while (parentIter != parent.end() && childIter != child.end() && (*childIter) == (*parentIter)) {
|
||||||
|
++childIter;
|
||||||
|
++parentIter;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::filesystem::path finalPath;
|
||||||
|
while (parentIter != parent.end()) {
|
||||||
|
finalPath /= "..";
|
||||||
|
++parentIter;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (childIter != child.end()) {
|
||||||
|
finalPath /= *childIter;
|
||||||
|
++childIter;
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalPath;
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectHandler::save(Context *ctx, std::string filename)
|
void ProjectHandler::save(Context *ctx, std::string filename)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
boost::filesystem::path proj(filename);
|
||||||
std::ofstream f(filename);
|
std::ofstream f(filename);
|
||||||
pt::ptree root;
|
pt::ptree root;
|
||||||
|
|
||||||
|
log_info("Saving project %s...\n", filename.c_str());
|
||||||
|
log_break();
|
||||||
|
|
||||||
root.put("project.version", 1);
|
root.put("project.version", 1);
|
||||||
root.put("project.name", boost::filesystem::basename(filename));
|
root.put("project.name", boost::filesystem::basename(filename));
|
||||||
root.put("project.arch.name", ctx->archId().c_str(ctx));
|
root.put("project.arch.name", ctx->archId().c_str(ctx));
|
||||||
root.put("project.arch.type", ctx->archArgsToId(ctx->archArgs()).c_str(ctx));
|
root.put("project.arch.type", ctx->archArgsToId(ctx->archArgs()).c_str(ctx));
|
||||||
/* root.put("project.input.json", );*/
|
std::string fn = ctx->settings[ctx->id("project/input/json")];
|
||||||
|
root.put("project.input.json", make_relative(fn, proj.parent_path()).string());
|
||||||
root.put("project.params.freq", int(ctx->target_freq / 1e6));
|
root.put("project.params.freq", int(ctx->target_freq / 1e6));
|
||||||
root.put("project.params.seed", ctx->rngstate);
|
root.put("project.params.seed", ctx->rngstate);
|
||||||
saveArch(ctx, root);
|
saveArch(ctx, root, proj.parent_path().string());
|
||||||
pt::write_json(f, root);
|
pt::write_json(f, root);
|
||||||
|
} catch (...) {
|
||||||
|
log_error("Error saving project file.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Context> ProjectHandler::load(std::string filename)
|
std::unique_ptr<Context> ProjectHandler::load(std::string filename)
|
||||||
@ -63,10 +97,10 @@ std::unique_ptr<Context> ProjectHandler::load(std::string filename)
|
|||||||
|
|
||||||
auto project = root.get_child("project");
|
auto project = root.get_child("project");
|
||||||
auto input = project.get_child("input");
|
auto input = project.get_child("input");
|
||||||
std::string filename = input.get<std::string>("json");
|
std::string fn = input.get<std::string>("json");
|
||||||
boost::filesystem::path json = proj.parent_path() / filename;
|
boost::filesystem::path json = proj.parent_path() / fn;
|
||||||
std::ifstream f(json.string());
|
std::ifstream f(json.string());
|
||||||
if (!parse_json_file(f, filename, ctx.get()))
|
if (!parse_json_file(f, fn, ctx.get()))
|
||||||
log_error("Loading design failed.\n");
|
log_error("Loading design failed.\n");
|
||||||
|
|
||||||
if (project.count("params")) {
|
if (project.count("params")) {
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#ifndef PROJECT_H
|
#ifndef PROJECT_H
|
||||||
#define PROJECT_H
|
#define PROJECT_H
|
||||||
|
|
||||||
|
#include <boost/filesystem/convenience.hpp>
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <boost/property_tree/ptree.hpp>
|
||||||
#include "nextpnr.h"
|
#include "nextpnr.h"
|
||||||
|
|
||||||
@ -32,11 +33,13 @@ struct ProjectHandler
|
|||||||
void save(Context *ctx, std::string filename);
|
void save(Context *ctx, std::string filename);
|
||||||
std::unique_ptr<Context> load(std::string filename);
|
std::unique_ptr<Context> load(std::string filename);
|
||||||
// implemented per arch
|
// implemented per arch
|
||||||
void saveArch(Context *ctx, pt::ptree &root);
|
void saveArch(Context *ctx, pt::ptree &root, std::string path);
|
||||||
std::unique_ptr<Context> createContext(pt::ptree &root);
|
std::unique_ptr<Context> createContext(pt::ptree &root);
|
||||||
void loadArch(Context *ctx, pt::ptree &root, std::string path);
|
void loadArch(Context *ctx, pt::ptree &root, std::string path);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
boost::filesystem::path make_relative(boost::filesystem::path child, boost::filesystem::path parent);
|
||||||
|
|
||||||
NEXTPNR_NAMESPACE_END
|
NEXTPNR_NAMESPACE_END
|
||||||
|
|
||||||
#endif // PROJECT_H
|
#endif // PROJECT_H
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root)
|
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root, std::string path)
|
||||||
{
|
{
|
||||||
root.put("project.arch.package", ctx->archArgs().package);
|
root.put("project.arch.package", ctx->archArgs().package);
|
||||||
root.put("project.arch.speed", ctx->archArgs().speed);
|
root.put("project.arch.speed", ctx->archArgs().speed);
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root) {}
|
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root, std::string path) {}
|
||||||
|
|
||||||
std::unique_ptr<Context> ProjectHandler::createContext(pt::ptree &root)
|
std::unique_ptr<Context> ProjectHandler::createContext(pt::ptree &root)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +52,6 @@ class MainWindow : public BaseMainWindow
|
|||||||
|
|
||||||
ArchArgs chipArgs;
|
ArchArgs chipArgs;
|
||||||
|
|
||||||
std::string currentProj;
|
|
||||||
std::string currentBaseConfig;
|
std::string currentBaseConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ void MainWindow::load_pcf(std::string filename)
|
|||||||
disableActions();
|
disableActions();
|
||||||
currentPCF = filename;
|
currentPCF = filename;
|
||||||
std::ifstream f(filename);
|
std::ifstream f(filename);
|
||||||
if (apply_pcf(ctx.get(), f)) {
|
if (apply_pcf(ctx.get(), filename, f)) {
|
||||||
log("Loading PCF successful.\n");
|
log("Loading PCF successful.\n");
|
||||||
actionPack->setEnabled(true);
|
actionPack->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -79,8 +79,9 @@ void Ice40CommandHandler::validate()
|
|||||||
void Ice40CommandHandler::customAfterLoad(Context *ctx)
|
void Ice40CommandHandler::customAfterLoad(Context *ctx)
|
||||||
{
|
{
|
||||||
if (vm.count("pcf")) {
|
if (vm.count("pcf")) {
|
||||||
std::ifstream pcf(vm["pcf"].as<std::string>());
|
std::string filename = vm["pcf"].as<std::string>();
|
||||||
if (!apply_pcf(ctx, pcf))
|
std::ifstream pcf(filename);
|
||||||
|
if (!apply_pcf(ctx, filename, pcf))
|
||||||
log_error("Loading PCF failed.\n");
|
log_error("Loading PCF failed.\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,7 @@ NEXTPNR_NAMESPACE_BEGIN
|
|||||||
// Read a w
|
// Read a w
|
||||||
|
|
||||||
// Apply PCF constraints to a pre-packing design
|
// Apply PCF constraints to a pre-packing design
|
||||||
bool apply_pcf(Context *ctx, std::istream &in)
|
bool apply_pcf(Context *ctx, std::string filename, std::istream &in)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (!in)
|
if (!in)
|
||||||
@ -66,6 +66,7 @@ bool apply_pcf(Context *ctx, std::istream &in)
|
|||||||
log_error("unsupported pcf command '%s'\n", cmd.c_str());
|
log_error("unsupported pcf command '%s'\n", cmd.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ctx->settings.emplace(ctx->id("project/input/pcf"), filename);
|
||||||
return true;
|
return true;
|
||||||
} catch (log_execution_error_exception) {
|
} catch (log_execution_error_exception) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
// Apply PCF constraints to a pre-packing design
|
// Apply PCF constraints to a pre-packing design
|
||||||
bool apply_pcf(Context *ctx, std::istream &in);
|
bool apply_pcf(Context *ctx, std::string filename, std::istream &in);
|
||||||
|
|
||||||
NEXTPNR_NAMESPACE_END
|
NEXTPNR_NAMESPACE_END
|
||||||
|
|
||||||
|
@ -25,11 +25,13 @@
|
|||||||
|
|
||||||
NEXTPNR_NAMESPACE_BEGIN
|
NEXTPNR_NAMESPACE_BEGIN
|
||||||
|
|
||||||
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root)
|
void ProjectHandler::saveArch(Context *ctx, pt::ptree &root, std::string path)
|
||||||
{
|
{
|
||||||
root.put("project.arch.package", ctx->archArgs().package);
|
root.put("project.arch.package", ctx->archArgs().package);
|
||||||
// if(!pcfFilename.empty())
|
if (ctx->settings.find(ctx->id("project/input/pcf")) != ctx->settings.end()) {
|
||||||
// root.put("project.input.pcf", pcfFilename);
|
std::string fn = ctx->settings[ctx->id("project/input/pcf")];
|
||||||
|
root.put("project.input.pcf", make_relative(fn, path).string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Context> ProjectHandler::createContext(pt::ptree &root)
|
std::unique_ptr<Context> ProjectHandler::createContext(pt::ptree &root)
|
||||||
@ -64,7 +66,7 @@ void ProjectHandler::loadArch(Context *ctx, pt::ptree &root, std::string path)
|
|||||||
auto input = root.get_child("project").get_child("input");
|
auto input = root.get_child("project").get_child("input");
|
||||||
boost::filesystem::path pcf = boost::filesystem::path(path) / input.get<std::string>("pcf");
|
boost::filesystem::path pcf = boost::filesystem::path(path) / input.get<std::string>("pcf");
|
||||||
std::ifstream f(pcf.string());
|
std::ifstream f(pcf.string());
|
||||||
if (!apply_pcf(ctx, f))
|
if (!apply_pcf(ctx, input.get<std::string>("pcf"), f))
|
||||||
log_error("Loading PCF failed.\n");
|
log_error("Loading PCF failed.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,6 +754,7 @@ bool parse_json_file(std::istream &f, std::string &filename, Context *ctx)
|
|||||||
|
|
||||||
log_info("Checksum: 0x%08x\n", ctx->checksum());
|
log_info("Checksum: 0x%08x\n", ctx->checksum());
|
||||||
log_break();
|
log_break();
|
||||||
|
ctx->settings.emplace(ctx->id("project/input/json"), filename);
|
||||||
return true;
|
return true;
|
||||||
} catch (log_execution_error_exception) {
|
} catch (log_execution_error_exception) {
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user