Skip to content

Commit 94af090

Browse files
committed
Align with modified llvm::writeSpirv API
1 parent 938aa87 commit 94af090

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

common_clang.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,18 @@ Copyright (c) Intel Corporation (2009-2017).
6363
#define CL_OUT_OF_HOST_MEMORY -6
6464

6565
#include "assert.h"
66-
#include <list>
66+
#include <algorithm>
6767
#include <iosfwd>
68-
#include <sstream>
6968
#include <iterator>
70-
#include <algorithm>
69+
#include <list>
70+
#include <streambuf>
7171
#ifdef _WIN32
7272
#include <ctype.h>
7373
#endif
7474

7575
#if defined _DEBUG
7676
#include <cstdlib>
77+
#include <sstream>
7778
#include <fstream>
7879
#include <thread>
7980
#endif
@@ -164,6 +165,25 @@ static void PrintCompileOptions(const char *pszOptions, const char *pszOptionsEx
164165
#endif
165166
}
166167

168+
class SmallVectorBuffer : public std::streambuf
169+
{
170+
// All memory management is delegated to llvm::SmallVectorImpl
171+
llvm::SmallVectorImpl<char> &OS;
172+
173+
// Since we don't touch any pointer in streambuf(pbase, pptr, epptr) this is
174+
// the only method we need to override.
175+
virtual std::streamsize xsputn(const char *s, std::streamsize n) override {
176+
OS.append(s, s + n);
177+
return n;
178+
}
179+
180+
public:
181+
SmallVectorBuffer() = delete;
182+
SmallVectorBuffer(const SmallVectorBuffer&) = delete;
183+
SmallVectorBuffer &operator=(const SmallVectorBuffer&) = delete;
184+
SmallVectorBuffer(llvm::SmallVectorImpl<char> &O) : OS(O) {}
185+
};
186+
167187
extern "C" CC_DLL_EXPORT int
168188
Compile(const char *pszProgramSource, const char **pInputHeaders,
169189
unsigned int uiNumInputHeaders, const char **pInputHeadersNames,
@@ -300,7 +320,8 @@ Compile(const char *pszProgramSource, const char **pInputHeaders,
300320
return CL_COMPILE_PROGRAM_FAILURE;
301321
}
302322
pResult->getIRBufferRef().clear();
303-
llvm::raw_svector_ostream OS(pResult->getIRBufferRef());
323+
SmallVectorBuffer StreamBuf(pResult->getIRBufferRef());
324+
std::ostream OS(&StreamBuf);
304325
std::string Err;
305326
success = llvm::writeSpirv(M.get(), OS, Err);
306327
err_ostream << Err.c_str();

0 commit comments

Comments
 (0)