From eed6c10b0c3669684d5c0186c95b92c734789a3f Mon Sep 17 00:00:00 2001 From: tangxifan Date: Thu, 28 Jul 2022 09:20:28 -0700 Subject: [PATCH] [lib] now io_net_place can output .place file --- libopenfpga/libpcf/src/base/io_net_place.cpp | 62 ++++++++++++++++++++ libopenfpga/libpcf/src/base/io_net_place.h | 4 ++ 2 files changed, 66 insertions(+) diff --git a/libopenfpga/libpcf/src/base/io_net_place.cpp b/libopenfpga/libpcf/src/base/io_net_place.cpp index f6383d14f..902103f29 100644 --- a/libopenfpga/libpcf/src/base/io_net_place.cpp +++ b/libopenfpga/libpcf/src/base/io_net_place.cpp @@ -61,4 +61,66 @@ void IoNetPlace::set_net_coord(const std::string& net, io_coords_[net][2] = z; } +int IoNetPlace::write_to_place_file(const std::string& fname, + const bool& include_time_stamp, + const bool& verbose) const { + std::string timer_message = std::string("Write I/O coordinates to a place file '") + fname + std::string("'"); + + std::string dir_path = format_dir_path(find_path_dir_name(fname)); + + /* Create directories */ + create_directory(dir_path); + + /* Start time count */ + vtr::ScopedStartFinishTimer timer(timer_message); + + /* Use default name if user does not provide one */ + VTR_ASSERT(true != fname.empty()); + + /* Create a file handler*/ + std::fstream fp; + /* Open a file */ + fp.open(fname, std::fstream::out | std::fstream::trunc); + + /* Validate the file stream */ + check_file_stream(fname.c_str(), fp); + + int err_code = 0; + + /* Write XML head */ + fp << "# FPGA Fixed I/O placement file" << std::endl; + fp << "# Generated by OpenFPGA" << std::endl; + + auto end = std::chrono::system_clock::now(); + std::time_t end_time = std::chrono::system_clock::to_time_t(end); + if (include_time_stamp) { + fp << "# Date: " << std::ctime(&end_time) ; + } + + fp << "#Block Name\tx\ty\tz" << std::endl; + fp << "#----------\t-\t-\t-" << std::endl; + + size_t io_cnt = 0; + + /* Walk through the fabric I/O location map data structure */ + for (auto pair : io_coords_) { + fp << pair.first.c_str() << "\t"; + fp << pair.second[0] << "\t"; + fp << pair.second[1] << "\t"; + fp << pair.second[2] << "\n"; + io_cnt++; + } + + /* close a file */ + fp.close(); + + VTR_LOGV(verbose, + "Outputted %lu I/Os to place file: %s\n", + io_cnt, + fname.c_str()); + + return err_code; +} + + } /* end namespace openfpga */ diff --git a/libopenfpga/libpcf/src/base/io_net_place.h b/libopenfpga/libpcf/src/base/io_net_place.h index acfe93d9f..e99e3775d 100644 --- a/libopenfpga/libpcf/src/base/io_net_place.h +++ b/libopenfpga/libpcf/src/base/io_net_place.h @@ -34,6 +34,10 @@ class IoNetPlace { size_t io_x(const std::string& net) const; size_t io_y(const std::string& net) const; size_t io_z(const std::string& net) const; + public: /* Writers */ + int write_to_place_file(const std::string& fname, + const bool& include_time_stamp, + const bool& verbose) const; public: /* Public mutators */ void set_net_coord(const std::string& net, const size_t& x,