clangformat run

This commit is contained in:
Miodrag Milanovic 2019-06-25 18:19:25 +02:00
parent ec47ce2320
commit be47fc3e9a
23 changed files with 171 additions and 162 deletions

View File

@ -27,8 +27,8 @@
#include "pybindings.h" #include "pybindings.h"
#endif #endif
#include <boost/algorithm/string/join.hpp>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/join.hpp>
#include <boost/filesystem/convenience.hpp> #include <boost/filesystem/convenience.hpp>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <fstream> #include <fstream>
@ -299,9 +299,9 @@ int CommandHandler::executeMain(std::unique_ptr<Context> ctx)
} else } else
#endif #endif
if (vm.count("json")) { if (vm.count("json")) {
bool do_pack = vm.count("pack-only")!=0 || vm.count("no-pack")==0; bool do_pack = vm.count("pack-only") != 0 || vm.count("no-pack") == 0;
bool do_place = vm.count("pack-only")==0 && vm.count("no-place")==0; bool do_place = vm.count("pack-only") == 0 && vm.count("no-place") == 0;
bool do_route = vm.count("pack-only")==0 && vm.count("no-route")==0; bool do_route = vm.count("pack-only") == 0 && vm.count("no-route") == 0;
if (do_pack) { if (do_pack) {
run_script_hook("pre-pack"); run_script_hook("pre-pack");
@ -370,7 +370,7 @@ int CommandHandler::exec()
if (executeBeforeContext()) if (executeBeforeContext())
return 0; return 0;
std::unordered_map<std::string,Property> values; std::unordered_map<std::string, Property> values;
if (vm.count("json")) { if (vm.count("json")) {
std::string filename = vm["json"].as<std::string>(); std::string filename = vm["json"].as<std::string>();
std::ifstream f(filename); std::ifstream f(filename);
@ -392,7 +392,7 @@ int CommandHandler::exec()
std::unique_ptr<Context> CommandHandler::load_json(std::string filename) std::unique_ptr<Context> CommandHandler::load_json(std::string filename)
{ {
vm.clear(); vm.clear();
std::unordered_map<std::string,Property> values; std::unordered_map<std::string, Property> values;
{ {
std::ifstream f(filename); std::ifstream f(filename);
if (!load_json_settings(f, filename, values)) if (!load_json_settings(f, filename, values))

View File

@ -23,8 +23,8 @@
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <fstream> #include <fstream>
#include "nextpnr.h"
#include "log.h" #include "log.h"
#include "nextpnr.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
@ -41,7 +41,7 @@ class CommandHandler
protected: protected:
virtual void setupArchContext(Context *ctx) = 0; virtual void setupArchContext(Context *ctx) = 0;
virtual std::unique_ptr<Context> createContext(std::unordered_map<std::string,Property> &values) = 0; virtual std::unique_ptr<Context> createContext(std::unordered_map<std::string, Property> &values) = 0;
virtual po::options_description getArchOptions() = 0; virtual po::options_description getArchOptions() = 0;
virtual void validate(){}; virtual void validate(){};
virtual void customAfterLoad(Context *ctx){}; virtual void customAfterLoad(Context *ctx){};

View File

@ -18,8 +18,8 @@
*/ */
#include "nextpnr.h" #include "nextpnr.h"
#include "log.h"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "log.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
@ -465,21 +465,21 @@ void BaseCtx::archInfoToAttributes()
ci->attrs[id("NEXTPNR_BEL")] = getCtx()->getBelName(ci->bel).c_str(this); ci->attrs[id("NEXTPNR_BEL")] = getCtx()->getBelName(ci->bel).c_str(this);
ci->attrs[id("BEL_STRENGTH")] = std::to_string((int)ci->belStrength); ci->attrs[id("BEL_STRENGTH")] = std::to_string((int)ci->belStrength);
} }
if (ci->constr_x!= ci->UNCONSTR) if (ci->constr_x != ci->UNCONSTR)
ci->attrs[id("CONSTR_X")] = std::to_string(ci->constr_x); ci->attrs[id("CONSTR_X")] = std::to_string(ci->constr_x);
if (ci->constr_y!= ci->UNCONSTR) if (ci->constr_y != ci->UNCONSTR)
ci->attrs[id("CONSTR_Y")] = std::to_string(ci->constr_y); ci->attrs[id("CONSTR_Y")] = std::to_string(ci->constr_y);
if (ci->constr_z!= ci->UNCONSTR) { if (ci->constr_z != ci->UNCONSTR) {
ci->attrs[id("CONSTR_Z")] = std::to_string(ci->constr_z); ci->attrs[id("CONSTR_Z")] = std::to_string(ci->constr_z);
ci->attrs[id("CONSTR_ABS_Z")] = std::to_string(ci->constr_abs_z ? 1 : 0); ci->attrs[id("CONSTR_ABS_Z")] = std::to_string(ci->constr_abs_z ? 1 : 0);
} }
if (ci->constr_parent!= nullptr) if (ci->constr_parent != nullptr)
ci->attrs[id("CONSTR_PARENT")] = ci->constr_parent->name.c_str(this); ci->attrs[id("CONSTR_PARENT")] = ci->constr_parent->name.c_str(this);
if (!ci->constr_children.empty()) { if (!ci->constr_children.empty()) {
std::string constr = ""; std::string constr = "";
for(auto &item : ci->constr_children) for (auto &item : ci->constr_children) {
{ if (!constr.empty())
if (!constr.empty()) constr += std::string(";"); constr += std::string(";");
constr += item->name.c_str(this); constr += item->name.c_str(this);
} }
ci->attrs[id("CONSTR_CHILDREN")] = constr; ci->attrs[id("CONSTR_CHILDREN")] = constr;
@ -490,7 +490,8 @@ void BaseCtx::archInfoToAttributes()
std::string routing; std::string routing;
bool first = true; bool first = true;
for (auto &item : ni->wires) { for (auto &item : ni->wires) {
if (!first) routing += ";"; if (!first)
routing += ";";
routing += getCtx()->getWireName(item.first).c_str(this); routing += getCtx()->getWireName(item.first).c_str(this);
routing += ";"; routing += ";";
if (item.second.pip != PipId()) if (item.second.pip != PipId())
@ -530,7 +531,7 @@ void BaseCtx::attributesToArchInfo()
val = ci->attrs.find(id("CONSTR_ABS_Z")); val = ci->attrs.find(id("CONSTR_ABS_Z"));
if (val != ci->attrs.end()) if (val != ci->attrs.end())
ci->constr_abs_z = std::stoi(val->second.str)==1; ci->constr_abs_z = std::stoi(val->second.str) == 1;
val = ci->attrs.find(id("CONSTR_PARENT")); val = ci->attrs.find(id("CONSTR_PARENT"));
if (val != ci->attrs.end()) { if (val != ci->attrs.end()) {
@ -541,9 +542,8 @@ void BaseCtx::attributesToArchInfo()
val = ci->attrs.find(id("CONSTR_CHILDREN")); val = ci->attrs.find(id("CONSTR_CHILDREN"));
if (val != ci->attrs.end()) { if (val != ci->attrs.end()) {
std::vector<std::string> strs; std::vector<std::string> strs;
boost::split(strs,val->second.str,boost::is_any_of(";")); boost::split(strs, val->second.str, boost::is_any_of(";"));
for(auto val : strs) for (auto val : strs) {
{
ci->constr_children.push_back(cells.find(id(val.c_str()))->second.get()); ci->constr_children.push_back(cells.find(id(val.c_str()))->second.get());
} }
} }
@ -553,12 +553,11 @@ void BaseCtx::attributesToArchInfo()
auto val = ni->attrs.find(id("ROUTING")); auto val = ni->attrs.find(id("ROUTING"));
if (val != ni->attrs.end()) { if (val != ni->attrs.end()) {
std::vector<std::string> strs; std::vector<std::string> strs;
boost::split(strs,val->second.str,boost::is_any_of(";")); boost::split(strs, val->second.str, boost::is_any_of(";"));
for(size_t i=0;i<strs.size()/3;i++) for (size_t i = 0; i < strs.size() / 3; i++) {
{ std::string wire = strs[i * 3];
std::string wire = strs[i*3]; std::string pip = strs[i * 3 + 1];
std::string pip = strs[i*3 + 1]; PlaceStrength strength = (PlaceStrength)std::stoi(strs[i * 3 + 2]);
PlaceStrength strength = (PlaceStrength)std::stoi(strs[i*3 + 2]);
if (pip.empty()) if (pip.empty())
getCtx()->bindWire(getCtx()->getWireByName(id(wire)), ni, strength); getCtx()->bindWire(getCtx()->getWireByName(id(wire)), ni, strength);
else else

View File

@ -299,22 +299,25 @@ struct Property
bool isString() const { return is_string; } bool isString() const { return is_string; }
void setNumber(int val) { is_string = false; num = val; str = std::to_string(val); } void setNumber(int val)
void setString(std::string val) { is_string = true; str = val; }
const char * c_str() const { return str.c_str(); }
operator std::string () const { return str; }
bool operator==(const std::string other) const
{ {
return str == other; is_string = false;
num = val;
str = std::to_string(val);
} }
bool operator!=(const std::string other) const void setString(std::string val)
{ {
return str != other; is_string = true;
str = val;
} }
Property& operator=(std::string other) const char *c_str() const { return str.c_str(); }
operator std::string() const { return str; }
bool operator==(const std::string other) const { return str == other; }
bool operator!=(const std::string other) const { return str != other; }
Property &operator=(std::string other)
{ {
is_string = true; is_string = true;
str = other; str = other;

View File

@ -374,7 +374,8 @@ class SAPlacer
assign_budget(ctx, true /* quiet */); assign_budget(ctx, true /* quiet */);
} }
require_legal = false; require_legal = false;
} else if (cfg.budgetBased && ctx->setting<int>("slack_redist_iter") > 0 && iter % ctx->setting<int>("slack_redist_iter") == 0) { } else if (cfg.budgetBased && ctx->setting<int>("slack_redist_iter") > 0 &&
iter % ctx->setting<int>("slack_redist_iter") == 0) {
assign_budget(ctx, true /* quiet */); assign_budget(ctx, true /* quiet */);
} }

View File

@ -19,8 +19,8 @@
#ifndef PLACE_H #ifndef PLACE_H
#define PLACE_H #define PLACE_H
#include "nextpnr.h"
#include "log.h" #include "log.h"
#include "nextpnr.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN

View File

@ -26,8 +26,8 @@
#ifndef PLACER_HEAP_H #ifndef PLACER_HEAP_H
#define PLACER_HEAP_H #define PLACER_HEAP_H
#include "nextpnr.h"
#include "log.h" #include "log.h"
#include "nextpnr.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN

View File

@ -20,8 +20,8 @@
#ifndef ROUTER1_H #ifndef ROUTER1_H
#define ROUTER1_H #define ROUTER1_H
#include "nextpnr.h"
#include "log.h" #include "log.h"
#include "nextpnr.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
struct Router1Cfg struct Router1Cfg

View File

@ -658,10 +658,11 @@ void assign_budget(Context *ctx, bool quiet)
{ {
if (!quiet) { if (!quiet) {
log_break(); log_break();
log_info("Annotating ports with timing budgets for target frequency %.2f MHz\n", ctx->setting<float>("target_freq") / 1e6); log_info("Annotating ports with timing budgets for target frequency %.2f MHz\n",
ctx->setting<float>("target_freq") / 1e6);
} }
Timing timing(ctx, ctx->setting<int>("slack_redist_iter")> 0 /* net_delays */, true /* update */); Timing timing(ctx, ctx->setting<int>("slack_redist_iter") > 0 /* net_delays */, true /* update */);
timing.assign_budget(); timing.assign_budget();
if (!quiet || ctx->verbose) { if (!quiet || ctx->verbose) {
@ -686,11 +687,12 @@ void assign_budget(Context *ctx, bool quiet)
// currently achieved maximum // currently achieved maximum
if (ctx->setting<bool>("auto_freq") && ctx->setting<int>("slack_redist_iter") > 0) { if (ctx->setting<bool>("auto_freq") && ctx->setting<int>("slack_redist_iter") > 0) {
delay_t default_slack = delay_t((1.0e9 / ctx->getDelayNS(1)) / ctx->setting<float>("target_freq")); delay_t default_slack = delay_t((1.0e9 / ctx->getDelayNS(1)) / ctx->setting<float>("target_freq"));
ctx->settings[ctx->id("target_freq")] = std::to_string(1.0e9 / ctx->getDelayNS(default_slack - timing.min_slack)); ctx->settings[ctx->id("target_freq")] =
std::to_string(1.0e9 / ctx->getDelayNS(default_slack - timing.min_slack));
if (ctx->verbose) if (ctx->verbose)
log_info("minimum slack for this assign = %.2f ns, target Fmax for next " log_info("minimum slack for this assign = %.2f ns, target Fmax for next "
"update = %.2f MHz\n", "update = %.2f MHz\n",
ctx->getDelayNS(timing.min_slack),ctx->setting<float>("target_freq") / 1e6); ctx->getDelayNS(timing.min_slack), ctx->setting<float>("target_freq") / 1e6);
} }
if (!quiet) if (!quiet)

View File

@ -17,8 +17,8 @@
* *
*/ */
#include "nextpnr.h"
#include "log.h" #include "log.h"
#include "nextpnr.h"
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN

View File

@ -34,7 +34,7 @@ class ECP5CommandHandler : public CommandHandler
public: public:
ECP5CommandHandler(int argc, char **argv); ECP5CommandHandler(int argc, char **argv);
virtual ~ECP5CommandHandler(){}; virtual ~ECP5CommandHandler(){};
std::unique_ptr<Context> createContext(std::unordered_map<std::string,Property> &values) override; std::unique_ptr<Context> createContext(std::unordered_map<std::string, Property> &values) override;
void setupArchContext(Context *ctx) override{}; void setupArchContext(Context *ctx) override{};
void customAfterLoad(Context *ctx) override; void customAfterLoad(Context *ctx) override;
void validate() override; void validate() override;
@ -100,16 +100,20 @@ void ECP5CommandHandler::customBitstream(Context *ctx)
static std::string speedString(ArchArgs::SpeedGrade speed) static std::string speedString(ArchArgs::SpeedGrade speed)
{ {
switch(speed){ switch (speed) {
case ArchArgs::SPEED_6: return "6"; case ArchArgs::SPEED_6:
case ArchArgs::SPEED_7: return "7"; return "6";
case ArchArgs::SPEED_8: return "8"; case ArchArgs::SPEED_7:
case ArchArgs::SPEED_8_5G: return "8"; return "7";
case ArchArgs::SPEED_8:
return "8";
case ArchArgs::SPEED_8_5G:
return "8";
} }
return ""; return "";
} }
std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<std::string,Property> &values) std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<std::string, Property> &values)
{ {
ArchArgs chipArgs; ArchArgs chipArgs;
chipArgs.type = ArchArgs::NONE; chipArgs.type = ArchArgs::NONE;
@ -157,12 +161,12 @@ std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<st
} else } else
chipArgs.speed = ArchArgs::SPEED_6; chipArgs.speed = ArchArgs::SPEED_6;
} }
if (values.find("arch.name")!=values.end()) { if (values.find("arch.name") != values.end()) {
std::string arch_name = values["arch.name"].str; std::string arch_name = values["arch.name"].str;
if (arch_name != "ecp5") if (arch_name != "ecp5")
log_error("Unsuported architecture '%s'.\n", arch_name.c_str()); log_error("Unsuported architecture '%s'.\n", arch_name.c_str());
} }
if (values.find("arch.type")!=values.end()) { if (values.find("arch.type") != values.end()) {
std::string arch_type = values["arch.type"].str; std::string arch_type = values["arch.type"].str;
if (chipArgs.type != ArchArgs::NONE) if (chipArgs.type != ArchArgs::NONE)
log_error("Overriding architecture is unsuported.\n"); log_error("Overriding architecture is unsuported.\n");
@ -187,14 +191,14 @@ std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<st
chipArgs.type = ArchArgs::LFE5UM5G_85F; chipArgs.type = ArchArgs::LFE5UM5G_85F;
if (chipArgs.type == ArchArgs::NONE) if (chipArgs.type == ArchArgs::NONE)
log_error("Unsuported FPGA type '%s'.\n",arch_type.c_str()); log_error("Unsuported FPGA type '%s'.\n", arch_type.c_str());
} }
if (values.find("arch.package")!=values.end()) { if (values.find("arch.package") != values.end()) {
if (vm.count("package")) if (vm.count("package"))
log_error("Overriding architecture is unsuported.\n"); log_error("Overriding architecture is unsuported.\n");
chipArgs.package = values["arch.package"].str; chipArgs.package = values["arch.package"].str;
} }
if (values.find("arch.speed")!=values.end()) { if (values.find("arch.speed") != values.end()) {
std::string arch_speed = values["arch.speed"].str; std::string arch_speed = values["arch.speed"].str;
if (arch_speed == "6") if (arch_speed == "6")
chipArgs.speed = ArchArgs::SPEED_6; chipArgs.speed = ArchArgs::SPEED_6;
@ -203,7 +207,7 @@ std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<st
else if (arch_speed == "8") else if (arch_speed == "8")
chipArgs.speed = ArchArgs::SPEED_8; chipArgs.speed = ArchArgs::SPEED_8;
else else
log_error("Unsuported speed '%s'.\n",arch_speed.c_str()); log_error("Unsuported speed '%s'.\n", arch_speed.c_str());
} }
if (chipArgs.type == ArchArgs::NONE) if (chipArgs.type == ArchArgs::NONE)
chipArgs.type = ArchArgs::LFE5U_45F; chipArgs.type = ArchArgs::LFE5U_45F;
@ -220,7 +224,7 @@ std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<st
} }
auto ctx = std::unique_ptr<Context>(new Context(chipArgs)); auto ctx = std::unique_ptr<Context>(new Context(chipArgs));
for(auto &val : values) for (auto &val : values)
ctx->settings[ctx->id(val.first)] = val.second; ctx->settings[ctx->id(val.first)] = val.second;
ctx->settings[ctx->id("arch.package")] = ctx->archArgs().package; ctx->settings[ctx->id("arch.package")] = ctx->archArgs().package;
ctx->settings[ctx->id("arch.speed")] = speedString(ctx->archArgs().speed); ctx->settings[ctx->id("arch.speed")] = speedString(ctx->archArgs().speed);

View File

@ -505,7 +505,8 @@ bool Arch::place()
} }
} }
bool Arch::route() { bool Arch::route()
{
bool retVal = router1(getCtx(), Router1Cfg(getCtx())); bool retVal = router1(getCtx(), Router1Cfg(getCtx()));
getCtx()->settings[getCtx()->id("route")] = "1"; getCtx()->settings[getCtx()->id("route")] = "1";
archInfoToAttributes(); archInfoToAttributes();

View File

@ -32,7 +32,7 @@ class GenericCommandHandler : public CommandHandler
public: public:
GenericCommandHandler(int argc, char **argv); GenericCommandHandler(int argc, char **argv);
virtual ~GenericCommandHandler(){}; virtual ~GenericCommandHandler(){};
std::unique_ptr<Context> createContext(std::unordered_map<std::string,Property> &values) override; std::unique_ptr<Context> createContext(std::unordered_map<std::string, Property> &values) override;
void setupArchContext(Context *ctx) override{}; void setupArchContext(Context *ctx) override{};
void customBitstream(Context *ctx) override; void customBitstream(Context *ctx) override;
@ -51,10 +51,10 @@ po::options_description GenericCommandHandler::getArchOptions()
void GenericCommandHandler::customBitstream(Context *ctx) {} void GenericCommandHandler::customBitstream(Context *ctx) {}
std::unique_ptr<Context> GenericCommandHandler::createContext(std::unordered_map<std::string,Property> &values) std::unique_ptr<Context> GenericCommandHandler::createContext(std::unordered_map<std::string, Property> &values)
{ {
ArchArgs chipArgs; ArchArgs chipArgs;
if (values.find("arch.name")!=values.end()) { if (values.find("arch.name") != values.end()) {
std::string arch_name = values["arch.name"].str; std::string arch_name = values["arch.name"].str;
if (arch_name != "generic") if (arch_name != "generic")
log_error("Unsuported architecture '%s'.\n", arch_name.c_str()); log_error("Unsuported architecture '%s'.\n", arch_name.c_str());

View File

@ -416,13 +416,12 @@ void BaseMainWindow::disableActions()
void BaseMainWindow::updateActions() void BaseMainWindow::updateActions()
{ {
if (ctx->settings.find(ctx->id("pack"))==ctx->settings.end()) if (ctx->settings.find(ctx->id("pack")) == ctx->settings.end())
actionPack->setEnabled(true); actionPack->setEnabled(true);
else if (ctx->settings.find(ctx->id("place"))==ctx->settings.end()) { else if (ctx->settings.find(ctx->id("place")) == ctx->settings.end()) {
actionAssignBudget->setEnabled(true); actionAssignBudget->setEnabled(true);
actionPlace->setEnabled(true); actionPlace->setEnabled(true);
} } else if (ctx->settings.find(ctx->id("route")) == ctx->settings.end())
else if (ctx->settings.find(ctx->id("route"))==ctx->settings.end())
actionRoute->setEnabled(true); actionRoute->setEnabled(true);
onUpdateActions(); onUpdateActions();

View File

@ -20,9 +20,9 @@
#ifndef BASEMAINWINDOW_H #ifndef BASEMAINWINDOW_H
#define BASEMAINWINDOW_H #define BASEMAINWINDOW_H
#include "command.h"
#include "nextpnr.h" #include "nextpnr.h"
#include "worker.h" #include "worker.h"
#include "command.h"
#include <QMainWindow> #include <QMainWindow>
#include <QMenu> #include <QMenu>

View File

@ -164,10 +164,11 @@ void MainWindow::onDisableActions()
actionSaveConfig->setEnabled(false); actionSaveConfig->setEnabled(false);
} }
void MainWindow::onUpdateActions() { void MainWindow::onUpdateActions()
if (ctx->settings.find(ctx->id("pack"))==ctx->settings.end()) {
if (ctx->settings.find(ctx->id("pack")) == ctx->settings.end())
actionLoadLPF->setEnabled(true); actionLoadLPF->setEnabled(true);
if (ctx->settings.find(ctx->id("route"))!=ctx->settings.end()) if (ctx->settings.find(ctx->id("route")) != ctx->settings.end())
actionSaveConfig->setEnabled(true); actionSaveConfig->setEnabled(true);
} }

View File

@ -186,10 +186,11 @@ void MainWindow::onDisableActions()
actionSaveAsc->setEnabled(false); actionSaveAsc->setEnabled(false);
} }
void MainWindow::onUpdateActions() { void MainWindow::onUpdateActions()
if (ctx->settings.find(ctx->id("pack"))==ctx->settings.end()) {
if (ctx->settings.find(ctx->id("pack")) == ctx->settings.end())
actionLoadPCF->setEnabled(true); actionLoadPCF->setEnabled(true);
if (ctx->settings.find(ctx->id("route"))!=ctx->settings.end()) if (ctx->settings.find(ctx->id("route")) != ctx->settings.end())
actionSaveAsc->setEnabled(true); actionSaveAsc->setEnabled(true);
} }

View File

@ -694,7 +694,8 @@ bool Arch::place()
return retVal; return retVal;
} }
bool Arch::route() { bool Arch::route()
{
bool retVal = router1(getCtx(), Router1Cfg(getCtx())); bool retVal = router1(getCtx(), Router1Cfg(getCtx()));
getCtx()->settings[getCtx()->id("route")] = "1"; getCtx()->settings[getCtx()->id("route")] = "1";
archInfoToAttributes(); archInfoToAttributes();

View File

@ -36,7 +36,7 @@ class Ice40CommandHandler : public CommandHandler
public: public:
Ice40CommandHandler(int argc, char **argv); Ice40CommandHandler(int argc, char **argv);
virtual ~Ice40CommandHandler(){}; virtual ~Ice40CommandHandler(){};
std::unique_ptr<Context> createContext(std::unordered_map<std::string,Property> &values) override; std::unique_ptr<Context> createContext(std::unordered_map<std::string, Property> &values) override;
void setupArchContext(Context *ctx) override; void setupArchContext(Context *ctx) override;
void validate() override; void validate() override;
void customAfterLoad(Context *ctx) override; void customAfterLoad(Context *ctx) override;
@ -116,7 +116,7 @@ void Ice40CommandHandler::setupArchContext(Context *ctx)
} }
} }
std::unique_ptr<Context> Ice40CommandHandler::createContext(std::unordered_map<std::string,Property> &values) std::unique_ptr<Context> Ice40CommandHandler::createContext(std::unordered_map<std::string, Property> &values)
{ {
ArchArgs chipArgs; ArchArgs chipArgs;
chipArgs.type = ArchArgs::NONE; chipArgs.type = ArchArgs::NONE;
@ -158,12 +158,12 @@ std::unique_ptr<Context> Ice40CommandHandler::createContext(std::unordered_map<s
if (vm.count("package")) if (vm.count("package"))
chipArgs.package = vm["package"].as<std::string>(); chipArgs.package = vm["package"].as<std::string>();
if (values.find("arch.name")!=values.end()) { if (values.find("arch.name") != values.end()) {
std::string arch_name = values["arch.name"].str; std::string arch_name = values["arch.name"].str;
if (arch_name != "ice40") if (arch_name != "ice40")
log_error("Unsuported architecture '%s'.\n", arch_name.c_str()); log_error("Unsuported architecture '%s'.\n", arch_name.c_str());
} }
if (values.find("arch.type")!=values.end()) { if (values.find("arch.type") != values.end()) {
std::string arch_type = values["arch.type"].str; std::string arch_type = values["arch.type"].str;
if (chipArgs.type != ArchArgs::NONE) if (chipArgs.type != ArchArgs::NONE)
log_error("Overriding architecture is unsuported.\n"); log_error("Overriding architecture is unsuported.\n");
@ -190,9 +190,9 @@ std::unique_ptr<Context> Ice40CommandHandler::createContext(std::unordered_map<s
chipArgs.type = ArchArgs::U4K; chipArgs.type = ArchArgs::U4K;
} }
if (chipArgs.type == ArchArgs::NONE) if (chipArgs.type == ArchArgs::NONE)
log_error("Unsuported FPGA type '%s'.\n",arch_type.c_str()); log_error("Unsuported FPGA type '%s'.\n", arch_type.c_str());
} }
if (values.find("arch.package")!=values.end()) { if (values.find("arch.package") != values.end()) {
if (vm.count("package")) if (vm.count("package"))
log_error("Overriding architecture is unsuported.\n"); log_error("Overriding architecture is unsuported.\n");
chipArgs.package = values["arch.package"].str; chipArgs.package = values["arch.package"].str;
@ -209,7 +209,7 @@ std::unique_ptr<Context> Ice40CommandHandler::createContext(std::unordered_map<s
#endif #endif
auto ctx = std::unique_ptr<Context>(new Context(chipArgs)); auto ctx = std::unique_ptr<Context>(new Context(chipArgs));
for(auto &val : values) for (auto &val : values)
ctx->settings[ctx->id(val.first)] = val.second; ctx->settings[ctx->id(val.first)] = val.second;
ctx->settings[ctx->id("arch.package")] = ctx->archArgs().package; ctx->settings[ctx->id("arch.package")] = ctx->archArgs().package;

View File

@ -341,9 +341,8 @@ static void pack_constants(Context *ctx)
gnd_net->driver.port = ctx->id("O"); gnd_net->driver.port = ctx->id("O");
gnd_cell->ports.at(ctx->id("O")).net = gnd_net.get(); gnd_cell->ports.at(ctx->id("O")).net = gnd_net.get();
NetInfo* gnd_net_info = gnd_net.get(); NetInfo *gnd_net_info = gnd_net.get();
if (ctx->nets.find(ctx->id("$PACKER_GND_NET"))!=ctx->nets.end()) if (ctx->nets.find(ctx->id("$PACKER_GND_NET")) != ctx->nets.end()) {
{
gnd_net_info = ctx->nets.find(ctx->id("$PACKER_GND_NET"))->second.get(); gnd_net_info = ctx->nets.find(ctx->id("$PACKER_GND_NET"))->second.get();
} }
@ -355,9 +354,8 @@ static void pack_constants(Context *ctx)
vcc_net->driver.port = ctx->id("O"); vcc_net->driver.port = ctx->id("O");
vcc_cell->ports.at(ctx->id("O")).net = vcc_net.get(); vcc_cell->ports.at(ctx->id("O")).net = vcc_net.get();
NetInfo* vcc_net_info = vcc_net.get(); NetInfo *vcc_net_info = vcc_net.get();
if (ctx->nets.find(ctx->id("$PACKER_VCC_NET"))!=ctx->nets.end()) if (ctx->nets.find(ctx->id("$PACKER_VCC_NET")) != ctx->nets.end()) {
{
vcc_net_info = ctx->nets.find(ctx->id("$PACKER_VCC_NET"))->second.get(); vcc_net_info = ctx->nets.find(ctx->id("$PACKER_VCC_NET"))->second.get();
} }
@ -387,8 +385,7 @@ static void pack_constants(Context *ctx)
} }
// Vcc cell always inserted for now, as it may be needed during carry legalisation (TODO: trim later if actually // Vcc cell always inserted for now, as it may be needed during carry legalisation (TODO: trim later if actually
// never used?) // never used?)
if (vcc_net_info == vcc_net.get()) if (vcc_net_info == vcc_net.get()) {
{
ctx->cells[vcc_cell->name] = std::move(vcc_cell); ctx->cells[vcc_cell->name] = std::move(vcc_cell);
ctx->nets[vcc_net->name] = std::move(vcc_net); ctx->nets[vcc_net->name] = std::move(vcc_net);
} }
@ -1239,7 +1236,8 @@ static void pack_special(Context *ctx)
} }
auto feedback_path = packed->params[ctx->id("FEEDBACK_PATH")]; auto feedback_path = packed->params[ctx->id("FEEDBACK_PATH")];
std::string fbp_value = feedback_path == "DELAY" std::string fbp_value =
feedback_path == "DELAY"
? "0" ? "0"
: feedback_path == "SIMPLE" : feedback_path == "SIMPLE"
? "1" ? "1"

View File

@ -352,8 +352,7 @@ void json_import_net_attrib(Context *ctx, string &modname, NetInfo *net, JsonNod
} else if (param->type == 'S') } else if (param->type == 'S')
(*dest)[pId].setString(param->data_string); (*dest)[pId].setString(param->data_string);
else else
log_error("JSON parameter type of \"%s\' of net \'%s\' not supported\n", pId.c_str(ctx), log_error("JSON parameter type of \"%s\' of net \'%s\' not supported\n", pId.c_str(ctx), net->name.c_str(ctx));
net->name.c_str(ctx));
if (json_debug) if (json_debug)
log_info(" Added parameter \'%s\'=%s to net \'%s\' " log_info(" Added parameter \'%s\'=%s to net \'%s\' "
"of module \'%s\'\n", "of module \'%s\'\n",
@ -377,8 +376,8 @@ void json_import_top_attrib(Context *ctx, string &modname, JsonNode *param_node,
else else
log_error("JSON parameter type of \"%s\' of module not supported\n", pId.c_str(ctx)); log_error("JSON parameter type of \"%s\' of module not supported\n", pId.c_str(ctx));
if (json_debug) if (json_debug)
log_info(" Added parameter \'%s\'=%s module \'%s\'\n", log_info(" Added parameter \'%s\'=%s module \'%s\'\n", pId.c_str(ctx), (*dest)[pId].c_str(),
pId.c_str(ctx), (*dest)[pId].c_str(), modname.c_str()); modname.c_str());
} }
static int const_net_idx = 0; static int const_net_idx = 0;
@ -669,7 +668,7 @@ static void insert_iobuf(Context *ctx, NetInfo *net, PortType type, const string
// During packing, this generic IO buffer will be converted to an // During packing, this generic IO buffer will be converted to an
// architecure primitive. // architecure primitive.
// //
if (ctx->settings.find(ctx->id("synth"))==ctx->settings.end()) { if (ctx->settings.find(ctx->id("synth")) == ctx->settings.end()) {
std::unique_ptr<CellInfo> iobuf = std::unique_ptr<CellInfo>(new CellInfo()); std::unique_ptr<CellInfo> iobuf = std::unique_ptr<CellInfo>(new CellInfo());
iobuf->name = ctx->id(name); iobuf->name = ctx->id(name);
std::copy(net->attrs.begin(), net->attrs.end(), std::inserter(iobuf->attrs, iobuf->attrs.begin())); std::copy(net->attrs.begin(), net->attrs.end(), std::inserter(iobuf->attrs, iobuf->attrs.begin()));
@ -897,12 +896,13 @@ void json_import(Context *ctx, string modname, JsonNode *node)
std::string name = std::string name =
basename + (num_bits == 1 ? "" : std::string("[") + std::to_string(i) + std::string("]")); basename + (num_bits == 1 ? "" : std::string("[") + std::to_string(i) + std::string("]"));
IdString net_id = ctx->id(name); IdString net_id = ctx->id(name);
if (here->data_dict.count("attributes") && ctx->nets.find(net_id)!=ctx->nets.end()) { if (here->data_dict.count("attributes") && ctx->nets.find(net_id) != ctx->nets.end()) {
NetInfo *this_net = ctx->nets[net_id].get(); NetInfo *this_net = ctx->nets[net_id].get();
JsonNode *attr_node = here->data_dict.at("attributes"); JsonNode *attr_node = here->data_dict.at("attributes");
if (attr_node->type != 'D') if (attr_node->type != 'D')
log_error("JSON attribute list of \'%s\' is not a data dictionary\n", this_net->name.c_str(ctx)); log_error("JSON attribute list of \'%s\' is not a data dictionary\n",
this_net->name.c_str(ctx));
// //
// Loop through all attributes, adding them into the // Loop through all attributes, adding them into the
@ -911,7 +911,6 @@ void json_import(Context *ctx, string modname, JsonNode *node)
for (int attrid = 0; attrid < GetSize(attr_node->data_dict_keys); attrid++) { for (int attrid = 0; attrid < GetSize(attr_node->data_dict_keys); attrid++) {
json_import_net_attrib(ctx, modname, this_net, attr_node, &this_net->attrs, attrid); json_import_net_attrib(ctx, modname, this_net, attr_node, &this_net->attrs, attrid);
} }
} }
} }
} }
@ -956,7 +955,7 @@ bool parse_json_file(std::istream &f, std::string &filename, Context *ctx)
} }
} }
bool load_json_settings(std::istream &f, std::string &filename, std::unordered_map<std::string,Property> &values) bool load_json_settings(std::istream &f, std::string &filename, std::unordered_map<std::string, Property> &values)
{ {
try { try {
using namespace JsonParser; using namespace JsonParser;
@ -993,7 +992,6 @@ bool load_json_settings(std::istream &f, std::string &filename, std::unordered_m
values[pId].setString(param->data_string); values[pId].setString(param->data_string);
else else
log_error("JSON parameter type of \"%s\' of module not supported\n", pId.c_str()); log_error("JSON parameter type of \"%s\' of module not supported\n", pId.c_str());
} }
} }
} }

View File

@ -27,7 +27,8 @@
NEXTPNR_NAMESPACE_BEGIN NEXTPNR_NAMESPACE_BEGIN
extern bool parse_json_file(std::istream &, std::string &, Context *); extern bool parse_json_file(std::istream &, std::string &, Context *);
extern bool load_json_settings(std::istream &f, std::string &filename, std::unordered_map<std::string,Property> &values); extern bool load_json_settings(std::istream &f, std::string &filename,
std::unordered_map<std::string, Property> &values);
NEXTPNR_NAMESPACE_END NEXTPNR_NAMESPACE_END
#endif #endif

View File

@ -43,17 +43,15 @@ std::string get_string(std::string str)
return newstr + "\""; return newstr + "\"";
} }
std::string get_name(IdString name, Context *ctx) std::string get_name(IdString name, Context *ctx) { return get_string(name.c_str(ctx)); }
{
return get_string(name.c_str(ctx));
}
void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map<IdString, Property> &parameters, bool for_module=false) void write_parameters(std::ostream &f, Context *ctx, const std::unordered_map<IdString, Property> &parameters,
bool for_module = false)
{ {
bool first = true; bool first = true;
for (auto &param : parameters) { for (auto &param : parameters) {
f << stringf("%s\n", first ? "" : ","); f << stringf("%s\n", first ? "" : ",");
f << stringf(" %s%s: ", for_module ? "" : " ", get_name(param.first,ctx).c_str()); f << stringf(" %s%s: ", for_module ? "" : " ", get_name(param.first, ctx).c_str());
if (param.second.isString()) if (param.second.isString())
f << get_string(param.second); f << get_string(param.second);
else else
@ -81,7 +79,8 @@ void write_module(std::ostream &f, Context *ctx)
auto &c = pair.second; auto &c = pair.second;
f << stringf("%s\n", first ? "" : ","); f << stringf("%s\n", first ? "" : ",");
f << stringf(" %s: {\n", get_name(c.name, ctx).c_str()); f << stringf(" %s: {\n", get_name(c.name, ctx).c_str());
f << stringf(" \"direction\": \"%s\",\n", c.type == PORT_IN ? "input" : c.type == PORT_INOUT ? "inout" : "output"); f << stringf(" \"direction\": \"%s\",\n",
c.type == PORT_IN ? "input" : c.type == PORT_INOUT ? "inout" : "output");
f << stringf(" \"bits\": [ %d ]\n", pair.first.index); f << stringf(" \"bits\": [ %d ]\n", pair.first.index);
f << stringf(" }"); f << stringf(" }");
first = false; first = false;
@ -118,9 +117,9 @@ void write_module(std::ostream &f, Context *ctx)
auto &p = conn.second; auto &p = conn.second;
f << stringf("%s\n", first2 ? "" : ","); f << stringf("%s\n", first2 ? "" : ",");
if (p.net) if (p.net)
f << stringf(" %s: [ %d ]", get_name(conn.first,ctx).c_str(), p.net->name.index); f << stringf(" %s: [ %d ]", get_name(conn.first, ctx).c_str(), p.net->name.index);
else else
f << stringf(" %s: [ ]", get_name(conn.first,ctx).c_str()); f << stringf(" %s: [ ]", get_name(conn.first, ctx).c_str());
first2 = false; first2 = false;
} }
@ -154,7 +153,8 @@ void write_module(std::ostream &f, Context *ctx)
void write_context(std::ostream &f, Context *ctx) void write_context(std::ostream &f, Context *ctx)
{ {
f << stringf("{\n"); f << stringf("{\n");
f << stringf(" \"creator\": %s,\n", get_string( "Next Generation Place and Route (git sha1 " GIT_COMMIT_HASH_STR ")").c_str()); f << stringf(" \"creator\": %s,\n",
get_string("Next Generation Place and Route (git sha1 " GIT_COMMIT_HASH_STR ")").c_str());
f << stringf(" \"modules\": {\n"); f << stringf(" \"modules\": {\n");
write_module(f, ctx); write_module(f, ctx);
f << stringf("\n }"); f << stringf("\n }");