Commit caa60efb authored by rmrf's avatar rmrf

Stage 3: Add support for templated waits.

This commit has several fixes in it.  The overall fix is
introducing a feature to recognize templated waits.  This is when the
class  has a template type, say D1, and the wait() uses it as an
argument such as wait(D1).

The commit works in a way where both non-templated and templated type
use the same WaitContainer class.
parent 505643f7
......@@ -29,7 +29,7 @@ set -x LLVM_CXX_FLAGS (eval $LLVMCONFIG --cxxflags)
# Generate all the flags.
# -fno-aligned-allocation needed for c++17
set -x LLVM_CXX_FLAGS "$LLVM_CXX_FLAGS -fvisibility-inlines-hidden -fno-aligned-allocation"
set -x LLVM_CXX_FLAGS "$LLVM_CXX_FLAGS -fvisibility-inlines-hidden -fno-aligned-allocation -Wsign-compare"
set -x LLVM_LIBS (eval $LLVMCONFIG --libs)
set -x LLVM_LD_FLAGS (eval $LLVMCONFIG --ldflags)
set -x LLVM_LD_FLAGS (echo $LLVM_LD_FLAGS | sed 's/ *$//g')
......@@ -21,7 +21,9 @@ bool FindNotify::VisitCallExpr(CallExpr *e) {
LangOpts.CPlusPlus = true;
PrintingPolicy Policy(LangOpts);
if (e->getDirectCallee()->getNameInfo().getAsString() == string("notify") &&
auto direct_callee{ e->getDirectCallee() };
if (direct_callee != nullptr ) {
if (direct_callee->getNameInfo().getAsString() == string("notify") &&
e->getNumArgs() <= 2) { // need a better checking.....
notify_call_list_.push_back(e);
// To get the 'x' from x.f(5) I must use getImplicitObjectArgument.
......@@ -49,6 +51,7 @@ bool FindNotify::VisitCallExpr(CallExpr *e) {
}
*/
}
}
return true;
}
......
......@@ -8,34 +8,60 @@ using namespace scpar;
using namespace std;
FindWait::FindWait(CXXMethodDecl *d, llvm::raw_ostream &os)
: entry_method_decl_{d}, os_{os}, wait_call_{nullptr} { //},
// first_arg_{nullptr},
// found_wait_{false} {
TraverseDecl(d);
: entry_method_decl_{d}, os_{os}, wait_call_{nullptr},
found_wait_{false} {
TraverseDecl(d);
// If there was a wait that was found. Then go through and dump them all out?
if (found_wait_) {
for (auto wait : wait_calls_list_) {
wait->dump(os_,2);
}
}
}
FindWait::~FindWait() {
// Delete all the pointers.
for (auto wait : wait_calls_list_ ) {
delete wait;
}
wait_calls_list_.clear();
}
FindWait::~FindWait() { wait_calls_list_.clear(); }
bool FindWait::VisitUnresolvedMemberExpr(UnresolvedMemberExpr *e) {
// This is for the templated wait calls.
// e should not be null if it gets here.
if (e->getMemberNameInfo().getAsString() == string("wait") ) {
wait_calls_list_.push_back(new WaitContainer(entry_method_decl_, wait_call_));
found_wait_ = true;
}
return true;
}
bool FindWait::VisitCallExpr(CallExpr *e) {
// bool duplicateWait = false;
clang::LangOptions LangOpts;
LangOpts.CPlusPlus = true;
clang::PrintingPolicy Policy(LangOpts);
os_ << "===============\n"; //
e->dump();
os_ << e->getNumArgs();
Expr * arge{ e->getArg(0) };
os_ << "\n argument dump\n";
arge->dump();
// e->getDirectCallee()->dump();
os_ << "END===============\n"; //
if (e->getDirectCallee()->getNameInfo().getAsString() == string("wait")) {
wait_calls_list_.push_back(new WaitContainer(entry_method_decl_, e));
}
return true;
clang::LangOptions LangOpts;
LangOpts.CPlusPlus = true;
clang::PrintingPolicy Policy(LangOpts);
// This allows templated wait calls to refer to the CallExpr as well.
wait_call_ = e;
// Check if the non-templated wait has a "wait" in it.
auto direct_callee{ e->getDirectCallee() };
if ( (direct_callee != nullptr) ) {
if ( (direct_callee->getNameInfo().getAsString() == string("wait") ) ) {
// Insert the information to parse the wait arguments.
wait_calls_list_.push_back(new WaitContainer(entry_method_decl_, wait_call_));
found_wait_ = true;
}
}
return true;
}
FindWait::waitListType FindWait::getWaitCalls() { return wait_calls_list_; }
......@@ -43,42 +69,42 @@ FindWait::waitListType FindWait::getWaitCalls() { return wait_calls_list_; }
CXXMethodDecl *FindWait::getEntryMethod() const { return entry_method_decl_; }
void FindWait::dump() {
/*
os_ << "\n ============== FindWait ===============";
os_ << "\n:> Print 'wait' statement informtion\n";
for (unsigned int i = 0; i < wait_calls_list_.size(); i++) {
if(wait_calls_list_.size() > 2) {
os_ << ":> wait pointer: " << wait_calls_list_[i] << "num. of args: " <<
wait_calls_list_[i]->getNumArgs()-1 << "\n";
for (unsigned int j = 0; j < wait_calls_list_[i]->getNumArgs()-1; j++) {
os_ << "- arg " << j << ": " << getArgumentName(wait_calls_list_[i]->getArg(j))
<< "\n";
}
}
else {
os_ << ":> wait pointer: " << wait_calls_list_[i] << "num. of args: " <<
wait_calls_list_[i]->getNumArgs() << "\n";
/*
os_ << "\n ============== FindWait ===============";
os_ << "\n:> Print 'wait' statement informtion\n";
for (unsigned int i = 0; i < wait_calls_list_.size(); i++) {
if(wait_calls_list_.size() > 2) {
os_ << ":> wait pointer: " << wait_calls_list_[i] << "num. of args: " <<
wait_calls_list_[i]->getNumArgs()-1 << "\n";
for (unsigned int j = 0; j < wait_calls_list_[i]->getNumArgs(); j++) {
os_ << "- arg " << j << ": " << getArgumentName(wait_calls_list_[i]->getArg(j))
<< "\n";
}
}
}
for (unsigned int j = 0; j < wait_calls_list_[i]->getNumArgs()-1; j++) {
os_ << "- arg " << j << ": " << getArgumentName(wait_calls_list_[i]->getArg(j))
<< "\n";
}
}
else {
os_ << ":> wait pointer: " << wait_calls_list_[i] << "num. of args: " <<
wait_calls_list_[i]->getNumArgs() << "\n";
os_ << "\n ============== END FindWait ===============";
for (unsigned int j = 0; j < wait_calls_list_[i]->getNumArgs(); j++) {
os_ << "- arg " << j << ": " << getArgumentName(wait_calls_list_[i]->getArg(j))
<< "\n";
}
}
}
os_ <<"\n Process and waiting on events ";
for (processWaitEventMapType::iterator it = _processWaitEventMap.begin(), eit =
_processWaitEventMap.end(); it != eit; it++) { os_ <<"\n Process :"
<<it->first->getDeclName().getAsString();
os_ << "\n ============== END FindWait ===============";
os_ <<"\n Waiting on event(s) : ";
vector<string> tmp = it->second;
for (int i = 0; i<tmp.size(); i++) {
os_ <<tmp.at(i)<<" ";
}
}
*/
os_ <<"\n Process and waiting on events ";
for (processWaitEventMapType::iterator it = _processWaitEventMap.begin(), eit =
_processWaitEventMap.end(); it != eit; it++) { os_ <<"\n Process :"
<<it->first->getDeclName().getAsString();
os_ <<"\n Waiting on event(s) : ";
vector<string> tmp = it->second;
for (int i = 0; i<tmp.size(); i++) {
os_ <<tmp.at(i)<<" ";
}
}
*/
}
......@@ -16,9 +16,10 @@ class FindWait : public RecursiveASTVisitor<FindWait> {
public:
typedef vector<WaitContainer *> waitListType;
typedef pair<CXXMethodDecl *, vector<string>> processWaitEventPairType;
typedef map<CXXMethodDecl *, vector<string>> processWaitEventMapType;
bool VisitUnresolvedMemberExpr(UnresolvedMemberExpr *e);
FindWait(CXXMethodDecl *, llvm::raw_ostream &);
virtual ~FindWait();
......@@ -32,9 +33,11 @@ private:
CXXMethodDecl *entry_method_decl_;
llvm::raw_ostream &os_;
CallExpr *wait_call_;
// UnresolvedMemberExpr *wait_unresolved_;
// Expr *first_arg_;
// bool found_wait_;
bool found_wait_;
waitListType wait_calls_list_;
};
} // namespace scpar
#endif
......@@ -338,7 +338,6 @@ json ModuleDecl::dump_json() {
module_j["module_name"] = module_name_;
// Template parameters.
std::cout << "\nTEMPPARM: " << template_parameters_.size() << std::endl;
for (const auto & parm: template_parameters_) {
module_j["template_parameters"].push_back( parm );
}
......
......@@ -6,83 +6,83 @@ using namespace llvm;
WaitContainer::~WaitContainer() {
// DO NOT free anything since nothing is dynamically allocated.
// DO NOT free anything since nothing is dynamically allocated.
// Clear _args.
_args.clear();
// Clear _args.
_args.clear();
}
WaitContainer::WaitContainer(CXXMethodDecl *m, CallExpr *c)
: _entryMethodDecl(m), _astNode(c), _numArgs(c->getNumArgs()) {
// Use CXXMemberCallExpr to populate the ARgMap.
populateArgMap();
// Use CXXMemberCallExpr to populate the ARgMap.
populateArgMap();
}
WaitContainer::WaitContainer(const WaitContainer &from) {
_entryMethodDecl = from._entryMethodDecl;
_astNode = from._astNode;
_numArgs = from._numArgs;
_entryMethodDecl = from._entryMethodDecl;
_astNode = from._astNode;
_numArgs = from._numArgs;
// TODO: Copy all strings (std::vector handles this)
_args = from._args;
// TODO: Copy all strings (std::vector handles this)
_args = from._args;
}
unsigned int WaitContainer::getNumArgs() { return _numArgs; }
CXXMethodDecl *WaitContainer::getEntryMethod() { return _entryMethodDecl; }
CallExpr *WaitContainer::getASTNode() { return _astNode; }
CallExpr *WaitContainer::getASTNode() { return _astNode;}
WaitContainer::waitArgVectorType WaitContainer::getArgList() { return _args; }
string WaitContainer::getArgString(Expr *e) {
if (!e) {
return string("NULL");
}
if (!e) {
return string("NULL");
}
LangOptions LO;
LangOptions LO;
LO.CPlusPlus = true;
PrintingPolicy Policy(LO);
string TypeS;
raw_string_ostream s(TypeS);
LO.CPlusPlus = true;
PrintingPolicy Policy(LO);
string TypeS;
raw_string_ostream s(TypeS);
e->printPretty(s, 0, Policy);
return s.str();
e->printPretty(s, 0, Policy);
return s.str();
}
void WaitContainer::populateArgMap() {
if (!_astNode) {
return;
}
if (!_astNode) {
return;
}
for (unsigned int i = 0; i < _astNode->getNumArgs(); i++) {
_args.push_back(getArgString(_astNode->getArg(i)));
}
for (unsigned int i = 0; i < _astNode->getNumArgs(); i++) {
_args.push_back(getArgString(_astNode->getArg(i)));
}
}
void WaitContainer::dump(raw_ostream &os, int tabn) {
for (int i = 0; i < tabn; i++) {
os << " ";
}
if (getNumArgs() > 2) {
os << "WaitContainer numargs: " << getNumArgs() - 1 << " ";
os << " arglist: ";
for (unsigned int i = 0; i < getNumArgs() - 1; i++) {
os << "'" << _args[i] << "' ";
}
} else {
os << "WaitContainer numargs: " << getNumArgs() << " ";
if (getNumArgs() > 0) {
os << " arglist: ";
for (int i = 0; i < tabn; i++) {
os << " ";
}
for (unsigned int i = 0; i < getNumArgs(); i++) {
os << "'" << _args[i] << "' ";
if (getNumArgs() > 2) {
os << "WaitContainer numargs: " << getNumArgs() - 1 << " ";
os << " arglist: ";
for (unsigned int i = 0; i < getNumArgs() - 1; i++) {
os << "'" << _args[i] << "' ";
}
} else {
os << "WaitContainer numargs: " << getNumArgs() << " ";
if (getNumArgs() > 0) {
os << " arglist: ";
}
for (unsigned int i = 0; i < getNumArgs(); i++) {
os << "'" << _args[i] << "' ";
}
}
}
os << "\n";
os << "\n";
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment