1 //===- subzero/src/WasmTranslator.h - WASM to Subzero Translation ---------===// 2 // 3 // The Subzero Code Generator 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 /// 10 /// \file 11 /// \brief Declares a driver for translating Wasm bitcode into PNaCl bitcode. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef SUBZERO_SRC_WASMTRANSLATOR_H 16 #define SUBZERO_SRC_WASMTRANSLATOR_H 17 18 #if ALLOW_WASM 19 20 #include "IceGlobalContext.h" 21 #include "IceTranslator.h" 22 23 #ifdef __clang__ 24 #pragma clang diagnostic push 25 #pragma clang diagnostic ignored "-Wunused-parameter" 26 #endif // __clang__ 27 28 #include "llvm/Support/StreamingMemoryObject.h" 29 30 #ifdef __clang__ 31 #pragma clang diagnostic pop 32 #endif // __clang__ 33 34 namespace v8 { 35 namespace internal { 36 class Zone; 37 namespace wasm { 38 struct FunctionBody; 39 } // end of namespace wasm 40 } // end of namespace internal 41 } // end of namespace v8 42 43 namespace Ice { 44 45 class WasmTranslator : public Translator { 46 WasmTranslator() = delete; 47 WasmTranslator(const WasmTranslator &) = delete; 48 WasmTranslator &operator=(const WasmTranslator &) = delete; 49 log(F Fn)50 template <typename F = std::function<void(Ostream &)>> void log(F Fn) { 51 if (BuildDefs::dump() && (getFlags().getVerbose() & IceV_Wasm)) { 52 Fn(Ctx->getStrDump()); 53 Ctx->getStrDump().flush(); 54 } 55 } 56 57 public: 58 explicit WasmTranslator(GlobalContext *Ctx); 59 60 void translate(const std::string &IRFilename, 61 std::unique_ptr<llvm::DataStreamer> InputStream); 62 63 /// Translates a single Wasm function. 64 /// 65 /// Parameters: 66 /// Zone - an arena for the V8 code to allocate from. 67 /// Body - information about the function to translate 68 std::unique_ptr<Cfg> 69 translateFunction(v8::internal::Zone *Zone, 70 v8::internal::wasm::FunctionBody &Body); 71 72 private: 73 std::vector<uint8_t> Buffer; 74 }; 75 } // namespace Ice 76 77 #endif // ALLOW_WASM 78 79 #endif // SUBZERO_SRC_WASMTRANSLATOR_H 80