systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
HDLMain.h
Go to the documentation of this file.
1#ifndef _HDL_H
2#define _HDL_H
3
4// clang-format off
5#include "SystemCClang.h"
6//#include "PluginAction.h"
7
8#include "llvm/Support/raw_ostream.h"
9#include "llvm/Support/Debug.h"
10#include "llvm/ADT/StringRef.h"
11#include "llvm/Support/FileSystem.h"
12#include "hNode.h"
13#include "HDLBody.h"
14#include "HDLType.h"
15// clang-format on
16
17using namespace clang;
18using namespace systemc_clang;
19using namespace hnode;
20using namespace llvm;
21//static llvm::cl::OptionCategory HDLcategory("systemc-clang options");
22
23namespace systemc_hdl {
24 class HDLMain: public SystemCConsumer {
25
26 public:
28 HDLMain(CompilerInstance &ci, std::string topModule = "!none",
29 const std::string &hdl_file_out = "default_hdl.txt")
30 : SystemCConsumer(ci, topModule), hdl_file_out_{hdl_file_out} {}
31 HDLMain(ASTUnit *from_ast, std::string topModule = "!none",
32 const std::string &hdl_file_out = "default_hdl.txt")
33 : SystemCConsumer(from_ast, topModule), hdl_file_out_{hdl_file_out} {}
34
35 bool postFire();
36
37 private:
38 void SCmodule2hcode(ModuleInstance *mod, hNodep &h_module,
39 llvm::raw_fd_ostream &SCout);
40 void GenerateInstanceNames(ModuleInstance *smod, std::vector<std::string> &instnames);
41 bool isValidMethod(CXXMethodDecl *method);
43 hNodep &h_info, hdecl_name_map_t &mod_vname_map);
45 hNodep &h_info, hdecl_name_map_t &mod_vname_map);
47 hNodep &h_port,hdecl_name_map_t &mod_vname_map,
49
50 //void SCportbindings2hcode(ModuleInstance * mod, hNodep &h_pb);
51 //following is obsolete and no longer called
53 //systemc_clang::ModuleInstance::portBindingMapType portbindingmap,
54 ModuleInstance* mod,
55 hNodep &h_pb);
56 void MakeResetMap( resetvar_map_t &threadresetmap, hNodep h_allsenslists);
57
58 clang::DiagnosticsEngine &main_diag_engine{getContext().getDiagnostics()};
59
60 hfunc_name_map_t allmethodecls; // all methods/functions called at top level of method
61
62 std::unordered_set<string> module_vars;
63
64 resetvar_map_t threadresetmap; // for each module; must be cleared before next module
65
67
69
71
72 //hmodinst_name_map_t mod_name_map;
73 //name_serve mod_newn{"_sc_module_"};
74
76
78 std::string hdl_file_out_;
79 };
80
81
82 // static llvm::cl::opt<std::string> HDLtop(
83 // "top",
84 // llvm::cl::desc("Specify top-level module declaration for entry point"),
85 // llvm::cl::cat(HDLcategory));
86 //
87 //
88
89 class HDLAXN : public ASTFrontendAction {
90 public:
91 HDLAXN(const std::string &top) : top_{top} {};
92 HDLAXN(const std::string &top, const std::string &hdl_file_out)
93 : top_{top}, hdl_file_out_{hdl_file_out} {};
94
95 private:
96 std::string top_;
97 std::string hdl_file_out_;
98
99 public:
100 virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(
101 clang::CompilerInstance &Compiler, llvm::StringRef inFile) {
102 return std::unique_ptr<ASTConsumer>(new HDLMain(Compiler, top_, hdl_file_out_));
103 }
104 };
105
107 class HDLFrontendActionFactory : public clang::tooling::FrontendActionFactory {
108 public:
109 HDLFrontendActionFactory(const std::string &top)
110 : top_module_declaration_{top}, hdl_file_out_{"default_hdl.txt"} {}
111
112 HDLFrontendActionFactory(const std::string &top,
113 const std::string &hdl_file_out)
114 : top_module_declaration_{top}, hdl_file_out_{hdl_file_out} {}
115
116 std::unique_ptr<clang::FrontendAction> create() override {
117 return std::unique_ptr<FrontendAction>(
119 }
120
121 protected:
123 std::string hdl_file_out_;
124 };
125
126 //std::unique_ptr<clang::tooling::FrontendActionFactory>
127 //newFrontendActionFactory(const std::string &top_module);
128
129
132 public:
133 HDLPluginAction(int argc, const char **argv) {
134 // Specify the top-level module.
135 //
136 //
137 //
138 llvm::cl::OptionCategory HDLcategory("HDL options");
139 llvm::cl::opt<std::string> topModule(
140 "top-module",
141 llvm::cl::desc(
142 "Specify top-level module declaration for synthesis entry point"),
143 llvm::cl::cat(HDLcategory));
144
145 llvm::cl::opt<bool> debug_mode(
146 "debug", llvm::cl::desc("Enable debug output from systemc-clang"),
147 llvm::cl::cat(HDLcategory));
148
149 llvm::cl::opt<std::string> debug_only(
150 "debug-only",
151 llvm::cl::desc("Enable debug only for the specified DEBUG_TYPE"),
152 llvm::cl::cat(HDLcategory));
153
154 llvm::cl::opt<std::string> hdl_file_out(
155 "hdl-file-out", llvm::cl::desc("HDL output file location"),
156 llvm::cl::cat(HDLcategory));
157
158 //CommonOptionsParser OptionsParser(argc, argv, HDLcategory);
159
160 llvm::Expected<clang::tooling::CommonOptionsParser> options_parser{
161 clang::tooling::CommonOptionsParser::create(argc, argv, HDLcategory)};
162
163 llvm::dbgs() << "Options parser\n";
164 if (auto err = options_parser.takeError() ) {
165 llvm::logAllUnhandledErrors(std::move(err), llvm::errs(), "[PluginAction Error]");
166 return;
167 }
168
169
170
171 ClangTool Tool(options_parser->getCompilations(),
172 options_parser->getSourcePathList());
173
175 //
176 if (debug_mode || (debug_only != "") ) {
177 LLVM_DEBUG(llvm::dbgs() << "Debug mode enabled\n";);
178 llvm::DebugFlag = true;
179 }
180
181 if (debug_only != "") {
182#ifdef __clang__
183 setCurrentDebugType(debug_only.c_str());
184#else
185 llvm::setCurrentDebugType(debug_only.c_str());
186#endif
187 }
188
189 if (hdl_file_out != "") {
190 LLVM_DEBUG(llvm::dbgs()
191 << "HDL output file specified: " << hdl_file_out << "\n";);
192 }
193
194 std::unique_ptr<FrontendActionFactory> FrontendFactory;
195 // FrontendFactory = newFrontendActionFactory<HDLAXN>();
196 //FrontendFactory = newFrontendActionFactory(h);
197
198 FrontendFactory = std::unique_ptr<tooling::FrontendActionFactory>(
199 new HDLFrontendActionFactory(topModule, hdl_file_out));
200 Tool.run(FrontendFactory.get());
201 };
202 };
203}
204#endif
Forward declarations.
std::map< std::string, ProcessDecl * > processMapType
std::map< std::string, SignalDecl * > signalMapType
std::vector< std::tuple< std::string, PortDecl * > > portMapType
This is the main consumer class that beings the parsing of SystemC.
clang::ASTContext & getContext() const
virtual std::unique_ptr< ASTConsumer > CreateASTConsumer(clang::CompilerInstance &Compiler, llvm::StringRef inFile)
Definition HDLMain.h:100
HDLAXN(const std::string &top)
Definition HDLMain.h:91
std::string hdl_file_out_
Definition HDLMain.h:97
HDLAXN(const std::string &top, const std::string &hdl_file_out)
Definition HDLMain.h:92
std::string top_
Definition HDLMain.h:96
HDLFrontendActionFactory(const std::string &top, const std::string &hdl_file_out)
Definition HDLMain.h:112
HDLFrontendActionFactory(const std::string &top)
Definition HDLMain.h:109
std::unique_ptr< clang::FrontendAction > create() override
Definition HDLMain.h:116
void SCport2hcode(ModuleInstance::portMapType pmap, hNode::hdlopsEnum h_op, hNodep &h_info, hdecl_name_map_t &mod_vname_map)
Definition HDLMain.cpp:578
clang::DiagnosticsEngine & main_diag_engine
Definition HDLMain.h:58
void SCportbindings2hcode(ModuleInstance *mod, hNodep &h_pb)
Definition HDLMain.cpp:855
hmodinst_name_map_t mod_name_map
Definition HDLMain.h:75
void SCmodule2hcode(ModuleInstance *mod, hNodep &h_module, llvm::raw_fd_ostream &SCout)
Definition HDLMain.cpp:135
void MakeResetMap(resetvar_map_t &threadresetmap, hNodep h_allsenslists)
Definition HDLMain.cpp:820
HDLMain(CompilerInstance &ci, std::string topModule="!none", const std::string &hdl_file_out="default_hdl.txt")
Provide hdl_file_out as argument.
Definition HDLMain.h:28
void SCsig2hcode(ModuleInstance::signalMapType pmap, hNode::hdlopsEnum h_op, hNodep &h_info, hdecl_name_map_t &mod_vname_map)
Definition HDLMain.cpp:684
void SCproc2hcode(ModuleInstance::processMapType pm, hNodep &h_top, hNodep &h_port, hdecl_name_map_t &mod_vname_map, overridden_method_map_t &overridden_method_map, resetvar_map_t &threadresetmap)
Definition HDLMain.cpp:750
HDLBody * xbodyp
Definition HDLMain.h:68
void GenerateInstanceNames(ModuleInstance *smod, std::vector< std::string > &instnames)
Definition HDLMain.cpp:523
resetvar_map_t threadresetmap
Definition HDLMain.h:64
std::unordered_set< string > module_vars
Definition HDLMain.h:62
bool isValidMethod(CXXMethodDecl *method)
Definition HDLMain.cpp:570
HDLMain(ASTUnit *from_ast, std::string topModule="!none", const std::string &hdl_file_out="default_hdl.txt")
Definition HDLMain.h:31
hfunc_name_map_t allmethodecls
Definition HDLMain.h:60
std::string hdl_file_out_
Command line options.
Definition HDLMain.h:78
HDLPluginAction(int argc, const char **argv)
Definition HDLMain.h:133
Clang forward declarations.
Definition FindArgument.h:6
Definition hNode.h:24
std::unordered_map< string, hNodep > resetvar_map_t
Definition hNode.h:631
std::unordered_map< const CXXMethodDecl *, const CXXMethodDecl * > overridden_method_map_t
Definition hNode.h:628