Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/create gate type from python #515

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions include/hal_core/netlist/gate_library/gate_library.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -95,11 +95,10 @@ namespace hal
const std::pair<std::string, std::string>& 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.
*/
Expand Down Expand Up @@ -198,7 +197,7 @@ namespace hal

std::vector<std::string> m_includes;

GateLibrary(const GateLibrary&) = delete;
GateLibrary(const GateLibrary&) = delete;
GateLibrary& operator=(const GateLibrary&) = delete;

u32 get_unique_gate_type_id();
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <functional>
#include <set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace hal

std::unique_ptr<GateTypeComponent> GateTypeComponent::create_ff_component(std::unique_ptr<GateTypeComponent> component, const BooleanFunction& next_state_bf, const BooleanFunction& clock_bf)
{
return std::make_unique<FFComponent>(std::move(component), next_state_bf.clone(), clock_bf.clone());
return std::make_unique<FFComponent>(std::move(component), next_state_bf, clock_bf);
}

std::unique_ptr<GateTypeComponent> GateTypeComponent::create_latch_component(std::unique_ptr<GateTypeComponent> component)
Expand Down Expand Up @@ -75,7 +75,7 @@ namespace hal
const BooleanFunction& enable_bf,
bool is_write)
{
return std::make_unique<RAMPortComponent>(std::move(component), data_group, addr_group, clock_bf.clone(), enable_bf.clone(), is_write);
return std::make_unique<RAMPortComponent>(std::move(component), data_group, addr_group, clock_bf, enable_bf, is_write);
}

GateTypeComponent* GateTypeComponent::get_component(const std::function<bool(const GateTypeComponent*)>& filter) const
Expand Down
61 changes: 53 additions & 8 deletions src/python_bindings/bindings/gate_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<GateTypeProperty>(), 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<GateTypeProperty> 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<GateTypeComponent> init_component = nullptr;
if (!init_category.empty() && !init_identifier.empty())
{
init_component = GateTypeComponent::create_init_component(init_category, {init_identifier});
}
std::unique_ptr<GateTypeComponent> state_component = GateTypeComponent::create_state_component(std::move(init_component), state_identifier, neg_state_identifier);
std::unique_ptr<GateTypeComponent> 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.
Expand Down