Skip to content

Commit 5194e78

Browse files
buggy and incomplete prototype for clock tree extraction
1 parent d0e0e8e commit 5194e78

6 files changed

Lines changed: 556 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
option(PL_CLOCK_TREE_EXTRACTOR "PL_CLOCK_TREE_EXTRACTOR" ON)
2+
3+
if(PL_CLOCK_TREE_EXTRACTOR OR BUILD_ALL_PLUGINS)
4+
5+
if(IWYU)
6+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "include-what-you-use")
7+
message(STATUS "include-what-you-use turned ON")
8+
else()
9+
message(STATUS "include-what-you-use turned OFF")
10+
endif()
11+
12+
file(GLOB_RECURSE CLOCK_TREE_EXTRACTOR_INC ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h)
13+
file(GLOB_RECURSE CLOCK_TREE_EXTRACTOR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc)
14+
file(GLOB_RECURSE CLOCK_TREE_EXTRACTOR_PYTHON_SRC ${CMAKE_CURRENT_SOURCE_DIR}/python/*.cc)
15+
16+
hal_add_plugin(clock_tree_extractor
17+
SHARED
18+
HEADER ${CLOCK_TREE_EXTRACTOR_INC}
19+
SOURCES ${CLOCK_TREE_EXTRACTOR_SRC} ${CLOCK_TREE_EXTRACTOR_PYTHON_SRC}
20+
LINK_LIBRARIES graph_algorithm
21+
COMPILE_OPTIONS "-march=native"
22+
)
23+
24+
endif()
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4+
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5+
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6+
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS").
7+
// All Rights reserved.
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in all
17+
// copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
// SOFTWARE.
26+
27+
#pragma once
28+
29+
#include "hal_core/defines.h"
30+
#include "hal_core/utilities/result.h"
31+
32+
#include <vector>
33+
34+
namespace hal
35+
{
36+
class Netlist;
37+
}
38+
39+
namespace hal
40+
{
41+
class Gate;
42+
}
43+
44+
namespace hal
45+
{
46+
class GateType;
47+
}
48+
49+
namespace hal
50+
{
51+
class Endpoint;
52+
}
53+
54+
namespace hal
55+
{
56+
namespace cte
57+
{
58+
class ClockTreeExtractor
59+
{
60+
public:
61+
ClockTreeExtractor() = default;
62+
63+
ClockTreeExtractor( const Netlist *netlist );
64+
65+
~ClockTreeExtractor() = default;
66+
67+
Result<u32> analyze( const std::string &pathname );
68+
69+
const std::vector<std::pair<std::string, std::string>> get_edges() const;
70+
71+
private:
72+
const Netlist *m_netlist;
73+
74+
std::vector<std::pair<std::string, std::string>> m_edges;
75+
};
76+
} // namespace cte
77+
} // namespace hal
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4+
// Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5+
// Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6+
// Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS").
7+
// All Rights reserved.
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in all
17+
// copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
// SOFTWARE.
26+
27+
#pragma once
28+
29+
#include "hal_core/defines.h"
30+
#include "hal_core/plugin_system/plugin_interface_base.h"
31+
32+
#include <set>
33+
#include <string>
34+
35+
namespace hal
36+
{
37+
class PLUGIN_API ClockTreeExtractorPlugin : public BasePluginInterface
38+
{
39+
public:
40+
ClockTreeExtractorPlugin() = default;
41+
42+
~ClockTreeExtractorPlugin() = default;
43+
44+
std::string get_name() const override;
45+
46+
std::string get_version() const override;
47+
48+
std::string get_description() const override;
49+
50+
std::set<std::string> get_dependencies() const override;
51+
52+
void initialize() override;
53+
54+
void on_load() override;
55+
56+
void on_unload() override;
57+
};
58+
} // namespace hal
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#include "hal_core/python_bindings/python_bindings.h"
2+
3+
#include "clock_tree_extractor/clock_tree_extractor.h"
4+
#include "clock_tree_extractor/plugin_clock_tree_extractor.h"
5+
#include "pybind11/pybind11.h"
6+
7+
#include <pybind11/detail/descr.h>
8+
#include <pybind11/pytypes.h>
9+
#include <set>
10+
#include <string>
11+
#include <vector>
12+
13+
namespace hal
14+
{
15+
class BasePluginInterface;
16+
}
17+
namespace hal
18+
{
19+
class Netlist;
20+
}
21+
22+
namespace py = pybind11;
23+
24+
namespace hal
25+
{
26+
27+
// the name in PYBIND11_MODULE/PYBIND11_PLUGIN *MUST* match the filename of the output library (without extension),
28+
// otherwise you will get "ImportError: dynamic module does not define module export function" when importing the
29+
// module
30+
31+
#ifdef PYBIND11_MODULE
32+
PYBIND11_MODULE( clock_tree_extractor, m )
33+
{
34+
m.doc() = "";
35+
#else
36+
PYBIND11_PLUGIN( clock_tree_extractor )
37+
{
38+
py::module m( "clock_tree_extractor", "" );
39+
#endif // ifdef PYBIND11_MODULE
40+
41+
py::class_<ClockTreeExtractorPlugin, RawPtrWrapper<ClockTreeExtractorPlugin>, BasePluginInterface>
42+
py_clock_tree_extractor_plugin( m, "ClockTreeExtractorPlugin", "" );
43+
44+
py_clock_tree_extractor_plugin.def_property_readonly( "name", &ClockTreeExtractorPlugin::get_name, R"(
45+
The name of the plugin.
46+
47+
:type: str
48+
)" );
49+
50+
py_clock_tree_extractor_plugin.def( "get_name", &ClockTreeExtractorPlugin::get_name, R"(
51+
Get the name of the plugin.
52+
53+
:returns: The name of the plugin.
54+
:rtype: str
55+
)" );
56+
57+
py_clock_tree_extractor_plugin.def_property_readonly( "version", &ClockTreeExtractorPlugin::get_version, R"(
58+
The version of the plugin.
59+
60+
:type: str
61+
)" );
62+
63+
py_clock_tree_extractor_plugin.def( "get_version", &ClockTreeExtractorPlugin::get_version, R"(
64+
Get the version of the plugin.
65+
66+
:returns: The version of the plugin.
67+
:rtype: str
68+
)" );
69+
70+
py_clock_tree_extractor_plugin.def_property_readonly(
71+
"description", &ClockTreeExtractorPlugin::get_description, R"(
72+
The description of the plugin.
73+
74+
:type: str
75+
)" );
76+
77+
py_clock_tree_extractor_plugin.def( "get_description", &ClockTreeExtractorPlugin::get_description, R"(
78+
Get the description of the plugin.
79+
80+
:returns: The description of the plugin.
81+
:rtype: str
82+
)" );
83+
84+
py_clock_tree_extractor_plugin.def_property_readonly(
85+
"dependencies", &ClockTreeExtractorPlugin::get_dependencies, R"(
86+
A set of plugin names that this plugin depends on.
87+
88+
:type: set[str]
89+
)" );
90+
91+
py_clock_tree_extractor_plugin.def( "get_dependencies", &ClockTreeExtractorPlugin::get_dependencies, R"(
92+
Get a set of plugin names that this plugin depends on.
93+
94+
:returns: A set of plugin names that this plugin depends on.
95+
:rtype: set[str]
96+
)" );
97+
98+
py::class_<cte::ClockTreeExtractor, RawPtrWrapper<cte::ClockTreeExtractor>> py_clock_tree_extractor(
99+
m, "ClockTreeExtractor", R"(
100+
101+
)" );
102+
103+
py_clock_tree_extractor.def( py::init<const Netlist *>(), py::arg( "netlist" ), R"(
104+
105+
)" );
106+
107+
py_clock_tree_extractor.def(
108+
"analyze",
109+
[]( cte::ClockTreeExtractor &self, const std::string &pathname ) -> std::optional<u32> {
110+
auto res = self.analyze( pathname );
111+
if( res.is_ok() )
112+
{
113+
return res.get();
114+
}
115+
else
116+
{
117+
log_error( "python_context", "{}", res.get_error().get() );
118+
return std::nullopt;
119+
}
120+
},
121+
py::arg( "pathname" ),
122+
R"(
123+
124+
)" );
125+
126+
#ifndef PYBIND11_MODULE
127+
return m.ptr();
128+
#endif // PYBIND11_MODULE
129+
}
130+
} // namespace hal

0 commit comments

Comments
 (0)