forked from KhronosGroup/SPIRV-LLVM-Translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SPIRVWriterPass.cpp
50 lines (43 loc) · 1.44 KB
/
SPIRVWriterPass.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//===- SPIRVWriterPass.cpp - SPIRV writing pass -----------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// SPIRVWriterPass implementation.
//
//===----------------------------------------------------------------------===//
#include "SPIRVWriterPass.h"
#include "LLVMSPIRVLib.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
using namespace llvm;
PreservedAnalyses SPIRVWriterPass::run(Module &M) {
// FIXME: at the moment LLVM/SPIR-V translation errors are ignored.
std::string Err;
writeSpirv(&M, OS, Err);
return PreservedAnalyses::all();
}
namespace {
class WriteSPIRVPass : public ModulePass {
std::ostream &OS; // std::ostream to print on
public:
static char ID; // Pass identification, replacement for typeid
explicit WriteSPIRVPass(std::ostream &O) : ModulePass(ID), OS(O) {}
StringRef getPassName() const override { return "SPIRV Writer"; }
bool runOnModule(Module &M) override {
// FIXME: at the moment LLVM/SPIR-V translation errors are ignored.
std::string Err;
writeSpirv(&M, OS, Err);
return false;
}
};
} // namespace
char WriteSPIRVPass::ID = 0;
ModulePass *llvm::createSPIRVWriterPass(std::ostream &Str) {
return new WriteSPIRVPass(Str);
}