Skip to content

Commit

Permalink
Add llvm:Optional to SPIRVStream.h
Browse files Browse the repository at this point in the history
SPIRVTypeImage uses std::vector<T> emulating std::optional behavior
This commit allows to use native llvm::Optional class in
SPIRVEncoder and SPIRVDecoder and replace std::vector in SPIRVTypeImage
  • Loading branch information
NikitaRudenkoIntel authored and AlexeySachkov committed Sep 9, 2020
1 parent 518ebe8 commit adc3cf9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/SPIRV/libSPIRV/SPIRVStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ const SPIRVDecoder &operator>>(const SPIRVDecoder &I, std::vector<T> &V) {
return I;
}

template <typename T>
const SPIRVDecoder &operator>>(const SPIRVDecoder &I, llvm::Optional<T> &V) {
if (V)
I >> V.getValue();
return I;
}

template <typename T>
const SPIRVEncoder &operator<<(const SPIRVEncoder &O, T V) {
#ifdef _SPIRV_SUPPORT_TEXT_FMT
Expand All @@ -194,6 +201,14 @@ const SPIRVEncoder &operator<<(const SPIRVEncoder &O, const std::vector<T> &V) {
return O;
}

template <typename T>
const SPIRVEncoder &operator<<(const SPIRVEncoder &O,
const llvm::Optional<T> &V) {
if (V)
O << V.getValue();
return O;
}

template <typename IterTy>
const SPIRVEncoder &operator<<(const SPIRVEncoder &Encoder,
const std::pair<IterTy, IterTy> &Range) {
Expand Down

0 comments on commit adc3cf9

Please sign in to comment.