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 #include "src/signature.h" | 5 #include "src/signature.h" |
6 | 6 |
7 #include "src/bit-vector.h" | 7 #include "src/bit-vector.h" |
8 #include "src/flags.h" | 8 #include "src/flags.h" |
9 #include "src/handles.h" | 9 #include "src/handles.h" |
10 #include "src/zone/zone-containers.h" | 10 #include "src/zone/zone-containers.h" |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 : WasmFullDecoder(zone, module, nullptr, body) {} | 463 : WasmFullDecoder(zone, module, nullptr, body) {} |
464 | 464 |
465 WasmFullDecoder(Zone* zone, TFBuilder* builder, const FunctionBody& body) | 465 WasmFullDecoder(Zone* zone, TFBuilder* builder, const FunctionBody& body) |
466 : WasmFullDecoder(zone, builder->module_env() == nullptr | 466 : WasmFullDecoder(zone, builder->module_env() == nullptr |
467 ? nullptr | 467 ? nullptr |
468 : builder->module_env()->module, | 468 : builder->module_env()->module, |
469 builder, body) {} | 469 builder, body) {} |
470 | 470 |
471 bool Decode() { | 471 bool Decode() { |
472 if (FLAG_wasm_code_fuzzer_gen_test) { | 472 if (FLAG_wasm_code_fuzzer_gen_test) { |
473 PrintWasmCodeForDebugging(start_, end_); | 473 PrintRawWasmCode(start_, end_); |
474 } | 474 } |
475 base::ElapsedTimer decode_timer; | 475 base::ElapsedTimer decode_timer; |
476 if (FLAG_trace_wasm_decode_time) { | 476 if (FLAG_trace_wasm_decode_time) { |
477 decode_timer.Start(); | 477 decode_timer.Start(); |
478 } | 478 } |
479 stack_.clear(); | 479 stack_.clear(); |
480 control_.clear(); | 480 control_.clear(); |
481 | 481 |
482 if (end_ < pc_) { | 482 if (end_ < pc_) { |
483 error("function body end < start"); | 483 error("function body end < start"); |
(...skipping 1388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1872 WasmFullDecoder decoder(&zone, builder, body); | 1872 WasmFullDecoder decoder(&zone, builder, body); |
1873 decoder.Decode(); | 1873 decoder.Decode(); |
1874 return decoder.toResult<DecodeStruct*>(nullptr); | 1874 return decoder.toResult<DecodeStruct*>(nullptr); |
1875 } | 1875 } |
1876 | 1876 |
1877 unsigned OpcodeLength(const byte* pc, const byte* end) { | 1877 unsigned OpcodeLength(const byte* pc, const byte* end) { |
1878 Decoder decoder(pc, end); | 1878 Decoder decoder(pc, end); |
1879 return WasmDecoder::OpcodeLength(&decoder, pc); | 1879 return WasmDecoder::OpcodeLength(&decoder, pc); |
1880 } | 1880 } |
1881 | 1881 |
1882 void PrintWasmCodeForDebugging(const byte* start, const byte* end) { | 1882 void PrintRawWasmCode(const byte* start, const byte* end) { |
1883 AccountingAllocator allocator; | 1883 AccountingAllocator allocator; |
1884 OFStream os(stdout); | 1884 PrintRawWasmCode(&allocator, FunctionBodyForTesting(start, end), nullptr); |
1885 PrintWasmCode(&allocator, FunctionBodyForTesting(start, end), nullptr, os, | |
1886 nullptr); | |
1887 } | 1885 } |
1888 | 1886 |
1889 bool PrintWasmCode(AccountingAllocator* allocator, const FunctionBody& body, | 1887 namespace { |
1890 const wasm::WasmModule* module, std::ostream& os, | 1888 const char* RawOpcodeName(WasmOpcode opcode) { |
1891 std::vector<std::tuple<uint32_t, int, int>>* offset_table) { | 1889 switch (opcode) { |
| 1890 #define DECLARE_NAME_CASE(name, opcode, sig) \ |
| 1891 case kExpr##name: \ |
| 1892 return "kExpr" #name; |
| 1893 FOREACH_OPCODE(DECLARE_NAME_CASE) |
| 1894 #undef DECLARE_NAME_CASE |
| 1895 default: |
| 1896 break; |
| 1897 } |
| 1898 return "Unknown"; |
| 1899 } |
| 1900 } // namespace |
| 1901 |
| 1902 bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body, |
| 1903 const wasm::WasmModule* module) { |
| 1904 OFStream os(stdout); |
1892 Zone zone(allocator, ZONE_NAME); | 1905 Zone zone(allocator, ZONE_NAME); |
1893 WasmFullDecoder decoder(&zone, module, body); | 1906 WasmFullDecoder decoder(&zone, module, body); |
1894 int line_nr = 0; | 1907 int line_nr = 0; |
1895 | 1908 |
1896 // Print the function signature. | 1909 // Print the function signature. |
1897 if (body.sig) { | 1910 if (body.sig) { |
1898 os << "// signature: " << *body.sig << std::endl; | 1911 os << "// signature: " << *body.sig << std::endl; |
1899 ++line_nr; | 1912 ++line_nr; |
1900 } | 1913 } |
1901 | 1914 |
(...skipping 28 matching lines...) Expand all Loading... |
1930 os << "// body: " << std::endl; | 1943 os << "// body: " << std::endl; |
1931 ++line_nr; | 1944 ++line_nr; |
1932 unsigned control_depth = 0; | 1945 unsigned control_depth = 0; |
1933 for (; i.has_next(); i.next()) { | 1946 for (; i.has_next(); i.next()) { |
1934 unsigned length = WasmDecoder::OpcodeLength(&decoder, i.pc()); | 1947 unsigned length = WasmDecoder::OpcodeLength(&decoder, i.pc()); |
1935 | 1948 |
1936 WasmOpcode opcode = i.current(); | 1949 WasmOpcode opcode = i.current(); |
1937 if (opcode == kExprElse) control_depth--; | 1950 if (opcode == kExprElse) control_depth--; |
1938 | 1951 |
1939 int num_whitespaces = control_depth < 32 ? 2 * control_depth : 64; | 1952 int num_whitespaces = control_depth < 32 ? 2 * control_depth : 64; |
1940 if (offset_table) { | |
1941 offset_table->push_back( | |
1942 std::make_tuple(i.pc_offset(), line_nr, num_whitespaces)); | |
1943 } | |
1944 | 1953 |
1945 // 64 whitespaces | 1954 // 64 whitespaces |
1946 const char* padding = | 1955 const char* padding = |
1947 " "; | 1956 " "; |
1948 os.write(padding, num_whitespaces); | 1957 os.write(padding, num_whitespaces); |
1949 os << "k" << WasmOpcodes::OpcodeName(opcode) << ","; | 1958 |
| 1959 os << RawOpcodeName(opcode) << ","; |
1950 | 1960 |
1951 for (size_t j = 1; j < length; ++j) { | 1961 for (size_t j = 1; j < length; ++j) { |
1952 os << " 0x" << AsHex(i.pc()[j], 2) << ","; | 1962 os << " 0x" << AsHex(i.pc()[j], 2) << ","; |
1953 } | 1963 } |
1954 | 1964 |
1955 switch (opcode) { | 1965 switch (opcode) { |
1956 case kExprElse: | 1966 case kExprElse: |
1957 os << " // @" << i.pc_offset(); | 1967 os << " // @" << i.pc_offset(); |
1958 control_depth++; | 1968 control_depth++; |
1959 break; | 1969 break; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2017 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 2027 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
2018 const byte* start, const byte* end) { | 2028 const byte* start, const byte* end) { |
2019 Decoder decoder(start, end); | 2029 Decoder decoder(start, end); |
2020 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start, | 2030 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start, |
2021 static_cast<int>(num_locals), zone); | 2031 static_cast<int>(num_locals), zone); |
2022 } | 2032 } |
2023 | 2033 |
2024 } // namespace wasm | 2034 } // namespace wasm |
2025 } // namespace internal | 2035 } // namespace internal |
2026 } // namespace v8 | 2036 } // namespace v8 |
OLD | NEW |