/* * yosys -- Yosys Open SYnthesis Suite * * Copyright (C) 2012 Clifford Wolf * * 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. * */ #include "kernel/yosys.h" YOSYS_NAMESPACE_BEGIN struct JsonNode { char type; // S=String, N=Number, A=Array, D=Dict string data_string; int data_number; vector data_array; dict data_dict; vector data_dict_keys; JsonNode(std::istream &f) { type = 0; data_number = 0; while (1) { int ch = f.get(); if (ch == EOF) log_error("Unexpected EOF in JSON file.\n"); if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n') continue; if (ch == '"') { type = 'S'; while (1) { ch = f.get(); if (ch == EOF) log_error("Unexpected EOF in JSON string.\n"); if (ch == '"') break; if (ch == '\\') { int ch = f.get(); if (ch == EOF) log_error("Unexpected EOF in JSON string.\n"); } data_string += ch; } break; } if ('0' <= ch && ch <= '9') { type = 'N'; data_number = ch - '0'; while (1) { ch = f.get(); if (ch == EOF) break; if (ch < '0' || '9' < ch) { f.unget(); break; } data_number = data_number*10 + (ch - '0'); } break; } if (ch == '[') { type = 'A'; while (1) { ch = f.get(); if (ch == EOF) log_error("Unexpected EOF in JSON file.\n"); if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == ',') continue; if (ch == ']') break; f.unget(); data_array.push_back(new JsonNode(f)); } break; } if (ch == '{') { type = 'D'; while (1) { ch = f.get(); if (ch == EOF) log_error("Unexpected EOF in JSON file.\n"); if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == ',') continue; if (ch == '}') break; f.unget(); JsonNode key(f); while (1) { ch = f.get(); if (ch == EOF) log_error("Unexpected EOF in JSON file.\n"); if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' || ch == ':') continue; f.unget(); break; } JsonNode *value = new JsonNode(f); if (key.type != 'S') log_error("Unexpected non-string key in JSON dict.\n"); data_dict[key.data_string] = value; data_dict_keys.push_back(key.data_string); } break; } log_error("Unexpected character in JSON file: '%c'\n", ch); } } ~JsonNode() { for (auto it : data_array) delete it; for (auto &it : data_dict) delete it.second; } }; void json_parse_attr_param(dict &results, JsonNode *node) { if (node->type != 'D') log_error("JSON attributes or parameters node is not a dictionary.\n"); for (auto it : node->data_dict) { IdString key = RTLIL::escape_id(it.first.c_str()); JsonNode *value_node = it.second; Const value; if (value_node->type == 'S') { string &s = value_node->data_string; if (s.find_first_not_of("01xz") == string::npos) value = Const::from_string(s); else value = Const(s); } else if (value_node->type == 'N') { value = Const(value_node->data_number, 32); } else if (value_node->type == 'A') { log_error("JSON attribute or parameter value is an array.\n"); } else if (value_node->type == 'D') { log_error("JSON attribute or parameter value is a dict.\n"); } else { log_abort(); } results[key] = value; } } void json_import(Design *design, string &modna
from libghdl import libghdl

Enable_Warning = libghdl.errorout__enable_warning



class Msgid:
    Msgid_Note = 0
    Warnid_Library = 1
    Warnid_Missing_Xref = 2
    Warnid_Default_Binding = 3
    Warnid_Binding = 4
    Warnid_Port = 5
    Warnid_Reserved_Word = 6
    Warnid_Pragma = 7
    Warnid_Nested_Comment = 8
    Warnid_Directive = 9
    Warnid_Parenthesis = 10
    Warnid_Vital_Generic = 11
    Warnid_Delayed_Checks = 12
    Warnid_Body = 13
    Warnid_Specs = 14
    Warnid_Universal = 15
    Warnid_Port_Bounds = 16
    Warnid_Runtime_Error = 17
    Warnid_Delta_Cycle = 18
    Warnid_Shared = 19
    Warnid_Hide = 20
    Warnid_Unused = 21
    Warnid_Others = 22
    Warnid_Pure = 23
    Warnid_Static = 24
    Msgid_Warning = 25
    Msgid_Error = 26
    Msgid_Fatal = 27
at("attributes")); if (cell_node->data_dict.count("parameters")) json_parse_attr_param(cell->parameters, cell_node->data_dict.at("parameters")); } } } struct JsonFrontend : public Frontend { JsonFrontend() : Frontend("json", "read JSON file") { } virtual void help() { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); log(" read_json [filename]\n"); log("\n"); log("Load modules from a JSON file into the current design See \"help write_json\"\n"); log("for a description of the file format.\n"); log("\n"); } virtual void execute(std::istream *&f, std::string filename, std::vector args, RTLIL::Design *design) { log_header(design, "Executing JSON frontend.\n"); size_t argidx; for (argidx = 1; argidx < args.size(); argidx++) { // std::string arg = args[argidx]; // if (arg == "-sop") { // sop_mode = true; // continue; // } break; } extra_args(f, filename, args, argidx); 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(design, it.first, it.second); } } } JsonFrontend; YOSYS_NAMESPACE_END