30 std::vector<llvm::APInt> *arr_sizes,
33 LLVM_DEBUG(llvm::dbgs() <<
"prefix "<< prefix <<
" HDLtype dump of templatetree args follows\n");
34 LLVM_DEBUG(template_argtp->
dump(llvm::dbgs()) ; );
35 LLVM_DEBUG(llvm::dbgs() <<
"as string: " << template_argtp->
dft() <<
"\n");
37 if (!(template_argtp && (template_argtp->
getRoot()))) {
38 LLVM_DEBUG(llvm::dbgs() <<
"HDLtype no root prefix is " << prefix <<
" "
39 << template_argtp <<
"\n");
46 if (
auto etype = dyn_cast<EnumType>(((template_argtp->
getRoot())->getDataPtr())->getTypePtr()) ) {
49 else tmps = ((template_argtp->
getRoot())->getDataPtr())->getTypeName();
50 if ((((template_argtp->
getRoot())->getDataPtr())->getTypePtr())->isBuiltinType())
52 hNodep h_typeinfo =
new hNode(hNode::hdlopsEnum::hTypeinfo);
55 hNodep h_typ =
new hNode(tmps, hNode::hdlopsEnum::hType);
56 if ((arr_sizes) && (arr_sizes->size() > 0)) {
57 string arr_string =
"array";
59 for (
int i = 0; i < arr_sizes->size(); i++) {
60 arr_size = arr_sizes->at(i).getLimitedValue();
63 hNodep h_arr =
new hNode(arr_string, hNode::hdlopsEnum::hType);
70 if ((((template_argtp->
getRoot())->getDataPtr())->getTypePtr())->isBuiltinType())
return;
72 if ((vectreeptr.size() == 0) && ((template_argtp->
getRoot())->getDataPtr())->getTypePtr()->isStructureType())
74 LLVM_DEBUG(llvm::dbgs() <<
"root node has no children, is structure type, type dump follows\n");
75 LLVM_DEBUG(((template_argtp->
getRoot())->getDataPtr())->getTypePtr()->dump() ; );
86 for (
int i = vectreeptr.size() - 1; i >= 0; i--) {
97 hNodep &h_info,
bool generate_initial_htype) {
100 string tmps = (node->
getDataPtr())->getTypeName();
101 if (((node->
getDataPtr())->getTypePtr())->isBuiltinType())
106 LLVM_DEBUG(llvm::dbgs() <<
"generatetype node name is " << tmps <<
" as string is " << node->
toString() <<
"\n");
108 if (generate_initial_htype) {
111 : hNode::hdlopsEnum::hType);
114 else nodetyp = h_info;
115 if (((node->
getDataPtr())->getTypePtr())->isBuiltinType())
122 auto const vectreeptr{treehead->
getChildren(node)};
124 for (
int i = vectreeptr.size() - 1; i >= 0; i--) {
135 const Type *typ = node->
getDataPtr()->getTypePtr();
153 string tmps_full = treehead->
dft();
154 size_t type_ix = tmps_full.find(tmps);
155 if (type_ix != string::npos) {
156 tmps = tmps_full.substr(type_ix);
160 LLVM_DEBUG(llvm::dbgs() <<
"user defined type full " << tmps+
" " + tmps_full <<
"\n");
161 const RecordType *tstp =
162 dyn_cast<RecordType>((node->
getDataPtr())->getTypePtr());
164 LLVM_DEBUG(llvm::dbgs() <<
"generatetype found record type and type pointer from RecordType is " << tstp <<
"\n");
168 ((tstp->getDecl())->getTypeForDecl())->getCanonicalTypeInternal();
172 ((node->
getDataPtr())->getTypePtr())->getCanonicalTypeInternal();
179 hNodep h_typdef =
new hNode(typname, hNode::hdlopsEnum::hTypedef);
180 LLVM_DEBUG(llvm::dbgs() <<
"addtype entered with type name " << typname
182 const Type *typ = qtyp.getTypePtr();
183 LLVM_DEBUG( typ->dump(llvm::dbgs(), astcontext ); );
184 if (typ->isBuiltinType()) {
185 string tmps = qtyp.getAsString();
187 hNodep hprim =
new hNode(tmps, hNode::hdlopsEnum::hType);
188 LLVM_DEBUG(llvm::dbgs() <<
"addtype found prim type " << tmps <<
"\n");
193 if (
const RecordType *rectype = dyn_cast<RecordType>(typ)) {
194 LLVM_DEBUG(llvm::dbgs()
195 <<
"addtype record type found, name is " << typname <<
" rectype ptr is " << rectype <<
"\n");
196 if (isa<ClassTemplateSpecializationDecl>(rectype->getDecl())) {
197 LLVM_DEBUG(llvm::dbgs()
198 <<
"addtype isa template specialzation decl found, name is "
200 ClassTemplateSpecializationDecl *ctsd =
201 dyn_cast<ClassTemplateSpecializationDecl>(rectype->getDecl());
202 ClassTemplateDecl *ctd = ctsd->getSpecializedTemplate();
203 LLVM_DEBUG(ctd->dump(llvm::dbgs()));
204 LLVM_DEBUG(llvm::dbgs() <<
"####### ============================== "
205 "MATCHER ========================= ##### \n");
207 MatchFinder matchRegistry{};
209 matchRegistry.match(*ctsd, astcontext);
210 LLVM_DEBUG(llvm::dbgs() <<
"####### ============================== END "
211 "MATCHER ========================= ##### \n");
213 TemplateParameterList *tpl = ctd->getTemplateParameters();
214 LLVM_DEBUG(llvm::dbgs() <<
"addtype here are template parameters\n");
215 for (
auto param : *tpl) {
216 LLVM_DEBUG(llvm::dbgs() <<
"addtype template param name is "
217 << param->getName() <<
"\n");
218 param->dump(llvm::dbgs());
219 LLVM_DEBUG(llvm::dbgs() <<
"end dump of param\n");
224 std::vector<const FieldDecl *> fields;
225 template_matcher.getArgFields(fields);
226 if (fields.size() > 0) {
227 for (
const FieldDecl *fld : fields) {
231 }
else if (!rectype->getDecl()->field_empty()) {
232 for (
auto const &fld : rectype->getDecl()->fields()) {
237 LLVM_DEBUG(llvm::dbgs() <<
"Found record with no fields, name is "
238 << (rectype->getDecl())->getName() <<
"\n");
240 new hNode(rectype->getDecl()->getName().str(), hNode::hdlopsEnum::hType));
248 LLVM_DEBUG(llvm::dbgs() <<
"field of record type \n");
249 LLVM_DEBUG(fld->dump(llvm::dbgs()));
250 LLVM_DEBUG(llvm::dbgs() <<
"field: found name " << fld->getName() <<
"\n");
252 const Type *field_type{fld->getType().getTypePtr()};
257 auto template_args{find_tt.getTemplateArgTreePtr()};
259 new hNode(fld->getNameAsString(), hNode::hdlopsEnum::hTypeField);
261 LLVM_DEBUG(llvm::dbgs() <<
"calling generatetype with template args of field\n");
262 if (template_args->getRoot())
263 generatetype(template_args->getRoot(), template_args, hfld);
265 LLVM_DEBUG(llvm::dbgs() <<
"FindTemplateTypes returned null root\n");
void SCtype2hcode(string prefix, Tree< TemplateType > *template_argtp, std::vector< llvm::APInt > *arr_sizes, hNode::hdlopsEnum h_op, hNodep &h_info)
void generatetype(systemc_clang::TreeNode< systemc_clang::TemplateType > *const &node, systemc_clang::Tree< systemc_clang::TemplateType > *const &treehead, hNodep &h_info, bool generate_initial_htype=true)