systemc-clang 2.0.0
Parsing SystemC constructs
Loading...
Searching...
No Matches
PluginAction.h
Go to the documentation of this file.
1//===-- src/PluginAction.h - systec-clang class definition -------*- C++
2//-*-===//
3//
4// systemc-clang: SystemC Parser
5//
6// This file is distributed under the TBD
7// License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
14//===----------------------------------------------------------------------===//
15#ifndef _PLUGIN_ACTION_H_
16#define _PLUGIN_ACTION_H_
17
18#include <clang/Tooling/Tooling.h>
19#include <llvm/Support/Error.h>
20#include "llvm/Support/Debug.h"
21
22#include "SystemCClang.h"
23
24namespace systemc_clang {
25
26using namespace llvm;
27
28static llvm::cl::OptionCategory category("systemc-clang options");
29// static llvm::cl::opt<std::string> topModule(
30// "top-module",
31// llvm::cl::desc("Specify top-level module declaration for entry point"),
32// llvm::cl::cat(category));
33//
34static llvm::cl::opt<bool> debug_mode(
35 "debug", llvm::cl::desc("Enable debug output from systemc-clang"),
36 llvm::cl::cat(category));
37
38static llvm::cl::opt<std::string> debug_only(
39 "debug-only",
40 llvm::cl::desc("Enable debug only for the specified DEBUG_TYPE"),
41 llvm::cl::cat(category));
42
43class SystemCClangAXN : public ASTFrontendAction {
44 public:
46
47 private:
48 std::string top_;
49
50 public:
51 virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(
52 clang::CompilerInstance &Compiler, llvm::StringRef inFile) {
53 return std::unique_ptr<ASTConsumer>(new SystemCConsumer(Compiler, top_));
54 }
55};
56
58 public:
59 PluginAction(int argc, const char **argv) {
61 llvm::Expected<clang::tooling::CommonOptionsParser> options_parser{
62 clang::tooling::CommonOptionsParser::create(argc, argv, category)};
63
64 llvm::dbgs() << "Options parser\n";
65 if (auto err = options_parser.takeError() ) {
66 llvm::logAllUnhandledErrors(std::move(err), llvm::errs(), "[PluginAction Error]");
67 return;
68 }
69
70 ClangTool Tool(options_parser->getCompilations(),
71 options_parser->getSourcePathList());
72
74 //
75 if (debug_mode || (debug_only != "")) {
76 LLVM_DEBUG(llvm::dbgs() << "Debug mode enabled\n";);
77 llvm::DebugFlag = true;
78 }
79
80 if (debug_only != "") {
81#ifdef __clang__
82 setCurrentDebugType(debug_only.c_str());
83#else
84 llvm::setCurrentDebugType(debug_only.c_str());
85#endif
86 }
87
88 std::unique_ptr<FrontendActionFactory> FrontendFactory;
89 FrontendFactory = newFrontendActionFactory<SystemCClangAXN>();
90
91 llvm::dbgs() << "Start SCCL\n";
92 Tool.run(FrontendFactory.get());
93 };
94};
95}; // namespace systemc_clang
96
97#endif /* _PLUGIN_ACTION_H_ */
PluginAction(int argc, const char **argv)
virtual std::unique_ptr< ASTConsumer > CreateASTConsumer(clang::CompilerInstance &Compiler, llvm::StringRef inFile)
This is the main consumer class that beings the parsing of SystemC.