aboutsummaryrefslogtreecommitdiffstats
path: root/json
diff options
context:
space:
mode:
authorMiodrag Milanovic <mmicko@gmail.com>2019-06-01 15:52:32 +0200
committerMiodrag Milanovic <mmicko@gmail.com>2019-06-01 15:52:32 +0200
commitd5d8213871d8cb68b2e4ef9b3557879c80ff5b51 (patch)
tree03b1c06d747986941187e2b5d72cc2f93ac2702b /json
parentccbe2dd18d12d9d201afd5499e9e70ed8d2539de (diff)
downloadnextpnr-d5d8213871d8cb68b2e4ef9b3557879c80ff5b51.tar.gz
nextpnr-d5d8213871d8cb68b2e4ef9b3557879c80ff5b51.tar.bz2
nextpnr-d5d8213871d8cb68b2e4ef9b3557879c80ff5b51.zip
Added support for attributes/properties types
Diffstat (limited to 'json')
-rw-r--r--json/jsonparse.cc12
-rw-r--r--json/jsonwrite.cc7
2 files changed, 11 insertions, 8 deletions
diff --git a/json/jsonparse.cc b/json/jsonparse.cc
index a78affbe..df21eb0f 100644
--- a/json/jsonparse.cc
+++ b/json/jsonparse.cc
@@ -309,7 +309,7 @@ bool is_blackbox(JsonNode *node)
}
void json_import_cell_params(Context *ctx, string &modname, CellInfo *cell, JsonNode *param_node,
- std::unordered_map<IdString, std::string> *dest, int param_id)
+ std::unordered_map<IdString, Property> *dest, int param_id)
{
//
JsonNode *param;
@@ -319,9 +319,9 @@ void json_import_cell_params(Context *ctx, string &modname, CellInfo *cell, Json
pId = ctx->id(param_node->data_dict_keys[param_id]);
if (param->type == 'N') {
- (*dest)[pId] = std::to_string(param->data_number);
+ (*dest)[pId].setNumber(param->data_number);
} else if (param->type == 'S')
- (*dest)[pId] = param->data_string;
+ (*dest)[pId].setString(param->data_string);
else
log_error("JSON parameter type of \"%s\' of cell \'%s\' not supported\n", pId.c_str(ctx),
cell->name.c_str(ctx));
@@ -333,7 +333,7 @@ void json_import_cell_params(Context *ctx, string &modname, CellInfo *cell, Json
}
void json_import_net_attrib(Context *ctx, string &modname, NetInfo *net, JsonNode *param_node,
- std::unordered_map<IdString, std::string> *dest, int param_id)
+ std::unordered_map<IdString, Property> *dest, int param_id)
{
//
JsonNode *param;
@@ -343,9 +343,9 @@ void json_import_net_attrib(Context *ctx, string &modname, NetInfo *net, JsonNod
pId = ctx->id(param_node->data_dict_keys[param_id]);
if (param->type == 'N') {
- (*dest)[pId] = std::to_string(param->data_number);
+ (*dest)[pId].setNumber(param->data_number);
} else if (param->type == 'S')
- (*dest)[pId] = param->data_string;
+ (*dest)[pId].setString(param->data_string);
else
log_error("JSON parameter type of \"%s\' of net \'%s\' not supported\n", pId.c_str(ctx),
net->name.c_str(ctx));
diff --git a/json/jsonwrite.cc b/json/jsonwrite.cc
index bedb2449..8c1f914f 100644
--- a/json/jsonwrite.cc
+++ b/json/jsonwrite.cc
@@ -48,13 +48,16 @@ std::string get_name(IdString name, Context *ctx)
return get_string(name.c_str(ctx));
}
-bool write_parameters(std::ostream &f, Context *ctx, const std::unordered_map<IdString, std::string> &parameters, bool for_module=false)
+bool write_parameters(std::ostream &f, Context *ctx, const std::unordered_map<IdString, Property> &parameters, bool for_module=false)
{
bool first = true;
for (auto &param : parameters) {
f << stringf("%s\n", first ? "" : ",");
f << stringf(" %s%s: ", for_module ? "" : " ", get_name(param.first,ctx).c_str());
- f << get_string(param.second);
+ if (param.second.isString())
+ f << get_string(param.second);
+ else
+ f << param.second.num;
first = false;
}
return first;