Skip to content

Commit

Permalink
revised _hdl syntax to be simpler and more deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
mayagokhale committed Jan 10, 2020
1 parent f4799e6 commit ffd4eba
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
4 changes: 2 additions & 2 deletions plugins/xlat/Xlat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool Xlat::postFire() {
//hNodep h_modname = new hNode(modname, hNode::hdlopsEnum::hModule);

// Ports
hNodep h_ports = new hNode(hNode::hdlopsEnum::hPortsiglist); // list of ports, signals
hNodep h_ports = new hNode(hNode::hdlopsEnum::hPortsigvarlist); // list of ports, signals
xlatport(instanceVec.at(i)->getIPorts(), hNode::hdlopsEnum::hPortin,
h_ports);
xlatport(instanceVec.at(i)->getOPorts(), hNode::hdlopsEnum::hPortout,
Expand Down Expand Up @@ -156,7 +156,7 @@ void Xlat::xlatproc(scpar::vector<EntryFunctionContainer *> efv, hNodep &h_top,
}
h_process->child_list.push_back(h_senslist);
CXXMethodDecl *emd = efc->getEntryMethod();
hNodep h_body = new hNode(hNode::hdlopsEnum::hCStmt);
hNodep h_body; // = new hNode(hNode::hdlopsEnum::hCStmt);
XlatMethod xmethod(emd, h_body, os_); //, xlatout);
h_process->child_list.push_back(h_body);
h_top->child_list.push_back(h_process);
Expand Down
45 changes: 18 additions & 27 deletions plugins/xlat/XlatEntryMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ bool XlatMethod::TraverseStmt(Stmt *stmt) {

bool XlatMethod::TraverseCompoundStmt(CompoundStmt* cstmt) {
// Traverse each statement and append it to the array
hNodep h_cstmt = new hNode(false);
h_cstmt->child_list.push_back(new hNode("", hNode::hdlopsEnum::hCStmt));

hNodep h_cstmt = new hNode(hNode::hdlopsEnum::hCStmt);

for (clang::Stmt* stmt : cstmt->body()) {
TRY_TO(TraverseStmt(stmt));
if (h_ret) {
Expand All @@ -134,14 +133,14 @@ bool XlatMethod::TraverseCompoundStmt(CompoundStmt* cstmt) {
}

bool XlatMethod::TraverseDeclStmt(DeclStmt * declstmt) {
hNodep h_varlist = new hNode(false);
hNodep h_varlist = new hNode(hNode::hdlopsEnum::hPortsigvarlist);
// from https://clang.llvm.org/doxygen/DeadStoresChecker_8cpp_source.html
for (auto *DI : declstmt->decls())
if (DI) {
auto *vardecl = dyn_cast<VarDecl>(DI);
if (!vardecl)
continue;
hNodep h_vardecl = new hNode(false);
hNodep h_vardecl = new hNode(vardecl->getName(), hNode::hdlopsEnum::hVardecl);
ProcessVarDecl(vardecl, h_vardecl);
h_varlist->child_list.push_back(h_vardecl);
}
Expand All @@ -150,9 +149,8 @@ bool XlatMethod::TraverseDeclStmt(DeclStmt * declstmt) {
}

bool XlatMethod::ProcessVarDecl( VarDecl * vardecl, hNodep &h_vardecl) {
h_vardecl->child_list.push_back(new hNode(vardecl->getName(), hNode::hdlopsEnum::hVardecl));
os_ << "ProcessVarDecl var name is " << vardecl->getName() << "\n";
hNodep h_typeinfo = new hNode(false);
hNodep h_typeinfo = new hNode( hNode::hdlopsEnum::hTypeinfo);
QualType q = vardecl->getType();
const Type *tp = q.getTypePtr();
os_ << "ProcessVarDecl type name is " << q.getAsString() << "\n";
Expand Down Expand Up @@ -182,11 +180,9 @@ bool XlatMethod::TraverseBinaryOperator(BinaryOperator* expr)
// SourceLocation *Loc = nullptr,
// bool isEvaluated = true) const;

hNodep h_binop = new hNode(false); // node to hold binop expr
hNodep h_binop = new hNode(expr->getOpcodeStr(), hNode::hdlopsEnum::hBinop); // node to hold binop expr
os_ << "in TraverseBinaryOperator, opcode is " << expr->getOpcodeStr() << "\n";

h_binop->child_list.push_back(new hNode(expr->getOpcodeStr(), hNode::hdlopsEnum::hBinop));

TRY_TO(TraverseStmt(expr->getLHS()));
h_binop->child_list.push_back(h_ret);

Expand All @@ -201,13 +197,13 @@ bool XlatMethod::TraverseBinaryOperator(BinaryOperator* expr)

bool XlatMethod::TraverseUnaryOperator(UnaryOperator* expr)
{
os_ << "in TraverseUnaryOperatory expr node is \n";
expr->dump(os_);

hNodep h_unop = new hNode(false); // node to hold unop expr
os_ << "in TraverseUnaryOperatory expr node is \n";
expr->dump(os_);
auto opcstr = expr->getOpcode();
h_unop->child_list.push_back(new hNode(expr->getOpcodeStr(opcstr), hNode::hdlopsEnum::hUnop));
auto opcstr = expr->getOpcode();

hNodep h_unop = new hNode(expr->getOpcodeStr(opcstr), hNode::hdlopsEnum::hUnop); // node to hold unop expr

TRY_TO(TraverseStmt(expr->getSubExpr()));
h_unop->child_list.push_back(h_ret);

Expand Down Expand Up @@ -248,8 +244,7 @@ bool XlatMethod::TraverseDeclRefExpr(DeclRefExpr* expr)
bool XlatMethod::TraverseArraySubscriptExpr(ArraySubscriptExpr* expr) {
os_ << "In TraverseArraySubscriptExpr, tree follows\n";
expr->dump(os_);
hNodep h_arrexpr = new hNode(false);
h_arrexpr->child_list.push_back(new hNode("[]", hNode::hdlopsEnum::hBinop));
hNodep h_arrexpr = new hNode("ARRAYSUBSCRIPT", hNode::hdlopsEnum::hBinop);
TRY_TO(TraverseStmt(expr->getLHS()));
h_arrexpr->child_list.push_back(h_ret);
TRY_TO(TraverseStmt(expr->getRHS()));
Expand Down Expand Up @@ -287,7 +282,6 @@ bool XlatMethod::TraverseCXXMemberCallExpr(CXXMemberCallExpr *callexpr) {

else methodname = "NOOP";

hNode * h_callp = new hNode(false); // list to hold call expr node
hNode::hdlopsEnum opc;

os_ << "found " << methodname << "\n";
Expand All @@ -300,7 +294,8 @@ bool XlatMethod::TraverseCXXMemberCallExpr(CXXMemberCallExpr *callexpr) {
opc = hNode::hdlopsEnum::hNoop;
}

h_callp -> child_list.push_back(new hNode(methodname, opc));
hNode * h_callp = new hNode(methodname, opc); // list to hold call expr node

TRY_TO(TraverseStmt(arg)); // traverse the x in x.f(5)

if (h_ret) h_callp -> child_list.push_back(h_ret);
Expand Down Expand Up @@ -335,8 +330,7 @@ bool XlatMethod::TraverseCXXOperatorCallExpr(CXXOperatorCallExpr * opcall) {
(isLogicalOp(opcall->getOperator()))) {
if (opcall->getNumArgs() == 2) {
os_ << "assignment or logical operator, 2 args\n";
hNodep h_assignop = new hNode (false); // node to hold assignment expr
h_assignop->child_list.push_back(new hNode("=", hNode::hdlopsEnum::hBinop));
hNodep h_assignop = new hNode ("=", hNode::hdlopsEnum::hBinop); // node to hold assignment expr
TRY_TO(TraverseStmt(opcall->getArg(0)));
h_assignop->child_list.push_back(h_ret);
TRY_TO(TraverseStmt(opcall->getArg(1)));
Expand All @@ -362,8 +356,7 @@ bool XlatMethod::TraverseMemberExpr(MemberExpr *memberexpr){

bool XlatMethod::TraverseIfStmt(IfStmt *ifs) {
hNodep h_ifstmt, h_ifc, h_ifthen, h_ifelse;
h_ifstmt = new hNode(false);
h_ifstmt->child_list.push_back(new hNode("", hNode::hdlopsEnum::hIfStmt));
h_ifstmt = new hNode(hNode::hdlopsEnum::hIfStmt);
if (ifs->getConditionVariable()) {
// Variable declarations are not allowed in if conditions
os_ << "Variable declarations are not allowed in if conditions, skipping\n";
Expand Down Expand Up @@ -391,8 +384,7 @@ bool XlatMethod::TraverseIfStmt(IfStmt *ifs) {
bool XlatMethod::TraverseForStmt(ForStmt *fors) {
hNodep h_forstmt, h_forinit, h_forcond, h_forinc, h_forbody;
os_ << "For stmt\n";
h_forstmt = new hNode(false);
h_forstmt->child_list.push_back(new hNode("", hNode::hdlopsEnum::hForStmt));
h_forstmt = new hNode(hNode::hdlopsEnum::hForStmt);
if (isa<CompoundStmt>(fors->getInit()))
os_ << "Compound stmt not handled in for init, skipping\n";
else TRY_TO(TraverseStmt(fors->getInit()));
Expand All @@ -417,8 +409,7 @@ bool XlatMethod::TraverseForStmt(ForStmt *fors) {
bool XlatMethod::TraverseWhileStmt(WhileStmt *whiles) {
hNodep h_whilestmt, h_whilecond, h_whilebody;
os_ << "While stmt\n";
h_whilestmt = new hNode(false);
h_whilestmt->child_list.push_back(new hNode("", hNode::hdlopsEnum::hWhileStmt));
h_whilestmt = new hNode(hNode::hdlopsEnum::hWhileStmt);
if (whiles->getConditionVariable()) {
os_ << "Variable declarations not handled in while condition, skipping\n";
}
Expand Down
9 changes: 7 additions & 2 deletions plugins/xlat/hNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace hnode {
etype(hProcesses), \
etype(hProcess), \
etype(hCStmt), \
etype(hPortsiglist), \
etype(hPortsigvarlist), \
etype(hPortin), \
etype(hPortout), \
etype(hPortio), \
Expand Down Expand Up @@ -94,6 +94,11 @@ namespace hnode {

}

void set( hdlopsEnum h, string s = "") {
h_op = h;
h_name = s;
}

string printname(hdlopsEnum opc) {
return hdlop_pn[static_cast<int>(opc)];
}
Expand All @@ -116,7 +121,7 @@ namespace hnode {
if (child_list.empty())
modelout << " NOLIST\n";
else {
modelout << "[\n";
modelout << " [\n";
for (auto child : child_list)
if (child)
child->print(modelout, indnt+2);
Expand Down

0 comments on commit ffd4eba

Please sign in to comment.