Skip to content

Commit 9b41b8d

Browse files
committed
vpr: base: read_blif: add support for parsing falling edge clocked FFs
Signed-off-by: Pawel Czarnecki <pczarnecki@antmicro.com>
1 parent 9b46841 commit 9b41b8d

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

vpr/src/base/read_blif.cpp

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,15 +194,20 @@ struct BlifAllocCallback : public blifparse::Callback {
194194
void latch(std::string input, std::string output, blifparse::LatchType type, std::string control, blifparse::LogicValue init) override {
195195
if (type == blifparse::LatchType::UNSPECIFIED) {
196196
VTR_LOGF_WARN(filename_.c_str(), lineno_, "Treating latch '%s' of unspecified type as rising edge triggered\n", output.c_str());
197-
} else if (type != blifparse::LatchType::RISING_EDGE) {
198-
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_, "Only rising edge latches supported\n");
197+
} else if (type != blifparse::LatchType::RISING_EDGE && type != blifparse::LatchType::FALLING_EDGE) {
198+
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_, "Only rising and falling edge latches supported\n");
199199
}
200200

201201
if (control.empty()) {
202202
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_, "Latch must have a clock\n");
203203
}
204204

205-
const t_model* blk_model = find_model(MODEL_LATCH);
205+
TriggeringEdge t_edge;
206+
if (type == blifparse::LatchType::FALLING_EDGE)
207+
t_edge = TriggeringEdge::FALLING_EDGE;
208+
else
209+
t_edge = TriggeringEdge::RISING_EDGE;
210+
const t_model *blk_model = find_latch_model(t_edge);
206211

207212
VTR_ASSERT_MSG(blk_model->inputs, "Has one input port");
208213
VTR_ASSERT_MSG(blk_model->inputs->next, "Has two input port");
@@ -211,7 +216,7 @@ struct BlifAllocCallback : public blifparse::Callback {
211216
VTR_ASSERT_MSG(!blk_model->outputs->next, "Has no more than one input port");
212217

213218
const t_model_ports* d_model_port = blk_model->inputs;
214-
const t_model_ports* clk_model_port = blk_model->inputs->next;
219+
t_model_ports* clk_model_port = blk_model->inputs->next;
215220
const t_model_ports* q_model_port = blk_model->outputs;
216221

217222
VTR_ASSERT(d_model_port->name == std::string("D"));
@@ -466,6 +471,31 @@ struct BlifAllocCallback : public blifparse::Callback {
466471
return arch_model;
467472
}
468473

474+
const t_model* find_latch_model(TriggeringEdge t_edge) {
475+
const t_model* arch_model = nullptr;
476+
for (const t_model* arch_models : {user_arch_models_, library_arch_models_}) {
477+
arch_model = arch_models;
478+
while (arch_model) {
479+
if (strcmp(MODEL_LATCH, arch_model->name) == 0) {
480+
if (t_edge == arch_model->inputs[1].trigg_edge) {
481+
//Found it
482+
break;
483+
}
484+
}
485+
arch_model = arch_model->next;
486+
}
487+
if (arch_model) {
488+
//Found it
489+
break;
490+
}
491+
}
492+
if (!arch_model) {
493+
vpr_throw(VPR_ERROR_BLIF_F, filename_.c_str(), lineno_, "Failed to find matching architecture model for '%s' with edge: %d\n",
494+
MODEL_LATCH, t_edge);
495+
}
496+
return arch_model;
497+
}
498+
469499
const t_model_ports* find_model_port(const t_model* blk_model, std::string port_name) {
470500
//We need to handle both single, and multi-bit port names
471501
//

0 commit comments

Comments
 (0)