Cleanup parse_json_file API, some other cleanups

Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
Clifford Wolf 2018-06-21 16:16:58 +02:00
parent 417e67938c
commit 4fefdbd57c
6 changed files with 22 additions and 36 deletions

View File

@ -52,8 +52,7 @@ void parse_json_shim(std::string filename, Context &d)
std::ifstream inf(filename);
if (!inf)
throw std::runtime_error("failed to open file " + filename);
std::istream *ifp = &inf;
parse_json_file(ifp, filename, &d);
parse_json_file(inf, filename, &d);
}
// Create a new Chip and load design from json file

View File

@ -102,7 +102,7 @@ PipId Arch::getPipByName(IdString name) const { return PipId(); }
IdString Arch::getPipName(PipId pip) const { return IdString(); }
uint32_t Arch::getWireChecksum(WireId wire) const { return 0; }
uint32_t Arch::getPipChecksum(PipId wire) const { return 0; }
void Arch::bindPip(PipId pip, IdString net) {}

View File

@ -795,39 +795,26 @@ void json_import(Context *ctx, string modname, JsonNode *node)
}
check_all_nets_driven(ctx);
}
struct JsonFrontend
{
// JsonFrontend() : Frontend("json", "read JSON file") { }
JsonFrontend(void) {}
virtual void help() {}
virtual void execute(std::istream *&f, std::string &filename, Context *ctx)
{
// log_header(ctx, "Executing JSON frontend.\n");
JsonNode root(*f);
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)
json_import(ctx, it.first, it.second);
}
}
}; // JsonFrontend;
}; // End Namespace JsonParser
void parse_json_file(std::istream *&f, std::string &filename, Context *ctx)
void parse_json_file(std::istream &f, std::string &filename, Context *ctx)
{
auto *parser = new JsonParser::JsonFrontend();
parser->execute(f, filename, ctx);
using namespace JsonParser;
JsonNode root(f);
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)
json_import(ctx, it.first, it.second);
}
log_info("Checksum: 0x%08x\n", ctx->checksum());
log_break();

View File

@ -26,7 +26,7 @@
NEXTPNR_NAMESPACE_BEGIN
extern void parse_json_file(std::istream *&, std::string &, Context *);
extern void parse_json_file(std::istream &, std::string &, Context *);
NEXTPNR_NAMESPACE_END

View File

@ -18,7 +18,7 @@ Worker::Worker(Context *_ctx) : ctx(_ctx)
void Worker::parsejson(const std::string &filename)
{
std::string fn = filename;
std::istream *f = new std::ifstream(fn);
std::ifstream f(fn);
parse_json_file(f, fn, ctx);
if (!pack_design(ctx))

View File

@ -283,7 +283,7 @@ int main(int argc, char *argv[])
if (vm.count("json")) {
std::string filename = vm["json"].as<std::string>();
std::istream *f = new std::ifstream(filename);
std::ifstream f(filename);
parse_json_file(f, filename, &ctx);