Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(400)

Side by Side Diff: src/wasm/function-body-decoder.cc

Issue 2657443003: [wasm] Fix the --wasm_code_fuzzer_gen_test again. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/function-body-decoder.h ('k') | test/fuzzer/wasm-code.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1863 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 PrintWasmCodeForDebugging(const byte* start, const byte* end) {
1883 AccountingAllocator allocator; 1883 AccountingAllocator allocator;
1884 OFStream os(stdout); 1884 PrintWasmCode(&allocator, FunctionBodyForTesting(start, end), nullptr, true);
1885 PrintWasmCode(&allocator, FunctionBodyForTesting(start, end), nullptr, os, 1885 }
1886 nullptr); 1886
1887 const char* OpcodeNameForDebugging(WasmOpcode opcode) {
titzer 2017/01/25 10:31:06 RawOpcodeName?
ahaas 2017/01/25 13:12:10 Done.
1888 switch (opcode) {
1889 #define DECLARE_NAME_CASE(name, opcode, sig) \
1890 case kExpr##name: \
1891 return "kExpr" #name;
1892 FOREACH_OPCODE(DECLARE_NAME_CASE)
1893 #undef DECLARE_NAME_CASE
1894 default:
1895 break;
1896 }
1897 return "Unknown";
1887 } 1898 }
1888 1899
1889 bool PrintWasmCode(AccountingAllocator* allocator, const FunctionBody& body, 1900 bool PrintWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
titzer 2017/01/25 10:31:06 I'd be OK with just renaming this method to PrintR
ahaas 2017/01/25 13:12:10 Done.
1890 const wasm::WasmModule* module, std::ostream& os, 1901 const wasm::WasmModule* module, bool for_debugging) {
1891 std::vector<std::tuple<uint32_t, int, int>>* offset_table) { 1902 OFStream os(stdout);
1892 Zone zone(allocator, ZONE_NAME); 1903 Zone zone(allocator, ZONE_NAME);
1893 WasmFullDecoder decoder(&zone, module, body); 1904 WasmFullDecoder decoder(&zone, module, body);
1894 int line_nr = 0; 1905 int line_nr = 0;
1895 1906
1896 // Print the function signature. 1907 // Print the function signature.
1897 if (body.sig) { 1908 if (body.sig) {
1898 os << "// signature: " << *body.sig << std::endl; 1909 os << "// signature: " << *body.sig << std::endl;
1899 ++line_nr; 1910 ++line_nr;
1900 } 1911 }
1901 1912
(...skipping 28 matching lines...) Expand all
1930 os << "// body: " << std::endl; 1941 os << "// body: " << std::endl;
1931 ++line_nr; 1942 ++line_nr;
1932 unsigned control_depth = 0; 1943 unsigned control_depth = 0;
1933 for (; i.has_next(); i.next()) { 1944 for (; i.has_next(); i.next()) {
1934 unsigned length = WasmDecoder::OpcodeLength(&decoder, i.pc()); 1945 unsigned length = WasmDecoder::OpcodeLength(&decoder, i.pc());
1935 1946
1936 WasmOpcode opcode = i.current(); 1947 WasmOpcode opcode = i.current();
1937 if (opcode == kExprElse) control_depth--; 1948 if (opcode == kExprElse) control_depth--;
1938 1949
1939 int num_whitespaces = control_depth < 32 ? 2 * control_depth : 64; 1950 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 1951
1945 // 64 whitespaces 1952 // 64 whitespaces
1946 const char* padding = 1953 const char* padding =
1947 " "; 1954 " ";
1948 os.write(padding, num_whitespaces); 1955 os.write(padding, num_whitespaces);
1949 os << "k" << WasmOpcodes::OpcodeName(opcode) << ","; 1956
1957 if (for_debugging) {
1958 os << OpcodeNameForDebugging(opcode) << ",";
1959 } else {
1960 os << "k" << WasmOpcodes::OpcodeName(opcode) << ",";
Clemens Hammacher 2017/01/24 18:51:02 Why is this outputting a "k" in front of the new o
titzer 2017/01/25 10:31:06 Right, the k shouldn't be necessary.
ahaas 2017/01/25 13:12:10 As suggested I changed the output to os << Raw
1961 }
1950 1962
1951 for (size_t j = 1; j < length; ++j) { 1963 for (size_t j = 1; j < length; ++j) {
1952 os << " 0x" << AsHex(i.pc()[j], 2) << ","; 1964 os << " 0x" << AsHex(i.pc()[j], 2) << ",";
1953 } 1965 }
1954 1966
1955 switch (opcode) { 1967 switch (opcode) {
1956 case kExprElse: 1968 case kExprElse:
1957 os << " // @" << i.pc_offset(); 1969 os << " // @" << i.pc_offset();
1958 control_depth++; 1970 control_depth++;
1959 break; 1971 break;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, 2029 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals,
2018 const byte* start, const byte* end) { 2030 const byte* start, const byte* end) {
2019 Decoder decoder(start, end); 2031 Decoder decoder(start, end);
2020 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start, 2032 return WasmDecoder::AnalyzeLoopAssignment(&decoder, start,
2021 static_cast<int>(num_locals), zone); 2033 static_cast<int>(num_locals), zone);
2022 } 2034 }
2023 2035
2024 } // namespace wasm 2036 } // namespace wasm
2025 } // namespace internal 2037 } // namespace internal
2026 } // namespace v8 2038 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/function-body-decoder.h ('k') | test/fuzzer/wasm-code.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698