Пример #1
0
 void MetaProcessor::setFileStream(llvm::StringRef file, bool append, int fd,
             llvm::SmallVector<llvm::SmallString<128>, 2>& prevFileStack) {
   // If we have a fileName to redirect to store it.
   if (!file.empty()) {
     prevFileStack.push_back(file);
     // pop and push a null terminating 0.
     // SmallVectorImpl<T> does not have a c_str(), thus instead of casting to
     // a SmallString<T> we null terminate the data that we have and pop the
     // 0 char back.
     prevFileStack.back().push_back(0);
     prevFileStack.back().pop_back();
     if (!append) {
       FILE * f;
       if (!(f = fopen(file.data(), "w"))) {
         llvm::errs() << "cling::MetaProcessor::setFileStream:"
                      " The file path " << file.data() << "is not valid.";
       } else {
         fclose(f);
       }
     }
   // Else unredirection, so switch to the previous file.
   } else {
     // If there is no previous file on the stack we pop the file
     if (!prevFileStack.empty()) {
       prevFileStack.pop_back();
     }
   }
 }
Пример #2
0
/**
 * Check if rank arguments of send, recv pair match.
 *
 * @return is matching
 */
bool MPICheckerAST::rankArgsMatch(const MPICall &sendCall,
                                  const MPICall &recvCall,
                                  const MPIRankCase &sendCase,
                                  const MPIRankCase &recvCase) const {
    // match special case
    if (isFirstLastPair(sendCall, recvCall, sendCase, recvCase)) return true;

    // compare ranks
    const auto &rankArgSend = sendCall.arg(MPIPointToPoint::kRank);
    const auto &rankArgRecv = recvCall.arg(MPIPointToPoint::kRank);

    if (rankArgSend.valueSequence().size() !=
            rankArgRecv.valueSequence().size())
        return false;

    // build sequences without last operator(skip first element)
    const llvm::SmallVector<std::string, 4> sendValSeq{
        rankArgSend.valueSequence().begin() + 1,
        rankArgSend.valueSequence().end()},
    recvValSeq{rankArgRecv.valueSequence().begin() + 1,
               rankArgRecv.valueSequence().end()};

    bool containsSubtraction{false};
    for (size_t i = 0; i < sendValSeq.size(); ++i) {
        if (sendValSeq[i] == "-" || recvValSeq[i] == "-") {
            containsSubtraction = true;
            break;
        }
    }

    // check ordered
    if (containsSubtraction && (sendValSeq != recvValSeq)) return false;
    // check permutation
    if (!containsSubtraction &&
            (!cont::isPermutation(sendValSeq, recvValSeq))) {
        return false;
    }
    // last (value|var|function) must be identical
    if (sendValSeq.back() != recvValSeq.back()) return false;
    // last operator must be inverse
    if (!rankArgSend.isLastOperatorInverse(rankArgRecv)) return false;

    return true;
}