OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include "src/wasm/wasm-interpreter.h" | 5 #include "src/wasm/wasm-interpreter.h" |
6 | 6 |
7 #include "src/utils.h" | 7 #include "src/utils.h" |
8 #include "src/wasm/ast-decoder.h" | |
9 #include "src/wasm/decoder.h" | 8 #include "src/wasm/decoder.h" |
| 9 #include "src/wasm/function-body-decoder.h" |
10 #include "src/wasm/wasm-external-refs.h" | 10 #include "src/wasm/wasm-external-refs.h" |
11 #include "src/wasm/wasm-limits.h" | 11 #include "src/wasm/wasm-limits.h" |
12 #include "src/wasm/wasm-module.h" | 12 #include "src/wasm/wasm-module.h" |
13 | 13 |
14 #include "src/zone/accounting-allocator.h" | 14 #include "src/zone/accounting-allocator.h" |
15 #include "src/zone/zone-containers.h" | 15 #include "src/zone/zone-containers.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 namespace wasm { | 19 namespace wasm { |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 | 714 |
715 static const int kRunSteps = 1000; | 715 static const int kRunSteps = 1000; |
716 | 716 |
717 // A helper class to compute the control transfers for each bytecode offset. | 717 // A helper class to compute the control transfers for each bytecode offset. |
718 // Control transfers allow Br, BrIf, BrTable, If, Else, and End bytecodes to | 718 // Control transfers allow Br, BrIf, BrTable, If, Else, and End bytecodes to |
719 // be directly executed without the need to dynamically track blocks. | 719 // be directly executed without the need to dynamically track blocks. |
720 class ControlTransfers : public ZoneObject { | 720 class ControlTransfers : public ZoneObject { |
721 public: | 721 public: |
722 ControlTransferMap map_; | 722 ControlTransferMap map_; |
723 | 723 |
724 ControlTransfers(Zone* zone, AstLocalDecls* locals, const byte* start, | 724 ControlTransfers(Zone* zone, BodyLocalDecls* locals, const byte* start, |
725 const byte* end) | 725 const byte* end) |
726 : map_(zone) { | 726 : map_(zone) { |
727 // Represents a control flow label. | 727 // Represents a control flow label. |
728 struct CLabel : public ZoneObject { | 728 struct CLabel : public ZoneObject { |
729 const byte* target; | 729 const byte* target; |
730 ZoneVector<const byte*> refs; | 730 ZoneVector<const byte*> refs; |
731 | 731 |
732 explicit CLabel(Zone* zone) : target(nullptr), refs(zone) {} | 732 explicit CLabel(Zone* zone) : target(nullptr), refs(zone) {} |
733 | 733 |
734 // Bind this label to the given PC. | 734 // Bind this label to the given PC. |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 if (result == map_.end()) { | 865 if (result == map_.end()) { |
866 V8_Fatal(__FILE__, __LINE__, "no control target for pc %zu", from); | 866 V8_Fatal(__FILE__, __LINE__, "no control target for pc %zu", from); |
867 } | 867 } |
868 return result->second; | 868 return result->second; |
869 } | 869 } |
870 }; | 870 }; |
871 | 871 |
872 // Code and metadata needed to execute a function. | 872 // Code and metadata needed to execute a function. |
873 struct InterpreterCode { | 873 struct InterpreterCode { |
874 const WasmFunction* function; // wasm function | 874 const WasmFunction* function; // wasm function |
875 AstLocalDecls locals; // local declarations | 875 BodyLocalDecls locals; // local declarations |
876 const byte* orig_start; // start of original code | 876 const byte* orig_start; // start of original code |
877 const byte* orig_end; // end of original code | 877 const byte* orig_end; // end of original code |
878 byte* start; // start of (maybe altered) code | 878 byte* start; // start of (maybe altered) code |
879 byte* end; // end of (maybe altered) code | 879 byte* end; // end of (maybe altered) code |
880 ControlTransfers* targets; // helper for control flow. | 880 ControlTransfers* targets; // helper for control flow. |
881 | 881 |
882 const byte* at(pc_t pc) { return start + pc; } | 882 const byte* at(pc_t pc) { return start + pc; } |
883 }; | 883 }; |
884 | 884 |
885 // The main storage for interpreter code. It maps {WasmFunction} to the | 885 // The main storage for interpreter code. It maps {WasmFunction} to the |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 CHECK(DecodeLocalDecls(code->locals, code->start, code->end)); | 931 CHECK(DecodeLocalDecls(code->locals, code->start, code->end)); |
932 code->targets = new (zone_) ControlTransfers( | 932 code->targets = new (zone_) ControlTransfers( |
933 zone_, &code->locals, code->orig_start, code->orig_end); | 933 zone_, &code->locals, code->orig_start, code->orig_end); |
934 } | 934 } |
935 return code; | 935 return code; |
936 } | 936 } |
937 | 937 |
938 int AddFunction(const WasmFunction* function, const byte* code_start, | 938 int AddFunction(const WasmFunction* function, const byte* code_start, |
939 const byte* code_end) { | 939 const byte* code_end) { |
940 InterpreterCode code = { | 940 InterpreterCode code = { |
941 function, AstLocalDecls(zone_), code_start, | 941 function, BodyLocalDecls(zone_), code_start, |
942 code_end, const_cast<byte*>(code_start), const_cast<byte*>(code_end), | 942 code_end, const_cast<byte*>(code_start), const_cast<byte*>(code_end), |
943 nullptr}; | 943 nullptr}; |
944 | 944 |
945 DCHECK_EQ(interpreter_code_.size(), function->func_index); | 945 DCHECK_EQ(interpreter_code_.size(), function->func_index); |
946 interpreter_code_.push_back(code); | 946 interpreter_code_.push_back(code); |
947 return static_cast<int>(interpreter_code_.size()) - 1; | 947 return static_cast<int>(interpreter_code_.size()) - 1; |
948 } | 948 } |
949 | 949 |
950 bool SetFunctionCode(const WasmFunction* function, const byte* start, | 950 bool SetFunctionCode(const WasmFunction* function, const byte* start, |
951 const byte* end) { | 951 const byte* end) { |
(...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1888 | 1888 |
1889 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( | 1889 ControlTransferMap WasmInterpreter::ComputeControlTransfersForTesting( |
1890 Zone* zone, const byte* start, const byte* end) { | 1890 Zone* zone, const byte* start, const byte* end) { |
1891 ControlTransfers targets(zone, nullptr, start, end); | 1891 ControlTransfers targets(zone, nullptr, start, end); |
1892 return targets.map_; | 1892 return targets.map_; |
1893 } | 1893 } |
1894 | 1894 |
1895 } // namespace wasm | 1895 } // namespace wasm |
1896 } // namespace internal | 1896 } // namespace internal |
1897 } // namespace v8 | 1897 } // namespace v8 |
OLD | NEW |