// o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o bool BRTMapKernelDef::CheckSemantics() const { FunctionType *fType; Decl *outArg = NULL; assert (decl->form->type == TT_Function); fType = (FunctionType *) decl->form; for (unsigned int i = 0; i < fType->nArgs; i++) { if (fType->args[i]->isReduce()) { std::cerr << location << "Reduce arguments are not allowed in " << *FunctionName() << ": "; fType->args[i]->print(std::cerr, true); std::cerr << ".\n"; return false; } if ((fType->args[i]->form->getQualifiers() & TQ_Out) != 0) { /* if (outArg) { std::cerr << location << "Multiple outputs not supported: "; outArg->print(std::cerr, true); std::cerr << ", "; fType->args[i]->print(std::cerr, true); std::cerr << ".\n"; return false; }*/ outArg = fType->args[i]; if (!recursiveIsStream(outArg->form)) { std::cerr << location << "Output is not a stream: "; outArg->print(std::cerr, true); std::cerr << ".\n"; return false; } if ((outArg->form->getQualifiers() & TQ_Iter) != 0) { std::cerr << location << "Output cannot be an iterator: "; outArg->print(std::cerr, true); std::cerr << ".\n"; return false; } } } if (outArg == NULL&&returnsVoid()) { std::cerr << location << "Warning: " << *FunctionName() << " has no output.\n"; } return true; }
// o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o void StructDef::print(std::ostream& out, Symbol *name, int level) const { if (isUnion()) out << "union "; else out << "struct "; if (tag) out << *tag << " "; out << "{\n"; for (int j=0; j < nComponents; j++) { indent(out,level+1); components[j]->print(out,true,level+1); Decl *decl = components[j]->next; while (decl != NULL) { out << ", "; decl->print(out,false,level+1); decl = decl->next; } out << ";\n"; } indent(out,level); out << "}"; if (name) out << " " << *name; }
// o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o+o bool BRTReduceKernelDef::CheckSemantics() const { FunctionType *fType; Decl *streamArg = NULL, *reduceArg = NULL; assert (decl->form->type == TT_Function); fType = (FunctionType *) decl->form; for (unsigned int i = 0; i < fType->nArgs; i++) { if (fType->args[i]->isReduce()) { if (reduceArg != NULL) { std::cerr << location << "Multiple reduce arguments in " << *FunctionName() << ": "; reduceArg->print(std::cerr, true); std::cerr << ", "; fType->args[i]->print(std::cerr, true); std::cerr << ".\n"; return false; } reduceArg = fType->args[i]; } else if (fType->args[i]->isStream()) { if (streamArg != NULL) { std::cerr << location << "Multiple non-reduce streams in " << *FunctionName() << ": "; streamArg->print(std::cerr, true); std::cerr << ", "; fType->args[i]->print(std::cerr, true); std::cerr << ".\n"; return false; } streamArg = fType->args[i]; } if ((fType->args[i]->form->getQualifiers() & TQ_Out) != 0) { std::cerr << location << "Non-reduce output in reduction kernel " << *FunctionName() << ".\n"; return false; } } if (reduceArg == NULL) { std::cerr << location << "Reduction kernel " << *FunctionName() << " has no reduce argument.\n"; return false; } if (streamArg == NULL) { std::cerr << location << "Reduction kernel " << *FunctionName() << " has no stream argument.\n"; return false; } return true; }
void ASTConsumerHTML::HandleInterestingDecl(DeclGroupRef D) { for (DeclGroupRef::iterator it = D.begin(); it != D.end(); ++it) { Decl *decl = *it; if (decl) { log << "\n" << decl << " HandleInterestingDecl" << "\n"; decl->print(log); log << "\n"; } } }
void ASTConsumerHTML::HandleTopLevelDecl(DeclGroupRef D) { static int count = 0; for (DeclGroupRef::iterator it = D.begin(); it != D.end(); ++it) { Decl *decl = *it; if (decl) { if (!preprocessor.getSourceManager().isFromMainFile(decl->getLocation())) { continue; } log << "\n" << decl << " HandleTopLevelDecl" << "\n"; decl->print(log); log << "\n"; decl->dumpXML(log); log << "\n"; html->HandleTopLevelDecl(decl); } } }
bool SimplePrinterConsumer::HandleTopLevelDecl(DeclGroupRef D) { if(D.begin() == D.end()) { return true; } Decl *firstD = *(D.begin()); if(compInst->getSourceManager().isInSystemHeader(firstD->getLocation())) { return true; } PrintingPolicy policy = compInst->getASTContext().getPrintingPolicy(); NullStmt *nullSt = new (compInst->getASTContext()) NullStmt(SourceLocation()); for(DeclGroupRef::iterator I = D.begin(), E = D.end(); I != E; ++I) { Decl *dd = *I; DPRINT("PrintingPolicy: %d %d %d %d %d", policy.SuppressSpecifiers, policy.SuppressScope, policy.SuppressTag, policy.SuppressUnwrittenScope, policy.SuppressSpecifiers); dd->print(out, policy); nullSt->printPretty(out, NULL, policy); if(dd->hasBody()) { Stmt *ss = dd->getBody(); // Print Stmts //dd->dump(); //StmtPrinter(compInst, dd->getBody()).TraverseDecl(dd); // CFG OwningPtr<CFG> cfg; cfg.reset(CFG::buildCFG((const Decl*)dd, (Stmt*)(dd->getBody()), &compInst->getASTContext(), CFG::BuildOptions())); assert(cfg.get() != NULL && "build CFG failed."); cfg->dump(compInst->getLangOpts(), true); cfg->viewCFG(compInst->getLangOpts()); } } return true; };