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

Side by Side Diff: courgette/adjustment_method_unittest.cc

Issue 2462993003: [Courgette] Refactor: Add and use Instruction*Receptor classes; call ParseFile() in 2 passes. (Closed)
Patch Set: Fix style and comments; lint; remove size param from InstructionStoreReceptor ctor. Created 4 years, 1 month 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 | « no previous file | courgette/assembly_program.h » ('j') | courgette/assembly_program.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium 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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 abs32_rvas.push_back(kRvaB); 42 abs32_rvas.push_back(kRvaB);
43 std::vector<courgette::RVA> rel32_rvas; // Stub. 43 std::vector<courgette::RVA> rel32_rvas; // Stub.
44 44
45 courgette::TrivialRvaVisitor abs32_visitor(abs32_rvas); 45 courgette::TrivialRvaVisitor abs32_visitor(abs32_rvas);
46 courgette::TrivialRvaVisitor rel32_visitor(rel32_rvas); 46 courgette::TrivialRvaVisitor rel32_visitor(rel32_rvas);
47 prog->PrecomputeLabels(&abs32_visitor, &rel32_visitor); 47 prog->PrecomputeLabels(&abs32_visitor, &rel32_visitor);
48 48
49 courgette::Label* labelA = prog->FindAbs32Label(kRvaA); 49 courgette::Label* labelA = prog->FindAbs32Label(kRvaA);
50 courgette::Label* labelB = prog->FindAbs32Label(kRvaB); 50 courgette::Label* labelB = prog->FindAbs32Label(kRvaB);
51 51
52 EXPECT_TRUE(prog->EmitAbs32(labelA)); 52 auto emit_all = [](courgette::Label* labelA, courgette::Label* labelB,
53 EXPECT_TRUE(prog->EmitAbs32(labelA)); 53 courgette::InstructionReceptor* receptor) {
54 EXPECT_TRUE(prog->EmitAbs32(labelB)); 54 EXPECT_TRUE(receptor->EmitAbs32(labelA));
55 EXPECT_TRUE(prog->EmitAbs32(labelA)); 55 EXPECT_TRUE(receptor->EmitAbs32(labelA));
56 EXPECT_TRUE(prog->EmitAbs32(labelA)); 56 EXPECT_TRUE(receptor->EmitAbs32(labelB));
57 EXPECT_TRUE(prog->EmitAbs32(labelB)); 57 EXPECT_TRUE(receptor->EmitAbs32(labelA));
58 EXPECT_TRUE(receptor->EmitAbs32(labelA));
59 EXPECT_TRUE(receptor->EmitAbs32(labelB));
60 };
61
62 // Pass 1: Count the space needed to store instructions.
63 courgette::InstructionCountReceptor* count_receptor = nullptr;
64 EXPECT_TRUE(prog->CreateInstructionCountReceptor(&count_receptor));
65 emit_all(labelA, labelB, count_receptor);
66
67 // Pass 2: Emit all instructions to preallocated buffer (uses Phase 1
68 // count).
69 courgette::InstructionStoreReceptor* store_receptor = nullptr;
70 EXPECT_TRUE(prog->CreateInstructionStoreReceptor(&store_receptor));
71 emit_all(labelA, labelB, store_receptor);
58 72
59 if (kind == 0) { 73 if (kind == 0) {
60 labelA->index_ = 0; 74 labelA->index_ = 0;
61 labelB->index_ = 1; 75 labelB->index_ = 1;
62 } else { 76 } else {
63 labelA->index_ = 1; 77 labelA->index_ = 1;
64 labelB->index_ = 0; 78 labelB->index_ = 0;
65 } 79 }
66 prog->AssignRemainingIndexes(); 80 prog->AssignRemainingIndexes();
67 81
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 std::string s5 = Serialize(std::move(prog5)); 132 std::string s5 = Serialize(std::move(prog5));
119 std::string s6 = Serialize(std::move(prog6)); 133 std::string s6 = Serialize(std::move(prog6));
120 134
121 EXPECT_TRUE(s1 == s5); // Adjustment did not change A (prog5) 135 EXPECT_TRUE(s1 == s5); // Adjustment did not change A (prog5)
122 EXPECT_TRUE(s5 == s6); // Adjustment did change B into A 136 EXPECT_TRUE(s5 == s6); // Adjustment did change B into A
123 } 137 }
124 138
125 TEST_F(AdjustmentMethodTest, All) { 139 TEST_F(AdjustmentMethodTest, All) {
126 Test1(); 140 Test1();
127 } 141 }
OLDNEW
« no previous file with comments | « no previous file | courgette/assembly_program.h » ('j') | courgette/assembly_program.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698