Skip to content

Commit

Permalink
put the hHode class in its own .h file
Browse files Browse the repository at this point in the history
  • Loading branch information
mayagokhale committed Jan 8, 2020
1 parent 47eb386 commit ddbe44f
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 116 deletions.
117 changes: 1 addition & 116 deletions plugins/xlat/XlatEntryMethod.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,127 +13,12 @@

// look at https://chromium.googlesource.com/chromium/src.git/+/62.0.3178.1/tools/clang/value_cleanup/ListValueRewriter.h#include "llvm/Support/FileSystem.h"

#include <stack>

#include "SystemCClang.h"
#include "hNode.h"

using namespace clang;
using namespace scpar;

namespace hnode {
class hNode;

typedef hNode * hNodep;

class hNode {

#define HNODEen \
etype(hNoop), \
etype(hModule), \
etype(hProcess), \
etype(hCStmt), \
etype(hPortin), \
etype(hPortout), \
etype(hPortio), \
etype(hSensvar), \
etype(hSensedge), \
etype(hType), \
etype(hInt), \
etype(hSigdecl), \
etype(hVardecl), \
etype(hVarref), \
etype(hSigAssignL), \
etype(hSigAssignR), \
etype(hVarAssign), \
etype(hBinop), \
etype(hUnop), \
etype(hIfStmt), \
etype(hForStmt), \
etype(hForInit), \
etype(hForCond), \
etype(hForInc), \
etype(hForBody), \
etype(hWhileStmt), \
etype(hLiteral), \
etype(hUnimpl), \
etype(hLast)


public:

#define etype(x) x

typedef enum { HNODEen } hdlopsEnum;

bool is_leaf;

string h_name;
hdlopsEnum h_op;
list<hNodep> child_list;

#undef etype
#define etype(x) #x

const string hdlop_pn [hLast+1] = { HNODEen };

hNode() { is_leaf = true;}
hNode(bool lf) {
is_leaf = lf;
h_op = hdlopsEnum::hNoop;
}

hNode(string s, hdlopsEnum h) {
is_leaf = true;
h_name = s;
h_op = h;
}

~hNode() { if (!is_leaf) child_list.clear(); }


void setleaf(string s, hdlopsEnum h) {
is_leaf = true;
h_name = s;
h_op = h;
}

string printname(hdlopsEnum opc) {
if (is_leaf) return hdlop_pn[static_cast<int>(opc)];
else return "NON_LEAF";
}

// for completeness
hdlopsEnum str2hdlopenum(string st) {
const int n = sizeof (hdlop_pn)/sizeof (hdlop_pn[0]);
for (int i = 0; i < n; i++) {
if (hdlop_pn[i] == st)
return (hdlopsEnum) i;
}
return hLast;
}
void print(llvm::raw_fd_ostream & modelout, unsigned int indnt=2) {
if (is_leaf) {
modelout.indent(indnt);
modelout << "(" << printname(h_op) << " " << h_name << ")" <<"\n";

}
else {
modelout.indent(indnt);
modelout << "[\n";
for (auto child : child_list)
if (child)
child->print(modelout, indnt+2);
else {
modelout.indent(indnt+2);
modelout << "<null child>\n";
}
modelout.indent(indnt);
modelout << "]\n";
}
}

};
}

using namespace hnode;

Expand Down
120 changes: 120 additions & 0 deletions plugins/xlat/hNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#include "llvm/Support/raw_ostream.h"

#include <stack>

using namespace scpar;

namespace hnode {
class hNode;

typedef hNode * hNodep;

class hNode {

#define HNODEen \
etype(hNoop), \
etype(hModule), \
etype(hProcess), \
etype(hCStmt), \
etype(hPortin), \
etype(hPortout), \
etype(hPortio), \
etype(hSensvar), \
etype(hSensedge), \
etype(hType), \
etype(hInt), \
etype(hSigdecl), \
etype(hVardecl), \
etype(hVarref), \
etype(hSigAssignL), \
etype(hSigAssignR), \
etype(hVarAssign), \
etype(hBinop), \
etype(hUnop), \
etype(hIfStmt), \
etype(hForStmt), \
etype(hForInit), \
etype(hForCond), \
etype(hForInc), \
etype(hForBody), \
etype(hWhileStmt), \
etype(hLiteral), \
etype(hUnimpl), \
etype(hLast)


public:

#define etype(x) x

typedef enum { HNODEen } hdlopsEnum;

bool is_leaf;

string h_name;
hdlopsEnum h_op;
list<hNodep> child_list;

#undef etype
#define etype(x) #x

const string hdlop_pn [hLast+1] = { HNODEen };

hNode() { is_leaf = true;}
hNode(bool lf) {
is_leaf = lf;
h_op = hdlopsEnum::hNoop;
}

hNode(string s, hdlopsEnum h) {
is_leaf = true;
h_name = s;
h_op = h;
}

~hNode() { if (!is_leaf) child_list.clear(); }


void setleaf(string s, hdlopsEnum h) {
is_leaf = true;
h_name = s;
h_op = h;
}

string printname(hdlopsEnum opc) {
if (is_leaf) return hdlop_pn[static_cast<int>(opc)];
else return "NON_LEAF";
}

// for completeness
hdlopsEnum str2hdlopenum(string st) {
const int n = sizeof (hdlop_pn)/sizeof (hdlop_pn[0]);
for (int i = 0; i < n; i++) {
if (hdlop_pn[i] == st)
return (hdlopsEnum) i;
}
return hLast;
}
void print(llvm::raw_fd_ostream & modelout, unsigned int indnt=2) {
if (is_leaf) {
modelout.indent(indnt);
modelout << "(" << printname(h_op) << " " << h_name << ")" <<"\n";

}
else {
modelout.indent(indnt);
modelout << "[\n";
for (auto child : child_list)
if (child)
child->print(modelout, indnt+2);
else {
modelout.indent(indnt+2);
modelout << "<null child>\n";
}
modelout.indent(indnt);
modelout << "]\n";
}
}

};
}

0 comments on commit ddbe44f

Please sign in to comment.