diff --git a/common/command.cc b/common/command.cc index 1a8f810e..ca054532 100644 --- a/common/command.cc +++ b/common/command.cc @@ -192,11 +192,11 @@ void CommandHandler::setupContext(Context *ctx) } if (vm.count("ignore-loops")) { - settings->set("timing/ignoreLoops", true); + ctx->settings[ctx->id("timing/ignoreLoops")] = std::to_string(true); } if (vm.count("timing-allow-fail")) { - settings->set("timing/allowFail", true); + ctx->settings[ctx->id("timing/allowFail")] = std::to_string(true); } if (vm.count("placer")) { @@ -205,20 +205,20 @@ void CommandHandler::setupContext(Context *ctx) Arch::availablePlacers.end()) log_error("Placer algorithm '%s' is not supported (available options: %s)\n", placer.c_str(), boost::algorithm::join(Arch::availablePlacers, ", ").c_str()); - settings->set("placer", placer); + ctx->settings[ctx->id("placer")] = placer; } else { - settings->set("placer", Arch::defaultPlacer); + ctx->settings[ctx->id("placer")] = Arch::defaultPlacer; } if (vm.count("cstrweight")) { - settings->set("placer1/constraintWeight", vm["cstrweight"].as()); + ctx->settings[ctx->id("placer1/constraintWeight")] = std::to_string(vm["cstrweight"].as()); } if (vm.count("starttemp")) { - settings->set("placer1/startTemp", vm["starttemp"].as()); + ctx->settings[ctx->id("placer1/startTemp")] = std::to_string(vm["starttemp"].as()); } if (vm.count("placer-budgets")) { - settings->set("placer1/budgetBased", true); + ctx->settings[ctx->id("placer1/budgetBased")] = std::to_string(true); } if (vm.count("freq")) { auto freq = vm["freq"].as(); @@ -230,9 +230,9 @@ void CommandHandler::setupContext(Context *ctx) if (vm.count("no-tmdriv")) ctx->timing_driven = false; - settings->set("arch.name", std::string(ctx->archId().c_str(ctx))); - settings->set("arch.type", std::string(ctx->archArgsToId(ctx->archArgs()).c_str(ctx))); - settings->set("seed", ctx->rngstate); + ctx->settings[ctx->id("arch.name")] = std::string(ctx->archId().c_str(ctx)); + ctx->settings[ctx->id("arch.type")] = std::string(ctx->archArgsToId(ctx->archArgs()).c_str(ctx)); + ctx->settings[ctx->id("seed")] = std::to_string(ctx->rngstate); } int CommandHandler::executeMain(std::unique_ptr ctx) @@ -366,7 +366,6 @@ int CommandHandler::exec() log_error("Loading design failed.\n"); } std::unique_ptr ctx = createContext(values); - settings = std::unique_ptr(new Settings(ctx.get())); setupContext(ctx.get()); setupArchContext(ctx.get()); int rc = executeMain(std::move(ctx)); @@ -388,7 +387,6 @@ std::unique_ptr CommandHandler::load_json(std::string filename) log_error("Loading design failed.\n"); } std::unique_ptr ctx = createContext(values); - settings = std::unique_ptr(new Settings(ctx.get())); setupContext(ctx.get()); setupArchContext(ctx.get()); { diff --git a/common/command.h b/common/command.h index c7b58517..b5908e3f 100644 --- a/common/command.h +++ b/common/command.h @@ -24,7 +24,7 @@ #include #include #include "nextpnr.h" -#include "settings.h" +#include "log.h" NEXTPNR_NAMESPACE_BEGIN @@ -59,7 +59,6 @@ class CommandHandler protected: po::variables_map vm; - std::unique_ptr settings; private: po::options_description options; diff --git a/common/nextpnr.h b/common/nextpnr.h index 66134456..b796b8aa 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -32,6 +32,7 @@ #include #include +#include #ifndef NEXTPNR_H #define NEXTPNR_H @@ -724,6 +725,18 @@ struct Context : Arch, DeterministicRNG void check() const; void archcheck() const; + + template T setting(const char *name, T defaultValue) + { + IdString new_id = id(name); + if (settings.find(new_id) != settings.end()) + return boost::lexical_cast(settings.find(new_id)->second.str); + else + settings[id(name)] = std::to_string(defaultValue); + + return defaultValue; + } + }; NEXTPNR_NAMESPACE_END diff --git a/common/placer1.cc b/common/placer1.cc index a8ddd8a6..89e4f919 100644 --- a/common/placer1.cc +++ b/common/placer1.cc @@ -1131,12 +1131,12 @@ class SAPlacer Placer1Cfg cfg; }; -Placer1Cfg::Placer1Cfg(Context *ctx) : Settings(ctx) +Placer1Cfg::Placer1Cfg(Context *ctx) { - constraintWeight = get("placer1/constraintWeight", 10); - minBelsForGridPick = get("placer1/minBelsForGridPick", 64); - budgetBased = get("placer1/budgetBased", false); - startTemp = get("placer1/startTemp", 1); + constraintWeight = ctx->setting("placer1/constraintWeight", 10); + minBelsForGridPick = ctx->setting("placer1/minBelsForGridPick", 64); + budgetBased = ctx->setting("placer1/budgetBased", false); + startTemp = ctx->setting("placer1/startTemp", 1); timingFanoutThresh = std::numeric_limits::max(); } diff --git a/common/placer1.h b/common/placer1.h index 4c7c7339..0f2e2894 100644 --- a/common/placer1.h +++ b/common/placer1.h @@ -20,11 +20,11 @@ #define PLACE_H #include "nextpnr.h" -#include "settings.h" +#include "log.h" NEXTPNR_NAMESPACE_BEGIN -struct Placer1Cfg : public Settings +struct Placer1Cfg { Placer1Cfg(Context *ctx); float constraintWeight; diff --git a/common/placer_heap.cc b/common/placer_heap.cc index f9b639f8..4d1f4863 100644 --- a/common/placer_heap.cc +++ b/common/placer_heap.cc @@ -1516,11 +1516,11 @@ int HeAPPlacer::CutSpreader::seq = 0; bool placer_heap(Context *ctx, PlacerHeapCfg cfg) { return HeAPPlacer(ctx, cfg).place(); } -PlacerHeapCfg::PlacerHeapCfg(Context *ctx) : Settings(ctx) +PlacerHeapCfg::PlacerHeapCfg(Context *ctx) { - alpha = get("placerHeap/alpha", 0.1); - criticalityExponent = get("placerHeap/criticalityExponent", 2); - timingWeight = get("placerHeap/timingWeight", 10); + alpha = ctx->setting("placerHeap/alpha", 0.1); + criticalityExponent = ctx->setting("placerHeap/criticalityExponent", 2); + timingWeight = ctx->setting("placerHeap/timingWeight", 10); } NEXTPNR_NAMESPACE_END @@ -1538,7 +1538,7 @@ bool placer_heap(Context *ctx, PlacerHeapCfg cfg) return false; } -PlacerHeapCfg::PlacerHeapCfg(Context *ctx) : Settings(ctx) {} +PlacerHeapCfg::PlacerHeapCfg(Context *ctx) {} NEXTPNR_NAMESPACE_END diff --git a/common/placer_heap.h b/common/placer_heap.h index 841aa0d9..2def5e75 100644 --- a/common/placer_heap.h +++ b/common/placer_heap.h @@ -27,11 +27,11 @@ #ifndef PLACER_HEAP_H #define PLACER_HEAP_H #include "nextpnr.h" -#include "settings.h" +#include "log.h" NEXTPNR_NAMESPACE_BEGIN -struct PlacerHeapCfg : public Settings +struct PlacerHeapCfg { PlacerHeapCfg(Context *ctx); diff --git a/common/router1.cc b/common/router1.cc index 28a422c8..02c817c7 100644 --- a/common/router1.cc +++ b/common/router1.cc @@ -733,12 +733,12 @@ struct Router1 NEXTPNR_NAMESPACE_BEGIN -Router1Cfg::Router1Cfg(Context *ctx) : Settings(ctx) +Router1Cfg::Router1Cfg(Context *ctx) { - maxIterCnt = get("router1/maxIterCnt", 200); - cleanupReroute = get("router1/cleanupReroute", true); - fullCleanupReroute = get("router1/fullCleanupReroute", true); - useEstimate = get("router1/useEstimate", true); + maxIterCnt = ctx->setting("router1/maxIterCnt", 200); + cleanupReroute = ctx->setting("router1/cleanupReroute", true); + fullCleanupReroute = ctx->setting("router1/fullCleanupReroute", true); + useEstimate = ctx->setting("router1/useEstimate", true); wireRipupPenalty = ctx->getRipupDelayPenalty(); netRipupPenalty = 10 * ctx->getRipupDelayPenalty(); diff --git a/common/router1.h b/common/router1.h index 80d7aa96..f3d325ad 100644 --- a/common/router1.h +++ b/common/router1.h @@ -21,11 +21,10 @@ #define ROUTER1_H #include "nextpnr.h" -#include "settings.h" - +#include "log.h" NEXTPNR_NAMESPACE_BEGIN -struct Router1Cfg : Settings +struct Router1Cfg { Router1Cfg(Context *ctx); diff --git a/common/settings.h b/common/settings.h deleted file mode 100644 index 9d43c774..00000000 --- a/common/settings.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * nextpnr -- Next Generation Place and Route - * - * Copyright (C) 2018 Miodrag Milanovic - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ -#ifndef SETTINGS_H -#define SETTINGS_H - -#include -#include "log.h" -#include "nextpnr.h" - -NEXTPNR_NAMESPACE_BEGIN - -class Settings -{ - public: - explicit Settings(Context *ctx) : ctx(ctx) {} - - template T get(const char *name, T defaultValue) - { - try { - IdString id = ctx->id(name); - if (ctx->settings.find(id) != ctx->settings.end()) - return boost::lexical_cast(ctx->settings.find(id)->second.str); - else - ctx->settings[ctx->id(name)] = std::to_string(defaultValue); - - } catch (boost::bad_lexical_cast &) { - log_error("Problem reading setting %s, using default value\n", name); - } - return defaultValue; - } - - template void set(const char *name, T value); - - private: - Context *ctx; -}; - -template inline void Settings::set(const char *name, T value) -{ - ctx->settings[ctx->id(name)] = std::to_string(value); -} - -template <> inline void Settings::set(const char *name, std::string value) -{ - ctx->settings[ctx->id(name)] = value; -} - -NEXTPNR_NAMESPACE_END - -#endif // SETTINGS_H diff --git a/common/timing_opt.h b/common/timing_opt.h index ceb35c71..cdc02406 100644 --- a/common/timing_opt.h +++ b/common/timing_opt.h @@ -18,13 +18,13 @@ */ #include "nextpnr.h" -#include "settings.h" +#include "log.h" NEXTPNR_NAMESPACE_BEGIN -struct TimingOptCfg : public Settings +struct TimingOptCfg { - TimingOptCfg(Context *ctx) : Settings(ctx) {} + TimingOptCfg(Context *ctx) {} // The timing optimiser will *only* optimise cells of these types // Normally these would only be logic cells (or tiles if applicable), the algorithm makes little sense