13 std::string double_to_string(
double d)
15 std::ostringstream oss;
16 oss << std::fixed << std::setprecision(4) << d;
23 std::setlocale(LC_NUMERIC,
"en_US");
26 std::string file_str =
"#" + gate_lib->
get_name() +
"\n";
32 for (
const auto& [
name, gt] : gate_lib->
get_gate_types([](
const GateType* gt) { return gt->has_property(GateTypeProperty::combinational); }))
36 log_warning(
"GenlibWriter",
"Skipping gate type {} because eventhough it is marked as combinational it does not have any boolean functions.",
name);
43 "Skipping gate type {} because it contains {} Boolean functions, but the genlib format only supports single output cells.",
51 u32 mux_value = (base_value - 1) * 0.15 + 1;
52 u32 other_values = base_value * 0.3 + 1;
58 auto bf_str = bf.is_constant() ? (bf.has_constant_value(0) ?
"CONST0" :
"CONST1") : bf.to_string();
61 bf_str =
utils::replace(bf_str, std::string(
"|"), std::string(
"+"));
62 bf_str =
utils::replace(bf_str, std::string(
"&"), std::string(
"*"));
64 std::string gate_str =
"GATE " +
name +
" " + double_to_string(gate_area) +
" " + output_pin +
"=" + bf_str +
";\n";
68 const std::string phase = (bf.get_top_level_node().is_operation() && (bf.get_top_level_node().type ==
BooleanFunction::NodeType::Not)) ?
"INV" :
"NONINV";
69 const std::string pin_str =
"PIN " + pin->get_name() +
" " + phase +
" 1 999 1 0 1 0";
70 gate_str += pin_str +
"\n";
79 log_warning(
"GenlibWriter",
"Skipping gate type {} because sequential gates are currently not supported",
name);
84 std::ofstream file(file_path);
std::unordered_map< std::string, GateType * > get_gate_types(const std::function< bool(const GateType *)> &filter=nullptr) const
std::string get_name() const
bool has_property(GateTypeProperty property) const
std::vector< GatePin * > get_input_pins() const
const std::unordered_map< std::string, BooleanFunction > & get_boolean_functions() const
bool write(const GateLibrary *gate_lib, const std::filesystem::path &file_path) override
Write all single output combinational gate types of the gate library to a genlib file at the provided...
#define log_warning(channel,...)
T replace(const T &str, const T &search, const T &replace)