summaryrefslogtreecommitdiff
path: root/src/wasm-io.h
blob: 803cbaf90c38a7f0c34ec45486e297f8d44e29f1 (plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
 * 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"
#include "parsing.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