コード例 #1
0
llvm::error_code create_directories(const llvm::Twine& path)
{
    using namespace llvm;
    using namespace llvm::sys;
    SmallString<128> path_storage;
    StringRef p = path.toStringRef(path_storage);
    StringRef parent = path::parent_path(p);
    if (!parent.empty()) {
        bool parent_exists;
        if (error_code ec = fs::exists(parent, parent_exists)) return ec;

        if (!parent_exists)
            if (error_code ec = create_directories(parent)) return ec;
    }

    return create_directory(p);
}
コード例 #2
0
ファイル: pConfig.cpp プロジェクト: weyrick/corvus
bool pConfigMgr::read(const llvm::Twine &file, pConfig &c) {

    llvm::SmallString<128> path_storage;
    llvm::StringRef fName = file.toStringRef(path_storage);

    llvm::OwningPtr<llvm::MemoryBuffer> contents;
    if (llvm::MemoryBuffer::getFile(fName, contents)) {
        return false;
    }

    llvm::SourceMgr sm;
    llvm::StringRef input = contents->getBufferStart();
    llvm::yaml::Stream stream(input, sm);
    llvm::SmallString<128> kstorage;
    llvm::SmallString<128> vstorage;

    for (llvm::yaml::document_iterator di = stream.begin(), de = stream.end();
       di != de; ++di) {
        llvm::yaml::MappingNode *n = llvm::dyn_cast<llvm::yaml::MappingNode>(di->getRoot());
        if (!n)
            break;
        for (llvm::yaml::MappingNode::iterator i = n->begin();
             i != n->end();
             ++i) {
            llvm::yaml::ScalarNode *keyN = llvm::dyn_cast<llvm::yaml::ScalarNode>(i->getKey());
            llvm::yaml::ScalarNode *valN = llvm::dyn_cast<llvm::yaml::ScalarNode>(i->getValue());
            if (!keyN || !valN)
                continue;
            //std::cout << "key is " << key->getValue(storage).str() << ", val is " << val->getValue(storage).str() << std::endl;

            pStringRef key = keyN->getValue(kstorage);
            pStringRef val = valN->getValue(vstorage);
            if (key == "include") {
                c.includePaths.push_back(val.str());
            }
            else if (key == "source_directory" || key == "source_file") {
                c.inputFiles.push_back(val.str());
            }
            else if (key == "diagnostic_file") {
                c.diagFiles.push_back(val.str());
            }
            else if (key == "db") {
                c.dbName = val.str();
            }
            else if (key == "exts") {
                c.exts = val.str();
            }
            else if (key == "verbosity") {
                llvm::APInt result;
                val.getAsInteger(10, result);
                c.verbosity = result.getLimitedValue();
            }
            else {
                std::cerr << "unknown key in config file: " << key.str() << std::endl;
            }

        }
    }

    return true;

}