From 61bce47f3cb7b4adf1d5292b3c431ca4048ad038 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Wed, 8 Aug 2018 20:14:18 +0200 Subject: Use settings for json and pcf --- ice40/main.cc | 5 +++-- ice40/pcf.cc | 3 ++- ice40/pcf.h | 2 +- ice40/project.cc | 10 ++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'ice40') diff --git a/ice40/main.cc b/ice40/main.cc index 2818a3ad..8bab360d 100644 --- a/ice40/main.cc +++ b/ice40/main.cc @@ -79,8 +79,9 @@ void Ice40CommandHandler::validate() void Ice40CommandHandler::customAfterLoad(Context *ctx) { if (vm.count("pcf")) { - std::ifstream pcf(vm["pcf"].as()); - if (!apply_pcf(ctx, pcf)) + std::string filename = vm["pcf"].as(); + std::ifstream pcf(filename); + if (!apply_pcf(ctx, filename, pcf)) log_error("Loading PCF failed.\n"); } } diff --git a/ice40/pcf.cc b/ice40/pcf.cc index 410fa1c9..d9fc4e68 100644 --- a/ice40/pcf.cc +++ b/ice40/pcf.cc @@ -27,7 +27,7 @@ NEXTPNR_NAMESPACE_BEGIN // Read a w // 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 { if (!in) @@ -66,6 +66,7 @@ bool apply_pcf(Context *ctx, std::istream &in) log_error("unsupported pcf command '%s'\n", cmd.c_str()); } } + ctx->settings.emplace(ctx->id("project/input/pcf"), filename); return true; } catch (log_execution_error_exception) { return false; diff --git a/ice40/pcf.h b/ice40/pcf.h index 315f6270..ecc81e59 100644 --- a/ice40/pcf.h +++ b/ice40/pcf.h @@ -27,7 +27,7 @@ NEXTPNR_NAMESPACE_BEGIN // 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 diff --git a/ice40/project.cc b/ice40/project.cc index d1f1674a..8ca10e36 100644 --- a/ice40/project.cc +++ b/ice40/project.cc @@ -25,11 +25,13 @@ 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); - // if(!pcfFilename.empty()) - // root.put("project.input.pcf", pcfFilename); + if (ctx->settings.find(ctx->id("project/input/pcf")) != ctx->settings.end()) { + std::string fn = ctx->settings[ctx->id("project/input/pcf")]; + root.put("project.input.pcf", make_relative(fn, path).string()); + } } std::unique_ptr 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"); boost::filesystem::path pcf = boost::filesystem::path(path) / input.get("pcf"); std::ifstream f(pcf.string()); - if (!apply_pcf(ctx, f)) + if (!apply_pcf(ctx, input.get("pcf"), f)) log_error("Loading PCF failed.\n"); } -- cgit v1.2.3