]>
Commit | Line | Data |
---|---|---|
5b943348 JP |
1 | From 94af090661d7c953c516c97a25ed053c744a0737 Mon Sep 17 00:00:00 2001 |
2 | From: Alexey Sotkin <alexey.sotkin@intel.com> | |
3 | Date: Mon, 18 Feb 2019 18:19:13 +0300 | |
4 | Subject: [PATCH] Align with modified llvm::writeSpirv API | |
5 | ||
6 | --- | |
7 | common_clang.cpp | 29 +++++++++++++++++++++++++---- | |
8 | 1 file changed, 25 insertions(+), 4 deletions(-) | |
9 | ||
10 | diff --git a/common_clang.cpp b/common_clang.cpp | |
11 | index eff1064..ee1ec9b 100644 | |
12 | --- a/common_clang.cpp | |
13 | +++ b/common_clang.cpp | |
14 | @@ -63,17 +63,18 @@ Copyright (c) Intel Corporation (2009-2017). | |
15 | #define CL_OUT_OF_HOST_MEMORY -6 | |
16 | ||
17 | #include "assert.h" | |
18 | -#include <list> | |
19 | +#include <algorithm> | |
20 | #include <iosfwd> | |
21 | -#include <sstream> | |
22 | #include <iterator> | |
23 | -#include <algorithm> | |
24 | +#include <list> | |
25 | +#include <streambuf> | |
26 | #ifdef _WIN32 | |
27 | #include <ctype.h> | |
28 | #endif | |
29 | ||
30 | #if defined _DEBUG | |
31 | #include <cstdlib> | |
32 | +#include <sstream> | |
33 | #include <fstream> | |
34 | #include <thread> | |
35 | #endif | |
36 | @@ -164,6 +165,25 @@ static void PrintCompileOptions(const char *pszOptions, const char *pszOptionsEx | |
37 | #endif | |
38 | } | |
39 | ||
40 | +class SmallVectorBuffer : public std::streambuf | |
41 | +{ | |
42 | + // All memory management is delegated to llvm::SmallVectorImpl | |
43 | + llvm::SmallVectorImpl<char> &OS; | |
44 | + | |
45 | + // Since we don't touch any pointer in streambuf(pbase, pptr, epptr) this is | |
46 | + // the only method we need to override. | |
47 | + virtual std::streamsize xsputn(const char *s, std::streamsize n) override { | |
48 | + OS.append(s, s + n); | |
49 | + return n; | |
50 | + } | |
51 | + | |
52 | +public: | |
53 | + SmallVectorBuffer() = delete; | |
54 | + SmallVectorBuffer(const SmallVectorBuffer&) = delete; | |
55 | + SmallVectorBuffer &operator=(const SmallVectorBuffer&) = delete; | |
56 | + SmallVectorBuffer(llvm::SmallVectorImpl<char> &O) : OS(O) {} | |
57 | +}; | |
58 | + | |
59 | extern "C" CC_DLL_EXPORT int | |
60 | Compile(const char *pszProgramSource, const char **pInputHeaders, | |
61 | unsigned int uiNumInputHeaders, const char **pInputHeadersNames, | |
62 | @@ -300,7 +320,8 @@ Compile(const char *pszProgramSource, const char **pInputHeaders, | |
63 | return CL_COMPILE_PROGRAM_FAILURE; | |
64 | } | |
65 | pResult->getIRBufferRef().clear(); | |
66 | - llvm::raw_svector_ostream OS(pResult->getIRBufferRef()); | |
67 | + SmallVectorBuffer StreamBuf(pResult->getIRBufferRef()); | |
68 | + std::ostream OS(&StreamBuf); | |
69 | std::string Err; | |
70 | success = llvm::writeSpirv(M.get(), OS, Err); | |
71 | err_ostream << Err.c_str(); |