Skip to content

Commit

Permalink
Merge pull request verilog-to-routing#2535 from verilog-to-routing/fi…
Browse files Browse the repository at this point in the history
…x_fasm_warnings

Fix fasm warnings
  • Loading branch information
vaughnbetz committed Apr 15, 2024
2 parents 3928ad8 + 1f92b0f commit 3e8d605
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 85 deletions.
2 changes: 1 addition & 1 deletion blifexplorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.16)

project("blifexplorer")

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

Expand Down
24 changes: 12 additions & 12 deletions libs/libvtrutil/src/vtr_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static int cont; /* line continued? (used by strtok)*/
*
* The split strings (excluding the delimiters) are returned
*/
std::vector<std::string> split(const char* text, const std::string& delims) {
std::vector<std::string> split(const char* text, std::string_view delims) {
if (text) {
std::string text_str(text);
return split(text_str, delims);
Expand All @@ -39,13 +39,13 @@ std::vector<std::string> split(const char* text, const std::string& delims) {
*
* The split strings (excluding the delimiters) are returned
*/
std::vector<std::string> split(const std::string& text, const std::string& delims) {
std::vector<std::string> split(std::string_view text, std::string_view delims) {
std::vector<std::string> tokens;

std::string curr_tok;
for (char c : text) {
if (delims.find(c) != std::string::npos) {
//Delimeter character
//Delimiter character
if (!curr_tok.empty()) {
//At the end of the token

Expand All @@ -58,7 +58,7 @@ std::vector<std::string> split(const std::string& text, const std::string& delim
//Pass
}
} else {
//Non-delimeter append to token
//Non-delimiter append to token
curr_tok += c;
}
}
Expand All @@ -72,18 +72,18 @@ std::vector<std::string> split(const std::string& text, const std::string& delim
}

///@brief Returns 'input' with the first instance of 'search' replaced with 'replace'
std::string replace_first(const std::string& input, const std::string& search, const std::string& replace) {
std::string replace_first(std::string_view input, std::string_view search, std::string_view replace) {
auto pos = input.find(search);

std::string output(input, 0, pos);
output += replace;
output += std::string(input, pos + search.size());
output += input.substr(pos + search.size());

return output;
}

///@brief Returns 'input' with all instances of 'search' replaced with 'replace'
std::string replace_all(const std::string& input, const std::string& search, const std::string& replace) {
std::string replace_all(std::string_view input, std::string_view search, std::string_view replace) {
std::string output;

size_t last = 0;
Expand All @@ -101,8 +101,8 @@ std::string replace_all(const std::string& input, const std::string& search, con
return output;
}

///@brief Retruns true if str starts with prefix
bool starts_with(const std::string& str, const std::string& prefix) {
///@brief Returns true if str starts with prefix
bool starts_with(const std::string& str, std::string_view prefix) {
return str.find(prefix) == 0;
}

Expand Down Expand Up @@ -195,7 +195,7 @@ char* strdup(const char* str) {
* and/or correct 'unexpected' behaviour of the standard c-functions
*/
template<class T>
T atoT(const std::string& value, const std::string& type_name) {
T atoT(const std::string& value, std::string_view type_name) {
//The c version of atof doesn't catch errors.
//
//This version uses stringstream to detect conversion errors
Expand Down Expand Up @@ -461,8 +461,8 @@ bool file_exists(const char* filename) {
*
* Returns true if the extension is correct, and false otherwise.
*/
bool check_file_name_extension(const std::string& file_name,
const std::string& file_extension) {
bool check_file_name_extension(std::string_view file_name,
std::string_view file_extension) {
auto ext = std::filesystem::path(file_name).extension();
return ext == file_extension;
}
Expand Down
25 changes: 13 additions & 12 deletions libs/libvtrutil/src/vtr_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>
#include <vector>
#include <string>
#include <string_view>
#include <cstdarg>
#include <array>

Expand All @@ -14,17 +15,17 @@ namespace vtr {
*
* The split strings (excluding the delimiters) are returned
*/
std::vector<std::string> split(const char* text, const std::string& delims = " \t\n");
std::vector<std::string> split(const std::string& text, const std::string& delims = " \t\n");
std::vector<std::string> split(const char* text, std::string_view string_view = " \t\n");
std::vector<std::string> split(std::string_view text, std::string_view delims = " \t\n");

///@brief Returns 'input' with the first instance of 'search' replaced with 'replace'
std::string replace_first(const std::string& input, const std::string& search, const std::string& replace);
std::string replace_first(std::string_view input, std::string_view search, std::string_view replace);

///@brief Returns 'input' with all instances of 'search' replaced with 'replace'
std::string replace_all(const std::string& input, const std::string& search, const std::string& replace);
std::string replace_all(std::string_view input, std::string_view search, std::string_view replace);

///@brief Retruns true if str starts with prefix
bool starts_with(const std::string& str, const std::string& prefix);
bool starts_with(const std::string& str, std::string_view prefix);

///@brief Returns a std::string formatted using a printf-style format string
std::string string_fmt(const char* fmt, ...);
Expand All @@ -39,13 +40,13 @@ std::string vstring_fmt(const char* fmt, va_list args);
* would return "home/user/my_files/test.blif"
*/
template<typename Iter>
std::string join(Iter begin, Iter end, std::string delim);
std::string join(Iter begin, Iter end, std::string_view delim);

template<typename Container>
std::string join(Container container, std::string delim);
std::string join(Container container, std::string_view delim);

template<typename T>
std::string join(std::initializer_list<T> list, std::string delim);
std::string join(std::initializer_list<T> list, std::string_view delim);

template<typename Container>
void uniquify(Container container);
Expand All @@ -69,7 +70,7 @@ double atod(const std::string& value);
*/
int get_file_line_number_of_last_opened_file();
bool file_exists(const char* filename);
bool check_file_name_extension(const std::string& file_name, const std::string& file_extension);
bool check_file_name_extension(std::string_view file_name, std::string_view file_extension);

extern std::string out_file_prefix;

Expand All @@ -82,7 +83,7 @@ std::vector<std::string> ReadLineTokens(FILE* InFile, int* LineNum);
* @brief Template join function implementation
*/
template<typename Iter>
std::string join(Iter begin, Iter end, std::string delim) {
std::string join(Iter begin, Iter end, std::string_view delim) {
std::string joined_str;
for (auto iter = begin; iter != end; ++iter) {
joined_str += *iter;
Expand All @@ -94,12 +95,12 @@ std::string join(Iter begin, Iter end, std::string delim) {
}

template<typename Container>
std::string join(Container container, std::string delim) {
std::string join(Container container, std::string_view delim) {
return join(std::begin(container), std::end(container), delim);
}

template<typename T>
std::string join(std::initializer_list<T> list, std::string delim) {
std::string join(std::initializer_list<T> list, std::string_view delim) {
return join(list.begin(), list.end(), delim);
}

Expand Down
47 changes: 19 additions & 28 deletions utils/fasm/src/fasm.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
#include "fasm.h"

#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>

#include "globals.h"

#include "rr_metadata.h"

#include "vtr_assert.h"
#include "vtr_logic.h"
#include "vtr_version.h"
#include "vpr_error.h"

#include "atom_netlist_utils.h"
#include "netlist_writer.h"
#include "vpr_utils.h"

#include "fasm_utils.h"

Expand Down Expand Up @@ -77,7 +70,7 @@ void FasmWriterVisitor::visit_clb_impl(ClusterBlockId blk_id, const t_pb* clb) {
std::vector<std::string> tag_defs = vtr::split(value->front().as_string().get(strings_), "\n");
for (auto& tag_def: tag_defs) {
auto parts = split_fasm_entry(tag_def, "=:", "\t ");
if (parts.size() == 0) {
if (parts.empty()) {
continue;
}

Expand All @@ -86,7 +79,7 @@ void FasmWriterVisitor::visit_clb_impl(ClusterBlockId blk_id, const t_pb* clb) {
VTR_ASSERT(tags_.count(parts.at(0)) == 0);

// When the value is "NULL" then substitute empty string
if (!parts.at(1).compare("NULL")) {
if (parts.at(1) == "NULL") {
tags_[parts.at(0)] = "";
}
else {
Expand Down Expand Up @@ -179,7 +172,7 @@ std::string FasmWriterVisitor::handle_fasm_prefix(const t_metadata_dict *meta,
}

std::string FasmWriterVisitor::build_clb_prefix(const t_pb *pb, const t_pb_graph_node* pb_graph_node, bool* is_parent_pb_null) const {
std::string clb_prefix = "";
std::string clb_prefix;

const t_pb *pb_for_graph_node = nullptr;

Expand Down Expand Up @@ -272,7 +265,7 @@ void FasmWriterVisitor::visit_all_impl(const t_pb_routes &pb_routes, const t_pb*
std::string clb_prefix = build_clb_prefix(pb, pb_graph_node, &is_parent_pb_null);
clb_prefix_map_.insert(std::make_pair(pb_graph_node, clb_prefix));
clb_prefix_ = clb_prefix;
if (is_parent_pb_null == true) {
if (is_parent_pb_null) {
return;
}

Expand Down Expand Up @@ -365,7 +358,7 @@ static LogicVec lut_outputs(const t_pb* atom_pb, size_t num_inputs, const t_pb_r
if(truth_table.size() == 1) {
VTR_ASSERT(truth_table[0].size() == 1);
lut.SetConstant(truth_table[0][0]);
} else if(truth_table.size() == 0) {
} else if(truth_table.empty()) {
lut.SetConstant(vtr::LogicValue::FALSE);
} else {
vpr_throw(VPR_ERROR_OTHER, __FILE__, __LINE__, "LUT truth table unexpected size is %d", truth_table.size());
Expand Down Expand Up @@ -420,7 +413,7 @@ static LogicVec lut_outputs(const t_pb* atom_pb, size_t num_inputs, const t_pb_r
return lut.table();
}

const t_metadata_dict *FasmWriterVisitor::get_fasm_type(const t_pb_graph_node* pb_graph_node, std::string target_type) const {
const t_metadata_dict *FasmWriterVisitor::get_fasm_type(const t_pb_graph_node* pb_graph_node, std::string_view target_type) const {
if(pb_graph_node == nullptr) {
return nullptr;
}
Expand Down Expand Up @@ -470,9 +463,8 @@ const LutOutputDefinition* FasmWriterVisitor::find_lut(const t_pb_graph_node* pb
VTR_ASSERT(value != nullptr);

std::vector<std::pair<std::string, LutOutputDefinition>> luts;
luts.push_back(std::make_pair(
vtr::string_fmt("%s[0]", pb_graph_node->pb_type->name),
LutOutputDefinition(value->as_string().get(strings_))));
luts.emplace_back(vtr::string_fmt("%s[0]", pb_graph_node->pb_type->name),
LutOutputDefinition(value->as_string().get(strings_)));

auto insert_result = lut_definitions_.insert(
std::make_pair(pb_graph_node->pb_type, luts));
Expand Down Expand Up @@ -505,8 +497,7 @@ const LutOutputDefinition* FasmWriterVisitor::find_lut(const t_pb_graph_node* pb
fasm_lut_str.c_str());
}

luts.push_back(std::make_pair(
parts[1], LutOutputDefinition(parts[0])));
luts.emplace_back(parts[1], LutOutputDefinition(parts[0]));
}

auto insert_result = lut_definitions_.insert(
Expand Down Expand Up @@ -569,9 +560,9 @@ void FasmWriterVisitor::check_for_param(const t_pb *atom) {
VTR_ASSERT(value != nullptr);

std::string fasm_params_str = value->as_string().get(strings_);
for(const auto param : vtr::split(fasm_params_str, "\n")) {
for(const auto& param : vtr::split(fasm_params_str, "\n")) {
auto param_parts = split_fasm_entry(param, "=", "\t ");
if(param_parts.size() == 0) {
if(param_parts.empty()) {
continue;
}
VTR_ASSERT(param_parts.size() == 2);
Expand All @@ -589,10 +580,10 @@ void FasmWriterVisitor::check_for_param(const t_pb *atom) {

auto &params = iter->second;

for(auto param : atom_ctx.nlist.block_params(atom_blk_id)) {
for(const auto& param : atom_ctx.nlist.block_params(atom_blk_id)) {
auto feature = params.EmitFasmFeature(param.first, param.second);

if(feature.size() > 0) {
if(!feature.empty()) {
output_fasm_features(feature);
}
}
Expand Down Expand Up @@ -668,7 +659,7 @@ void FasmWriterVisitor::find_clb_prefix(const t_pb_graph_node *node,
}
}

void FasmWriterVisitor::output_fasm_mux(std::string fasm_mux_str,
void FasmWriterVisitor::output_fasm_mux(std::string_view fasm_mux_str,
t_interconnect *interconnect,
const t_pb_graph_pin *mux_input_pin) {
auto *pb_name = mux_input_pin->parent_node->pb_type->name;
Expand Down Expand Up @@ -697,7 +688,7 @@ void FasmWriterVisitor::output_fasm_mux(std::string fasm_mux_str,
for(const auto &mux_input : mux_inputs) {
auto mux_parts = split_fasm_entry(mux_input, "=:", "\t ");

if(mux_parts.size() == 0) {
if(mux_parts.empty()) {
// Swallow whitespace.
continue;
}
Expand Down Expand Up @@ -750,15 +741,15 @@ void FasmWriterVisitor::output_fasm_mux(std::string fasm_mux_str,

vpr_throw(VPR_ERROR_OTHER, __FILE__, __LINE__,
"fasm_mux %s[%d].%s[%d] found no matches in:\n%s\n",
pb_name, pb_index, port_name, pin_index, fasm_mux_str.c_str());
pb_name, pb_index, port_name, pin_index, fasm_mux_str.data());
}

void FasmWriterVisitor::output_fasm_features(const std::string features) const {
void FasmWriterVisitor::output_fasm_features(const std::string& features) const {
output_fasm_features(features, clb_prefix_, blk_prefix_);
}

void FasmWriterVisitor::output_fasm_features(const std::string features, const std::string clb_prefix, const std::string blk_prefix) const {
std::stringstream os(features);
void FasmWriterVisitor::output_fasm_features(const std::string& features, std::string_view clb_prefix, std::string_view blk_prefix) const {
std::istringstream os(features);

while(os) {
std::string feature;
Expand Down
9 changes: 5 additions & 4 deletions utils/fasm/src/fasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <set>
#include <sstream>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -66,12 +67,12 @@ class FasmWriterVisitor : public NetlistVisitor {
void finish_impl() override;

private:
void output_fasm_features(const std::string features) const;
void output_fasm_features(const std::string features, const std::string clb_prefix, const std::string blk_prefix) const;
void output_fasm_features(const std::string& features) const;
void output_fasm_features(const std::string& features, std::string_view clb_prefix, std::string_view blk_prefix) const;
void check_features(const t_metadata_dict *meta) const;
void check_interconnect(const t_pb_routes &pb_route, int inode);
void check_for_lut(const t_pb* atom);
void output_fasm_mux(std::string fasm_mux, t_interconnect *interconnect, const t_pb_graph_pin *mux_input_pin);
void output_fasm_mux(std::string_view fasm_mux, t_interconnect *interconnect, const t_pb_graph_pin *mux_input_pin);
void walk_routing();
void walk_route_tree(const RRGraphBuilder& rr_graph_builder, const RouteTreeNode& root);
std::string build_clb_prefix(const t_pb *pb, const t_pb_graph_node* pb_graph_node, bool* is_parent_pb_null) const;
Expand All @@ -83,7 +84,7 @@ class FasmWriterVisitor : public NetlistVisitor {
bool *have_prefix, std::string *clb_prefix) const;
std::string handle_fasm_prefix(const t_metadata_dict *meta,
const t_pb_graph_node *pb_graph_node, const t_pb_type *pb_type) const;
const t_metadata_dict *get_fasm_type(const t_pb_graph_node* pb_graph_node, std::string target_type) const;
const t_metadata_dict *get_fasm_type(const t_pb_graph_node* pb_graph_node, std::string_view target_type) const;

vtr::string_internment *strings_;
std::ostream& os_;
Expand Down
Loading

0 comments on commit 3e8d605

Please sign in to comment.