5#include "clang/Basic/OperatorKinds.h"
6#include "clang/Basic/Diagnostic.h"
12#include <unordered_map>
20#define DEBUG_TYPE "HDL"
67 : diag_e{diag_engine},
68 ast_context_{ast_context},
69 mod_vname_map_{mod_vname_map},
70 allmethodecls_{allmethodecls},
71 overridden_method_map_{overridden_method_map} {
72 LLVM_DEBUG(llvm::dbgs() <<
"Entering HDLBody constructor\n");
79 LLVM_DEBUG(llvm::dbgs() <<
"Entering HDLBody Run Method\n");
102 LLVM_DEBUG(llvm::dbgs() <<
"Exiting HDLBody Run Method\n");
105 LLVM_DEBUG(llvm::dbgs() <<
"[[ Destructor HDLBody ]]\n");
112 LLVM_DEBUG(llvm::dbgs() <<
"In TraverseStmt\n");
113 if (stmt ==
nullptr)
return false;
115 if (isa<CompoundStmt>(stmt)) {
116 LLVM_DEBUG(llvm::dbgs()
117 <<
"calling traverse compoundstmt from traversestmt\n");
119 }
else if (isa<DeclStmt>(stmt)) {
120 RecursiveASTVisitor::TraverseStmt(stmt);
122 }
else if (isa<CallExpr>(stmt)) {
123 if (CXXOperatorCallExpr *opercall = dyn_cast<CXXOperatorCallExpr>(stmt)) {
124 LLVM_DEBUG(llvm::dbgs() <<
"found cxxoperatorcallexpr\n");
126 }
else if (isa<CXXMemberCallExpr>(stmt)) {
131 }
else if (isa<CXXDefaultArgExpr>(stmt)) {
133 }
else if (isa<ReturnStmt>(stmt)) {
134 RecursiveASTVisitor::TraverseStmt(stmt);
135 }
else if (isa<CXXTemporaryObjectExpr>(stmt)) {
136 RecursiveASTVisitor::TraverseStmt(stmt);
138 if (isa<CXXConstructExpr>(stmt)) {
139 CXXConstructExpr *exp = (CXXConstructExpr *)stmt;
145 if ((exp->getNumArgs() == 1) &&
146 ((isa<IntegerLiteral>(exp->getArg(0))) || (isa<CXXBoolLiteralExpr>(exp->getArg(0)))) ) {
147 LLVM_DEBUG(llvm::dbgs()
148 <<
"CXXConstructExpr followed by integer literal found\n");
151 if (isa<IntegerLiteral>(exp->getArg(0))) {
152 IntegerLiteral *lit = (IntegerLiteral *)exp->getArg(0);
156 CXXBoolLiteralExpr * boollit = (CXXBoolLiteralExpr *) exp->getArg(0);
157 if (boollit->getValue()) s =
"1";
else s =
"0";
158 h_ret =
new hNode(s, hNode::hdlopsEnum::hLiteral);
163 te->
Enumerate((exp->getType()).getTypePtr());
165 hNodep h_tmp =
new hNode(hNode::hdlopsEnum::hNoop);
167 hNode::hdlopsEnum::hLiteral, h_tmp);
172 LLVM_DEBUG(llvm::dbgs()
173 <<
"stmt type " << stmt->getStmtClassName()
174 <<
" not recognized, calling default recursive ast visitor\n");
176 RecursiveASTVisitor::TraverseStmt(stmt);
177 if (
h_ret != oldh_ret) {
180 <<
"default recursive ast visitor called - returning translation\n");
183 for (
auto arg : stmt->children()) {
184 LLVM_DEBUG(llvm::dbgs() <<
"child stmt type "
185 << ((Stmt *)arg)->getStmtClassName() <<
"\n");
186 if (isa<CXXThisExpr>(arg))
continue;
188 if (
h_ret == oldh_ret) {
189 LLVM_DEBUG(llvm::dbgs() <<
"child stmt not handled\n");
191 h_ret =
new hNode(arg->getStmtClassName(), hNode::hdlopsEnum::hUnimpl);
200 int nargs = ((CXXTemporaryObjectExpr *)stmt)->getNumArgs();
204 (hNode::hdlopsEnum::hLiteral));
206 Expr **objargs = ((CXXTemporaryObjectExpr *)stmt)->getArgs();
207 for (
int i = 0; i < nargs; i++) {
215 hNodep h_initlist =
new hNode(hNode::hdlopsEnum::hVarInitList);
216 for (
auto tmpexpr : ((InitListExpr *)stmt)->inits()) {
225 hNodep hretstmt =
new hNode(hNode::hdlopsEnum::hReturnStmt);
226 if (((ReturnStmt *)stmt)->getRetValue() !=
nullptr) {
235 LLVM_DEBUG(llvm::dbgs() <<
"Found case stmt\n");
237 hNodep hcasep =
new hNode(hNode::hdlopsEnum::hSwitchCase);
238 if (ConstantExpr *expr =
239 dyn_cast<ConstantExpr>(((CaseStmt *)stmt)->getLHS())) {
240 llvm::APSInt val = expr->getResultAsAPSInt();
243 hNode::hdlopsEnum::hLiteral));
247 if (
h_ret != old_hret)
259 hNodep hcasep =
new hNode(hNode::hdlopsEnum::hSwitchDefault);
261 if (
h_ret != old_hret)
271 LLVM_DEBUG(llvm::dbgs() <<
"Found break stmt\n");
273 : hNode::hdlopsEnum::hBreak);
278 LLVM_DEBUG(llvm::dbgs() <<
"Found continue stmt\n");
279 h_ret =
new hNode(hNode::hdlopsEnum::hContinue);
286 hNodep h_cstmt =
new hNode(hNode::hdlopsEnum::hCStmt);
288 for (clang::Stmt *stmt : cstmt->body()) {
302 LLVM_DEBUG(llvm::dbgs() <<
"stmt result was empty\n");
321 for (
auto *DI : declstmt->decls())
323 auto *vardecl = dyn_cast<VarDecl>(DI);
324 if (!vardecl)
continue;
333 LLVM_DEBUG(llvm::dbgs() <<
"ProcessVarDecl var name is " << vardecl->getName()
336 hNodep h_varlist =
new hNode(hNode::hdlopsEnum::hPortsigvarlist);
338 QualType q = vardecl->getType();
339 const Type *tp = q.getTypePtr();
340 LLVM_DEBUG(llvm::dbgs() <<
"ProcessVarDecl type name is " << q.getAsString()
346 std::vector<llvm::APInt> array_sizes =
350 hNode::hdlopsEnum::hVardecl, h_varlist);
354 if (h_varlist->
child_list.size() == 0)
return true;
360 bool isuserdefinedclass =
false;
370 LLVM_DEBUG(HDLt.
print(llvm::dbgs()));
376 isuserdefinedclass =
true;
399 string qualmethodname =
"ConstructorMethod";
400 if (Expr *declinit = vardecl->getInit()) {
401 LLVM_DEBUG(llvm::dbgs() <<
"ProcessVarDecl has an init: \n");
403 CXXConstructExpr *tmpdeclinit = dyn_cast<CXXConstructExpr>(declinit);
404 if (isuserdefinedclass && (tmpdeclinit != NULL)) {
412 const CXXConstructorDecl *cnstrdcl = tmpdeclinit->getConstructor();
413 string methodname = cnstrdcl->getNameAsString();
414 qualmethodname = cnstrdcl->getQualifiedNameAsString();
416 LLVM_DEBUG(llvm::dbgs() <<
"ConstructorDecl " << methodname <<
", "
417 << qualmethodname <<
" for var follows\n");
418 LLVM_DEBUG(cnstrdcl->dump());
421 new hNode(qualmethodname, hNode::hdlopsEnum::hMethodCall);
422 const std::vector<StringRef> tmpmodstr{
"sc_module"};
424 LLVM_DEBUG(llvm::dbgs()
425 <<
"user-defined class is defined in sc module\n");
443 hNodep varinitp =
new hNode(hNode::hdlopsEnum::hVarAssign);
461 new hNode(expr->getOpcodeStr().str(),
462 hNode::hdlopsEnum::hBinop);
464 string opcodestr = expr->getOpcodeStr().str();
465 string exprtypstr = expr->getType().getAsString();
466 LLVM_DEBUG(llvm::dbgs() <<
"in TraverseBinaryOperator, opcode is "
467 << opcodestr <<
"\n");
489 if ((opcodestr ==
",") &&
496 LLVM_DEBUG(llvm::dbgs() <<
"found comma, with sc type, expr follows\n");
498 h_binop->
set(
"concat");
505 if (
h_ret == save_h_ret)
516 LLVM_DEBUG(llvm::dbgs() <<
"in TraverseUnaryOperator expr node is \n");
519 auto opcstr = expr->getOpcode();
523 if ((expr->getOpcodeStr(opcstr).str() ==
"++") ||
524 (expr->getOpcodeStr(opcstr).str() ==
"--")) {
525 if (expr->isPostfix())
526 h_unop =
new hNode(expr->getOpcodeStr(opcstr).str(),
527 hNode::hdlopsEnum::hPostfix);
529 h_unop =
new hNode(expr->getOpcodeStr(opcstr).str(),
530 hNode::hdlopsEnum::hPrefix);
532 h_unop =
new hNode(expr->getOpcodeStr(opcstr).str(),
533 hNode::hdlopsEnum::hUnop);
544 LLVM_DEBUG(llvm::dbgs() <<
"in VisitConditionalOperator expr node is \n");
547 hNodep h_condop =
new hNode(hNode::hdlopsEnum::hCondop);
559 LLVM_DEBUG(llvm::dbgs() <<
"In integerliteral\n");
561 h_ret =
new hNode(s, hNode::hdlopsEnum::hLiteral);
567 LLVM_DEBUG(llvm::dbgs() <<
"In boollitexpr\n");
568 bool v = b->getValue();
569 h_ret =
new hNode(v ?
"1" :
"0", hNode::hdlopsEnum::hLiteral);
576 LLVM_DEBUG(llvm::dbgs() <<
"In TraverseDeclRefExpr\n");
578 ValueDecl *value = expr->getDecl();
579 if (isa<EnumConstantDecl>(value)) {
580 EnumConstantDecl *cd = (EnumConstantDecl *)value;
581 LLVM_DEBUG(llvm::dbgs()
582 <<
"got enum constant value " << cd->getInitVal() <<
"\n");
584 hNode::hdlopsEnum::hLiteral);
590 string name = (expr->getNameInfo()).getName().getAsString();
591 LLVM_DEBUG(llvm::dbgs() <<
"name is " << name <<
"\n");
594 if (isa<VarDecl>(value) && ((VarDecl *)value)->isConstexpr()) {
595 VarDecl *vard = (VarDecl *)value;
596 Expr *einit = vard->getInit();
597 clang::Expr::EvalResult result;
598 if (einit->EvaluateAsInt(result, vard->getASTContext())) {
601 hNode::hdlopsEnum::hLiteral);
605 if (isa<FunctionDecl>(value)) {
621 FunctionDecl *funval = (FunctionDecl *)value;
623 string qualfuncname{value->getQualifiedNameAsString()};
633 hNodep hfuncall =
new hNode(qualfuncname, hNode::hdlopsEnum::hMethodCall);
636 string tmpname =
FindFname((FunctionDecl *)value);
638 LLVM_DEBUG(llvm::dbgs() <<
"adding method " << qualfuncname
639 <<
" with pointer " << value <<
" \n");
643 hfuncall->
set(tmpname);
648 string typname = (expr->getType()).getAsString();
649 if (typname.find(
"sc_dt::sc_concat") != std::string::npos) {
651 hNodep hconcat =
new hNode(name, hNode::hdlopsEnum::hBinop);
655 h_ret =
new hNode(name, hNode::hdlopsEnum::hBuiltinFunction);
661 string newname =
FindVname(expr->getDecl());
662 LLVM_DEBUG(llvm::dbgs() <<
"new name is " << newname <<
"\n");
663 LLVM_DEBUG(expr->getDecl()->dump(llvm::dbgs()));
666 new hNode(newname.empty() ? name : newname, hNode::hdlopsEnum::hVarref);
671 LLVM_DEBUG(llvm::dbgs()
672 <<
"In TraverseArraySubscriptExpr, base, idx, tree follow\n");
673 LLVM_DEBUG(llvm::dbgs() <<
"base:\n");
674 LLVM_DEBUG(expr->getBase()->dump(llvm::dbgs(),
ast_context_));
675 LLVM_DEBUG(llvm::dbgs() <<
"idx:\n");
676 LLVM_DEBUG(expr->getIdx()->dump(llvm::dbgs(),
ast_context_));
677 LLVM_DEBUG(llvm::dbgs() <<
"tree:\n");
679 hNodep h_arrexpr =
new hNode(
"ARRAYSUBSCRIPT", hNode::hdlopsEnum::hBinop);
689 bool is_explicitly_overridden =
false;
691 LangOptions LangOpts;
693 LangOpts.CPlusPlus =
true;
694 const PrintingPolicy Policy(LangOpts);
696 LLVM_DEBUG(llvm::dbgs()
697 <<
"In TraverseCXXMemberCallExpr, printing implicit object arg\n");
701 Expr *rawarg = (callexpr->getImplicitObjectArgument());
702 LLVM_DEBUG(llvm::dbgs() <<
"raw implicitobjectargument follows\n");
705 Expr *objarg = (callexpr->getImplicitObjectArgument())->IgnoreImplicit();
707 llvm::dbgs() <<
"implicitobjectargument, ignore implicit follows\n");
709 CXXRecordDecl *cdecl = callexpr->getRecordDecl();
710 const Type *typeformethodclass = cdecl->getTypeForDecl();
711 LLVM_DEBUG(llvm::dbgs() <<
"Type pointer from RecordDecl is "
712 << typeformethodclass <<
"\n");
715 if (dyn_cast<ImplicitCastExpr>(rawarg)) {
716 argtyp = rawarg->getType();
717 is_explicitly_overridden =
true;
719 argtyp = objarg->getType();
721 LLVM_DEBUG(llvm::dbgs() <<
"type of x in x.f(5) is "
722 << argtyp.getAsString(Policy) <<
"\n");
723 QualType objtyp = callexpr->getObjectType();
724 LLVM_DEBUG(llvm::dbgs() <<
"... and object type is "
725 << objtyp.getAsString(Policy) <<
"\n");
726 string methodname =
"NoMethod", qualmethodname =
"NoQualMethod";
728 CXXMethodDecl *methdcl = callexpr->getMethodDecl();
733 LLVM_DEBUG(llvm::dbgs() <<
"methoddecl follows\n");
734 LLVM_DEBUG(methdcl->dump(llvm::dbgs()));
735 if (isa<NamedDecl>(methdcl) && methdcl->getDeclName()) {
736 methodname = methdcl->getNameAsString();
737 qualmethodname = methdcl->getQualifiedNameAsString();
742 LLVM_DEBUG(llvm::dbgs()
743 <<
"here is method printname " << methodname <<
" and qual name "
744 << qualmethodname <<
" and declp " << methdcl <<
" \n");
745 if (methodname.compare(0, 8,
"operator") ==
748 LLVM_DEBUG(llvm::dbgs() <<
"Found operator conversion node\n");
755 hNode *h_callp = NULL;
756 LLVM_DEBUG(llvm::dbgs() <<
"found " << methodname <<
"\n");
767 bool foundsctype =
lutil.
isSCType(qualmethodname, typeformethodclass);
784 if ((methodname ==
"read") && foundsctype)
785 opc = hNode::hdlopsEnum::hSigAssignR;
786 else if ((methodname ==
"write") && foundsctype)
787 opc = hNode::hdlopsEnum::hSigAssignL;
789 opc = hNode::hdlopsEnum::hWait;
790 else if (foundsctype) {
791 opc = hNode::hdlopsEnum::hBuiltinFunction;
793 opc = hNode::hdlopsEnum::hMethodCall;
796 qualmethodname +=
":" + methodname;
800 h_callp =
new hNode(qualmethodname, opc);
803 string tmpname =
FindFname((FunctionDecl *)methdcl);
805 LLVM_DEBUG(llvm::dbgs() <<
"adding method " << qualmethodname
806 <<
" with pointer " << methdcl <<
" \n");
820 h_callp->
set(tmpname);
822 methodname = qualmethodname;
826 h_callp =
new hNode(methodname, opc);
829 if ((opc == hNode::hdlopsEnum::hWait) && (callexpr->getNumArgs() > 0)) {
840 if ((
add_info) || ((opc != hNode::hdlopsEnum::hMethodCall) ||
841 (opc == hNode::hdlopsEnum::hMethodCall) &&
847 for (
auto arg : callexpr->arguments()) {
861 case OO_GreaterEqual:
862 case OO_ExclaimEqual:
872 string operatorname = getOperatorSpelling(opcall->getOperator());
873 string operatortype = (opcall->getType()).getAsString();
876 LLVM_DEBUG(llvm::dbgs() <<
"In TraverseCXXOperatorCallExpr, Operator name is "
877 << operatorname <<
"\n");
878 LLVM_DEBUG(llvm::dbgs() <<
"Type name " << operatortype <<
"\n");
879 LLVM_DEBUG(opcall->getType()->dump(llvm::dbgs(),
ast_context_));
882 const Type *optypepointer = opcall->getType().getTypePtr();
904 if ((operatorname ==
"=") ||
909 (opcall->getType())->isBuiltinType() ||
910 ((operatorname ==
"<<") &&
911 (operatortype.find(
"sensitive") != std::string::npos))) {
912 LLVM_DEBUG(llvm::dbgs() <<
"Processing operator call type\n");
914 if ((operatorname.compare(
"()") == 0) &&
915 (operatortype.find(
"subref") != string::npos) &&
916 (opcall->getNumArgs() == 3)) {
918 h_operop =
new hNode(
"SLICE", hNode::hdlopsEnum::hBinop);
920 if (operatorname ==
"[]")
921 h_operop =
new hNode(
"ARRAYSUBSCRIPT", hNode::hdlopsEnum::hBinop);
922 else if ((operatorname ==
"++") || (operatorname ==
"--")) {
923 if (opcall->getNumArgs() == 2)
924 h_operop =
new hNode(operatorname, hNode::hdlopsEnum::hPostfix);
926 h_operop =
new hNode(operatorname, hNode::hdlopsEnum::hPrefix);
928 if (opcall->getNumArgs() == 1)
929 h_operop =
new hNode(operatorname, hNode::hdlopsEnum::hUnop);
931 h_operop =
new hNode(operatorname, hNode::hdlopsEnum::hBinop);
933 if ((operatorname ==
",") )
934 h_operop->
set(
"concat");
939 int nargs = (h_operop->
getopc() == hNode::hdlopsEnum::hPostfix ||
940 h_operop->
getopc() == hNode::hdlopsEnum::hPrefix)
942 : opcall->getNumArgs();
943 for (
int i = 0; i < nargs; i++) {
946 if (
h_ret == save_h_ret)
950 LLVM_DEBUG(llvm::dbgs()
951 <<
"operator call argument " << i <<
" follows\n");
952 LLVM_DEBUG(opcall->getArg(i)->dump(llvm::dbgs(),
ast_context_));
958 LLVM_DEBUG(llvm::dbgs() <<
"not yet implemented operator call expr, opc is "
959 << clang::getOperatorSpelling(opcall->getOperator())
960 <<
" num arguments " << opcall->getNumArgs()
963 h_ret =
new hNode(hNode::hdlopsEnum::hUnimpl);
968 bool founduserclass =
false;
969 LLVM_DEBUG(llvm::dbgs() <<
"In TraverseMemberExpr\n");
970 string nameinfo = (memberexpr->getMemberNameInfo()).getName().getAsString();
971 LLVM_DEBUG(llvm::dbgs() <<
"name is " << nameinfo
972 <<
", base and memberdecl trees follow\n");
973 LLVM_DEBUG(llvm::dbgs() <<
"base is \n");
974 LLVM_DEBUG(memberexpr->getBase()->dump(llvm::dbgs(),
ast_context_););
975 LLVM_DEBUG(llvm::dbgs() <<
"memberdecl is " << memberexpr->getMemberDecl()
978 LLVM_DEBUG(memberexpr->getMemberDecl()->dump(llvm::dbgs()));
979 if (FieldDecl *fld = dyn_cast<FieldDecl>(memberexpr->getMemberDecl())) {
980 LLVM_DEBUG(llvm::dbgs() <<
"and field decl parent record pointer is "
981 << fld->getParent() <<
"\n");
982 const Type *classrectype = fld->getParent()->getTypeForDecl();
983 LLVM_DEBUG(llvm::dbgs() <<
"and field decl parent record type is "
984 << classrectype <<
"\n");
986 LLVM_DEBUG(llvm::dbgs()
987 <<
"member expr, found user defined class in usertypes "
988 << classrectype <<
"\n");
989 founduserclass =
true;
993 string thisref = founduserclass ?
"hthis##" :
"";
997 if (
h_ret != old_h_ret) {
998 if (
h_ret->
h_op == hNode::hdlopsEnum::hVarref) {
1001 hNode::hdlopsEnum::hVarref);
1003 h_ret = memexprnode;
1007 LLVM_DEBUG(llvm::dbgs()
1008 <<
"Value returned from member expr base was not Varref\n");
1010 string newname =
FindVname(memberexpr->getMemberDecl());
1011 LLVM_DEBUG(llvm::dbgs()
1012 <<
"member with base expr new name is " << newname <<
"\n");
1014 LLVM_DEBUG(llvm::dbgs() <<
"vname lookup of memberdecl is null, "
1015 "assuming field reference\n");
1016 hNodep hfieldref =
new hNode(hNode::hdlopsEnum::hFieldaccess);
1019 new hNode(thisref + nameinfo, hNode::hdlopsEnum::hField));
1024 new hNode(newname ==
"" ? thisref + nameinfo : thisref + newname,
1025 hNode::hdlopsEnum::hVarref);
1027 h_ret = memexprnode;
1033 string newname =
FindVname(memberexpr->getMemberDecl());
1034 LLVM_DEBUG(llvm::dbgs() <<
"member expr new name is " << newname <<
"\n");
1036 h_ret =
new hNode(newname.empty() ? thisref + nameinfo : thisref + newname,
1037 hNode::hdlopsEnum::hVarref);
1046 if (isa<FunctionDecl>(callexpr->getCalleeDecl()) &&
1047 ((FunctionDecl *)callexpr->getCalleeDecl())->isConstexpr()) {
1048 Expr::EvalResult res;
1049 if (callexpr->EvaluateAsRValue(
1050 res, callexpr->getCalleeDecl()->getASTContext())) {
1052 hNode::hdlopsEnum::hLiteral);
1067 hNode::hdlopsEnum::hMethodCall);
1070 for (
auto arg : callexpr->arguments()) {
1073 if (
h_ret != sret) {
1078 LLVM_DEBUG(llvm::dbgs() <<
"found a call expr"
1079 <<
" AST follows\n ");
1080 LLVM_DEBUG(callexpr->dump(llvm::dbgs(),
ast_context_););
1085 hNodep h_ifstmt, h_ifc = NULL, h_ifthen = NULL, h_ifelse = NULL;
1086 h_ifstmt =
new hNode(hNode::hdlopsEnum::hIfStmt);
1087 if (ifs->getConditionVariable()) {
1089 LLVM_DEBUG(llvm::dbgs() <<
"Variable declarations are not allowed in if "
1090 "conditions, skipping\n");
1100 if (ifs->getElse()) {
1106 if (h_ifelse) h_ifstmt->
child_list.push_back(h_ifelse);
1112 hNodep h_forstmt, h_forinit, h_forcond, h_forinc, h_forbody;
1113 LLVM_DEBUG(llvm::dbgs() <<
"For stmt\n");
1114 h_forstmt =
new hNode(hNode::hdlopsEnum::hForStmt);
1115 if ((fors->getInit() != NULL) && (isa<CompoundStmt>(fors->getInit())))
1116 LLVM_DEBUG(llvm::dbgs()
1117 <<
"Compound stmt not handled in for init, skipping\n");
1119 if ((fors->getInit() != NULL) && isa<DeclStmt>(fors->getInit())) {
1120 LLVM_DEBUG(llvm::dbgs() <<
"for init is a decl stmt\n");
1121 LLVM_DEBUG((fors->getInit())->dump(llvm::dbgs(),
ast_context_));
1125 h_forinit = (
h_ret == NULL) ?
new hNode(hNode::hdlopsEnum::hNoop)
1128 h_forcond = (
h_ret == NULL) ?
new hNode(hNode::hdlopsEnum::hNoop)
1131 h_forinc =(
h_ret == NULL) ?
new hNode(hNode::hdlopsEnum::hNoop)
1133 LLVM_DEBUG(llvm::dbgs() <<
"For loop body\n");
1134 LLVM_DEBUG(fors->getBody()->dump(llvm::dbgs(),
ast_context_););
1147 LLVM_DEBUG(llvm::dbgs() <<
"In ProcessSwitchCase\n");
1150 if (isa<DefaultStmt>(sc)) {
1151 LLVM_DEBUG(llvm::dbgs() <<
"Found default stmt in switchcase\n");
1152 hcasep =
new hNode(hNode::hdlopsEnum::hSwitchDefault);
1155 LLVM_DEBUG(llvm::dbgs() <<
"Found case stmt in switchcase\n");
1156 hcasep =
new hNode(hNode::hdlopsEnum::hSwitchCase);
1157 if (ConstantExpr *expr =
1158 dyn_cast<ConstantExpr>(((CaseStmt *)sc)->getLHS())) {
1159 llvm::APSInt val = expr->getResultAsAPSInt();
1162 hNode::hdlopsEnum::hLiteral));
1166 if (
h_ret != old_hret) {
1177 LLVM_DEBUG(llvm::dbgs() <<
"Switch stmt body -----\n");
1178 LLVM_DEBUG(switchs->getBody()->dump(llvm::dbgs(),
ast_context_););
1179 LLVM_DEBUG(llvm::dbgs() <<
"End Switch stmt body -----\n");
1181 h_switchstmt =
new hNode(hNode::hdlopsEnum::hSwitchStmt);
1188 if (
h_ret != old_ret) {
1191 h_switchstmt->
child_list.push_back(
new hNode(hNode::hdlopsEnum::hUnimpl));
1197 if (
h_ret != old_ret) {
1223 h_ret = h_switchstmt;
1229 hNodep h_whilestmt, h_whilecond, h_whilebody;
1230 LLVM_DEBUG(llvm::dbgs() <<
"While stmt\n");
1231 h_whilestmt =
new hNode(hNode::hdlopsEnum::hWhileStmt);
1232 if (whiles->getConditionVariable()) {
1235 <<
"Variable declarations not handled in while condition, skipping\n");
1239 h_whilecond =
h_ret;
1244 h_whilebody =
h_ret;
1245 h_whilestmt->
child_list.push_back(h_whilecond);
1246 h_whilestmt->
child_list.push_back(h_whilebody);
1247 h_ret = h_whilestmt;
1256 hNodep h_whilestmt, h_whilecond, h_whilebody;
1257 LLVM_DEBUG(llvm::dbgs() <<
"Do stmt\n");
1258 h_whilestmt =
new hNode(hNode::hdlopsEnum::hDoStmt);
1261 h_whilecond =
h_ret;
1265 h_whilebody =
h_ret;
1266 h_whilestmt->
child_list.push_back(h_whilecond);
1267 h_whilestmt->
child_list.push_back(h_whilebody);
1268 h_ret = h_whilestmt;
1295 LLVM_DEBUG(llvm::dbgs() <<
"Vname Dump\n");
1298 LLVM_DEBUG(llvm::dbgs() <<
"(" << var.first <<
"," << var.second.oldn
1299 <<
", " << var.second.newn <<
")\n");
1300 if (
add_info && (var.second.newn.find(gvar_prefix) == std::string::npos)) {
1304 var.second.h_vardeclp->h_op = hNode::hdlopsEnum::hVardeclrn;
1305 var.second.h_vardeclp->child_list.push_back(
1306 new hNode(var.second.oldn, hNode::hdlopsEnum::hLiteral));
1308 if (var.second.newn.find(gvar_prefix) == std::string::npos)
1310 hvns->
child_list.push_back(var.second.h_vardeclp);
1319 hNodep hassignchain =
new hNode(hNode::hdlopsEnum::hCStmt);
1328 std::reverse(hassignchain->
child_list.begin(),
1330 return hassignchain;
1333 int64_t waitarg = 0;
1335 clang::Expr::EvalResult result{};
1337 waitarg = result.Val.getInt().getExtValue();
1338 llvm::dbgs() <<
" wait arg val: " << waitarg <<
"\n";
1340 hNodep arglit =
new hNode( std::to_string(waitarg), hNode::hdlopsEnum::hLiteral);
1345 if (hswitchstmt->
child_list.size() == 0)
return;
1347 for (
int i = 1; i < hswitchstmt->
child_list.size(); i++) {
1349 hNode::hdlopsEnum::hSwitchCase) &&
1351 hNode::hdlopsEnum::hSwitchDefault)) {
1356 hswitchstmt->
child_list[i]->set(hNode::hdlopsEnum::hLast);
1363 [](
hNodep hp) { return hp->getopc() == hNode::hdlopsEnum::hLast; }),
void print(llvm::raw_ostream &modelout=llvm::outs(), unsigned int indnt=2)
usertype_info_t usertype_info
void SCtype2hcode(string prefix, Tree< TemplateType > *template_argtp, std::vector< llvm::APInt > *arr_sizes, hNode::hdlopsEnum h_op, hNodep &h_info)
void set(hdlopsEnum h, string s="")
std::vector< hNodep > child_list
void print(llvm::raw_ostream &modelout=llvm::outs(), unsigned int indnt=2)
void print(llvm::raw_ostream &modelout=llvm::outs(), unsigned int indnt=2)
method_object_map_t methodobjtypemap
void add_entry(T declp, string old_name, hNodep hnp)
void set_prefix(string prefix)
string find_entry_newn(T declp, bool set_ref=false)
bool isSCFunc(const string &tstring)
bool isSCMacro(const std::string &str_in)
bool isSCBuiltinType(const string &tstring, const Type *typ=NULL)
bool isSCType(const string &tstring, const clang::Type *typ=NULL)
static void make_ident(string &nm)
Tree< TemplateType > * getTemplateArgTreePtr()
void Enumerate(const clang::Type *type)
const ASTContext & ast_context_
bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr *opcall)
bool VisitBinaryOperator(BinaryOperator *expr)
bool isLogicalOp(clang::OverloadedOperatorKind opc)
bool VisitCaseStmt(CaseStmt *stmt)
string FindFname(FunctionDecl *funcd)
hdecl_name_map_t vname_map
overridden_method_map_t & overridden_method_map_
hfunc_name_map_t methodecls
bool VisitCompoundStmt(CompoundStmt *compoundStmt)
bool VisitDefaultStmt(DefaultStmt *stmt)
void NormalizeSwitchStmt(hNodep hswitchbody)
void GetWaitArg(hNodep &h_callp, Expr *callarg)
bool VisitConditionalOperator(ConditionalOperator *expr)
bool VisitReturnStmt(ReturnStmt *stmt)
bool VisitDeclStmt(DeclStmt *declstmt)
bool ProcessVarDecl(VarDecl *vardecl)
bool VisitMemberExpr(MemberExpr *memberexpr)
string generate_vname(string nm)
bool VisitUnaryOperator(UnaryOperator *expr)
bool isUserClass(const Type *classrectype)
bool VisitArraySubscriptExpr(ArraySubscriptExpr *expr)
void AddVnames(hNodep &hvns)
bool VisitSwitchStmt(SwitchStmt *switchs)
bool TraverseStmt(Stmt *stmt)
HDLBody(clang::DiagnosticsEngine &diag_engine, const ASTContext &ast_context, hdecl_name_map_t &mod_vname_map, hfunc_name_map_t &allmethodecls, overridden_method_map_t &overridden_method_map)
hdecl_name_map_t & mod_vname_map_
hfunc_name_map_t & allmethodecls_
bool isAssignOp(hNodep hp)
bool VisitWhileStmt(WhileStmt *whiles)
bool VisitContinueStmt(ContinueStmt *stmt)
HDLType * HDLt_userclassesp_
void Run(Stmt *stmt, hNodep &h_top, HDLBodyMode runmode, HDLType *HDLt_userclassesp=NULL)
hNodep NormalizeAssignmentChain(hNodep hinp)
bool VisitInitListExpr(InitListExpr *stmt)
bool ProcessSwitchCase(SwitchCase *cases)
bool VisitDoStmt(DoStmt *whiles)
bool VisitCXXBoolLiteralExpr(CXXBoolLiteralExpr *b)
bool VisitIfStmt(IfStmt *ifs)
bool VisitCallExpr(CallExpr *callexpr)
bool VisitCXXTemporaryObjectExpr(CXXTemporaryObjectExpr *stmt)
bool VisitBreakStmt(BreakStmt *stmt)
string FindVname(NamedDecl *vard)
bool VisitCXXMemberCallExpr(CXXMemberCallExpr *callexpr)
bool VisitDeclRefExpr(DeclRefExpr *expr)
bool VisitForStmt(ForStmt *fors)
bool VisitIntegerLiteral(IntegerLiteral *lit)
std::unordered_map< const CXXMethodDecl *, const CXXMethodDecl * > overridden_method_map_t
ArraySizesType getConstantArraySizes(const clang::ValueDecl *fd)
bool isCXXMemberCallExprSystemCCall(const clang::CallExpr *ce, const std::vector< llvm::StringRef > &names)
bool isInNamespace(const clang::ValueDecl *fd, const std::vector< llvm::StringRef > &names)
std::string toString(const T &i)
userrectype_map_t userrectypes