Applied clang-format to my own contributions

This commit is contained in:
ZipCPU 2018-06-07 15:38:24 -04:00
parent a4f687548e
commit 4499864024
9 changed files with 831 additions and 840 deletions

View File

@ -17,20 +17,20 @@
* *
*/ */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <vector>
#include <list> #include <list>
#include <map> #include <map>
#include <set> #include <set>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include "log.h"
#include "design.h" #include "design.h"
#include "log.h"
std::vector<FILE*> log_files; std::vector<FILE *> log_files;
std::vector<std::ostream*> log_streams; std::vector<std::ostream *> log_streams;
FILE *log_errfile = NULL; FILE *log_errfile = NULL;
bool log_error_stderr = false; bool log_error_stderr = false;
@ -49,11 +49,11 @@ std::string vstringf(const char *fmt, va_list ap)
char *str = NULL; char *str = NULL;
#ifdef _WIN32 #ifdef _WIN32
int sz = 64+strlen(fmt), rc; int sz = 64 + strlen(fmt), rc;
while (1) { while (1) {
va_list apc; va_list apc;
va_copy(apc, ap); va_copy(apc, ap);
str = (char*)realloc(str, sz); str = (char *)realloc(str, sz);
rc = vsnprintf(str, sz, fmt, apc); rc = vsnprintf(str, sz, fmt, apc);
va_end(apc); va_end(apc);
if (rc >= 0 && rc < sz) if (rc >= 0 && rc < sz)
@ -210,23 +210,17 @@ void log_cmd_error(const char *format, ...)
void log_spacer() void log_spacer()
{ {
if (log_newline_count < 2) log("\n"); if (log_newline_count < 2)
if (log_newline_count < 2) log("\n"); log("\n");
if (log_newline_count < 2)
log("\n");
} }
void log_push() void log_push() {}
{
}
void log_pop() void log_pop() { log_flush(); }
{
log_flush();
}
void log_reset_stack() void log_reset_stack() { log_flush(); }
{
log_flush();
}
void log_flush() void log_flush()
{ {
@ -237,12 +231,6 @@ void log_flush()
f->flush(); f->flush();
} }
void log_cell(CellInfo *cell, std::string indent) void log_cell(CellInfo *cell, std::string indent) {}
{
}
void log_net(NetInfo *net, std::string indent)
{
}
void log_net(NetInfo *net, std::string indent) {}

View File

@ -21,12 +21,12 @@
#define LOG_H #define LOG_H
#include <ostream> #include <ostream>
#include <ostream>
#include <set>
#include <stdarg.h>
#include <stdio.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <set>
#include <ostream>
#include <stdio.h>
#include <stdarg.h>
#include "design.h" #include "design.h"
@ -35,10 +35,12 @@
#define NXP_NORETURN #define NXP_NORETURN
#define NXP_ATTRIBUTE(...) __attribute__((__VA_ARGS__)) #define NXP_ATTRIBUTE(...) __attribute__((__VA_ARGS__))
struct log_cmd_error_exception { }; struct log_cmd_error_exception
{
};
extern std::vector<FILE*> log_files; extern std::vector<FILE *> log_files;
extern std::vector<std::ostream*> log_streams; extern std::vector<std::ostream *> log_streams;
extern FILE *log_errfile; extern FILE *log_errfile;
extern bool log_quiet_warnings; extern bool log_quiet_warnings;
@ -81,16 +83,21 @@ void log_cell(CellInfo *cell, std::string indent = "");
void log_net(NetInfo *net, std::string indent = ""); void log_net(NetInfo *net, std::string indent = "");
#ifndef NDEBUG #ifndef NDEBUG
static inline void log_assert_worker(bool cond, const char *expr, const char *file, int line) { static inline void log_assert_worker(bool cond, const char *expr,
if (!cond) log_error("Assert `%s' failed in %s:%d.\n", expr, file, line); const char *file, int line)
{
if (!cond)
log_error("Assert `%s' failed in %s:%d.\n", expr, file, line);
} }
# define log_assert(_assert_expr_) YOSYS_NAMESPACE_PREFIX log_assert_worker(_assert_expr_, #_assert_expr_, __FILE__, __LINE__) #define log_assert(_assert_expr_) \
YOSYS_NAMESPACE_PREFIX log_assert_worker(_assert_expr_, #_assert_expr_, \
__FILE__, __LINE__)
#else #else
# define log_assert(_assert_expr_) #define log_assert(_assert_expr_)
#endif #endif
#define log_abort() log_error("Abort in %s:%d.\n", __FILE__, __LINE__) #define log_abort() log_error("Abort in %s:%d.\n", __FILE__, __LINE__)
#define log_ping() log("-- %s:%d %s --\n", __FILE__, __LINE__, __PRETTY_FUNCTION__) #define log_ping() \
log("-- %s:%d %s --\n", __FILE__, __LINE__, __PRETTY_FUNCTION__)
#endif #endif

View File

@ -18,26 +18,27 @@
*/ */
#include <iostream> #include <iostream>
#include <ostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <vector>
#include <list> #include <list>
#include <map> #include <map>
#include <ostream>
#include <set> #include <set>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include "log.h"
#include "design.h" #include "design.h"
#include "log.h"
#include "place.h" #include "place.h"
void place_design(Design *design) { void place_design(Design *design)
{
std::set<IdString> types_used; std::set<IdString> types_used;
std::set<IdString>::iterator not_found, element; std::set<IdString>::iterator not_found, element;
std::set<BelType> used_bels; std::set<BelType> used_bels;
for(auto cell_entry : design->cells) { for (auto cell_entry : design->cells) {
CellInfo *cell = cell_entry.second; CellInfo *cell = cell_entry.second;
BelType bel_type; BelType bel_type;
@ -49,26 +50,27 @@ void place_design(Design *design) {
bel_type = belTypeFromId(cell->type); bel_type = belTypeFromId(cell->type);
if (bel_type == BelType()) { if (bel_type == BelType()) {
log_error("No Bel of type \'%s\' defined for " log_error("No Bel of type \'%s\' defined for "
"this chip\n", cell->type.c_str()); "this chip\n",
cell->type.c_str());
} }
types_used.insert(cell->type); types_used.insert(cell->type);
std::cout << cell->type << std::endl; std::cout << cell->type << std::endl;
} }
for(auto bel_type_name : types_used) { for (auto bel_type_name : types_used) {
auto blist = design->chip.getBels(); auto blist = design->chip.getBels();
BelType bel_type = belTypeFromId(bel_type_name); BelType bel_type = belTypeFromId(bel_type_name);
auto bi = blist.begin(); auto bi = blist.begin();
for(auto cell_entry : design->cells) { for (auto cell_entry : design->cells) {
CellInfo *cell = cell_entry.second; CellInfo *cell = cell_entry.second;
// Only place one type of Bel at a time // Only place one type of Bel at a time
if (cell->type.compare(bel_type_name)!=0) if (cell->type.compare(bel_type_name) != 0)
continue; continue;
while((bi != blist.end()) while ((bi != blist.end()) &&
&&(design->chip.getBelType(*bi) != bel_type)) (design->chip.getBelType(*bi) != bel_type))
bi++; bi++;
if (bi == blist.end()) if (bi == blist.end())
log_error("Too many \'%s\' used in design\n", log_error("Too many \'%s\' used in design\n",
@ -77,4 +79,3 @@ void place_design(Design *design) {
} }
} }
} }

View File

@ -1,68 +1,72 @@
#include <string>
#include <assert.h> #include <assert.h>
#include <string>
#include "design.h" #include "design.h"
#include "log.h" #include "log.h"
bool check_all_nets_driven(Design *design) { bool check_all_nets_driven(Design *design)
{
const bool debug = false; const bool debug = false;
log_info("Rule checker, Verifying pre-placed design\n"); log_info("Rule checker, Verifying pre-placed design\n");
for(auto cell_entry : design->cells) { for (auto cell_entry : design->cells) {
CellInfo *cell = cell_entry.second; CellInfo *cell = cell_entry.second;
if (debug) log_info(" Examining cell \'%s\', of type \'%s\'\n", if (debug)
cell->name.c_str(), log_info(" Examining cell \'%s\', of type \'%s\'\n",
cell->type.c_str()); cell->name.c_str(), cell->type.c_str());
for(auto port_entry : cell->ports) { for (auto port_entry : cell->ports) {
PortInfo &port = port_entry.second; PortInfo &port = port_entry.second;
if (debug) log_info(" Checking name of port \'%s\' " if (debug)
log_info(" Checking name of port \'%s\' "
"against \'%s\'\n", "against \'%s\'\n",
port_entry.first.c_str(), port_entry.first.c_str(), port.name.c_str());
port.name.c_str()); assert(port.name.compare(port_entry.first) == 0);
assert(port.name.compare(port_entry.first)==0);
assert(port.name.size() > 0); assert(port.name.size() > 0);
if (port.net == NULL) { if (port.net == NULL) {
if (debug) log_warning(" Port \'%s\' in cell \'%s\' is unconnected\n", if (debug)
log_warning(
" Port \'%s\' in cell \'%s\' is unconnected\n",
port.name.c_str(), cell->name.c_str()); port.name.c_str(), cell->name.c_str());
} else { } else {
assert(port.net); assert(port.net);
if (debug) log_info(" Checking for a net named \'%s\'\n", if (debug)
log_info(" Checking for a net named \'%s\'\n",
port.net->name.c_str()); port.net->name.c_str());
assert(design->nets.count(port.net->name)>0); assert(design->nets.count(port.net->name) > 0);
} }
} }
} }
for(auto net_entry : design->nets) { for (auto net_entry : design->nets) {
NetInfo *net = net_entry.second; NetInfo *net = net_entry.second;
assert(net->name.compare(net_entry.first) == 0); assert(net->name.compare(net_entry.first) == 0);
if ((net->driver.cell != NULL) if ((net->driver.cell != NULL) &&
&&(net->driver.cell->type.compare("GND") != 0) (net->driver.cell->type.compare("GND") != 0) &&
&&(net->driver.cell->type.compare("VCC") != 0)) { (net->driver.cell->type.compare("VCC") != 0)) {
if (debug) log_info(" Checking for a driver cell named \'%s\'\n", if (debug)
log_info(" Checking for a driver cell named \'%s\'\n",
net->driver.cell->name.c_str()); net->driver.cell->name.c_str());
assert(design->cells.count(net->driver.cell->name) >0); assert(design->cells.count(net->driver.cell->name) > 0);
} }
for(auto user : net->users) { for (auto user : net->users) {
if ((user.cell != NULL) if ((user.cell != NULL) && (user.cell->type.compare("GND") != 0) &&
&&(user.cell->type.compare("GND") != 0) (user.cell->type.compare("VCC") != 0)) {
&&(user.cell->type.compare("VCC") != 0)) {
if (debug) log_info(" Checking for a user cell named \'%s\'\n", if (debug)
log_info(" Checking for a user cell named \'%s\'\n",
user.cell->name.c_str()); user.cell->name.c_str());
assert(design->cells.count(user.cell->name) >0); assert(design->cells.count(user.cell->name) > 0);
} }
} }
} }
if (debug) log_info(" Verified!\n"); if (debug)
log_info(" Verified!\n");
return true; return true;
} }

View File

@ -21,33 +21,32 @@
* *
*/ */
#include <string>
#include <iostream>
#include <fstream>
#include <assert.h>
#include <log.h>
#include "design.h"
#include "chip.h"
#include "jsonparse.h" #include "jsonparse.h"
#include <assert.h>
#include <fstream>
#include <iostream>
#include <log.h>
#include <string>
#include "chip.h"
#include "design.h"
extern bool check_all_nets_driven(Design *design); extern bool check_all_nets_driven(Design *design);
namespace JsonParser { namespace JsonParser {
const bool json_debug = false; const bool json_debug = false;
typedef std::string string; typedef std::string string;
template<typename T> int GetSize(const T &obj) { return obj.size(); }
template <typename T> int GetSize(const T &obj) { return obj.size(); }
struct JsonNode struct JsonNode
{ {
char type; // S=String, N=Number, A=Array, D=Dict char type; // S=String, N=Number, A=Array, D=Dict
string data_string; string data_string;
int data_number; int data_number;
vector<JsonNode*> data_array; vector<JsonNode *> data_array;
dict<string, JsonNode*> data_dict; dict<string, JsonNode *> data_dict;
vector<string> data_dict_keys; vector<string> data_dict_keys;
JsonNode(std::istream &f) JsonNode(std::istream &f)
@ -55,8 +54,7 @@ struct JsonNode
type = 0; type = 0;
data_number = 0; data_number = 0;
while (1) while (1) {
{
int ch = f.get(); int ch = f.get();
if (ch == EOF) if (ch == EOF)
@ -65,12 +63,10 @@ struct JsonNode
if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n') if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n')
continue; continue;
if (ch == '\"') if (ch == '\"') {
{
type = 'S'; type = 'S';
while (1) while (1) {
{
ch = f.get(); ch = f.get();
if (ch == EOF) if (ch == EOF)
@ -94,14 +90,12 @@ struct JsonNode
break; break;
} }
if ('0' <= ch && ch <= '9') if ('0' <= ch && ch <= '9') {
{
type = 'N'; type = 'N';
data_number = ch - '0'; data_number = ch - '0';
data_string += ch; data_string += ch;
while (1) while (1) {
{
ch = f.get(); ch = f.get();
if (ch == EOF) if (ch == EOF)
@ -115,8 +109,7 @@ struct JsonNode
break; break;
} }
data_number = data_number*10 data_number = data_number * 10 + (ch - '0');
+ (ch - '0');
data_string += ch; data_string += ch;
} }
@ -128,8 +121,7 @@ struct JsonNode
data_number = 0; data_number = 0;
data_string += ch; data_string += ch;
while (1) while (1) {
{
ch = f.get(); ch = f.get();
if (ch == EOF) if (ch == EOF)
@ -146,22 +138,18 @@ struct JsonNode
break; break;
} }
if (ch == '[') if (ch == '[') {
{
type = 'A'; type = 'A';
while (1) while (1) {
{
ch = f.get(); ch = f.get();
if (ch == EOF) if (ch == EOF)
log_error("Unexpected EOF " log_error("Unexpected EOF "
"in JSON file.\n"); "in JSON file.\n");
if (ch == ' ' || ch == '\t' if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' ||
|| ch == '\r' ch == ',')
|| ch == '\n'
|| ch == ',')
continue; continue;
if (ch == ']') if (ch == ']')
@ -174,22 +162,18 @@ struct JsonNode
break; break;
} }
if (ch == '{') if (ch == '{') {
{
type = 'D'; type = 'D';
while (1) while (1) {
{
ch = f.get(); ch = f.get();
if (ch == EOF) if (ch == EOF)
log_error("Unexpected EOF " log_error("Unexpected EOF "
"in JSON file.\n"); "in JSON file.\n");
if (ch == ' ' || ch == '\t' if (ch == ' ' || ch == '\t' || ch == '\r' || ch == '\n' ||
|| ch == '\r' ch == ',')
|| ch == '\n'
|| ch == ',')
continue; continue;
if (ch == '}') if (ch == '}')
@ -198,18 +182,15 @@ struct JsonNode
f.unget(); f.unget();
JsonNode key(f); JsonNode key(f);
while (1) while (1) {
{
ch = f.get(); ch = f.get();
if (ch == EOF) if (ch == EOF)
log_error("Unexpected EOF " log_error("Unexpected EOF "
"in JSON file.\n"); "in JSON file.\n");
if (ch == ' ' || ch == '\t' if (ch == ' ' || ch == '\t' || ch == '\r' ||
|| ch == '\r' ch == '\n' || ch == ':')
|| ch == '\n'
|| ch == ':')
continue; continue;
f.unget(); f.unget();
@ -224,15 +205,13 @@ struct JsonNode
"in JSON dict.\n"); "in JSON dict.\n");
data_dict[key.data_string] = value; data_dict[key.data_string] = value;
data_dict_keys.push_back( data_dict_keys.push_back(key.data_string);
key.data_string);
} }
break; break;
} }
log_error("Unexpected character in JSON file: '%c'\n", log_error("Unexpected character in JSON file: '%c'\n", ch);
ch);
} }
} }
@ -245,8 +224,8 @@ struct JsonNode
} }
}; };
NetInfo *ground_net(NetInfo *net)
NetInfo *ground_net(NetInfo *net) { {
CellInfo *cell = new CellInfo; CellInfo *cell = new CellInfo;
PortInfo port_info; PortInfo port_info;
PortRef port_ref; PortRef port_ref;
@ -268,7 +247,8 @@ NetInfo *ground_net(NetInfo *net) {
return net; return net;
} }
NetInfo *vcc_net(NetInfo *net) { NetInfo *vcc_net(NetInfo *net)
{
CellInfo *cell = new CellInfo; CellInfo *cell = new CellInfo;
PortInfo port_info; PortInfo port_info;
PortRef port_ref; PortRef port_ref;
@ -290,7 +270,8 @@ NetInfo *vcc_net(NetInfo *net) {
return net; return net;
} }
NetInfo *floating_net(NetInfo *net) { NetInfo *floating_net(NetInfo *net)
{
PortInfo port_info; PortInfo port_info;
PortRef port_ref; PortRef port_ref;
@ -313,17 +294,18 @@ NetInfo *floating_net(NetInfo *net) {
// An item is deemed to be a blackbox if this entry exists and if its // An item is deemed to be a blackbox if this entry exists and if its
// value is not zero. If the item is a black box, this routine will return // value is not zero. If the item is a black box, this routine will return
// true, false otherwise // true, false otherwise
bool is_blackbox(JsonNode *node) { bool is_blackbox(JsonNode *node)
{
JsonNode *attr_node, *bbox_node; JsonNode *attr_node, *bbox_node;
if (node->data_dict.count("attributes")==0) if (node->data_dict.count("attributes") == 0)
return false; return false;
attr_node = node->data_dict.at("attributes"); attr_node = node->data_dict.at("attributes");
if (attr_node == NULL) if (attr_node == NULL)
return false; return false;
if (attr_node->type != 'D') if (attr_node->type != 'D')
return false; return false;
if (GetSize(attr_node->data_dict)==0) if (GetSize(attr_node->data_dict) == 0)
return false; return false;
if (attr_node->data_dict.count("blackbox") == 0) if (attr_node->data_dict.count("blackbox") == 0)
return false; return false;
@ -332,45 +314,50 @@ bool is_blackbox(JsonNode *node) {
return false; return false;
if (bbox_node->type != 'N') if (bbox_node->type != 'N')
log_error("JSON module blackbox is not a number\n"); log_error("JSON module blackbox is not a number\n");
if (bbox_node->data_number==0) if (bbox_node->data_number == 0)
return false; return false;
return true; return true;
} }
void json_import_cell_attributes(Design *design, string &modname, void json_import_cell_attributes(Design *design, string &modname,
CellInfo *cell, JsonNode *param_node, int param_id) { CellInfo *cell, JsonNode *param_node,
int param_id)
{
// //
JsonNode *param; JsonNode *param;
IdString pId; IdString pId;
// //
param = param_node->data_dict.at( param = param_node->data_dict.at(param_node->data_dict_keys[param_id]);
param_node->data_dict_keys[param_id]);
pId = param_node->data_dict_keys[param_id]; pId = param_node->data_dict_keys[param_id];
if (param->type == 'N') { if (param->type == 'N') {
cell->params[pId] = std::to_string(param_node->data_number);; cell->params[pId] = std::to_string(param_node->data_number);
;
} else if (param->type == 'S') } else if (param->type == 'S')
cell->params[pId] = param->data_string; cell->params[pId] = param->data_string;
else else
log_error("JSON parameter type of \"%s\' of cell \'%s\' not supported\n", log_error(
pId.c_str(), "JSON parameter type of \"%s\' of cell \'%s\' not supported\n",
cell->name.c_str()); pId.c_str(), cell->name.c_str());
if (json_debug) log_info(" Added parameter \'%s\'=%s to cell \'%s\' " if (json_debug)
log_info(" Added parameter \'%s\'=%s to cell \'%s\' "
"of module \'%s\'\n", "of module \'%s\'\n",
pId.c_str(), cell->params[pId].c_str(), pId.c_str(), cell->params[pId].c_str(), cell->name.c_str(),
cell->name.c_str(), modname.c_str()); modname.c_str());
} }
void json_import_cell_ports(Design *design, string &modname, CellInfo *cell, void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
string &port_name, JsonNode *dir_node,JsonNode *wire_group_node) string &port_name, JsonNode *dir_node,
JsonNode *wire_group_node)
{ {
// Examine and connect a single port of the given cell to its nets, // Examine and connect a single port of the given cell to its nets,
// generating them as necessary // generating them as necessary
assert(dir_node); assert(dir_node);
if (json_debug) log_info(" Examining port %s, node %s\n", port_name.c_str(), if (json_debug)
log_info(" Examining port %s, node %s\n", port_name.c_str(),
cell->name.c_str()); cell->name.c_str());
if (!wire_group_node) if (!wire_group_node)
@ -387,17 +374,16 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
PortInfo port_info; PortInfo port_info;
port_info.name = port_name; port_info.name = port_name;
if(dir_node->data_string.compare("input")==0) if (dir_node->data_string.compare("input") == 0)
port_info.type = PORT_IN; port_info.type = PORT_IN;
else if(dir_node->data_string.compare("output")==0) else if (dir_node->data_string.compare("output") == 0)
port_info.type = PORT_OUT; port_info.type = PORT_OUT;
else if(dir_node->data_string.compare("inout")==0) else if (dir_node->data_string.compare("inout") == 0)
port_info.type = PORT_INOUT; port_info.type = PORT_INOUT;
else else
log_error("JSON unknown port direction \'%s\' in node \'%s\' " log_error("JSON unknown port direction \'%s\' in node \'%s\' "
"of module \'%s\'\n", "of module \'%s\'\n",
dir_node->data_string.c_str(), dir_node->data_string.c_str(), cell->name.c_str(),
cell->name.c_str(),
modname.c_str()); modname.c_str());
// //
// Find an update, or create a net to connect // Find an update, or create a net to connect
@ -410,7 +396,7 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
// If this port references a bus, then there will be multiple nets // If this port references a bus, then there will be multiple nets
// connected to it, all specified as part of an array. // connected to it, all specified as part of an array.
// //
is_bus = (wire_group_node->data_array.size()>1); is_bus = (wire_group_node->data_array.size() > 1);
// Now loop through all of the connections to this port. // Now loop through all of the connections to this port.
if (wire_group_node->data_array.size() == 0) { if (wire_group_node->data_array.size() == 0) {
@ -427,10 +413,12 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
cell->ports[this_port.name] = this_port; cell->ports[this_port.name] = this_port;
if (json_debug) log_info(" Port \'%s\' has no connection in \'%s\'\n", if (json_debug)
log_info(" Port \'%s\' has no connection in \'%s\'\n",
this_port.name.c_str(), cell->name.c_str()); this_port.name.c_str(), cell->name.c_str());
} else for(int index=0; index < wire_group_node->data_array.size(); } else
for (int index = 0; index < wire_group_node->data_array.size();
index++) { index++) {
// //
JsonNode *wire_node; JsonNode *wire_node;
@ -445,8 +433,8 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
// //
// Pick a name for this port // Pick a name for this port
if (is_bus) if (is_bus)
this_port.name = port_info.name + '[' this_port.name =
+ std::to_string(index) + ']'; port_info.name + '[' + std::to_string(index) + ']';
else else
this_port.name = port_info.name; this_port.name = port_info.name;
this_port.type = port_info.type; this_port.type = port_info.type;
@ -463,7 +451,8 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
// The net doesn't exist in the design (yet) // The net doesn't exist in the design (yet)
// Create in now // Create in now
if (json_debug) log_info(" Generating a new net, \'%d\'\n", if (json_debug)
log_info(" Generating a new net, \'%d\'\n",
net_num); net_num);
this_net = new NetInfo; this_net = new NetInfo;
@ -477,10 +466,11 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
// We'll connect to it // We'll connect to it
// //
this_net = design->nets[net_id]; this_net = design->nets[net_id];
if (json_debug) log_info(" Reusing net \'%s\', id \'%s\', " if (json_debug)
log_info(" Reusing net \'%s\', id \'%s\', "
"with driver \'%s\'\n", "with driver \'%s\'\n",
this_net->name.c_str(), net_id.c_str(), this_net->name.c_str(), net_id.c_str(),
(this_net->driver.cell!=NULL) (this_net->driver.cell != NULL)
? this_net->driver.port.c_str() ? this_net->driver.port.c_str()
: "NULL"); : "NULL");
} }
@ -495,29 +485,28 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
this_net->name = net_id; this_net->name = net_id;
const_input = (this_port.type == PORT_IN); const_input = (this_port.type == PORT_IN);
if (wire_node->data_string.compare(string("0"))==0) { if (wire_node->data_string.compare(string("0")) == 0) {
if (json_debug) log_info(" Generating a constant " if (json_debug)
log_info(" Generating a constant "
"zero net\n"); "zero net\n");
this_net = ground_net(this_net); this_net = ground_net(this_net);
} else if (wire_node->data_string.compare(string("1")) } else if (wire_node->data_string.compare(string("1")) == 0) {
==0) {
if (json_debug) log_info(" Generating a constant " if (json_debug)
log_info(" Generating a constant "
"one net\n"); "one net\n");
this_net = vcc_net(this_net); this_net = vcc_net(this_net);
} else if (wire_node->data_string.compare(string("x")) } else if (wire_node->data_string.compare(string("x")) == 0) {
==0) {
this_net = floating_net(this_net); this_net = floating_net(this_net);
log_warning(" Floating wire node value, " log_warning(" Floating wire node value, "
"\'%s\' of port \'%s\' " "\'%s\' of port \'%s\' "
"in cell \'%s\' of module \'%s\'\n", "in cell \'%s\' of module \'%s\'\n",
wire_node->data_string.c_str(), wire_node->data_string.c_str(),
port_name.c_str(), port_name.c_str(), cell->name.c_str(),
cell->name.c_str(),
modname.c_str()); modname.c_str());
} else } else
@ -526,7 +515,8 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
wire_node->data_string.c_str()); wire_node->data_string.c_str());
} }
if (json_debug) log_info(" Inserting port \'%s\' into cell \'%s\'\n", if (json_debug)
log_info(" Inserting port \'%s\' into cell \'%s\'\n",
this_port.name.c_str(), cell->name.c_str()); this_port.name.c_str(), cell->name.c_str());
this_port.net = this_net; this_port.net = this_net;
@ -545,7 +535,8 @@ void json_import_cell_ports(Design *design, string &modname, CellInfo *cell,
} }
void json_import_cell(Design *design, string modname, JsonNode *cell_node, void json_import_cell(Design *design, string modname, JsonNode *cell_node,
string cell_name) { string cell_name)
{
JsonNode *cell_type, *param_node; JsonNode *cell_type, *param_node;
cell_type = cell_node->data_dict.at("type"); cell_type = cell_node->data_dict.at("type");
@ -559,25 +550,24 @@ void json_import_cell(Design *design, string modname, JsonNode *cell_node,
cell->type = cell_type->data_string; cell->type = cell_type->data_string;
// No BEL assignment here/yet // No BEL assignment here/yet
if (json_debug) log_info(" Processing %s $ %s\n", if (json_debug)
modname.c_str(), cell->name.c_str()); log_info(" Processing %s $ %s\n", modname.c_str(), cell->name.c_str());
param_node = cell_node->data_dict.at("parameters"); param_node = cell_node->data_dict.at("parameters");
if (param_node->type != 'D') if (param_node->type != 'D')
log_error("JSON parameter list of \'%s\' is not a data dictionary\n", cell->name.c_str()); log_error("JSON parameter list of \'%s\' is not a data dictionary\n",
cell->name.c_str());
// //
// Loop through all parameters, adding them into the // Loop through all parameters, adding them into the
// design to annotate the cell // design to annotate the cell
// //
for(int paramid = 0; paramid < GetSize(param_node->data_dict_keys); for (int paramid = 0; paramid < GetSize(param_node->data_dict_keys);
paramid++) { paramid++) {
json_import_cell_attributes(design, modname, cell, param_node, json_import_cell_attributes(design, modname, cell, param_node, paramid);
paramid);
} }
// //
// Now connect the ports of this module. The ports are defined by // Now connect the ports of this module. The ports are defined by
// both the port directions node as well as the connections node. // both the port directions node as well as the connections node.
@ -591,38 +581,36 @@ void json_import_cell(Design *design, string modname, JsonNode *cell_node,
if (pdir_node->type != 'D') if (pdir_node->type != 'D')
log_error("JSON port_directions node of \'%s\' " log_error("JSON port_directions node of \'%s\' "
"in module \'%s\' is not a " "in module \'%s\' is not a "
"dictionary\n", cell->name.c_str(), "dictionary\n",
modname.c_str()); cell->name.c_str(), modname.c_str());
} else if (cell_node->data_dict.count("ports") > 0) { } else if (cell_node->data_dict.count("ports") > 0) {
pdir_node = cell_node->data_dict.at("ports"); pdir_node = cell_node->data_dict.at("ports");
if (pdir_node->type != 'D') if (pdir_node->type != 'D')
log_error("JSON ports node of \'%s\' " log_error("JSON ports node of \'%s\' "
"in module \'%s\' is not a " "in module \'%s\' is not a "
"dictionary\n", cell->name.c_str(), "dictionary\n",
modname.c_str()); cell->name.c_str(), modname.c_str());
} }
JsonNode *connections JsonNode *connections = cell_node->data_dict.at("connections");
= cell_node->data_dict.at("connections");
if (connections->type != 'D') if (connections->type != 'D')
log_error("JSON connections node of \'%s\' " log_error("JSON connections node of \'%s\' "
"in module \'%s\' is not a " "in module \'%s\' is not a "
"dictionary\n", cell->name.c_str(), "dictionary\n",
modname.c_str()); cell->name.c_str(), modname.c_str());
if (GetSize(pdir_node->data_dict_keys) if (GetSize(pdir_node->data_dict_keys) !=
!= GetSize(connections->data_dict_keys)) GetSize(connections->data_dict_keys))
log_error("JSON number of connections doesnt " log_error("JSON number of connections doesnt "
"match number of ports in node \'%s\' " "match number of ports in node \'%s\' "
"of module \'%s\'\n", "of module \'%s\'\n",
cell->name.c_str(), cell->name.c_str(), modname.c_str());
modname.c_str());
// //
// Loop through all of the ports of this logic element // Loop through all of the ports of this logic element
// //
for(int portid=0; portid<GetSize(pdir_node->data_dict_keys); for (int portid = 0; portid < GetSize(pdir_node->data_dict_keys);
portid++) { portid++) {
// //
string port_name; string port_name;
@ -633,15 +621,16 @@ void json_import_cell(Design *design, string modname, JsonNode *cell_node,
dir_node = pdir_node->data_dict.at(port_name); dir_node = pdir_node->data_dict.at(port_name);
wire_group_node = connections->data_dict.at(port_name); wire_group_node = connections->data_dict.at(port_name);
json_import_cell_ports(design, modname, cell, json_import_cell_ports(design, modname, cell, port_name, dir_node,
port_name, dir_node, wire_group_node); wire_group_node);
} }
design->cells[cell->name] = cell; design->cells[cell->name] = cell;
// check_all_nets_driven(design); // check_all_nets_driven(design);
} }
void json_import(Design *design, string modname, JsonNode *node) { void json_import(Design *design, string modname, JsonNode *node)
{
if (is_blackbox(node)) if (is_blackbox(node))
return; return;
@ -654,27 +643,25 @@ void json_import(Design *design, string modname, JsonNode *node) {
// Loop through all of the logic elements in a flattened design // Loop through all of the logic elements in a flattened design
// //
// //
for(int cellid=0; cellid < GetSize(cell_parent->data_dict_keys); for (int cellid = 0; cellid < GetSize(cell_parent->data_dict_keys);
cellid ++) { cellid++) {
JsonNode *cell_type, *here, *param_node; JsonNode *cell_type, *here, *param_node;
here = cell_parent->data_dict.at( here = cell_parent->data_dict.at(
cell_parent->data_dict_keys[cellid]); cell_parent->data_dict_keys[cellid]);
json_import_cell(design, modname, here, json_import_cell(design, modname, here,
cell_parent->data_dict_keys[cellid]); cell_parent->data_dict_keys[cellid]);
} }
} }
check_all_nets_driven(design); check_all_nets_driven(design);
} }
struct JsonFrontend { struct JsonFrontend
{
// JsonFrontend() : Frontend("json", "read JSON file") { } // JsonFrontend() : Frontend("json", "read JSON file") { }
JsonFrontend(void) { } JsonFrontend(void) {}
virtual void help() virtual void help() {}
{
}
virtual void execute(std::istream *&f, std::string &filename, virtual void execute(std::istream *&f, std::string &filename,
Design *design) Design *design)
{ {
@ -685,8 +672,7 @@ struct JsonFrontend {
if (root.type != 'D') if (root.type != 'D')
log_error("JSON root node is not a dictionary.\n"); log_error("JSON root node is not a dictionary.\n");
if (root.data_dict.count("modules") != 0) if (root.data_dict.count("modules") != 0) {
{
JsonNode *modules = root.data_dict.at("modules"); JsonNode *modules = root.data_dict.at("modules");
if (modules->type != 'D') if (modules->type != 'D')
@ -700,7 +686,8 @@ struct JsonFrontend {
}; // End Namespace JsonParser }; // End Namespace JsonParser
void parse_json_file(std::istream *&f, std::string &filename, Design *design){ void parse_json_file(std::istream *&f, std::string &filename, Design *design)
{
auto *parser = new JsonParser::JsonFrontend(); auto *parser = new JsonParser::JsonFrontend();
parser->execute(f, filename, design); parser->execute(f, filename, design);
} }

View File

@ -20,8 +20,8 @@
#ifndef JSON_PARSER #ifndef JSON_PARSER
#define JSON_PARSER #define JSON_PARSER
#include <string>
#include <istream> #include <istream>
#include <string>
#include "design.h" #include "design.h"
extern void parse_json_file(std::istream *&, std::string &, Design *); extern void parse_json_file(std::istream *&, std::string &, Design *);

View File

@ -173,8 +173,13 @@ struct BelIterator
{ {
int cursor; int cursor;
BelIterator operator++() { cursor++; return *this; } BelIterator operator++()
BelIterator operator++(int) { {
cursor++;
return *this;
}
BelIterator operator++(int)
{
BelIterator prior(*this); BelIterator prior(*this);
cursor++; cursor++;
return prior; return prior;

View File

@ -23,11 +23,11 @@
#include "design.h" #include "design.h"
#include "jsonparse.h" #include "jsonparse.h"
#include "log.h" #include "log.h"
#include "log.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "place.h"
#include "pybindings.h" #include "pybindings.h"
#include "version.h" #include "version.h"
#include "log.h"
#include "place.h"
void svg_dump_el(const GraphicElement &el) void svg_dump_el(const GraphicElement &el)
{ {
@ -254,7 +254,6 @@ int main(int argc, char *argv[])
execute_python_file(filename.c_str()); execute_python_file(filename.c_str());
} }
if (vm.count("gui")) { if (vm.count("gui")) {
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow w; MainWindow w;