Load properties from json and propagate to context create
This commit is contained in:
parent
4de147d9e4
commit
03dff10cbd
@ -358,7 +358,14 @@ int CommandHandler::exec()
|
|||||||
if (executeBeforeContext())
|
if (executeBeforeContext())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
std::unique_ptr<Context> ctx = createContext();
|
std::unordered_map<std::string,Property> values;
|
||||||
|
if (vm.count("json")) {
|
||||||
|
std::string filename = vm["json"].as<std::string>();
|
||||||
|
std::ifstream f(filename);
|
||||||
|
if (!load_json_settings(f, filename, values))
|
||||||
|
log_error("Loading design failed.\n");
|
||||||
|
}
|
||||||
|
std::unique_ptr<Context> ctx = createContext(values);
|
||||||
settings = std::unique_ptr<Settings>(new Settings(ctx.get()));
|
settings = std::unique_ptr<Settings>(new Settings(ctx.get()));
|
||||||
setupContext(ctx.get());
|
setupContext(ctx.get());
|
||||||
setupArchContext(ctx.get());
|
setupArchContext(ctx.get());
|
||||||
|
@ -39,7 +39,7 @@ class CommandHandler
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setupArchContext(Context *ctx) = 0;
|
virtual void setupArchContext(Context *ctx) = 0;
|
||||||
virtual std::unique_ptr<Context> createContext() = 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){};
|
||||||
|
@ -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() 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;
|
||||||
@ -98,7 +98,7 @@ void ECP5CommandHandler::customBitstream(Context *ctx)
|
|||||||
write_bitstream(ctx, basecfg, textcfg);
|
write_bitstream(ctx, basecfg, textcfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<Context> ECP5CommandHandler::createContext()
|
std::unique_ptr<Context> ECP5CommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
||||||
{
|
{
|
||||||
chipArgs.type = ArchArgs::LFE5U_45F;
|
chipArgs.type = ArchArgs::LFE5U_45F;
|
||||||
|
|
||||||
|
@ -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() 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,7 +51,7 @@ po::options_description GenericCommandHandler::getArchOptions()
|
|||||||
|
|
||||||
void GenericCommandHandler::customBitstream(Context *ctx) {}
|
void GenericCommandHandler::customBitstream(Context *ctx) {}
|
||||||
|
|
||||||
std::unique_ptr<Context> GenericCommandHandler::createContext()
|
std::unique_ptr<Context> GenericCommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
||||||
{
|
{
|
||||||
return std::unique_ptr<Context>(new Context(chipArgs));
|
return std::unique_ptr<Context>(new Context(chipArgs));
|
||||||
}
|
}
|
||||||
|
@ -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() 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::unique_ptr<Context> Ice40CommandHandler::createContext(std::unordered_map<std::string,Property> &values)
|
||||||
{
|
{
|
||||||
if (vm.count("lp384")) {
|
if (vm.count("lp384")) {
|
||||||
chipArgs.type = ArchArgs::LP384;
|
chipArgs.type = ArchArgs::LP384;
|
||||||
|
@ -914,4 +914,53 @@ 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)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
using namespace JsonParser;
|
||||||
|
|
||||||
|
if (!f)
|
||||||
|
log_error("failed to open JSON file.\n");
|
||||||
|
|
||||||
|
int lineno = 1;
|
||||||
|
|
||||||
|
JsonNode root(f, lineno);
|
||||||
|
|
||||||
|
if (root.type != 'D')
|
||||||
|
log_error("JSON root node is not a dictionary.\n");
|
||||||
|
|
||||||
|
if (root.data_dict.count("modules") != 0) {
|
||||||
|
JsonNode *modules = root.data_dict.at("modules");
|
||||||
|
|
||||||
|
if (modules->type != 'D')
|
||||||
|
log_error("JSON modules node is not a dictionary.\n");
|
||||||
|
|
||||||
|
for (auto &it : modules->data_dict) {
|
||||||
|
JsonNode *node = it.second;
|
||||||
|
if (is_blackbox(node))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (node->data_dict.count("settings")) {
|
||||||
|
JsonNode *attr_node = node->data_dict.at("settings");
|
||||||
|
for (int attrid = 0; attrid < GetSize(attr_node->data_dict_keys); attrid++) {
|
||||||
|
JsonNode *param = attr_node->data_dict.at(attr_node->data_dict_keys[attrid]);
|
||||||
|
std::string pId = attr_node->data_dict_keys[attrid];
|
||||||
|
if (param->type == 'N') {
|
||||||
|
values[pId].setNumber(param->data_number);
|
||||||
|
} else if (param->type == 'S')
|
||||||
|
values[pId].setString(param->data_string);
|
||||||
|
else
|
||||||
|
log_error("JSON parameter type of \"%s\' of module not supported\n", pId.c_str());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (log_execution_error_exception) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NEXTPNR_NAMESPACE_END
|
NEXTPNR_NAMESPACE_END
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
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);
|
||||||
NEXTPNR_NAMESPACE_END
|
NEXTPNR_NAMESPACE_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user