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

Side by Side Diff: test/unittests/interpreter/bytecode-decoder-unittest.cc

Issue 2135273002: [interpreter] Reduce dependencies in bytecodes.{h,cc} (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix static const Register definitions for bot in roll for Windows. Created 4 years, 5 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/v8.gyp ('k') | test/unittests/interpreter/bytecodes-unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <vector>
6
7 #include "src/v8.h"
8
9 #include "src/interpreter/bytecode-decoder.h"
10 #include "test/unittests/interpreter/bytecode-utils.h"
11 #include "test/unittests/test-utils.h"
12
13 namespace v8 {
14 namespace internal {
15 namespace interpreter {
16
17 TEST(BytecodeDecoder, DecodeBytecodeAndOperands) {
18 struct BytecodesAndResult {
19 const uint8_t bytecode[32];
20 const size_t length;
21 int parameter_count;
22 const char* output;
23 };
24
25 const BytecodesAndResult cases[] = {
26 {{B(LdaSmi), U8(1)}, 2, 0, " LdaSmi [1]"},
27 {{B(Wide), B(LdaSmi), U16(1000)}, 4, 0, " LdaSmi.Wide [1000]"},
28 {{B(ExtraWide), B(LdaSmi), U32(100000)},
29 6,
30 0,
31 "LdaSmi.ExtraWide [100000]"},
32 {{B(LdaSmi), U8(-1)}, 2, 0, " LdaSmi [-1]"},
33 {{B(Wide), B(LdaSmi), U16(-1000)}, 4, 0, " LdaSmi.Wide [-1000]"},
34 {{B(ExtraWide), B(LdaSmi), U32(-100000)},
35 6,
36 0,
37 "LdaSmi.ExtraWide [-100000]"},
38 {{B(Star), R8(5)}, 2, 0, " Star r5"},
39 {{B(Wide), B(Star), R16(136)}, 4, 0, " Star.Wide r136"},
40 {{B(Wide), B(Call), R16(134), R16(135), U16(2), U16(177)},
41 10,
42 0,
43 "Call.Wide r134, r135, #2, [177]"},
44 {{B(Ldar),
45 static_cast<uint8_t>(Register::FromParameterIndex(2, 3).ToOperand())},
46 2,
47 3,
48 " Ldar a1"},
49 {{B(Wide), B(CreateObjectLiteral), U16(513), U16(1027), U8(165)},
50 7,
51 0,
52 "CreateObjectLiteral.Wide [513], [1027], #165"},
53 {{B(ExtraWide), B(JumpIfNull), U32(123456789)},
54 6,
55 0,
56 "JumpIfNull.ExtraWide [123456789]"},
57 };
58
59 for (size_t i = 0; i < arraysize(cases); ++i) {
60 // Generate reference string by prepending formatted bytes.
61 std::stringstream expected_ss;
62 std::ios default_format(nullptr);
63 default_format.copyfmt(expected_ss);
64 // Match format of BytecodeDecoder::Decode() for byte representations.
65 expected_ss.fill('0');
66 expected_ss.flags(std::ios::right | std::ios::hex);
67 for (size_t b = 0; b < cases[i].length; b++) {
68 expected_ss << std::setw(2) << static_cast<uint32_t>(cases[i].bytecode[b])
69 << ' ';
70 }
71 expected_ss.copyfmt(default_format);
72 expected_ss << cases[i].output;
73
74 // Generate decoded byte output.
75 std::stringstream actual_ss;
76 BytecodeDecoder::Decode(actual_ss, cases[i].bytecode,
77 cases[i].parameter_count);
78
79 // Compare.
80 CHECK_EQ(actual_ss.str(), expected_ss.str());
81 }
82 }
83
84 } // namespace interpreter
85 } // namespace internal
86 } // namespace v8
OLDNEW
« no previous file with comments | « src/v8.gyp ('k') | test/unittests/interpreter/bytecodes-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698