| 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 29 matching lines...) Expand all Loading... |
| 40 bool exported_; | 40 bool exported_; |
| 41 bool external_; | 41 bool external_; |
| 42 ZoneVector<uint8_t> body_; | 42 ZoneVector<uint8_t> body_; |
| 43 ZoneVector<char> name_; | 43 ZoneVector<char> name_; |
| 44 | 44 |
| 45 bool HasLocals() const { | 45 bool HasLocals() const { |
| 46 return (local_i32_count_ + local_i64_count_ + local_f32_count_ + | 46 return (local_i32_count_ + local_i64_count_ + local_f32_count_ + |
| 47 local_f64_count_) > 0; | 47 local_f64_count_) > 0; |
| 48 } | 48 } |
| 49 | 49 |
| 50 bool HasName() const { return exported_ && name_.size() > 0; } | 50 bool HasName() const { return (exported_ || external_) && name_.size() > 0; } |
| 51 }; | 51 }; |
| 52 | 52 |
| 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); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 public: | 126 public: |
| 127 explicit WasmModuleBuilder(Zone* zone); | 127 explicit WasmModuleBuilder(Zone* zone); |
| 128 uint16_t AddFunction(); | 128 uint16_t AddFunction(); |
| 129 uint32_t AddGlobal(MachineType type, bool exported); | 129 uint32_t AddGlobal(MachineType type, bool exported); |
| 130 WasmFunctionBuilder* FunctionAt(size_t index); | 130 WasmFunctionBuilder* FunctionAt(size_t index); |
| 131 void AddDataSegment(WasmDataSegmentEncoder* data); | 131 void AddDataSegment(WasmDataSegmentEncoder* data); |
| 132 uint16_t AddSignature(FunctionSig* sig); | 132 uint16_t AddSignature(FunctionSig* sig); |
| 133 void AddIndirectFunction(uint16_t index); | 133 void AddIndirectFunction(uint16_t index); |
| 134 WasmModuleWriter* Build(Zone* zone); | 134 WasmModuleWriter* Build(Zone* zone); |
| 135 | 135 |
| 136 private: | |
| 137 struct CompareFunctionSigs { | 136 struct CompareFunctionSigs { |
| 138 bool operator()(FunctionSig* a, FunctionSig* b) const; | 137 bool operator()(FunctionSig* a, FunctionSig* b) const; |
| 139 }; | 138 }; |
| 140 typedef ZoneMap<FunctionSig*, uint16_t, CompareFunctionSigs> SignatureMap; | 139 typedef ZoneMap<FunctionSig*, uint16_t, CompareFunctionSigs> SignatureMap; |
| 141 | 140 |
| 141 private: |
| 142 Zone* zone_; | 142 Zone* zone_; |
| 143 ZoneVector<FunctionSig*> signatures_; | 143 ZoneVector<FunctionSig*> signatures_; |
| 144 ZoneVector<WasmFunctionBuilder*> functions_; | 144 ZoneVector<WasmFunctionBuilder*> functions_; |
| 145 ZoneVector<WasmDataSegmentEncoder*> data_segments_; | 145 ZoneVector<WasmDataSegmentEncoder*> data_segments_; |
| 146 ZoneVector<uint16_t> indirect_functions_; | 146 ZoneVector<uint16_t> indirect_functions_; |
| 147 ZoneVector<std::pair<MachineType, bool>> globals_; | 147 ZoneVector<std::pair<MachineType, bool>> globals_; |
| 148 SignatureMap signature_map_; | 148 SignatureMap signature_map_; |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 std::vector<uint8_t> UnsignedLEB128From(uint32_t result); | 151 std::vector<uint8_t> UnsignedLEB128From(uint32_t result); |
| 152 } // namespace wasm | 152 } // namespace wasm |
| 153 } // namespace internal | 153 } // namespace internal |
| 154 } // namespace v8 | 154 } // namespace v8 |
| 155 | 155 |
| 156 #endif // V8_WASM_ENCODER_H_ | 156 #endif // V8_WASM_ENCODER_H_ |
| OLD | NEW |