xref: /oneTBB/examples/graph/logic_sim/D_latch.hpp (revision b15aabb3)
1 /*
2     Copyright (c) 2005-2021 Intel Corporation
3 
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7 
8         http://www.apache.org/licenses/LICENSE-2.0
9 
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16 
17 #ifndef TBB_examples_logic_sim_dlatch_H
18 #define TBB_examples_logic_sim_dlatch_H
19 
20 #include "basics.hpp"
21 
22 class D_latch : public oneapi::tbb::flow::composite_node<std::tuple<signal_t, signal_t>,
23                                                          std::tuple<signal_t, signal_t>> {
24     oneapi::tbb::flow::broadcast_node<signal_t> D_port;
25     oneapi::tbb::flow::broadcast_node<signal_t> E_port;
26     not_gate a_not;
27     and_gate<2> first_and;
28     and_gate<2> second_and;
29     nor_gate<2> first_nor;
30     nor_gate<2> second_nor;
31     oneapi::tbb::flow::graph& my_graph;
32     typedef oneapi::tbb::flow::composite_node<std::tuple<signal_t, signal_t>,
33                                               std::tuple<signal_t, signal_t>>
34         base_type;
35 
36 public:
D_latch(oneapi::tbb::flow::graph & g)37     D_latch(oneapi::tbb::flow::graph& g)
38             : base_type(g),
39               my_graph(g),
40               D_port(g),
41               E_port(g),
42               a_not(g),
43               first_and(g),
44               second_and(g),
45               first_nor(g),
46               second_nor(g) {
47         make_edge(D_port, input_port<0>(a_not));
48         make_edge(D_port, input_port<1>(second_and));
49         make_edge(E_port, input_port<1>(first_and));
50         make_edge(E_port, input_port<0>(second_and));
51         make_edge(a_not, input_port<0>(first_and));
52         make_edge(first_and, input_port<0>(first_nor));
53         make_edge(second_and, input_port<1>(second_nor));
54         make_edge(first_nor, input_port<0>(second_nor));
55         make_edge(second_nor, input_port<1>(first_nor));
56 
57         base_type::input_ports_type input_tuple(D_port, E_port);
58         base_type::output_ports_type output_tuple(output_port<0>(first_nor),
59                                                   output_port<0>(second_nor));
60 
61         base_type::set_external_ports(input_tuple, output_tuple);
62         base_type::add_visible_nodes(
63             D_port, E_port, a_not, first_and, second_and, first_nor, second_nor);
64     }
~D_latch()65     ~D_latch() {}
66 };
67 
68 #endif /* TBB_examples_logic_sim_dlatch_H */
69