| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_WASM_ENCODER_H_ | 5 #ifndef V8_WASM_ENCODER_H_ |
| 6 #define V8_WASM_ENCODER_H_ | 6 #define V8_WASM_ENCODER_H_ |
| 7 | 7 |
| 8 #include "src/signature.h" | 8 #include "src/signature.h" |
| 9 #include "src/zone-containers.h" | 9 #include "src/zone-containers.h" |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 class WasmFunctionBuilder : public ZoneObject { | 53 class WasmFunctionBuilder : public ZoneObject { |
| 54 public: | 54 public: |
| 55 uint16_t AddParam(LocalType type); | 55 uint16_t AddParam(LocalType type); |
| 56 uint16_t AddLocal(LocalType type); | 56 uint16_t AddLocal(LocalType type); |
| 57 void ReturnType(LocalType type); | 57 void ReturnType(LocalType type); |
| 58 void EmitCode(const byte* code, uint32_t code_size); | 58 void EmitCode(const byte* code, uint32_t code_size); |
| 59 void EmitCode(const byte* code, uint32_t code_size, | 59 void EmitCode(const byte* code, uint32_t code_size, |
| 60 const uint32_t* local_indices, uint32_t indices_size); | 60 const uint32_t* local_indices, uint32_t indices_size); |
| 61 void Emit(WasmOpcode opcode); | 61 void Emit(WasmOpcode opcode); |
| 62 void EmitWithU8(WasmOpcode opcode, const byte immediate); | 62 void EmitWithU8(WasmOpcode opcode, const byte immediate); |
| 63 void EmitWithLocal(WasmOpcode opcode); | |
| 64 uint32_t EmitEditableImmediate(const byte immediate); | 63 uint32_t EmitEditableImmediate(const byte immediate); |
| 65 void EditImmediate(uint32_t offset, const byte immediate); | 64 void EditImmediate(uint32_t offset, const byte immediate); |
| 66 void Exported(uint8_t flag); | 65 void Exported(uint8_t flag); |
| 67 void External(uint8_t flag); | 66 void External(uint8_t flag); |
| 68 void SetName(const unsigned char* name, int name_length); | 67 void SetName(const unsigned char* name, int name_length); |
| 69 WasmFunctionEncoder* Build(Zone* zone, WasmModuleBuilder* mb) const; | 68 WasmFunctionEncoder* Build(Zone* zone, WasmModuleBuilder* mb) const; |
| 70 | 69 |
| 71 private: | 70 private: |
| 72 explicit WasmFunctionBuilder(Zone* zone); | 71 explicit WasmFunctionBuilder(Zone* zone); |
| 73 friend class WasmModuleBuilder; | 72 friend class WasmModuleBuilder; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 uint16_t AddFunction(); | 128 uint16_t AddFunction(); |
| 130 uint32_t AddGlobal(MachineType type, bool exported); | 129 uint32_t AddGlobal(MachineType type, bool exported); |
| 131 WasmFunctionBuilder* FunctionAt(size_t index); | 130 WasmFunctionBuilder* FunctionAt(size_t index); |
| 132 void AddDataSegment(WasmDataSegmentEncoder* data); | 131 void AddDataSegment(WasmDataSegmentEncoder* data); |
| 133 uint16_t AddSignature(FunctionSig* sig); | 132 uint16_t AddSignature(FunctionSig* sig); |
| 134 void AddIndirectFunction(uint16_t index); | 133 void AddIndirectFunction(uint16_t index); |
| 135 WasmModuleWriter* Build(Zone* zone); | 134 WasmModuleWriter* Build(Zone* zone); |
| 136 | 135 |
| 137 private: | 136 private: |
| 138 struct CompareFunctionSigs { | 137 struct CompareFunctionSigs { |
| 139 int operator()(FunctionSig* a, FunctionSig* b) const; | 138 bool operator()(FunctionSig* a, FunctionSig* b) const; |
| 140 }; | 139 }; |
| 141 typedef ZoneMap<FunctionSig*, uint16_t, CompareFunctionSigs> SignatureMap; | 140 typedef ZoneMap<FunctionSig*, uint16_t, CompareFunctionSigs> SignatureMap; |
| 142 | 141 |
| 143 Zone* zone_; | 142 Zone* zone_; |
| 144 ZoneVector<FunctionSig*> signatures_; | 143 ZoneVector<FunctionSig*> signatures_; |
| 145 ZoneVector<WasmFunctionBuilder*> functions_; | 144 ZoneVector<WasmFunctionBuilder*> functions_; |
| 146 ZoneVector<WasmDataSegmentEncoder*> data_segments_; | 145 ZoneVector<WasmDataSegmentEncoder*> data_segments_; |
| 147 ZoneVector<uint16_t> indirect_functions_; | 146 ZoneVector<uint16_t> indirect_functions_; |
| 148 ZoneVector<std::pair<MachineType, bool>> globals_; | 147 ZoneVector<std::pair<MachineType, bool>> globals_; |
| 149 SignatureMap signature_map_; | 148 SignatureMap signature_map_; |
| 150 }; | 149 }; |
| 151 | 150 |
| 152 std::vector<uint8_t> UnsignedLEB128From(uint32_t result); | 151 std::vector<uint8_t> UnsignedLEB128From(uint32_t result); |
| 153 } // namespace wasm | 152 } // namespace wasm |
| 154 } // namespace internal | 153 } // namespace internal |
| 155 } // namespace v8 | 154 } // namespace v8 |
| 156 | 155 |
| 157 #endif // V8_WASM_ENCODER_H_ | 156 #endif // V8_WASM_ENCODER_H_ |
| OLD | NEW |