136 llvm::raw_fd_ostream &HCodeOut) {
146 LLVM_DEBUG( llvm::dbgs() <<
"Processing module " << mod->
getName() <<
" instance " << mod->
getInstanceName() <<
"\n");
147 LLVM_DEBUG( llvm::dbgs() <<
"dumping base instances \n");
149 LLVM_DEBUG( llvm::dbgs() <<
"end base instances \n");
152 LLVM_DEBUG( llvm::dbgs() <<
"Methods in this module\n");
153 for (
const auto &method : cdecl->methods()) {
155 if (method->isVirtual()) {
156 LLVM_DEBUG( llvm::dbgs() <<
"Virtual ");
158 LLVM_DEBUG(llvm::dbgs() <<
"Method name is " << method->getParent()->getNameAsString() <<
"::" << method->getNameAsString()
160 QualType qtype{method->getThisType()};
161 LLVM_DEBUG(qtype.getTypePtr()->dump());
162 LLVM_DEBUG(llvm::dbgs() <<
"\n");
163 if (method->getBody() != NULL) {
164 LLVM_DEBUG(llvm::dbgs() <<
"Body of method non-null\n");
167 else LLVM_DEBUG(llvm::dbgs() <<
"Empty method body\n");
169 for (
const auto &ometh : method->overridden_methods()) {
170 LLVM_DEBUG(llvm::dbgs() <<
" overridden method " << ometh->getParent()->getNameAsString() <<
"::" << ometh->getNameAsString() <<
"\n");
171 if (ometh->hasBody()) {
172 overridden_method_map[ometh] = method;
174 else LLVM_DEBUG(llvm::dbgs() <<
"Empty overridden method body\n");
179 LLVM_DEBUG(llvm::dbgs() <<
"Overridden method map\n");
180 for (
auto ov: overridden_method_map) {
181 LLVM_DEBUG(llvm::dbgs() <<
"Overridden method\n");
182 LLVM_DEBUG(ov.first->dump(llvm::dbgs()));
183 LLVM_DEBUG(llvm::dbgs() <<
"Overriding method\n");
184 LLVM_DEBUG(ov.second->dump(llvm::dbgs()));
186 LLVM_DEBUG(llvm::dbgs() <<
"end Overridden method map\n");
187 LLVM_DEBUG( llvm::dbgs() <<
"End Methods in this module\n\n");
199 LLVM_DEBUG(llvm::dbgs() <<
"submodule count is " << submodv.size() <<
"\n");
210 new hNode(hNode::hdlopsEnum::hPortsigvarlist);
215 for (
int i = 0; i <= basemods.size(); i++) {
220 h_ports, mod_vname_map);
227 if (i == basemods.size())
break;
233 for (
const auto &smod : submodv) {
234 std::vector<std::string> instnames;
235 if (smod->getInstanceInfo().isArrayType()) {
236 LLVM_DEBUG(llvm::dbgs() <<
"Array submodule " << smod->getInstanceInfo().getVarName() <<
"\n");
239 LLVM_DEBUG(llvm::dbgs() <<
"Non-Array submodule " << smod->getInstanceInfo().getVarName() <<
"\n");
247 bool frsttime =
true;
248 for (
auto instname: instnames) {
249 LLVM_DEBUG(llvm::dbgs() <<
"Instance " << instname <<
"\n");
252 new hNode(instname, hNode::hdlopsEnum::hModdecl);
254 hNodep h_smodtypinfo =
new hNode(hNode::hdlopsEnum::hTypeinfo);
257 h_smod->
set(instname);
269 hNodep h_modinitblockhead =
new hNode( hNode::hdlopsEnum::hNoop);
271 hNodep h_allsenslists =
new hNode( hNode::hdlopsEnum::hNoop);
272 for (
int i = 0; i <= basemods.size(); i++) {
275 hNode::hdlopsEnum::hModinitblock);
281 LLVM_DEBUG(llvm::dbgs() <<
"HDL output for module constructor body\n");
282 LLVM_DEBUG(h_constructor->
print(llvm::dbgs()));
286 h_modinitblockhead->
child_list.push_back(modinithp);
288 std::vector<hNodep> slvec;
290 h_allsenslists->
child_list.insert(h_allsenslists->
child_list.end(), slvec.begin(), slvec.end());
294 if (i == basemods.size())
break;
305 LLVM_DEBUG(llvm::dbgs() <<
"Module vname map size is " << mod_vname_map.
size() <<
" \n");
308 hNodep h_processes =
new hNode(hNode::hdlopsEnum::hProcesses);
310 for (
int i = 0; i <= basemods.size(); i++) {
313 if (i == basemods.size())
break;
320 for (
auto const &var: mod_vname_map) {
321 if (var.second.referenced) {
322 hNodep hvp =
new hNode(
"_main_"+var.second.h_vardeclp->getname(), var.second.h_vardeclp->getopc());
323 hvp->
child_list = var.second.h_vardeclp->child_list;
330 if (h_modinitblockhead->
size()>0) {
334 for (
int i = 1; i< h_modinitblockhead->
size(); i++) {
337 h_modinitblockhead->
child_list[i]->child_list.begin(),
338 h_modinitblockhead->
child_list[i]->child_list.end());
347 std::set<Decl *> generated_functions;
348 bool addfunc =
false;
351 LLVM_DEBUG(llvm::dbgs() <<
"Module Method/Function Map\n");
356 LLVM_DEBUG(llvm::dbgs()
359 LLVM_DEBUG(llvm::dbgs()
360 <<
"size of generated_functions is " << generated_functions.size() <<
"\n");
361 LLVM_DEBUG(llvm::dbgs()
362 <<
"size of modmethodecls is " << modmethodecls.
size() <<
"\n");
365 for (
auto const &m : modmethodecls) {
367 LLVM_DEBUG(llvm::dbgs() <<
"Method --------\n"
368 << m.first <<
" " << m.second.newn <<
" generatedcount is " << generated_functions.count(m.first)<<
"\n");
369 LLVM_DEBUG(m.first->dump(llvm::dbgs()));
370 LLVM_DEBUG(llvm::dbgs() <<
"---------\n");
371 if (generated_functions.count(m.first) > 0)
continue;
372 generated_functions.insert(m.first);
374 if (m.first->hasBody()) {
377 hNodep hfunc =
new hNode(m.second.newn, hNode::hdlopsEnum::hFunction);
378 QualType qrettype = m.first->getReturnType();
379 const clang::Type *rettype = qrettype.getTypePtr();
385 hNode::hdlopsEnum::hFunctionRetType, hfunc);
386 CXXMethodDecl * thismethod = dyn_cast<CXXMethodDecl>(m.first);
387 bool isUserDefinedMethod = (thismethod != NULL) && (modmethodecls.
methodobjtypemap.count(thismethod));
388 if (thismethod != NULL) {
389 LLVM_DEBUG(llvm::dbgs() << thismethod->getParent()->getQualifiedNameAsString() <<
" " << m.second.newn <<
" is a Method\n");
391 else LLVM_DEBUG(llvm::dbgs() << m.second.newn <<
" is a Function\n");
392 if ((m.first->getNumParams() > 0) || (thismethod != NULL)) {
393 hNodep hparams =
new hNode(hNode::hdlopsEnum::hFunctionParams);
394 hNodep hparam_assign_list =
new hNode(hNode::hdlopsEnum::hCStmt);
397 if (isUserDefinedMethod) {
398 hNodep hthisparam =
new hNode(
"hthis", hNode::hdlopsEnum::hFunctionParamIO);
399 hNodep hthistype =
new hNode(hNode::hdlopsEnum::hTypeinfo);
402 LLVM_DEBUG(llvm::dbgs() <<
"Couldn't find methodobjtypemap entry for " << thismethod <<
"\n");
406 LLVM_DEBUG(llvm::dbgs() <<
"Found methodobjtypemap entry for " << thismethod <<
" and userrectypes gives " <<
HDLt.
usertype_info.
userrectypes[tp] <<
"\n");
409 LLVM_DEBUG(llvm::dbgs() <<
"Couldn't find userrectypes entry for " << tp <<
"\n");
414 hNode::hdlopsEnum::hType));
415 hthisparam->
append(hthistype);
416 hparams->
append(hthisparam);
418 for (
int i = 0; i < m.first->getNumParams(); i++) {
419 ParmVarDecl *vardecl = m.first->getParamDecl(i);
420 QualType q = vardecl->getType();
421 const clang::Type *tp = q.getTypePtr();
422 LLVM_DEBUG(llvm::dbgs() <<
"ProcessParmVarDecl type name is "
423 << q.getAsString() <<
"\n");
439 llvm::dbgs() <<
"@@@@ isSCMacro does not match. t1 = " << t1 <<
", t2 = " << t2 <<
" " << m.second.oldn <<
"\n";
440 assert(0 &&
"isSCMacro does not match");
445 paramtype = hNode::hdlopsEnum::hFunctionParamI;
447 else if ((vardecl->getType()->isReferenceType()) && !(vardecl->getType().getNonReferenceType().isConstQualified()))
448 paramtype = hNode::hdlopsEnum::hFunctionParamRef;
451 paramtype = hNode::hdlopsEnum::hFunctionParamI;
453 string objname = vardecl->getName().str()+
"_actual";
456 &array_sizes, hNode::hdlopsEnum::hVardecl, h_ports);
458 hNodep hparam_assign =
new hNode(
"=", hNode::hdlopsEnum::hBinop);
460 hparam_assign->
append(hv);
461 hv =
new hNode(vardecl->getName().str(), hNode::hdlopsEnum::hVarref);
462 hparam_assign->
append(hv);
463 hparam_assign_list->
append(hparam_assign);
467 &array_sizes, paramtype, hparams);
470 if (hparam_assign_list->
child_list.size()>0) {
471 hNodep htmpf =
new hNode( hNode::hdlopsEnum::hCStmt);
472 if (isUserDefinedMethod) {
486 if (isUserDefinedMethod) {
495 LLVM_DEBUG(llvm::dbgs() <<
" No parameters found for " << m.second.newn <<
"\n");
496 hNodep htmpf =
new hNode( hNode::hdlopsEnum::hCStmt);
508 h_module->
print(HCodeOut);
512 for (
const auto &smod : submodv) {
515 LLVM_DEBUG(llvm::dbgs() <<
"generate submodule " << smod->getName()
516 <<
" renamed " << modname <<
"\n");
517 hNodep h_submod =
new hNode(modname, hNode::hdlopsEnum::hModule);
582 const unsigned cxx_record_id1 =
main_diag_engine.getCustomDiagID(clang::DiagnosticsEngine::Remark,
"Pointer type not synthesized, '%0' skipped.");
583 for (ModuleInstance::portMapType::iterator mit = pmap.begin(); mit != pmap.end();
585 string objname = get<0>(*mit);
587 LLVM_DEBUG(llvm::dbgs() <<
"object name is " << objname <<
" and h_op is "
595 clang::DiagnosticBuilder diag_builder{
main_diag_engine.Report(decl->getLocation(), cxx_record_id1)};
596 diag_builder << decl->getName();
619 LLVM_DEBUG(llvm::dbgs() <<
"duplicate object " << objname <<
"\n");
625 if ((h_op == hNode::hdlopsEnum::hVardecl) && (portdecl)) mod_vname_map.
add_entry(portdecl, objname, h_info->
child_list.back());
629 if (h_op == hNode::hdlopsEnum::hVardecl) {
632 LLVM_DEBUG(llvm::dbgs() <<
"var decl dump follows\n");
633 LLVM_DEBUG(vard->dump(llvm::dbgs()));
634 if (vard->hasInit()) {
635 APValue *apval = vard->getEvaluatedValue();
636 if (apval && apval->isInt()) {
638 hNode::hdlopsEnum::hLiteral);
639 hNodep h_varinit =
new hNode(hNode::hdlopsEnum::hVarInit);
641 (h_info->
child_list.back())->child_list.push_back(h_varinit);
647 LLVM_DEBUG(llvm::dbgs() <<
"field decl dump follows\n");
648 LLVM_DEBUG(fieldd->dump(llvm::dbgs()));
649 Expr* initializer = fieldd->getInClassInitializer();
650 if (initializer != NULL) {
651 LLVM_DEBUG(llvm::dbgs() <<
"field initializer dump follows\n");
652 LLVM_DEBUG(initializer->dump(llvm::dbgs(),
getContext()));
653 hNodep h_init =
new hNode(hNode::hdlopsEnum::hVarInit);
654 if (
const CXXConstructExpr *ce = dyn_cast<CXXConstructExpr>(initializer->IgnoreUnlessSpelledInSource())) {
655 if (ce->isListInitialization()) {
656 for (
const auto arg : ce->arguments()) {
657 const Expr *ex{arg->IgnoreUnlessSpelledInSource()};
659 if (
auto il = dyn_cast<IntegerLiteral>(ex)) {
660 llvm::dbgs() <<
">> IntegerLiteral value is " << il->getValue() <<
"\n";
664 if (
auto booll = dyn_cast<CXXBoolLiteralExpr>(ex)) {
665 bool val = booll->getValue();
666 llvm::dbgs() <<
">> CXXBoolLiteralExpr value is " << val <<
"\n";
668 (h_info->
child_list.back())->child_list.push_back(h_init);
675 (h_info->
child_list.back())->child_list.push_back(h_init);
761 clang::DiagnosticsEngine::Remark,
"non-SC_METHOD/THREAD '%0' skipped.");
763 for (
auto const &pm_entry : pm) {
766 if (efc->getProcessType() == PROCESS_TYPE::METHOD) {
767 hNodep h_process =
new hNode(efc->getName(), hNode::hdlopsEnum::hProcess);
768 LLVM_DEBUG(llvm::dbgs() <<
"process " << efc->getName() <<
"\n");
769 CXXMethodDecl *emd = efc->getEntryMethod();
770 if (emd->hasBody()) {
771 hNodep h_body =
new hNode(efc->getName(), hNode::hdlopsEnum::hMethod);
772 LLVM_DEBUG(llvm::dbgs() <<
"HDLMain allmethodecls_ size is " <<
allmethodecls.
size() <<
"\n");
779 LLVM_DEBUG(llvm::dbgs() <<
"Entry Method is null\n");
782 if ((efc->getProcessType() == PROCESS_TYPE::THREAD) ||
783 (efc->getProcessType() == PROCESS_TYPE::CTHREAD)) {
784 hNodep h_thread =
new hNode(efc->getName(), hNode::hdlopsEnum::hProcess);
785 LLVM_DEBUG(llvm::dbgs() <<
"thread " << efc->getName() <<
"\n");
786 CXXMethodDecl *emd = efc->getEntryMethod();
787 if (emd->hasBody()) {
792 (efc->getEntryMethod())->getLocation(),
794 clang::DiagnosticsEngine::Remark,
"Reset not found in SC_[C]THREAD."))};
795 diag_builder <<
"\n";
796 auto h_resetvarinfo = (got ==
threadresetmap.end() ? NULL : got->second);
806 LLVM_DEBUG(llvm::dbgs() <<
"Entry Thread is null\n");
810 clang::DiagnosticBuilder diag_builder{
main_diag_engine.Report((efc->getEntryMethod())->getLocation(), cxx_record_id1)};
811 diag_builder << efc->getName();
813 LLVM_DEBUG(llvm::dbgs() <<
"process " << efc->getName()
814 <<
" not SC_METHOD, THREAD, or CTHREAD, skipping\n");