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" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 103 | " 5: SuspendCheck\n" |
| 104 | " 6: 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" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 110 | " 2: SuspendCheck\n" |
| 111 | " 3: Goto 2\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 112 | "BasicBlock 4, pred: 2\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 113 | " 4: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 114 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 115 | const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 116 | Instruction::GOTO | 0x200, |
| 117 | Instruction::RETURN_VOID, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 118 | Instruction::GOTO | 0xFF00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 119 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 120 | TestCode(data1, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 121 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 122 | const uint16_t data2[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 123 | Instruction::GOTO_16, 3, |
| 124 | Instruction::RETURN_VOID, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 125 | Instruction::GOTO_16, 0xFFFF); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 126 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 127 | TestCode(data2, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 128 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 129 | const uint16_t data3[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 130 | Instruction::GOTO_32, 4, 0, |
| 131 | Instruction::RETURN_VOID, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 132 | Instruction::GOTO_32, 0xFFFF, 0xFFFF); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 133 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 134 | TestCode(data3, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | TEST(PrettyPrinterTest, CFG4) { |
| 138 | const char* expected = |
| 139 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 140 | " 3: SuspendCheck\n" |
| 141 | " 4: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 142 | "BasicBlock 1, pred: 0, 1, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 143 | " 0: SuspendCheck\n" |
| 144 | " 1: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 145 | "BasicBlock 2\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 146 | " 2: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 147 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 148 | const uint16_t data1[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 149 | Instruction::NOP, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 150 | Instruction::GOTO | 0xFF00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 151 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 152 | TestCode(data1, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 153 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 154 | const uint16_t data2[] = ZERO_REGISTER_CODE_ITEM( |
| 155 | Instruction::GOTO_32, 0, 0); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 156 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 157 | TestCode(data2, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | TEST(PrettyPrinterTest, CFG5) { |
| 161 | const char* expected = |
| 162 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 163 | " 4: SuspendCheck\n" |
| 164 | " 5: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 165 | "BasicBlock 1, pred: 0, 2, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 166 | " 0: ReturnVoid\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 167 | "BasicBlock 2, succ: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 168 | " 1: SuspendCheck\n" |
| 169 | " 2: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 170 | "BasicBlock 3, pred: 1\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 171 | " 3: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 172 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 173 | const uint16_t data[] = ZERO_REGISTER_CODE_ITEM( |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 174 | Instruction::RETURN_VOID, |
| 175 | Instruction::GOTO | 0x100, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 176 | Instruction::GOTO | 0xFE00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 177 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 178 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 179 | } |
| 180 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 181 | TEST(PrettyPrinterTest, CFG6) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 182 | const char* expected = |
| 183 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 184 | " 0: Local [4, 3, 2]\n" |
| 185 | " 1: IntConstant [2]\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 186 | " 10: SuspendCheck\n" |
| 187 | " 11: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 188 | "BasicBlock 1, pred: 0, succ: 3, 2\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 189 | " 2: StoreLocal(0, 1)\n" |
| 190 | " 3: LoadLocal(0) [5]\n" |
| 191 | " 4: LoadLocal(0) [5]\n" |
| 192 | " 5: Equal(3, 4) [6]\n" |
| 193 | " 6: If(5)\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 194 | "BasicBlock 2, pred: 1, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 195 | " 7: Goto 3\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 196 | "BasicBlock 3, pred: 1, 2, succ: 4\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 197 | " 8: ReturnVoid\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 198 | "BasicBlock 4, pred: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 199 | " 9: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 200 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 201 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 202 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 203 | Instruction::IF_EQ, 3, |
| 204 | Instruction::GOTO | 0x100, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 205 | Instruction::RETURN_VOID); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 206 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 207 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 210 | TEST(PrettyPrinterTest, CFG7) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 211 | const char* expected = |
| 212 | "BasicBlock 0, succ: 1\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 213 | " 0: Local [4, 3, 2]\n" |
| 214 | " 1: IntConstant [2]\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 215 | " 11: SuspendCheck\n" |
| 216 | " 12: Goto 1\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 217 | "BasicBlock 1, pred: 0, succ: 3, 2\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 218 | " 2: StoreLocal(0, 1)\n" |
| 219 | " 3: LoadLocal(0) [5]\n" |
| 220 | " 4: LoadLocal(0) [5]\n" |
| 221 | " 5: Equal(3, 4) [6]\n" |
| 222 | " 6: If(5)\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 223 | "BasicBlock 2, pred: 1, 3, succ: 3\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 224 | " 7: Goto 3\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 225 | "BasicBlock 3, pred: 1, 2, succ: 2\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 226 | " 8: SuspendCheck\n" |
| 227 | " 9: Goto 2\n" |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 228 | "BasicBlock 4\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 229 | " 10: Exit\n"; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 230 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 231 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 232 | Instruction::CONST_4 | 0 | 0, |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 233 | Instruction::IF_EQ, 3, |
| 234 | Instruction::GOTO | 0x100, |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 235 | Instruction::GOTO | 0xFF00); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 236 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 237 | TestCode(data, expected); |
| 238 | } |
| 239 | |
| 240 | TEST(PrettyPrinterTest, IntConstant) { |
| 241 | const char* expected = |
| 242 | "BasicBlock 0, succ: 1\n" |
| 243 | " 0: Local [2]\n" |
| 244 | " 1: IntConstant [2]\n" |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 245 | " 5: SuspendCheck\n" |
| 246 | " 6: Goto 1\n" |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 247 | "BasicBlock 1, pred: 0, succ: 2\n" |
| 248 | " 2: StoreLocal(0, 1)\n" |
| 249 | " 3: ReturnVoid\n" |
| 250 | "BasicBlock 2, pred: 1\n" |
| 251 | " 4: Exit\n"; |
| 252 | |
| 253 | const uint16_t data[] = ONE_REGISTER_CODE_ITEM( |
| 254 | Instruction::CONST_4 | 0 | 0, |
| 255 | Instruction::RETURN_VOID); |
| 256 | |
| 257 | TestCode(data, expected); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 258 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 259 | } // namespace art |