Skip to content

Commit

Permalink
Use private template functions for port insertions
Browse files Browse the repository at this point in the history
  • Loading branch information
rmrf committed Dec 14, 2019
1 parent 9342e23 commit d619052
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
35 changes: 17 additions & 18 deletions src/Matchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ auto match_non_sc_types = cxxRecordDecl(

// add instance matcher
// Not nested.
instance_matcher.registerMatchers( finder );
instance_matcher.registerMatchers(finder);

// finder.addMatcher( match_clock_ports, this );
finder.addMatcher(match_sc_in_clk, this);
Expand All @@ -118,7 +118,13 @@ auto match_non_sc_types = cxxRecordDecl(
finder.addMatcher(match_in_out_ports, this);
finder.addMatcher(match_internal_signal, this);
finder.addMatcher(match_non_sc_types, this);
}

template <typename T>
void ModuleDeclarationMatcher::insert_port(PortType &port, T *decl) {
auto name{decl->getIdentifier()->getNameStart()};
port.push_back(
std::make_tuple(name, new PortDecl(name, decl, parseTemplateType(decl))));
}

void ModuleDeclarationMatcher::run(const MatchFinder::MatchResult &result) {
Expand All @@ -133,7 +139,7 @@ void ModuleDeclarationMatcher::run(const MatchFinder::MatchResult &result) {
if (auto decl = const_cast<CXXRecordDecl *>(
result.Nodes.getNodeAs<CXXRecordDecl>("sc_module"))) {
cout << " Found sc_module: " << decl->getIdentifier()->getNameStart()
<< endl;
<< " CXXRecordDecl*: " << decl << endl;
std::string name{decl->getIdentifier()->getNameStart()};
// decl->dump();
//
Expand All @@ -151,48 +157,41 @@ void ModuleDeclarationMatcher::run(const MatchFinder::MatchResult &result) {
*/
}

if (auto fd = result.Nodes.getNodeAs<FieldDecl>("sc_in_clk")) {
if (auto fd = checkMatch<FieldDecl>("sc_in_clk", result)) {
std::string port_name{fd->getIdentifier()->getNameStart()};
cout << " Found sc_in_clk: " << port_name << endl;
clock_ports_.push_back(std::make_tuple(
port_name, new PortDecl(port_name, fd, parseTemplateType(fd))));

insert_port(clock_ports_, fd);
}

if (auto fd = result.Nodes.getNodeAs<FieldDecl>("sc_in")) {
if (auto fd = checkMatch<FieldDecl>("sc_in", result)) {
auto port_name{fd->getIdentifier()->getNameStart()};
cout << " Found sc_in: " << port_name << endl;
// cout << fd->getParent()->getIdentifier()->getNameStart() << endl;

in_ports_.push_back(std::make_tuple(
port_name, new PortDecl(port_name, fd, parseTemplateType(fd))));
insert_port(in_ports_, fd);
}

if (auto fd = checkMatch<FieldDecl>("sc_out", result)) {
auto port_name{fd->getIdentifier()->getNameStart()};
cout << " Found sc_out: " << port_name << endl;
out_ports_.push_back(std::make_tuple(
port_name, new PortDecl(port_name, fd, parseTemplateType(fd))));
insert_port(out_ports_, fd);
}

if (auto fd = checkMatch<FieldDecl>("sc_inout", result)) {
auto port_name{fd->getIdentifier()->getNameStart()};
cout << " Found sc_inout: " << port_name << endl;
inout_ports_.push_back(std::make_tuple(
port_name, new PortDecl(port_name, fd, parseTemplateType(fd))));
insert_port(inout_ports_, fd);
}

if (auto fd = checkMatch<FieldDecl>("sc_signal", result)) {
auto signal_name{fd->getIdentifier()->getNameStart()};
cout << " Found sc_signal: " << signal_name << endl;
signal_fields_.push_back(std::make_tuple(
signal_name, new PortDecl(signal_name, fd, parseTemplateType(fd))));
insert_port(signal_fields_, fd);
}

if (auto fd = checkMatch<FieldDecl>("other_fields", result)) {
auto field_name{fd->getIdentifier()->getNameStart()};
cout << " Found others fields: " << field_name << endl;
other_fields_.push_back(std::make_tuple(
field_name, new PortDecl(field_name, fd, parseTemplateType(fd))));
insert_port(other_fields_, fd);
}
}

Expand Down
31 changes: 23 additions & 8 deletions src/Matchers.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class InstanceMatcher : public MatchFinder::MatchCallback {
std::string name{instance->getIdentifier()->getNameStart()};
cout << "Found a member field instance: " << name << endl;
list_instance_fields_.push_back(std::make_tuple(name, instance));

// Get the pointer to the type declaration.
auto qtype{instance->getType().getTypePtr()};
qtype->dump();
}

if (auto instance = const_cast<VarDecl *>(
Expand All @@ -58,18 +62,24 @@ class InstanceMatcher : public MatchFinder::MatchCallback {
list_instance_vars_.push_back(std::make_tuple(name, instance));

// const Type * returned
//
/*
//
cout << "Figure out type of vardecl\n";
auto qtype{instance->getType().getTypePtr()};
if (auto dp = qtype->getAs<TemplateSpecializationType>()) {
auto tn{dp->getTemplateName()};
auto tunder{tn.getUnderlying()};
auto name{tunder.getAsTemplateDecl()->getNameAsString()};
cout << "NAME: " << name << endl;
if (auto dp = qtype->getAs<TemplateSpecializationType>()) {
auto tn{dp->getTemplateName()};
auto tunder{tn.getUnderlying()};
auto name{tunder.getAsTemplateDecl()->getNameAsString()};
cout << "template name: \n";
tn.dump();
cout << ", NAME: " << name << endl;

if (dp->isRecordType() ) {
auto rt{ dp->getAsCXXRecordDecl() };
cout << "RECORD type: " << rt << "\n";
}
}

qtype->dump();
*/
}
}

Expand Down Expand Up @@ -128,6 +138,11 @@ class ModuleDeclarationMatcher : public MatchFinder::MatchCallback {
ModuleDeclarationType;
typedef std::vector<std::tuple<std::string, PortDecl *> > PortType;

private:
// Template functions.
template <typename T>
void insert_port( PortType & port, T *decl );

public:
void registerMatchers(MatchFinder &finder);
virtual void run(const MatchFinder::MatchResult &result);
Expand Down

0 comments on commit d619052

Please sign in to comment.