diff --git a/include/hal_core/netlist/gate_library/gate_library.h b/include/hal_core/netlist/gate_library/gate_library.h index f9b7888dacd..2adf02eed4e 100644 --- a/include/hal_core/netlist/gate_library/gate_library.h +++ b/include/hal_core/netlist/gate_library/gate_library.h @@ -1,20 +1,20 @@ // MIT License -// +// // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved. // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved. // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved. // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved. -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -95,11 +95,10 @@ namespace hal const std::pair& get_gate_location_data_identifiers() const; /** - * TODO pybind * Create a new gate type, add it to the gate library, and return it. * * @param[in] name - The name of the gate type. - * @param[in] properties - The properties of the gate type. + * @param[in] properties - The properties of the gate type. Defaults to `GateTypeProperty::combinational`. * @param[in] component - A component adding additional functionality to the gate type. * @returns The new gate type instance on success, a nullptr otherwise. */ @@ -198,7 +197,7 @@ namespace hal std::vector m_includes; - GateLibrary(const GateLibrary&) = delete; + GateLibrary(const GateLibrary&) = delete; GateLibrary& operator=(const GateLibrary&) = delete; u32 get_unique_gate_type_id(); diff --git a/include/hal_core/netlist/gate_library/gate_type_component/ff_component.h b/include/hal_core/netlist/gate_library/gate_type_component/ff_component.h index 0f492e03ec0..a9ec81a2c32 100644 --- a/include/hal_core/netlist/gate_library/gate_type_component/ff_component.h +++ b/include/hal_core/netlist/gate_library/gate_type_component/ff_component.h @@ -1,20 +1,20 @@ // MIT License -// +// // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved. // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved. // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved. // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved. -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/include/hal_core/netlist/gate_library/gate_type_component/gate_type_component.h b/include/hal_core/netlist/gate_library/gate_type_component/gate_type_component.h index 981ad4b4627..cd46251e6ed 100644 --- a/include/hal_core/netlist/gate_library/gate_type_component/gate_type_component.h +++ b/include/hal_core/netlist/gate_library/gate_type_component/gate_type_component.h @@ -27,6 +27,7 @@ #include "hal_core/defines.h" #include "hal_core/netlist/boolean_function.h" +#include "hal_core/netlist/gate_library/enums/async_set_reset_behavior.h" #include #include diff --git a/src/netlist/gate_library/gate_type_component/gate_type_component.cpp b/src/netlist/gate_library/gate_type_component/gate_type_component.cpp index 1b65c586c21..37be62a5f88 100644 --- a/src/netlist/gate_library/gate_type_component/gate_type_component.cpp +++ b/src/netlist/gate_library/gate_type_component/gate_type_component.cpp @@ -33,7 +33,7 @@ namespace hal std::unique_ptr GateTypeComponent::create_ff_component(std::unique_ptr component, const BooleanFunction& next_state_bf, const BooleanFunction& clock_bf) { - return std::make_unique(std::move(component), next_state_bf.clone(), clock_bf.clone()); + return std::make_unique(std::move(component), next_state_bf, clock_bf); } std::unique_ptr GateTypeComponent::create_latch_component(std::unique_ptr component) @@ -75,7 +75,7 @@ namespace hal const BooleanFunction& enable_bf, bool is_write) { - return std::make_unique(std::move(component), data_group, addr_group, clock_bf.clone(), enable_bf.clone(), is_write); + return std::make_unique(std::move(component), data_group, addr_group, clock_bf, enable_bf, is_write); } GateTypeComponent* GateTypeComponent::get_component(const std::function& filter) const diff --git a/src/python_bindings/bindings/gate_library.cpp b/src/python_bindings/bindings/gate_library.cpp index a51437d02ce..e4c91428a5f 100644 --- a/src/python_bindings/bindings/gate_library.cpp +++ b/src/python_bindings/bindings/gate_library.cpp @@ -68,14 +68,59 @@ namespace hal :rtype: tuple(str,str) )"); - // py_gate_library.def("create_gate_type", &GateLibrary::create_gate_type, py::arg("name"), py::arg("properties") = std::set(), R"( - // Create a new gate type, add it to the gate library, and return it. - - // :param str name: The name of the gate type. - // :param set[hal_py.GateTypeProperty] properties: The properties of the gate type. - // :returns: The new gate type instance on success, None otherwise. - // :rtype: hal_py.GateType - // )"); + py_gate_library.def( + "create_gate_type", + [](GateLibrary& self, const std::string& name, std::set properties = {GateTypeProperty::combinational}) -> GateType* { return self.create_gate_type(name, properties); }, + py::arg("name"), + py::arg("properties") = std::set({GateTypeProperty::combinational}), + R"( + Create a new gate type, add it to the gate library, and return it. + + :param str name: The name of the gate type. + :param set[hal_py.GateTypeProperty] properties: The properties of the gate type. Defaults to ``hal_py.GateTypeProperty.combinational``. + :returns: The new gate type instance on success, None otherwise. + :rtype: hal_py.GateType or None + )"); + + py_gate_library.def( + "create_ff_gate_type", + [](GateLibrary& self, + const std::string& name, + const std::string& state_identifier, + const std::string& neg_state_identifier, + const BooleanFunction& next_state_bf, + const BooleanFunction& clock_bf, + const std::string& init_category = "", + const std::string& init_identifier = "") -> GateType* { + std::unique_ptr init_component = nullptr; + if (!init_category.empty() && !init_identifier.empty()) + { + init_component = GateTypeComponent::create_init_component(init_category, {init_identifier}); + } + std::unique_ptr state_component = GateTypeComponent::create_state_component(std::move(init_component), state_identifier, neg_state_identifier); + std::unique_ptr ff_component = GateTypeComponent::create_ff_component(std::move(state_component), next_state_bf, clock_bf); + return self.create_gate_type(name, {GateTypeProperty::sequential, GateTypeProperty::ff}, std::move(ff_component)); + }, + py::arg("name"), + py::arg("state_identifier"), + py::arg("neg_state_identifier"), + py::arg("next_state_bf"), + py::arg("clock_bf"), + py::arg("init_category") = "", + py::arg("init_identifier") = "", + R"( + Create a new gate type, add it to the gate library, and return it. + + :param str name: The name of the gate type. + :param str state_identifier: The identifier of the internal state. + :param str neg_state_identifier: The identifier of the negated internal state. + :param hal_py.BooleanFunction next_state_bf: The function describing the internal state. + :param hal_py.BooleanFunction clock_bf: The function describing the clock input. + :param str init_category: The initialization data category. Defaults to an empty string. + :param str init_identifier: The initialization data identifier. Defaults to an empty string. + :returns: The new flip-flop gate type instance on success, None otherwise. + :rtype: hal_py.GateType or None + )"); py_gate_library.def("contains_gate_type", &GateLibrary::contains_gate_type, py::arg("gate_type"), R"( Check whether the given gate type is contained in this library.