HAL
project_manager.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"
32 
33 #include <filesystem>
34 #include <string>
35 #include <unordered_map>
36 
37 namespace hal
38 {
39  class Netlist;
40  class ProjectSerializer;
41 
48  {
49  public:
54  {
55  NONE,
57  SAVED
58  };
59 
60  private:
62 
63  static ProjectManager* inst;
64 
65  ProjectStatus m_project_status;
66  Netlist* m_netlist_save;
67  std::unique_ptr<Netlist> m_netlist_load;
68  ProjectDirectory m_proj_dir;
69  std::string m_proj_file;
70  std::string m_netlist_file;
71  std::string m_gatelib_path;
72  std::unordered_map<std::string, ProjectSerializer*> m_serializer;
73  std::unordered_map<std::string, std::string> m_filename;
74 
75  bool serialize_external(bool shadow);
76 
82  bool deserialize();
83 
89  bool serialize_to_projectfile(bool shadow) const;
90 
91  public:
97  static ProjectManager* instance();
98 
105  void register_serializer(const std::string& tagname, ProjectSerializer* serializer);
106 
111  void unregister_serializer(const std::string& tagname);
112 
119 
126  void set_project_status(ProjectStatus status);
127 
134  std::string get_filename(const std::string& serializer_name);
135 
141  std::unique_ptr<Netlist>& get_netlist();
142 
146  void dump() const;
147 
153  void set_gate_library_path(const std::string& gl_path);
154 
162  bool serialize_project(Netlist* netlist, bool shadow = false);
163 
170  bool open_project(const std::string& path = "");
171 
178 
184  void set_project_directory(const std::string& path);
185 
190 
198  bool create_project_directory(const std::string& path);
199 
206 
212  std::string get_netlist_filename() const;
213 
217  static const std::string s_project_file;
218  };
219 } // namespace hal
static ProjectManager * instance()
void set_project_status(ProjectStatus status)
bool create_project_directory(const std::string &path)
void unregister_serializer(const std::string &tagname)
bool serialize_project(Netlist *netlist, bool shadow=false)
std::unique_ptr< Netlist > & get_netlist()
void register_serializer(const std::string &tagname, ProjectSerializer *serializer)
void set_gate_library_path(const std::string &gl_path)
std::string get_filename(const std::string &serializer_name)
ProjectStatus get_project_status() const
void restore_project_file_from_autosave()
static const std::string s_project_file
std::string get_netlist_filename() const
bool open_project(const std::string &path="")
const ProjectDirectory & get_project_directory() const
void set_project_directory(const std::string &path)