Propagate errors
This commit is contained in:
parent
8436191307
commit
503fafd574
@ -75,6 +75,8 @@ struct GateMateCCFReader
|
|||||||
if (name == "LOC") {
|
if (name == "LOC") {
|
||||||
if (is_default)
|
if (is_default)
|
||||||
log_error("Value '%s' can not be defined for default GPIO in line %d.\n", name.c_str(), lineno);
|
log_error("Value '%s' can not be defined for default GPIO in line %d.\n", name.c_str(), lineno);
|
||||||
|
if (ctx->get_package_pin_bel(ctx->id(value)) == BelId())
|
||||||
|
log_error("Unknown location '%s' used in line %d.\n", value.c_str(), lineno);
|
||||||
props->emplace(ctx->id(name.c_str()), Property(value));
|
props->emplace(ctx->id(name.c_str()), Property(value));
|
||||||
} else if (name == "SCHMITT_TRIGGER" || name == "PULLUP" || name == "PULLDOWN" || name == "KEEPER" ||
|
} else if (name == "SCHMITT_TRIGGER" || name == "PULLUP" || name == "PULLDOWN" || name == "KEEPER" ||
|
||||||
name == "FF_IBF" || name == "FF_OBF" || name == "LVDS_BOOST" || name == "LVDS_RTERM") {
|
name == "FF_IBF" || name == "FF_OBF" || name == "LVDS_BOOST" || name == "LVDS_RTERM") {
|
||||||
@ -119,99 +121,93 @@ struct GateMateCCFReader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool run()
|
void run()
|
||||||
{
|
{
|
||||||
try {
|
log_info("Parsing CCF file..\n");
|
||||||
log_info("Parsing CCF file..\n");
|
|
||||||
|
|
||||||
std::string line;
|
std::string line;
|
||||||
std::string linebuf;
|
std::string linebuf;
|
||||||
defaults.clear();
|
defaults.clear();
|
||||||
|
|
||||||
auto isempty = [](const std::string &str) {
|
auto isempty = [](const std::string &str) {
|
||||||
return std::all_of(str.begin(), str.end(), [](char c) { return isblank(c) || c == '\r' || c == '\n'; });
|
return std::all_of(str.begin(), str.end(), [](char c) { return isblank(c) || c == '\r' || c == '\n'; });
|
||||||
};
|
};
|
||||||
lineno = 0;
|
lineno = 0;
|
||||||
while (std::getline(in, line)) {
|
while (std::getline(in, line)) {
|
||||||
++lineno;
|
++lineno;
|
||||||
// Both // and # are considered start of comment
|
// Both // and # are considered start of comment
|
||||||
size_t com_start = line.find("//");
|
size_t com_start = line.find("//");
|
||||||
if (com_start != std::string::npos)
|
if (com_start != std::string::npos)
|
||||||
line = line.substr(0, com_start);
|
line = line.substr(0, com_start);
|
||||||
com_start = line.find('#');
|
com_start = line.find('#');
|
||||||
if (com_start != std::string::npos)
|
if (com_start != std::string::npos)
|
||||||
line = line.substr(0, com_start);
|
line = line.substr(0, com_start);
|
||||||
if (isempty(line))
|
if (isempty(line))
|
||||||
continue;
|
continue;
|
||||||
linebuf += line;
|
linebuf += line;
|
||||||
|
|
||||||
size_t pos = linebuf.find(';');
|
size_t pos = linebuf.find(';');
|
||||||
// Need to concatenate lines until there is closing ; sign
|
// Need to concatenate lines until there is closing ; sign
|
||||||
while (pos != std::string::npos) {
|
while (pos != std::string::npos) {
|
||||||
std::string content = linebuf.substr(0, pos);
|
std::string content = linebuf.substr(0, pos);
|
||||||
|
|
||||||
std::vector<std::string> params;
|
std::vector<std::string> params;
|
||||||
boost::split(params, content, boost::is_any_of("|"));
|
boost::split(params, content, boost::is_any_of("|"));
|
||||||
std::string command = params.at(0);
|
std::string command = params.at(0);
|
||||||
|
|
||||||
std::stringstream ss(command);
|
std::stringstream ss(command);
|
||||||
std::vector<std::string> words;
|
std::vector<std::string> words;
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
while (ss >> tmp)
|
while (ss >> tmp)
|
||||||
words.push_back(tmp);
|
words.push_back(tmp);
|
||||||
std::string type = words.at(0);
|
std::string type = words.at(0);
|
||||||
|
|
||||||
boost::algorithm::to_lower(type);
|
boost::algorithm::to_lower(type);
|
||||||
if (type == "default_gpio") {
|
if (type == "default_gpio") {
|
||||||
if (words.size() != 1)
|
if (words.size() != 1)
|
||||||
log_error("line with default_GPIO should not contain only parameters (in line %d).\n",
|
log_error("line with default_GPIO should not contain only parameters (in line %d).\n", lineno);
|
||||||
lineno);
|
params.erase(params.begin());
|
||||||
params.erase(params.begin());
|
parse_params(params, true, &defaults);
|
||||||
parse_params(params, true, &defaults);
|
|
||||||
|
|
||||||
} else if (type == "pin_in" || type == "pin_out" || type == "pin_inout") {
|
} else if (type == "pin_in" || type == "pin_out" || type == "pin_inout") {
|
||||||
if (words.size() < 3 || words.size() > 5)
|
if (words.size() < 3 || words.size() > 5)
|
||||||
log_error("pin definition line not properly formed (in line %d).\n", lineno);
|
log_error("pin definition line not properly formed (in line %d).\n", lineno);
|
||||||
std::string pin_name = strip_quotes(words.at(1));
|
std::string pin_name = strip_quotes(words.at(1));
|
||||||
|
|
||||||
// put back other words and use them as parameters
|
// put back other words and use them as parameters
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
for (size_t i = 2; i < words.size(); i++)
|
for (size_t i = 2; i < words.size(); i++)
|
||||||
ss << words.at(i);
|
ss << words.at(i);
|
||||||
params[0] = ss.str();
|
params[0] = ss.str();
|
||||||
|
|
||||||
IdString cellname = ctx->id(pin_name);
|
IdString cellname = ctx->id(pin_name);
|
||||||
if (ctx->cells.count(cellname)) {
|
if (ctx->cells.count(cellname)) {
|
||||||
CellInfo *cell = ctx->cells.at(cellname).get();
|
CellInfo *cell = ctx->cells.at(cellname).get();
|
||||||
for (auto p : defaults)
|
for (auto p : defaults)
|
||||||
cell->params[p.first] = p.second;
|
cell->params[p.first] = p.second;
|
||||||
parse_params(params, false, &cell->params);
|
parse_params(params, false, &cell->params);
|
||||||
} else
|
} else
|
||||||
log_warning("Pad with name '%s' not found in netlist.\n", pin_name.c_str());
|
log_warning("Pad with name '%s' not found in netlist.\n", pin_name.c_str());
|
||||||
} else {
|
} else {
|
||||||
log_error("unknown type '%s' in line %d.\n", type.c_str(), lineno);
|
log_error("unknown type '%s' in line %d.\n", type.c_str(), lineno);
|
||||||
}
|
|
||||||
|
|
||||||
linebuf = linebuf.substr(pos + 1);
|
|
||||||
pos = linebuf.find(';');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linebuf = linebuf.substr(pos + 1);
|
||||||
|
pos = linebuf.find(';');
|
||||||
}
|
}
|
||||||
if (!isempty(linebuf))
|
|
||||||
log_error("unexpected end of CCF file\n");
|
|
||||||
return true;
|
|
||||||
} catch (log_execution_error_exception) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
if (!isempty(linebuf))
|
||||||
|
log_error("unexpected end of CCF file\n");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool GateMateImpl::parse_ccf(const std::string &filename)
|
void GateMateImpl::parse_ccf(const std::string &filename)
|
||||||
{
|
{
|
||||||
std::ifstream in(filename);
|
std::ifstream in(filename);
|
||||||
if (!in)
|
if (!in)
|
||||||
log_error("failed to open CCF file '%s'\n", filename.c_str());
|
log_error("failed to open CCF file '%s'\n", filename.c_str());
|
||||||
GateMateCCFReader reader(ctx, in);
|
GateMateCCFReader reader(ctx, in);
|
||||||
return reader.run();
|
reader.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
NEXTPNR_NAMESPACE_END
|
NEXTPNR_NAMESPACE_END
|
||||||
|
@ -45,7 +45,7 @@ struct GateMateImpl : HimbaechelAPI
|
|||||||
|
|
||||||
void drawBel(std::vector<GraphicElement> &g, GraphicElement::style_t style, IdString bel_type, Loc loc) override;
|
void drawBel(std::vector<GraphicElement> &g, GraphicElement::style_t style, IdString bel_type, Loc loc) override;
|
||||||
|
|
||||||
bool parse_ccf(const std::string &filename);
|
void parse_ccf(const std::string &filename);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HimbaechelHelpers h;
|
HimbaechelHelpers h;
|
||||||
|
Loading…
Reference in New Issue
Block a user