From 8b8c82da1bc350773cb0d37d72c9e6c909835b93 Mon Sep 17 00:00:00 2001 From: rmrf Date: Tue, 10 Dec 2019 10:54:35 -0500 Subject: [PATCH] Disable AST matching inclusion into systemc-clang --- release-it.json | 46 ----------------- src/Matchers.h | 115 +++++++++++++++++++++++-------------------- src/ModuleDecl.cpp | 60 +++++++++++++++++----- src/ModuleDecl.h | 22 +++++++-- src/SystemCClang.cpp | 6 ++- 5 files changed, 132 insertions(+), 117 deletions(-) delete mode 100644 release-it.json diff --git a/release-it.json b/release-it.json deleted file mode 100644 index 45aad318e..000000000 --- a/release-it.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "hooks": {}, - "git": { - "changelog": "git log --pretty=format:\"* %s (%h)\" ${latestTag}...HEAD", - "requireCleanWorkingDir": true, - "requireUpstream": true, - "requireCommits": false, - "addUntrackedFiles": false, - "commit": true, - "commitMessage": "Release ${version}", - "commitArgs": "", - "tag": true, - "tagName": "${version}", - "tagAnnotation": "Release ${version}", - "tagArgs": "", - "push": true, - "pushArgs": "--follow-tags", - "pushRepo": "origin" - }, - "npm": { - "publish": false, - "publishPath": ".", - "access": null, - "otp": null - }, - "github": { - "release": true, - "releaseName": "Release ${version}", - "releaseNotes": null, - "preRelease": false, - "draft": false, - "tokenRef": "GITHUB_TOKEN", - "assets": null, - "host": null, - "timeout": 0, - "proxy": null - }, - "gitlab": { - "release": false, - "releaseName": "Release ${version}", - "releaseNotes": null, - "tokenRef": "GITLAB_TOKEN", - "assets": null, - "origin": null - } -} diff --git a/src/Matchers.h b/src/Matchers.h index 8e5c09f5f..c00dadcb2 100644 --- a/src/Matchers.h +++ b/src/Matchers.h @@ -1,12 +1,13 @@ #ifndef _MATCHERS_HPP_ -#define _MATCHERS_HPP_ +#define _MATCHERS_HPP_ +#include #include #include -#include -#include "clang/ASTMatchers/ASTMatchers.h" -#include "clang/ASTMatchers/ASTMatchFinder.h" #include "FindTemplateTypes.h" +#include "ModuleDecl.h" #include "PortDecl.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" using namespace clang; using namespace clang::ast_matchers; @@ -14,11 +15,15 @@ using namespace scpar; namespace sc_ast_matchers { - // InstanceMatcher - class InstanceMatcher : public MatchFinder::MatchCallback { - public: - void registerMatchers(MatchFinder &finder) { - //clang-format off +// InstanceMatcher +class InstanceMatcher : public MatchFinder::MatchCallback { + public: + typedef std::vector > instance_fields; + typedef std::vector > instance_vars; + + public: + void registerMatchers(MatchFinder &finder) { + /* clang-format off */ auto match_instances = fieldDecl( hasType( @@ -32,32 +37,38 @@ namespace sc_ast_matchers { cxxRecordDecl(isDerivedFrom(hasName("::sc_core::sc_module"))) ) ).bind("instances_in_vardecl"); - //clang-format on - - finder.addMatcher(match_instances, this); - finder.addMatcher(match_instances_vars, this); - } - - virtual void run(const MatchFinder::MatchResult &result) { - /* - if (auto field_decl = const_cast( - result.Nodes.getNodeAs("sc_in"))) { - std::string name{field_decl->getIdentifier()->getNameStart()}; - input_port_names.push_back(name); - } - */ - cout << " Found an instance: "<< endl; - } + /* clang-format on */ - public: - std::vector input_port_names; -}; + finder.addMatcher(match_instances, this); + finder.addMatcher(match_instances_vars, this); + } + virtual void run(const MatchFinder::MatchResult &result) { + if (auto instance = const_cast( + result.Nodes.getNodeAs("instances_in_fielddecl"))) { + std::string name{instance->getIdentifier()->getNameStart()}; + cout << " Found a member field instance: " << name << endl; + list_instance_fields_.push_back(std::make_tuple(name, instance)); + } + + if (auto instance = const_cast( + result.Nodes.getNodeAs("instances_in_vardecl"))) { + std::string name{instance->getIdentifier()->getNameStart()}; + cout << " Found a member variable instance: " << name << endl; + list_instance_vars_.push_back(std::make_tuple(name, instance)); + } + } + + private: + instance_fields list_instance_fields_; + instance_vars list_instance_vars_; +}; // FieldMatcher class class FieldMatcher : public MatchFinder::MatchCallback { public: void registerMatchers(MatchFinder &finder) { + /* clang-format off */ auto match_module_decls = cxxRecordDecl( // isExpansionInMainFile(), isDerivedFrom(hasName("::sc_core::sc_module")), @@ -66,7 +77,7 @@ class FieldMatcher : public MatchFinder::MatchCallback { auto match_in_ports = cxxRecordDecl(forEach( fieldDecl(hasType(cxxRecordDecl(hasName("sc_in")))).bind("sc_in"))); - //clang-format on + /* clang-format off */ finder.addMatcher(match_in_ports, this); } @@ -85,33 +96,31 @@ class FieldMatcher : public MatchFinder::MatchCallback { std::vector input_port_names; }; - - class ModuleDeclarationMatcher : public MatchFinder::MatchCallback { -// - public: - typedef std::vector< std::tuple > ModuleDeclarationTuple; - typedef std::vector< std::tuple > PortType; - - public: - void registerMatchers( MatchFinder &finder ); - virtual void run( const MatchFinder::MatchResult &result ); - const ModuleDeclarationTuple& getFoundModuleDeclarations() const; - const PortType& getFields( const std::string & port_type ); - - void dump(); - private: - ModuleDeclarationTuple found_declarations_; - PortType clock_ports_; - PortType in_ports_; - PortType out_ports_; - PortType inout_ports_; - PortType other_fields_; - PortType signal_fields_; + // + public: + typedef std::vector > + ModuleDeclarationTuple; + typedef std::vector > PortType; + public: + void registerMatchers(MatchFinder &finder); + virtual void run(const MatchFinder::MatchResult &result); + const ModuleDeclarationTuple &getFoundModuleDeclarations() const; + const PortType &getFields(const std::string &port_type); + + void dump(); + + private: + ModuleDeclarationTuple found_declarations_; + PortType clock_ports_; + PortType in_ports_; + PortType out_ports_; + PortType inout_ports_; + PortType other_fields_; + PortType signal_fields_; }; -}; // namespace sc_ast_matchers +}; // namespace sc_ast_matchers #endif - diff --git a/src/ModuleDecl.cpp b/src/ModuleDecl.cpp index a5850dc64..18ee4b684 100644 --- a/src/ModuleDecl.cpp +++ b/src/ModuleDecl.cpp @@ -8,10 +8,19 @@ using namespace scpar; using namespace std; ModuleDecl::ModuleDecl() - : module_name_{"NONE"}, class_decl_{nullptr}, constructor_stmt_{nullptr} {} + : module_name_{"NONE"}, + instance_name_{"NONE"}, + class_decl_{nullptr}, + constructor_stmt_{nullptr}, + instance_field_decl_{nullptr}, + instance_var_decl_{nullptr} {} ModuleDecl::ModuleDecl(const string &name, CXXRecordDecl *decl) - : module_name_{name}, class_decl_{decl} {} + : module_name_{name}, + instance_name_{"NONE"}, + class_decl_{decl}, + instance_field_decl_{nullptr}, + instance_var_decl_{nullptr} {} ModuleDecl::ModuleDecl( const std::tuple &element) @@ -19,8 +28,12 @@ ModuleDecl::ModuleDecl( ModuleDecl::ModuleDecl(const ModuleDecl &from) { module_name_ = from.module_name_; + instance_name_ = from.instance_name_; + class_decl_ = from.class_decl_; constructor_stmt_ = from.constructor_stmt_; + instance_field_decl_ = from.instance_field_decl_; + instance_var_decl_ = from.instance_var_decl_; process_map_ = from.process_map_; in_ports_ = from.in_ports_; @@ -37,8 +50,8 @@ ModuleDecl::ModuleDecl(const ModuleDecl &from) { signals_ = from.signals_; instance_list_ = from.instance_list_; - _portSignalMap = from._portSignalMap; - _vef = from._vef; + port_signal_map_ = from.port_signal_map_; + vef_ = from.vef_; // Class template parameters. template_parameters_ = from.template_parameters_; @@ -46,8 +59,12 @@ ModuleDecl::ModuleDecl(const ModuleDecl &from) { ModuleDecl &ModuleDecl::operator=(const ModuleDecl &from) { module_name_ = from.module_name_; + instance_name_ = from.instance_name_; + class_decl_ = from.class_decl_; constructor_stmt_ = from.constructor_stmt_; + instance_field_decl_ = from.instance_field_decl_; + instance_var_decl_ = from.instance_var_decl_; process_map_ = from.process_map_; in_ports_ = from.in_ports_; @@ -64,8 +81,8 @@ ModuleDecl &ModuleDecl::operator=(const ModuleDecl &from) { signals_ = from.signals_; instance_list_ = from.instance_list_; - _portSignalMap = from._portSignalMap; - _vef = from._vef; + port_signal_map_ = from.port_signal_map_; + vef_ = from.vef_; // Class template parameters. template_parameters_ = from.template_parameters_; @@ -75,6 +92,9 @@ ModuleDecl &ModuleDecl::operator=(const ModuleDecl &from) { ModuleDecl::~ModuleDecl() { class_decl_ = nullptr; constructor_stmt_ = nullptr; + instance_field_decl_ = nullptr; + instance_var_decl_ = nullptr; + // Delete all pointers in ports. for (auto input_port : in_ports_) { // It is a tuple @@ -119,7 +139,7 @@ void ModuleDecl::addInstances(const vector &instanceList) { } void ModuleDecl::addSignalBinding(map portSignalMap) { - _portSignalMap.insert(portSignalMap.begin(), portSignalMap.end()); + port_signal_map_.insert(portSignalMap.begin(), portSignalMap.end()); } void ModuleDecl::addSignals(const FindSignals::signalMapType &signal_map) { @@ -240,7 +260,7 @@ void ModuleDecl::addConstructor(Stmt *constructor) { } void ModuleDecl::addProcess(FindEntryFunctions::entryFunctionVectorType *efv) { - _vef = *efv; + vef_ = *efv; for (unsigned int i = 0; i < efv->size(); ++i) { EntryFunctionContainer *ef = (*efv)[i]; @@ -276,7 +296,7 @@ void ModuleDecl::addProcess(FindEntryFunctions::entryFunctionVectorType *efv) { vector ModuleDecl::getInstanceList() { return instance_list_; } vector ModuleDecl::getEntryFunctionContainer() { - return _vef; + return vef_; } int ModuleDecl::getNumInstances() { return instance_list_.size(); } @@ -313,7 +333,9 @@ ModuleDecl::interfaceMapType ModuleDecl::getIOInterfaces() { return iointerfaces_; } -string ModuleDecl::getName() { return module_name_; } +string ModuleDecl::getName() const { return module_name_; } + +string ModuleDecl::getInstanceName() const { return instance_name_; } bool ModuleDecl::isModuleClassDeclNull() { return (class_decl_ == nullptr); } @@ -322,6 +344,20 @@ CXXRecordDecl *ModuleDecl::getModuleClassDecl() { return class_decl_; } +FieldDecl *ModuleDecl::getInstanceFieldDecl() { return instance_field_decl_; } +VarDecl *ModuleDecl::getInstanceVarDecl() { return instance_var_decl_; } + +bool ModuleDecl::isInstanceFieldDecl() const { + if ((instance_field_decl_ != nullptr) && (instance_var_decl_ == nullptr)) { + return true; + } + if ((instance_field_decl_ == nullptr) && (instance_var_decl_ != nullptr)) { + return false; + } + + return false; +} + void ModuleDecl::dumpInstances(raw_ostream &os, int tabn) { if (instance_list_.empty()) { os << " none \n"; @@ -333,12 +369,12 @@ void ModuleDecl::dumpInstances(raw_ostream &os, int tabn) { } void ModuleDecl::dumpSignalBinding(raw_ostream &os, int tabn) { - if (_portSignalMap.empty()) { + if (port_signal_map_.empty()) { os << " none\n"; return; } - for (auto it : _portSignalMap) { + for (auto it : port_signal_map_) { os << "\nPort : " << it.first << " bound to signal : " << it.second; } } diff --git a/src/ModuleDecl.h b/src/ModuleDecl.h index c3638c7c3..11b36ac4e 100644 --- a/src/ModuleDecl.h +++ b/src/ModuleDecl.h @@ -73,6 +73,7 @@ class ModuleDecl { void addOtherVars(const FindPorts::PortType &); void addPorts(const PortType &found_ports, const std::string &port_type); + void addConstructor(Stmt *); void addInputInterfaces(FindTLMInterfaces::interfaceType); void addOutputInterfaces(FindTLMInterfaces::interfaceType); void addInputOutputInterfaces(FindTLMInterfaces::interfaceType); @@ -82,9 +83,15 @@ class ModuleDecl { void setModuleName(const string &); void setTemplateParameters(const vector &); vector getTemplateParameters() const; - void addConstructor(Stmt *); - string getName(); + + string getName() const; + string getInstanceName() const; + CXXRecordDecl *getModuleClassDecl(); + FieldDecl *getInstanceFieldDecl(); + VarDecl *getInstanceVarDecl(); + bool isInstanceFieldDecl() const; + bool isModuleClassDeclNull(); portMapType getOPorts(); portMapType getIPorts(); @@ -115,8 +122,15 @@ class ModuleDecl { private: string module_name_; + string instance_name_; + + // Declaration CXXRecordDecl *class_decl_; + // Constructor statement Stmt *constructor_stmt_; + // Instance fieldDecl or varDecl + FieldDecl *instance_field_decl_; + VarDecl *instance_var_decl_; processMapType process_map_; portMapType in_ports_; @@ -133,8 +147,8 @@ class ModuleDecl { signalMapType signals_; vector instance_list_; - portSignalMapType _portSignalMap; - vector _vef; + portSignalMapType port_signal_map_; + vector vef_; // Class template parameters. vector template_parameters_; diff --git a/src/SystemCClang.cpp b/src/SystemCClang.cpp index 5857f158a..ce43ea4d5 100644 --- a/src/SystemCClang.cpp +++ b/src/SystemCClang.cpp @@ -64,16 +64,19 @@ bool SystemCConsumer::fire() { // 1. Add every module declaration to the model. // =========================================================== // Every module declaration that is found should be added to the model. + // + + /* for (auto const &element : found_module_declarations) { auto module_declaration{new ModuleDecl{get<0>(element), get<1>(element)}}; os_ << "@@@@@ name: " << get<0>(element) << "\n"; systemcModel_->addModuleDecl(module_declaration); } + */ // Find the sc_modules // // - /* FindSCModules scmod{tu, os_}; FindSCModules::moduleMapType scmodules{scmod.getSystemCModulesMap()}; @@ -85,7 +88,6 @@ bool SystemCConsumer::fire() { systemcModel_->addModuleDecl(md); } - */ //////////////////////////////////////////////////////////////// // Find the sc_main