diff --git a/libopenfpga/libpcf/CMakeLists.txt b/libopenfpga/libpcf/CMakeLists.txt index be7f12ffd..0d0d268a0 100644 --- a/libopenfpga/libpcf/CMakeLists.txt +++ b/libopenfpga/libpcf/CMakeLists.txt @@ -23,6 +23,7 @@ target_link_libraries(libpcf libarchfpga libarchopenfpga libvtrutil + libblifparse libpugixml libpugiutil) diff --git a/libopenfpga/libpcf/src/io/blif_head_reader.cpp b/libopenfpga/libpcf/src/io/blif_head_reader.cpp new file mode 100644 index 000000000..02bfc1fbc --- /dev/null +++ b/libopenfpga/libpcf/src/io/blif_head_reader.cpp @@ -0,0 +1,72 @@ +#include +#include + +#include "blif_head_reader.h" + +namespace blifparse { + +void BlifHeadReader::start_parse() { + //Pass +} + +void BlifHeadReader::finish_parse() { + //Pass +} + +void BlifHeadReader::begin_model(std::string model_name) { + // Pass +} + +void BlifHeadReader::inputs(std::vector input_conns) { + input_pins_ = input_conns; +} + +void BlifHeadReader::outputs(std::vector output_conns) { + output_pins_ = output_conns; +} + +void BlifHeadReader::names(std::vector nets, std::vector> so_cover) { + // Pass +} + +void BlifHeadReader::latch(std::string input, std::string output, LatchType type, std::string control, LogicValue init) { + // Pass +} + +void BlifHeadReader::subckt(std::string model, std::vector ports, std::vector nets) { + // Pass +} + +void BlifHeadReader::blackbox() { + // Pass +} + +void BlifHeadReader::end_model() { + // Pass +} + +void BlifHeadReader::conn(std::string src, std::string dst) { + // Pass +} + +void BlifHeadReader::cname(std::string cell_name) { + // Pass +} + +void BlifHeadReader::attr(std::string name, std::string value) { + // Pass +} + +void BlifHeadReader::param(std::string name, std::string value) { + // Pass +} + +void BlifHeadReader::filename(std::string fname) { + // Pass +} + +void BlifHeadReader::lineno(int line_num) { + // Pass +} + +} diff --git a/libopenfpga/libpcf/src/io/blif_head_reader.h b/libopenfpga/libpcf/src/io/blif_head_reader.h new file mode 100644 index 000000000..7fe58c98d --- /dev/null +++ b/libopenfpga/libpcf/src/io/blif_head_reader.h @@ -0,0 +1,54 @@ +#ifndef BLIF_HEAD_READER +#define BLIF_HEAD_READER +#include +#include "blifparse.hpp" +#include "vtr_log.h" + +namespace blifparse { + +//An example callback which pretty-prints to stdout +//the BLIF which is being parsed +class BlifHeadReader : public Callback { + public: + void start_parse() override; + void filename(std::string fname) override; + void lineno(int line_num) override; + void begin_model(std::string model_name) override; + void inputs(std::vector inputs) override; + void outputs(std::vector outputs) override; + + void names(std::vector nets, std::vector> so_cover) override; + + void latch(std::string input, std::string output, LatchType type, std::string control, LogicValue init) override; + + void subckt(std::string model, std::vector ports, std::vector nets) override; + + void blackbox() override; + + void end_model() override; + + //BLIF Extensions + void conn(std::string src, std::string dst) override; + void cname(std::string cell_name) override; + void attr(std::string name, std::string value) override; + void param(std::string name, std::string value) override; + + void finish_parse() override; + + void parse_error(const int curr_lineno, const std::string& near_text, const std::string& msg) override { + VTR_LOG_ERROR("Error when parsing .blif at line %d near '%s': %s\n", curr_lineno, near_text.c_str(), msg.c_str()); + had_error_ = true; + } + + bool had_error() { return had_error_; } + std::vector input_pins() { return input_pins_; } + std::vector output_pins() { return output_pins_; } + + private: + std::vector input_pins_; + std::vector output_pins_; + bool had_error_ = false; +}; + +} +#endif diff --git a/libopenfpga/libpcf/test/test_blif_head_reader.cpp b/libopenfpga/libpcf/test/test_blif_head_reader.cpp new file mode 100644 index 000000000..56e6e4105 --- /dev/null +++ b/libopenfpga/libpcf/test/test_blif_head_reader.cpp @@ -0,0 +1,42 @@ +/******************************************************************** + * Unit test functions to validate the correctness of + * 1. parser of data structures + * 2. writer of data structures + *******************************************************************/ +/* Headers from vtrutils */ +#include "vtr_assert.h" +#include "vtr_log.h" + +/* Headers from fabric key */ +#include "blif_head_reader.h" + +int main(int argc, const char** argv) { + /* Ensure we have only one or two argument */ + VTR_ASSERT(2 == argc); + + /* Parse the blif */ + blifparse::BlifHeadReader callback; + blifparse::blif_parse_filename(argv[1], callback); + VTR_LOG("Read the blif from a file: %s.\n", + argv[1]); + + if (callback.had_error()) { + return 1; + } else { + return 0; + } + + /* Output */ + VTR_LOG("Input pins: \n"); + for (const std::string& pin : callback.input_pins()) { + VTR_LOG("%s\n", pin.c_str()); + } + VTR_LOG("Output pins: \n"); + for (const std::string& pin : callback.output_pins()) { + VTR_LOG("%s\n", pin.c_str()); + } + + return 0; +} + +