851f1c1f by rmrf

TemplateType class added

1 parent d1888682
1 #include "FindTemplateTypes.h"
2
3 using namespace scpar;
4
5 //////////////////////////////////////////////////////////////////////
6 // TemplateType
7 //////////////////////////////////////////////////////////////////////
8
9 TemplateType::TemplateType( string name, const Type* t ):
10 type_name_{ name }, type_ptr_{t} {}
11
12 TemplateType::TemplateType( const TemplateType & from ) {
13 type_name_ = from.type_name_;
14 type_ptr_ = from.type_ptr_;
15 }
16
17 TemplateType::~TemplateType() {
18 type_ptr_ = nullptr;
19 }
20
21 string TemplateType::getTypeName() const { return type_name_; }
22
23 const Type* TemplateType::getTypePtr() { return type_ptr_; }
24
25 //////////////////////////////////////////////////////////////////////
26 // FindTemplateTypes
27 //////////////////////////////////////////////////////////////////////
28
29 // Constructor
30 FindTemplateTypes::FindTemplateTypes() {}
31
32 /// Copy constructor
33 FindTemplateTypes::FindTemplateTypes(const FindTemplateTypes &rhs) {
34 copy(rhs.template_types_.begin(), rhs.template_types_.end(),
35 back_inserter(template_types_));
36 }
37
38 FindTemplateTypes::FindTemplateTypes(const FindTemplateTypes *rhs) {
39 copy(rhs->template_types_.begin(), rhs->template_types_.end(),
40 back_inserter(template_types_));
41 }
42
43 // Destructor
44 FindTemplateTypes::~FindTemplateTypes() {
45 // TODO: We should convert these into objects.
46 template_types_.clear();
47 }
48
49 string FindTemplateTypes::getTemplateType() {
50 string s{};
51
52 // type_vector_t::iterator
53 for (auto mit = template_types_.begin(); mit != template_types_.end();
54 ++mit) {
55 // for ( auto const &mit: template_types_ ) {
56 if (mit != template_types_.begin()) {
57 s += "<";
58 }
59 s += mit->getTypeName();
60 if (mit != template_types_.begin()) {
61 s += ">";
62 }
63 }
64 return s;
65 }
66
67 FindTemplateTypes::type_vector_t FindTemplateTypes::Enumerate(const Type *type) {
68 template_types_.clear();
69 if (!type) {
70 return template_types_;
71 }
72
73 TraverseType(QualType(type, 0));
74 return template_types_;
75 }
76
77 bool FindTemplateTypes::VisitType( Type *type ) {
78 QualType q{type->getCanonicalTypeInternal()};
79 // cout << "\n###### Type: " << q.getAsString() << " \n" ;
80 if (type->isBuiltinType()) {
81 template_types_.push_back( TemplateType( q.getAsString(), type) );
82 //template_types_.push_back( pair<string, const Type *>(q.getAsString(), type) );
83 return true;
84 }
85
86 CXXRecordDecl *p_cxx_record{type->getAsCXXRecordDecl()};
87 if (p_cxx_record != nullptr) {
88 IdentifierInfo *info{p_cxx_record->getIdentifier()};
89 if (info != nullptr) {
90 template_types_.push_back( TemplateType( info->getNameStart(), type ) );
91 //template_types_.push_back( pair<string, const Type *>(info->getNameStart(), type) );
92 }
93 }
94 return true;
95 }
96
97 bool FindTemplateTypes::VisitIntegerLiteral(IntegerLiteral *l) {
98 //_os << "\n####### IntegerLiteral: " << l->getValue().toString(10,true) <<
99 //"\n"; _os << "== type ptr: " << l->getType().getTypePtr() << "\n"; _os <<
100 //"== type name: " << l->getType().getAsString() << "\n";
101 template_types_.push_back( TemplateType( l->getValue().toString(10, true), l->getType().getTypePtr() ) );
102 //template_types_.push_back(pair<string, const Type *>(l->getValue().toString(10, true), l->getType().getTypePtr()));
103
104 return true;
105 }
106
107 FindTemplateTypes::type_vector_t FindTemplateTypes::getTemplateArgumentsType() { return template_types_; }
108
109 void FindTemplateTypes::printTemplateArguments(llvm::raw_ostream &os) {
110 vector<string> template_arguments;
111 for (auto const &mit : template_types_) {
112 template_arguments.push_back( mit.getTypeName() );
113 }
114
115 // Print the template arguments to the output stream
116 os << ", " << template_arguments.size() << " arguments, ";
117 for (auto const &targ : template_arguments) {
118 os << targ << " ";
119 }
120 }
121
122 vector<string> FindTemplateTypes::getTemplateArguments() {
123 vector<string> template_arguments;
124 for (auto const &mit : template_types_) {
125 string name{ mit.getTypeName() };
126 if (name == "sc_in" || name == "sc_out" || name == "sc_inout") {
127 break;
128 }
129 template_arguments.push_back( name );
130 }
131 return template_arguments;
132 }
133
134 size_t FindTemplateTypes::size() { return template_types_.size(); }
This diff could not be displayed because it is too large.
1 #ifndef _SYSTEMC_CLANG_H_
2 #define _SYSTEMC_CLANG_H_
3 #include <sstream>
4 #include <string>
5 #include <iostream>
6 #include "json.hpp"
7
8 namespace scpar {
9
10
11 using json = nlohmann::json;
12
13 template < typename T>
14 std::string to_string( T * pointer ) {
15 std::ostringstream address;
16 address << pointer;
17 return address.str();
18 }
19
20 };
21
22 #endif
1 #include "systemc.h"
2 SC_MODULE( test ){
3 sc_in<int> in;
4 sc_out<int> out;
5 void entry_function_1() {
6 while(true) {
7 // do nothing
8 }
9 }
10
11 void entry_function_2() {
12 while(true) {
13 // do nothing
14 }
15 }
16
17 SC_CTOR( test ) {
18 SC_THREAD(entry_function_1);
19 SC_THREAD(entry_function_2);
20 }
21 };
22
23 int sc_main(int argc, char *argv[]) {
24
25 sc_signal<int> sig1;
26 test test_instance("testing");
27 test_instance.in(sig1);
28 test_instance.out(sig1);
29
30 return 0;
31 }