HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
verilator.h
Go to the documentation of this file.
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"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include "hal_core/defines.h"
30 
31 #include <filesystem>
32 #include <set>
33 #include <vector>
34 
35 namespace hal
36 {
37  class Netlist;
38  class Gate;
39  class GateType;
40  class Net;
41 
42  namespace verilator
43  {
47  namespace converter
48  {
57  bool convert_gate_library_to_verilog(const Netlist* nl, const std::filesystem::path verilator_sim_path, const std::filesystem::path model_path = "");
58 
67  std::set<std::string> get_provided_models(const std::filesystem::path model_path, const std::filesystem::path gate_definition_path);
68 
75  std::unordered_map<GateType *, std::string> get_gate_gate_types_from_netlist(const Netlist* nl);
76 
83  std::vector<std::string> get_parameters_for_gate(const GateType* gt);
84 
90  std::string get_name_for_gate_type(const GateType* gt);
91 
98  std::string get_prologue_for_gate_type(const GateType* gt);
99 
107  Result<std::string> verilog_function_printer(const BooleanFunction::Node& node, std::vector<std::string>&& operands);
108 
109  // gate functionality
116  std::string get_function_for_gate(const GateType* gt);
117 
124  std::string get_function_for_lut(const GateType* gt);
125 
132  std::string get_function_for_combinational_gate(const GateType* gt);
133 
140  std::string get_function_for_ff(const GateType* gt);
141 
148  std::string get_function_for_latch(const GateType* gt);
149 
155  std::string get_epilogue_for_gate_type();
156  } // namespace converter
157 
162  {
163  // path to VCD file with results when simulation done is SimulationEngine::mResultFilename
164 
165  static const int s_command_lines;
166 
167  public:
168  VerilatorEngine(const std::string& nam);
169  std::unique_ptr<Netlist> m_partial_netlist;
170  std::filesystem::path m_simulator_dir;
171 
172  std::string m_design_name;
173 
174  bool setSimulationInput(SimulationInput* simInput) override;
175  int numberCommandLines() const override;
176  std::vector<std::string> commandLine(int lineIndex) const override;
177  bool finalize() override;
178 
179  private:
180  bool write_testbench_files(SimulationInput* simInput);
181  int m_num_of_threads = 4;
182  std::string m_compiler;
183  };
184 
189  {
190  public:
192  {
193  }
194  SimulationEngine* createEngine() const override;
195  };
196  } // namespace verilator
197 
198 } // namespace hal
SimulationEngine * createEngine() const override
Definition: verilator.cpp:309
VerilatorEngine(const std::string &nam)
Definition: verilator.cpp:297
bool setSimulationInput(SimulationInput *simInput) override
Definition: verilator.cpp:120
std::unique_ptr< Netlist > m_partial_netlist
Definition: verilator.h:169
std::vector< std::string > commandLine(int lineIndex) const override
Definition: verilator.cpp:225
int numberCommandLines() const override
Definition: verilator.cpp:220
std::filesystem::path m_simulator_dir
Definition: verilator.h:170
bool convert_gate_library_to_verilog(const Netlist *nl, const std::filesystem::path verilator_sim_path, const std::filesystem::path model_path="")
Definition: converter.cpp:29
std::vector< std::string > get_parameters_for_gate(const GateType *gt)
Definition: converter.cpp:177
std::string get_function_for_latch(const GateType *gt)
std::string get_prologue_for_gate_type(const GateType *gt)
Definition: converter.cpp:236
std::string get_function_for_ff(const GateType *gt)
Definition: ff_function.cpp:23
std::string get_function_for_lut(const GateType *gt)
Result< std::string > verilog_function_printer(const BooleanFunction::Node &node, std::vector< std::string > &&operands)
Definition: converter.cpp:304
std::string get_function_for_combinational_gate(const GateType *gt)
std::unordered_map< GateType *, std::string > get_gate_gate_types_from_netlist(const Netlist *nl)
Definition: converter.cpp:144
std::string get_function_for_gate(const GateType *gt)
Definition: converter.cpp:338
std::set< std::string > get_provided_models(const std::filesystem::path model_path, const std::filesystem::path gate_definition_path)
Definition: converter.cpp:103
std::string get_epilogue_for_gate_type()
Definition: converter.cpp:365
std::string get_name_for_gate_type(const GateType *gt)
Definition: converter.cpp:156
Definition: defines.h:45