Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "base/stringprintf.h" |
| 18 | #include "builder.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 19 | #include "dex_file.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 20 | #include "dex_instruction.h" |
| 21 | #include "nodes.h" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 22 | #include "optimizing_unit_test.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 23 | #include "pretty_printer.h" |
| 24 | #include "utils/arena_allocator.h" |
| 25 | |
| 26 | #include "gtest/gtest.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 30 | static void TestCode(const uint16_t* data, const char* expected) { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 31 | ArenaPool pool; |
| 32 | ArenaAllocator allocator(&pool); |
| 33 | HGraphBuilder builder(&allocator); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 34 | const DexFile::CodeItem* item = reinterpret_cast<const DexFile::CodeItem*>(data); |
| 35 | HGraph* graph = builder.BuildGraph(*item); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 36 | ASSERT_NE(graph, nullptr); |
| 37 | StringPrettyPrinter printer(graph); |
| 38 | printer.VisitInsertionOrder(); |
| 39 | ASSERT_STREQ(expected, printer.str().c_str()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 42 | TEST(PrettyPrinterTest, ReturnVoid) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 43 | const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( |
| 44 | Instruction::RETURN_VOID); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 45 | |
| 46 | const char* expected = |
| 47 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 48 | " 2: SuspendCheck\n" |
| 49 | " 3: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 50 | "BasicBlock 1, pred: 0, succ: 2\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 51 | " 0: ReturnVoid\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 52 | "BasicBlock 2, pred: 1\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 53 | " 1: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 54 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 55 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | TEST(PrettyPrinterTest, CFG1) { |
| 59 | const char* expected = |
| 60 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 61 | " 3: SuspendCheck\n" |
| 62 | " 4: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 63 | "BasicBlock 1, pred: 0, succ: 2\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 64 | " 0: Goto 2\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 65 | "BasicBlock 2, pred: 1, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 66 | " 1: ReturnVoid\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 67 | "BasicBlock 3, pred: 2\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 68 | " 2: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 69 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 70 | const uint16_t data[] = |
| 71 | ZERO_REGISTER_CODE_ITEM( |
| 72 | Instruction::GOTO | 0x100, |
| 73 | Instruction::RETURN_VOID); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 74 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 75 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | TEST(PrettyPrinterTest, CFG2) { |
| 79 | const char* expected = |
| 80 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 81 | " 4: SuspendCheck\n" |
| 82 | " 5: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 83 | "BasicBlock 1, pred: 0, succ: 2\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 84 | " 0: Goto 2\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 85 | "BasicBlock 2, pred: 1, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 86 | " 1: Goto 3\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 87 | "BasicBlock 3, pred: 2, succ: 4\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 88 | " 2: ReturnVoid\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 89 | "BasicBlock 4, pred: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 90 | " 3: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 91 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 92 | const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 93 | Instruction::GOTO | 0x100, |
| 94 | Instruction::GOTO | 0x100, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 95 | Instruction::RETURN_VOID); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 96 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 97 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | TEST(PrettyPrinterTest, CFG3) { |
| 101 | const char* expected = |
| 102 | "BasicBlock 0, succ: 1\n" |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame^] | 103 | " 4: SuspendCheck\n" |
| 104 | " 5: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 105 | "BasicBlock 1, pred: 0, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 106 | " 0: Goto 3\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 107 | "BasicBlock 2, pred: 3, succ: 4\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 108 | " 1: ReturnVoid\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 109 | "BasicBlock 3, pred: 1, succ: 2\n" |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame^] | 110 | " 2: Goto 2\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 111 | "BasicBlock 4, pred: 2\n" |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame^] | 112 | " 3: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 113 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 114 | const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 115 | Instruction::GOTO | 0x200, |
| 116 | Instruction::RETURN_VOID, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 117 | Instruction::GOTO | 0xFF00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 118 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 119 | TestCode(data1, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 120 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 121 | const uint16_t data2[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 122 | Instruction::GOTO_16, 3, |
| 123 | Instruction::RETURN_VOID, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 124 | Instruction::GOTO_16, 0xFFFF); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 125 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 126 | TestCode(data2, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 127 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 128 | const uint16_t data3[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 129 | Instruction::GOTO_32, 4, 0, |
| 130 | Instruction::RETURN_VOID, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 131 | Instruction::GOTO_32, 0xFFFF, 0xFFFF); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 132 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 133 | TestCode(data3, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | TEST(PrettyPrinterTest, CFG4) { |
| 137 | const char* expected = |
| 138 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 139 | " 3: SuspendCheck\n" |
| 140 | " 4: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 141 | "BasicBlock 1, pred: 0, 1, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 142 | " 0: SuspendCheck\n" |
| 143 | " 1: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 144 | "BasicBlock 2\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 145 | " 2: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 146 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 147 | const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 148 | Instruction::NOP, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 149 | Instruction::GOTO | 0xFF00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 150 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 151 | TestCode(data1, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 152 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 153 | const uint16_t data2[] = ZERO_REGISTER_CODE_ITEM( |
| 154 | Instruction::GOTO_32, 0, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 155 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 156 | TestCode(data2, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | TEST(PrettyPrinterTest, CFG5) { |
| 160 | const char* expected = |
| 161 | "BasicBlock 0, succ: 1\n" |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame^] | 162 | " 3: SuspendCheck\n" |
| 163 | " 4: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 164 | "BasicBlock 1, pred: 0, 2, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 165 | " 0: ReturnVoid\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 166 | "BasicBlock 2, succ: 1\n" |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame^] | 167 | " 1: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 168 | "BasicBlock 3, pred: 1\n" |
David Brazdil | 2fd6aa5 | 2015-02-02 18:58:27 +0000 | [diff] [blame^] | 169 | " 2: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 170 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 171 | const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 172 | Instruction::RETURN_VOID, |
| 173 | Instruction::GOTO | 0x100, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 174 | Instruction::GOTO | 0xFE00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 175 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 176 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 177 | } |
| 178 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 179 | TEST(PrettyPrinterTest, CFG6) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 180 | const char* expected = |
| 181 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 182 | " 0: Local [4, 3, 2]\n" |
| 183 | " 1: IntConstant [2]\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 184 | " 10: SuspendCheck\n" |
| 185 | " 11: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 186 | "BasicBlock 1, pred: 0, succ: 3, 2\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 187 | " 2: StoreLocal(0, 1)\n" |
| 188 | " 3: LoadLocal(0) [5]\n" |
| 189 | " 4: LoadLocal(0) [5]\n" |
| 190 | " 5: Equal(3, 4) [6]\n" |
| 191 | " 6: If(5)\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 192 | "BasicBlock 2, pred: 1, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 193 | " 7: Goto 3\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 194 | "BasicBlock 3, pred: 1, 2, succ: 4\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 195 | " 8: ReturnVoid\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 196 | "BasicBlock 4, pred: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 197 | " 9: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 198 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 199 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 200 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 201 | Instruction::IF_EQ, 3, |
| 202 | Instruction::GOTO | 0x100, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 203 | Instruction::RETURN_VOID); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 204 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 205 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 208 | TEST(PrettyPrinterTest, CFG7) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 209 | const char* expected = |
| 210 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 211 | " 0: Local [4, 3, 2]\n" |
| 212 | " 1: IntConstant [2]\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 213 | " 11: SuspendCheck\n" |
| 214 | " 12: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 215 | "BasicBlock 1, pred: 0, succ: 3, 2\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 216 | " 2: StoreLocal(0, 1)\n" |
| 217 | " 3: LoadLocal(0) [5]\n" |
| 218 | " 4: LoadLocal(0) [5]\n" |
| 219 | " 5: Equal(3, 4) [6]\n" |
| 220 | " 6: If(5)\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 221 | "BasicBlock 2, pred: 1, 3, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 222 | " 7: Goto 3\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 223 | "BasicBlock 3, pred: 1, 2, succ: 2\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 224 | " 8: SuspendCheck\n" |
| 225 | " 9: Goto 2\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 226 | "BasicBlock 4\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 227 | " 10: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 228 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 229 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 230 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 231 | Instruction::IF_EQ, 3, |
| 232 | Instruction::GOTO | 0x100, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 233 | Instruction::GOTO | 0xFF00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 234 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 235 | TestCode(data, expected); |
| 236 | } |
| 237 | |
| 238 | TEST(PrettyPrinterTest, IntConstant) { |
| 239 | const char* expected = |
| 240 | "BasicBlock 0, succ: 1\n" |
| 241 | " 0: Local [2]\n" |
| 242 | " 1: IntConstant [2]\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 243 | " 5: SuspendCheck\n" |
| 244 | " 6: Goto 1\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 245 | "BasicBlock 1, pred: 0, succ: 2\n" |
| 246 | " 2: StoreLocal(0, 1)\n" |
| 247 | " 3: ReturnVoid\n" |
| 248 | "BasicBlock 2, pred: 1\n" |
| 249 | " 4: Exit\n"; |
| 250 | |
| 251 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 252 | Instruction::CONST_4 | 0 | 0, |
| 253 | Instruction::RETURN_VOID); |
| 254 | |
| 255 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 256 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 257 | } // namespace art |