Home | History | Annotate | Download | only in SPIRV
      1 //===- SPIRVWriterPass.cpp - SPIRV writing pass -----------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // SPIRVWriterPass implementation.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "SPIRVWriterPass.h"
     15 #include "llvm/IR/Module.h"
     16 #include "llvm/IR/PassManager.h"
     17 #include "llvm/Pass.h"
     18 #include "llvm/Support/SPIRV.h"
     19 using namespace llvm;
     20 
     21 PreservedAnalyses SPIRVWriterPass::run(Module &M) {
     22   // FIXME: at the moment LLVM/SPIR-V translation errors are ignored.
     23   std::string err;
     24   WriteSPIRV(&M, OS, err);
     25   return PreservedAnalyses::all();
     26 }
     27 
     28 namespace {
     29   class WriteSPIRVPass : public ModulePass {
     30     raw_ostream &OS; // raw_ostream to print on
     31   public:
     32     static char ID; // Pass identification, replacement for typeid
     33     explicit WriteSPIRVPass(raw_ostream &o)
     34       : ModulePass(ID), OS(o) {}
     35 
     36     const char *getPassName() const override { return "SPIRV Writer"; }
     37 
     38     bool runOnModule(Module &M) override {
     39       // FIXME: at the moment LLVM/SPIR-V translation errors are ignored.
     40       std::string err;
     41       WriteSPIRV(&M, OS, err);
     42       return false;
     43     }
     44   };
     45 }
     46 
     47 char WriteSPIRVPass::ID = 0;
     48 
     49 ModulePass *llvm::createSPIRVWriterPass(raw_ostream &Str) {
     50   return new WriteSPIRVPass(Str);
     51 }
     52