Commit 6e5991b5 authored by rmrf's avatar rmrf

Introduce TemplateType class

parent e95a4b33
...@@ -43,13 +43,14 @@ bool FindPorts::VisitFieldDecl(FieldDecl *fd) { ...@@ -43,13 +43,14 @@ bool FindPorts::VisitFieldDecl(FieldDecl *fd) {
if (args.size() == 0) { if (args.size() == 0) {
return true; return true;
} }
if (ait->first == "sc_in") { string port_type{ (*ait)->getTypeName()};
if (port_type == "sc_in") {
// os_ << "\n+ sc_in"; // os_ << "\n+ sc_in";
_inPorts.insert(kvType(fname, te)); _inPorts.insert(kvType(fname, te));
} else if (ait->first == "sc_out") { } else if (port_type == "sc_out") {
// os_ << "\n+ sc_out"; // os_ << "\n+ sc_out";
_outPorts.insert(kvType(fname, te)); _outPorts.insert(kvType(fname, te));
} else if (ait->first == "sc_inout") { } else if (port_type == "sc_inout") {
// os_ << "\n+ sc_inout"; // os_ << "\n+ sc_inout";
_inoutPorts.insert(kvType(fname, te)); _inoutPorts.insert(kvType(fname, te));
} else { } else {
......
...@@ -45,8 +45,9 @@ bool FindSensitivity::VisitMemberExpr(MemberExpr *e) { ...@@ -45,8 +45,9 @@ bool FindSensitivity::VisitMemberExpr(MemberExpr *e) {
return true; return true;
/// Is it a port type /// Is it a port type
if (!(ait->first == "sc_in" || ait->first == "sc_out" || string port_type{ (*ait)->getTypeName() };
ait->first == "sc_inout")) { if (!(port_type == "sc_in" || port_type == "sc_out" ||
port_type == "sc_inout")) {
return true; return true;
} }
......
...@@ -33,21 +33,23 @@ bool FindTLMInterfaces::VisitFieldDecl(FieldDecl *fd) { ...@@ -33,21 +33,23 @@ bool FindTLMInterfaces::VisitFieldDecl(FieldDecl *fd) {
te->Enumerate(tp); te->Enumerate(tp);
FindTemplateTypes::argVectorType args = te->getTemplateArgumentsType(); FindTemplateTypes::type_vector_t args = te->getTemplateArgumentsType();
FindTemplateTypes::argVectorType::iterator ait = args.begin(); FindTemplateTypes::argVectorType::iterator ait = args.begin();
if (args.size() == 0) { if (args.size() == 0) {
return true; return true;
} }
if (ait->first == "sc_fifo_in") { // There could be more than one type though. Are you only referring to the first one?
string template_type_name { (*ait)->getTypeName() };
if ( template_type_name == "sc_fifo_in") {
_inInterfaces.insert(kvType(fname, te)); _inInterfaces.insert(kvType(fname, te));
} }
else if (ait->first == "sc_fifo_out") { else if ( template_type_name == "sc_fifo_out") {
_outInterfaces.insert(kvType(fname, te)); _outInterfaces.insert(kvType(fname, te));
} }
else if (ait->first == "sc_fifo_inout") { else if ( template_type_name == "sc_fifo_inout") {
_inoutInterfaces.insert(kvType(fname, te)); _inoutInterfaces.insert(kvType(fname, te));
} }
......
...@@ -12,34 +12,57 @@ ...@@ -12,34 +12,57 @@
#include <iostream> #include <iostream>
namespace scpar { namespace scpar {
using namespace clang; using namespace clang;
using namespace std; using namespace std;
// This class is going to find the arguments from templates // This class holds the name of the type, and a pointer to the
class FindTemplateTypes : public RecursiveASTVisitor<FindTemplateTypes> { // type object.
public: class TemplateType {
/// Typedefs public:
typedef vector<pair<string, const Type *>> type_vector_t; TemplateType( string, const Type* );
typedef vector<pair<string, const Type *>> argVectorType; string getTypeName();
const Type* getTypePtr();
// Constructor
FindTemplateTypes(); private:
string type_name_;
/// Copy constructor const Type * type_ptr_;
FindTemplateTypes(const FindTemplateTypes &rhs); };
FindTemplateTypes(const FindTemplateTypes *rhs);
string getTemplateType(); // This class is going to find the arguments from templates
type_vector_t Enumerate(const Type *type); class FindTemplateTypes : public RecursiveASTVisitor<FindTemplateTypes> {
bool VisitType(Type *type); public:
bool VisitIntegerLiteral(IntegerLiteral *l); /// Typedefs
type_vector_t getTemplateArgumentsType(); typedef TemplateType* TemplateTypePtr;
void printTemplateArguments(llvm::raw_ostream &os); //typedef vector< TemplateTypePtr > type_vector_t_new;
vector<string> getTemplateArguments(); //typedef vector<pair<string, const Type *>> type_vector_t;
size_t size(); typedef vector< TemplateTypePtr > type_vector_t;
typedef vector< TemplateTypePtr > argVectorType;
private: //typedef vector<pair<string, const Type *>> argVectorType;
// (string, Type*)
type_vector_t template_types_; // Constructor
}; FindTemplateTypes();
/// Copy constructor
FindTemplateTypes(const FindTemplateTypes &rhs);
FindTemplateTypes(const FindTemplateTypes *rhs);
string getTemplateType();
bool VisitType(Type *type);
bool VisitIntegerLiteral(IntegerLiteral *l);
type_vector_t Enumerate(const Type *type);
type_vector_t getTemplateArgumentsType();
void printTemplateArguments(llvm::raw_ostream &os);
vector<string> getTemplateArguments();
size_t size();
private:
// (string, Type*)
// Classes such as sc_port and sc_in can have nested types within it.
// For example: sc_in< sc_int<16> >
// The general way to handle this would be to have a vector starting from the
// outside type to the inside type.
type_vector_t template_types_;
//type_vector_t_new template_types_new_;
};
} // namespace scpar } // namespace scpar
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment