diff options
Diffstat (limited to 'src/wasm-io.h')
-rw-r--r-- | src/wasm-io.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/wasm-io.h b/src/wasm-io.h new file mode 100644 index 000000000..7d7358f9c --- /dev/null +++ b/src/wasm-io.h @@ -0,0 +1,68 @@ +/* + * Copyright 2017 WebAssembly Community Group participants + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// Abstracts reading and writing, supporting both text and binary. +// + +#ifndef wasm_wasm_io_h +#define wasm_wasm_io_h + +#include "wasm.h" + +namespace wasm { + +class ModuleIO { +protected: + bool debug = false; + +public: + void setDebug(bool debug_) { debug = debug_; } +}; + +class ModuleReader : public ModuleIO { +public: + // read text + void readText(std::string filename, Module& wasm); + // read binary + void readBinary(std::string filename, Module& wasm); + // read text or binary, checking the contents for what it is + void read(std::string filename, Module& wasm); +}; + +class ModuleWriter : public ModuleIO { + bool binary = true; + bool debugInfo = false; + std::string symbolMap; + +public: + void setBinary(bool binary_) { binary = binary_; } + void setDebugInfo(bool debugInfo_) { debugInfo = debugInfo_; } + void setSymbolMap(std::string symbolMap_) { symbolMap = symbolMap_; } + + // write text + void writeText(Module& wasm, std::string filename); + // write binary + void writeBinary(Module& wasm, std::string filename); + // write text or binary, defaulting to binary unless setBinary(false), + // and unless there is no output file (in which case we write text + // to stdout). + void write(Module& wasm, std::string filename); +}; + +} + +#endif // wasm_wasm_io_h |