146 llvm::raw_fd_ostream &HCodeOut) {
156 LLVM_DEBUG( llvm::dbgs() <<
"Processing module " << mod->
getName() <<
" instance " << mod->
getInstanceName() <<
"\n");
157 LLVM_DEBUG( llvm::dbgs() <<
"dumping base instances \n");
159 LLVM_DEBUG( llvm::dbgs() <<
"end base instances \n");
162 LLVM_DEBUG( llvm::dbgs() <<
"Methods in this module\n");
163 for (
const auto &method : cdecl->methods()) {
165 if (method->isVirtual()) {
166 LLVM_DEBUG( llvm::dbgs() <<
"Virtual ");
168 LLVM_DEBUG(llvm::dbgs() <<
"Method name is " << method->getParent()->getNameAsString() <<
"::" << method->getNameAsString()
170 QualType qtype{method->getThisType()};
171 LLVM_DEBUG(qtype.getTypePtr()->dump());
172 LLVM_DEBUG(llvm::dbgs() <<
"\n");
173 if (method->getBody() != NULL) {
174 LLVM_DEBUG(llvm::dbgs() <<
"Body of method non-null\n");
177 else LLVM_DEBUG(llvm::dbgs() <<
"Empty method body\n");
179 for (
const auto &ometh : method->overridden_methods()) {
180 LLVM_DEBUG(llvm::dbgs() <<
" overridden method " << ometh->getParent()->getNameAsString() <<
"::" << ometh->getNameAsString() <<
"\n");
181 if (ometh->hasBody()) {
182 overridden_method_map[ometh] = method;
184 else LLVM_DEBUG(llvm::dbgs() <<
"Empty overridden method body\n");
189 LLVM_DEBUG(llvm::dbgs() <<
"Overridden method map\n");
190 for (
auto ov: overridden_method_map) {
191 LLVM_DEBUG(llvm::dbgs() <<
"Overridden method\n");
192 LLVM_DEBUG(ov.first->dump(llvm::dbgs()));
193 LLVM_DEBUG(llvm::dbgs() <<
"Overriding method\n");
194 LLVM_DEBUG(ov.second->dump(llvm::dbgs()));
196 LLVM_DEBUG(llvm::dbgs() <<
"end Overridden method map\n");
197 LLVM_DEBUG( llvm::dbgs() <<
"End Methods in this module\n\n");
209 LLVM_DEBUG(llvm::dbgs() <<
"submodule count is " << submodv.size() <<
"\n");
220 new hNode(hNode::hdlopsEnum::hPortsigvarlist);
225 for (
int i = 0; i <= basemods.size(); i++) {
230 h_ports, mod_vname_map);
237 if (i == basemods.size())
break;
243 for (
const auto &smod : submodv) {
245 if (smod->getInstanceInfo().isArrayType()) {
246 LLVM_DEBUG(llvm::dbgs() <<
"Array submodule " << smod->getInstanceInfo().getVarName() <<
"\n");
249 LLVM_DEBUG(llvm::dbgs() <<
"Non-Array submodule " << smod->getInstanceInfo().getVarName() <<
"\n");
262 LLVM_DEBUG(llvm::dbgs() <<
"Submod name is " << smod->getName() <<
"\n");
264 LLVM_DEBUG(llvm::dbgs() <<
"Instance Var name is " << smod->getInstanceInfo().getVarName() <<
"\n");
265 LLVM_DEBUG(llvm::dbgs() <<
"Instance name is " << smod->getInstanceInfo().getInstanceNames()[0] <<
"\n");
266 string instname = smod->getInstanceInfo().getVarName();
269 new hNode(instname, hNode::hdlopsEnum::hModdecl);
271 hNodep h_smodtypinfo =
new hNode(hNode::hdlopsEnum::hTypeinfo);
274 h_smod->
set(instname);
277 hNodep h_smod_typep =
new hNode( hNode::hdlopsEnum::hType);
278 if (smod->getInstanceInfo().isArrayType()) {
279 h_smod_typep->
set(
"array##"+std::to_string(smod->getInstanceInfo().getInstanceNames().size()));
285 h_smodtypinfo->
child_list.push_back(h_smod_typep);
291 hNodep h_modinitblockhead =
new hNode( hNode::hdlopsEnum::hNoop);
293 hNodep h_allsenslists =
new hNode( hNode::hdlopsEnum::hNoop);
294 for (
int i = 0; i <= basemods.size(); i++) {
297 hNode::hdlopsEnum::hModinitblock);
304 LLVM_DEBUG(llvm::dbgs() <<
"HDL output for module constructor body\n");
305 LLVM_DEBUG(h_constructor->
print(llvm::dbgs()));
309 h_modinitblockhead->
child_list.push_back(modinithp);
311 std::vector<hNodep> slvec;
313 h_allsenslists->
child_list.insert(h_allsenslists->
child_list.end(), slvec.begin(), slvec.end());
317 if (i == basemods.size())
break;
328 LLVM_DEBUG(llvm::dbgs() <<
"Module vname map size is " << mod_vname_map.
size() <<
" \n");
331 hNodep h_processes =
new hNode(hNode::hdlopsEnum::hProcesses);
333 for (
int i = 0; i <= basemods.size(); i++) {
336 if (i == basemods.size())
break;
343 for (
auto const &var: mod_vname_map) {
344 if (var.second.referenced) {
345 hNodep hvp =
new hNode(
"_main_"+var.second.h_vardeclp->getname(), var.second.h_vardeclp->getopc());
346 hvp->
child_list = var.second.h_vardeclp->child_list;
353 if (h_modinitblockhead->
size()>0) {
357 for (
int i = 1; i< h_modinitblockhead->
size(); i++) {
360 h_modinitblockhead->
child_list[i]->child_list.begin(),
361 h_modinitblockhead->
child_list[i]->child_list.end());
370 std::set<Decl *> generated_functions;
371 bool addfunc =
false;
374 LLVM_DEBUG(llvm::dbgs() <<
"Module Method/Function Map\n");
379 LLVM_DEBUG(llvm::dbgs()
382 LLVM_DEBUG(llvm::dbgs()
383 <<
"size of generated_functions is " << generated_functions.size() <<
"\n");
384 LLVM_DEBUG(llvm::dbgs()
385 <<
"size of modmethodecls is " << modmethodecls.
size() <<
"\n");
388 for (
auto const &m : modmethodecls) {
390 LLVM_DEBUG(llvm::dbgs() <<
"Method --------\n"
391 << m.first <<
" " << m.second.newn <<
" generatedcount is " << generated_functions.count(m.first)<<
"\n");
392 LLVM_DEBUG(m.first->dump(llvm::dbgs()));
393 LLVM_DEBUG(llvm::dbgs() <<
"---------\n");
394 if (generated_functions.count(m.first) > 0)
continue;
395 generated_functions.insert(m.first);
397 if (m.first->hasBody()) {
400 hNodep hfunc =
new hNode(m.second.newn, hNode::hdlopsEnum::hFunction);
401 QualType qrettype = m.first->getReturnType();
402 const clang::Type *rettype = qrettype.getTypePtr();
408 hNode::hdlopsEnum::hFunctionRetType, hfunc);
409 CXXMethodDecl * thismethod = dyn_cast<CXXMethodDecl>(m.first);
410 bool isUserDefinedMethod = (thismethod != NULL) && (modmethodecls.
methodobjtypemap.count(thismethod));
411 if (thismethod != NULL) {
412 LLVM_DEBUG(llvm::dbgs() << thismethod->getParent()->getQualifiedNameAsString() <<
" " << m.second.newn <<
" is a Method\n");
414 else LLVM_DEBUG(llvm::dbgs() << m.second.newn <<
" is a Function\n");
415 if ((m.first->getNumParams() > 0) || (thismethod != NULL)) {
416 hNodep hparams =
new hNode(hNode::hdlopsEnum::hFunctionParams);
417 hNodep hparam_assign_list =
new hNode(hNode::hdlopsEnum::hCStmt);
420 if (isUserDefinedMethod) {
421 hNodep hthisparam =
new hNode(
"hthis", hNode::hdlopsEnum::hFunctionParamIO);
422 hNodep hthistype =
new hNode(hNode::hdlopsEnum::hTypeinfo);
425 LLVM_DEBUG(llvm::dbgs() <<
"Couldn't find methodobjtypemap entry for " << thismethod <<
"\n");
429 LLVM_DEBUG(llvm::dbgs() <<
"Found methodobjtypemap entry for " << thismethod <<
" and userrectypes gives " <<
HDLt.
usertype_info.
userrectypes[tp] <<
"\n");
432 LLVM_DEBUG(llvm::dbgs() <<
"Couldn't find userrectypes entry for " << tp <<
"\n");
437 hNode::hdlopsEnum::hType));
438 hthisparam->
append(hthistype);
439 hparams->
append(hthisparam);
441 for (
int i = 0; i < m.first->getNumParams(); i++) {
442 ParmVarDecl *vardecl = m.first->getParamDecl(i);
443 QualType q = vardecl->getType();
444 const clang::Type *tp = q.getTypePtr();
445 LLVM_DEBUG(llvm::dbgs() <<
"ProcessParmVarDecl type name is "
446 << q.getAsString() <<
"\n");
462 llvm::dbgs() <<
"@@@@ isSCMacro does not match. t1 = " << t1 <<
", t2 = " << t2 <<
" " << m.second.oldn <<
"\n";
463 assert(0 &&
"isSCMacro does not match");
468 paramtype = hNode::hdlopsEnum::hFunctionParamI;
470 else if ((vardecl->getType()->isReferenceType()) && !(vardecl->getType().getNonReferenceType().isConstQualified()))
471 paramtype = hNode::hdlopsEnum::hFunctionParamRef;
477 paramtype = hNode::hdlopsEnum::hFunctionParamI;
479 string objname = vardecl->getName().str()+
"_actual";
482 &array_sizes, hNode::hdlopsEnum::hVardecl, h_ports);
484 hNodep hparam_assign =
new hNode(
"=", hNode::hdlopsEnum::hBinop);
486 hparam_assign->
append(hv);
487 hv =
new hNode(vardecl->getName().str(), hNode::hdlopsEnum::hVarref);
489 hparam_assign->
append(hv);
490 hparam_assign_list->
append(hparam_assign);
494 &array_sizes, paramtype, hparams);
497 if (hparam_assign_list->
child_list.size()>0) {
498 hNodep htmpf =
new hNode( hNode::hdlopsEnum::hCStmt);
499 if (isUserDefinedMethod) {
513 if (isUserDefinedMethod) {
522 LLVM_DEBUG(llvm::dbgs() <<
" No parameters found for " << m.second.newn <<
"\n");
523 hNodep htmpf =
new hNode( hNode::hdlopsEnum::hCStmt);
535 h_module->
print(HCodeOut);
539 for (
const auto &smod : submodv) {
542 LLVM_DEBUG(llvm::dbgs() <<
"generate submodule " << smod->getName()
543 <<
" renamed " << modname <<
"\n");
544 hNodep h_submod =
new hNode(modname, hNode::hdlopsEnum::hModule);
609 const unsigned cxx_record_id1 =
main_diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Remark,
"Pointer type not synthesized, '%0' skipped.");
610 for (ModuleInstance::portMapType::iterator mit = pmap.begin(); mit != pmap.end();
612 string objname = get<0>(*mit);
614 LLVM_DEBUG(llvm::dbgs() <<
"object name is " << objname <<
" and h_op is "
622 clang::DiagnosticBuilder diag_builder{
main_diag_engine.Report(decl->getLocation(), cxx_record_id1)};
623 diag_builder << decl->getName();
646 LLVM_DEBUG(llvm::dbgs() <<
"duplicate object " << objname <<
"\n");
652 if ((h_op == hNode::hdlopsEnum::hVardecl) && (portdecl)) mod_vname_map.
add_entry(portdecl, objname, h_info->
child_list.back());
656 if (h_op == hNode::hdlopsEnum::hVardecl) {
659 LLVM_DEBUG(llvm::dbgs() <<
"var decl dump follows\n");
660 LLVM_DEBUG(vard->dump(llvm::dbgs()));
661 if (vard->hasInit()) {
662 APValue *apval = vard->getEvaluatedValue();
663 if (apval && apval->isInt()) {
665 hNode::hdlopsEnum::hLiteral);
666 hNodep h_varinit =
new hNode(hNode::hdlopsEnum::hVarInit);
668 (h_info->
child_list.back())->child_list.push_back(h_varinit);
674 LLVM_DEBUG(llvm::dbgs() <<
"field decl dump follows\n");
675 LLVM_DEBUG(fieldd->dump(llvm::dbgs()));
676 Expr* initializer = fieldd->getInClassInitializer();
677 if (initializer != NULL) {
678 LLVM_DEBUG(llvm::dbgs() <<
"field initializer dump follows\n");
679 LLVM_DEBUG(initializer->dump(llvm::dbgs(),
getContext()));
680 hNodep h_init =
new hNode(hNode::hdlopsEnum::hVarInit);
681 if (
const CXXConstructExpr *ce = dyn_cast<CXXConstructExpr>(initializer->IgnoreUnlessSpelledInSource())) {
682 if (ce->isListInitialization()) {
683 for (
const auto arg : ce->arguments()) {
684 const Expr *ex{arg->IgnoreUnlessSpelledInSource()};
686 if (
auto il = dyn_cast<IntegerLiteral>(ex)) {
687 llvm::dbgs() <<
">> IntegerLiteral value is " << il->getValue() <<
"\n";
691 if (
auto booll = dyn_cast<CXXBoolLiteralExpr>(ex)) {
692 bool val = booll->getValue();
693 llvm::dbgs() <<
">> CXXBoolLiteralExpr value is " << val <<
"\n";
695 (h_info->
child_list.back())->child_list.push_back(h_init);
702 (h_info->
child_list.back())->child_list.push_back(h_init);