| 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 |
| 11 #include "src/base/smart-pointers.h" | 11 #include "src/base/smart-pointers.h" |
| 12 | 12 |
| 13 #include "src/wasm/wasm-macro-gen.h" |
| 13 #include "src/wasm/wasm-module.h" | 14 #include "src/wasm/wasm-module.h" |
| 14 #include "src/wasm/wasm-opcodes.h" | 15 #include "src/wasm/wasm-opcodes.h" |
| 15 #include "src/wasm/wasm-result.h" | 16 #include "src/wasm/wasm-result.h" |
| 16 | 17 |
| 17 namespace v8 { | 18 namespace v8 { |
| 18 namespace internal { | 19 namespace internal { |
| 19 namespace wasm { | 20 namespace wasm { |
| 20 | 21 |
| 21 class WasmModuleBuilder; | 22 class WasmModuleBuilder; |
| 22 | 23 |
| 23 class WasmFunctionEncoder : public ZoneObject { | 24 class WasmFunctionEncoder : public ZoneObject { |
| 24 public: | 25 public: |
| 25 uint32_t HeaderSize() const; | 26 uint32_t HeaderSize() const; |
| 27 uint32_t LocalDeclSize() const { |
| 28 return static_cast<uint32_t>(local_decls_.Size()); |
| 29 } |
| 26 uint32_t BodySize() const; | 30 uint32_t BodySize() const; |
| 27 uint32_t NameSize() const; | 31 uint32_t NameSize() const; |
| 28 void Serialize(byte* buffer, byte** header, byte** body) const; | 32 void Serialize(byte* buffer, byte** header, byte** body) const; |
| 29 | 33 |
| 30 private: | 34 private: |
| 31 WasmFunctionEncoder(Zone* zone, LocalType return_type, bool exported, | 35 WasmFunctionEncoder(Zone* zone, LocalType return_type, bool exported, |
| 32 bool external); | 36 bool external); |
| 33 friend class WasmFunctionBuilder; | 37 friend class WasmFunctionBuilder; |
| 34 uint16_t signature_index_; | 38 uint16_t signature_index_; |
| 35 ZoneVector<LocalType> params_; | 39 ZoneVector<LocalType> params_; |
| 36 uint16_t local_i32_count_; | 40 LocalDeclEncoder local_decls_; |
| 37 uint16_t local_i64_count_; | |
| 38 uint16_t local_f32_count_; | |
| 39 uint16_t local_f64_count_; | |
| 40 bool exported_; | 41 bool exported_; |
| 41 bool external_; | 42 bool external_; |
| 42 ZoneVector<uint8_t> body_; | 43 ZoneVector<uint8_t> body_; |
| 43 ZoneVector<char> name_; | 44 ZoneVector<char> name_; |
| 44 | 45 |
| 45 bool HasLocals() const { | |
| 46 return (local_i32_count_ + local_i64_count_ + local_f32_count_ + | |
| 47 local_f64_count_) > 0; | |
| 48 } | |
| 49 | |
| 50 bool HasName() const { return (exported_ || external_) && name_.size() > 0; } | 46 bool HasName() const { return (exported_ || external_) && name_.size() > 0; } |
| 51 }; | 47 }; |
| 52 | 48 |
| 53 class WasmFunctionBuilder : public ZoneObject { | 49 class WasmFunctionBuilder : public ZoneObject { |
| 54 public: | 50 public: |
| 55 uint16_t AddParam(LocalType type); | 51 uint16_t AddParam(LocalType type); |
| 56 uint16_t AddLocal(LocalType type); | 52 uint16_t AddLocal(LocalType type); |
| 57 void ReturnType(LocalType type); | 53 void ReturnType(LocalType type); |
| 58 void EmitCode(const byte* code, uint32_t code_size); | 54 void EmitCode(const byte* code, uint32_t code_size); |
| 59 void EmitCode(const byte* code, uint32_t code_size, | 55 void EmitCode(const byte* code, uint32_t code_size, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 SignatureMap signature_map_; | 146 SignatureMap signature_map_; |
| 151 int start_function_index_; | 147 int start_function_index_; |
| 152 }; | 148 }; |
| 153 | 149 |
| 154 std::vector<uint8_t> UnsignedLEB128From(uint32_t result); | 150 std::vector<uint8_t> UnsignedLEB128From(uint32_t result); |
| 155 } // namespace wasm | 151 } // namespace wasm |
| 156 } // namespace internal | 152 } // namespace internal |
| 157 } // namespace v8 | 153 } // namespace v8 |
| 158 | 154 |
| 159 #endif // V8_WASM_ENCODER_H_ | 155 #endif // V8_WASM_ENCODER_H_ |
| OLD | NEW |