Skip to content

Commit

Permalink
Align with modified llvm::writeSpirv API
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexeySotkin committed Aug 16, 2019
1 parent 938aa87 commit 94af090
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions common_clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,18 @@ Copyright (c) Intel Corporation (2009-2017).
#define CL_OUT_OF_HOST_MEMORY -6

#include "assert.h"
#include <list>
#include <algorithm>
#include <iosfwd>
#include <sstream>
#include <iterator>
#include <algorithm>
#include <list>
#include <streambuf>
#ifdef _WIN32
#include <ctype.h>
#endif

#if defined _DEBUG
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <thread>
#endif
Expand Down Expand Up @@ -164,6 +165,25 @@ static void PrintCompileOptions(const char *pszOptions, const char *pszOptionsEx
#endif
}

class SmallVectorBuffer : public std::streambuf
{
// All memory management is delegated to llvm::SmallVectorImpl
llvm::SmallVectorImpl<char> &OS;

// Since we don't touch any pointer in streambuf(pbase, pptr, epptr) this is
// the only method we need to override.
virtual std::streamsize xsputn(const char *s, std::streamsize n) override {
OS.append(s, s + n);
return n;
}

public:
SmallVectorBuffer() = delete;
SmallVectorBuffer(const SmallVectorBuffer&) = delete;
SmallVectorBuffer &operator=(const SmallVectorBuffer&) = delete;
SmallVectorBuffer(llvm::SmallVectorImpl<char> &O) : OS(O) {}
};

extern "C" CC_DLL_EXPORT int
Compile(const char *pszProgramSource, const char **pInputHeaders,
unsigned int uiNumInputHeaders, const char **pInputHeadersNames,
Expand Down Expand Up @@ -300,7 +320,8 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
return CL_COMPILE_PROGRAM_FAILURE;
}
pResult->getIRBufferRef().clear();
llvm::raw_svector_ostream OS(pResult->getIRBufferRef());
SmallVectorBuffer StreamBuf(pResult->getIRBufferRef());
std::ostream OS(&StreamBuf);
std::string Err;
success = llvm::writeSpirv(M.get(), OS, Err);
err_ostream << Err.c_str();
Expand Down

0 comments on commit 94af090

Please sign in to comment.