851f1c1f by rmrf

TemplateType class added

1 parent d1888682
#include "FindTemplateTypes.h"
using namespace scpar;
//////////////////////////////////////////////////////////////////////
// TemplateType
//////////////////////////////////////////////////////////////////////
TemplateType::TemplateType( string name, const Type* t ):
type_name_{ name }, type_ptr_{t} {}
TemplateType::TemplateType( const TemplateType & from ) {
type_name_ = from.type_name_;
type_ptr_ = from.type_ptr_;
}
TemplateType::~TemplateType() {
type_ptr_ = nullptr;
}
string TemplateType::getTypeName() const { return type_name_; }
const Type* TemplateType::getTypePtr() { return type_ptr_; }
//////////////////////////////////////////////////////////////////////
// FindTemplateTypes
//////////////////////////////////////////////////////////////////////
// Constructor
FindTemplateTypes::FindTemplateTypes() {}
/// Copy constructor
FindTemplateTypes::FindTemplateTypes(const FindTemplateTypes &rhs) {
copy(rhs.template_types_.begin(), rhs.template_types_.end(),
back_inserter(template_types_));
}
FindTemplateTypes::FindTemplateTypes(const FindTemplateTypes *rhs) {
copy(rhs->template_types_.begin(), rhs->template_types_.end(),
back_inserter(template_types_));
}
// Destructor
FindTemplateTypes::~FindTemplateTypes() {
// TODO: We should convert these into objects.
template_types_.clear();
}
string FindTemplateTypes::getTemplateType() {
string s{};
// type_vector_t::iterator
for (auto mit = template_types_.begin(); mit != template_types_.end();
++mit) {
// for ( auto const &mit: template_types_ ) {
if (mit != template_types_.begin()) {
s += "<";
}
s += mit->getTypeName();
if (mit != template_types_.begin()) {
s += ">";
}
}
return s;
}
FindTemplateTypes::type_vector_t FindTemplateTypes::Enumerate(const Type *type) {
template_types_.clear();
if (!type) {
return template_types_;
}
TraverseType(QualType(type, 0));
return template_types_;
}
bool FindTemplateTypes::VisitType( Type *type ) {
QualType q{type->getCanonicalTypeInternal()};
// cout << "\n###### Type: " << q.getAsString() << " \n" ;
if (type->isBuiltinType()) {
template_types_.push_back( TemplateType( q.getAsString(), type) );
//template_types_.push_back( pair<string, const Type *>(q.getAsString(), type) );
return true;
}
CXXRecordDecl *p_cxx_record{type->getAsCXXRecordDecl()};
if (p_cxx_record != nullptr) {
IdentifierInfo *info{p_cxx_record->getIdentifier()};
if (info != nullptr) {
template_types_.push_back( TemplateType( info->getNameStart(), type ) );
//template_types_.push_back( pair<string, const Type *>(info->getNameStart(), type) );
}
}
return true;
}
bool FindTemplateTypes::VisitIntegerLiteral(IntegerLiteral *l) {
//_os << "\n####### IntegerLiteral: " << l->getValue().toString(10,true) <<
//"\n"; _os << "== type ptr: " << l->getType().getTypePtr() << "\n"; _os <<
//"== type name: " << l->getType().getAsString() << "\n";
template_types_.push_back( TemplateType( l->getValue().toString(10, true), l->getType().getTypePtr() ) );
//template_types_.push_back(pair<string, const Type *>(l->getValue().toString(10, true), l->getType().getTypePtr()));
return true;
}
FindTemplateTypes::type_vector_t FindTemplateTypes::getTemplateArgumentsType() { return template_types_; }
void FindTemplateTypes::printTemplateArguments(llvm::raw_ostream &os) {
vector<string> template_arguments;
for (auto const &mit : template_types_) {
template_arguments.push_back( mit.getTypeName() );
}
// Print the template arguments to the output stream
os << ", " << template_arguments.size() << " arguments, ";
for (auto const &targ : template_arguments) {
os << targ << " ";
}
}
vector<string> FindTemplateTypes::getTemplateArguments() {
vector<string> template_arguments;
for (auto const &mit : template_types_) {
string name{ mit.getTypeName() };
if (name == "sc_in" || name == "sc_out" || name == "sc_inout") {
break;
}
template_arguments.push_back( name );
}
return template_arguments;
}
size_t FindTemplateTypes::size() { return template_types_.size(); }
This diff could not be displayed because it is too large.
#ifndef _SYSTEMC_CLANG_H_
#define _SYSTEMC_CLANG_H_
#include <sstream>
#include <string>
#include <iostream>
#include "json.hpp"
namespace scpar {
using json = nlohmann::json;
template < typename T>
std::string to_string( T * pointer ) {
std::ostringstream address;
address << pointer;
return address.str();
}
};
#endif
#include "systemc.h"
SC_MODULE( test ){
sc_in<int> in;
sc_out<int> out;
void entry_function_1() {
while(true) {
// do nothing
}
}
void entry_function_2() {
while(true) {
// do nothing
}
}
SC_CTOR( test ) {
SC_THREAD(entry_function_1);
SC_THREAD(entry_function_2);
}
};
int sc_main(int argc, char *argv[]) {
sc_signal<int> sig1;
test test_instance("testing");
test_instance.in(sig1);
test_instance.out(sig1);
return 0;
}