summaryrefslogtreecommitdiffstats
path: root/compiler/optimizing/codegen_test.cc
diff options
context:
space:
mode:
authorNicolas Geoffray <ngeoffray@google.com>2014-02-28 10:23:58 +0000
committerNicolas Geoffray <ngeoffray@google.com>2014-03-04 16:19:11 +0000
commitd4dd255db1d110ceb5551f6d95ff31fb57420994 (patch)
tree93c9dfff8d16f2b9675c35477cc4bcd8ea3f630c /compiler/optimizing/codegen_test.cc
parentb565506a63e75dac4a8bb9dd54dabf5259e5b95f (diff)
downloadart-d4dd255db1d110ceb5551f6d95ff31fb57420994.zip
art-d4dd255db1d110ceb5551f6d95ff31fb57420994.tar.gz
art-d4dd255db1d110ceb5551f6d95ff31fb57420994.tar.bz2
Add codegen support to the optimizing compiler.
Change-Id: I9aae76908ff1d6e64fb71a6718fc1426b67a5c28
Diffstat (limited to 'compiler/optimizing/codegen_test.cc')
-rw-r--r--compiler/optimizing/codegen_test.cc124
1 files changed, 124 insertions, 0 deletions
diff --git a/compiler/optimizing/codegen_test.cc b/compiler/optimizing/codegen_test.cc
new file mode 100644
index 0000000..dc4999b
--- /dev/null
+++ b/compiler/optimizing/codegen_test.cc
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "builder.h"
+#include "code_generator.h"
+#include "common_compiler_test.h"
+#include "dex_instruction.h"
+#include "instruction_set.h"
+#include "nodes.h"
+
+#include "gtest/gtest.h"
+
+namespace art {
+
+class ExecutableMemoryAllocator : public CodeAllocator {
+ public:
+ ExecutableMemoryAllocator() { }
+
+ virtual uint8_t* Allocate(size_t size) {
+ memory_.reset(new uint8_t[size]);
+ CommonCompilerTest::MakeExecutable(memory_.get(), size);
+ return memory_.get();
+ }
+
+ uint8_t* memory() const { return memory_.get(); }
+
+ private:
+ UniquePtr<uint8_t[]> memory_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExecutableMemoryAllocator);
+};
+
+static void TestCode(const uint16_t* data, int length) {
+ ArenaPool pool;
+ ArenaAllocator arena(&pool);
+ HGraphBuilder builder(&arena);
+ HGraph* graph = builder.BuildGraph(data, data + length);
+ ASSERT_NE(graph, nullptr);
+ ExecutableMemoryAllocator allocator;
+ CHECK(CodeGenerator::CompileGraph(graph, kX86, &allocator));
+ typedef void (*fptr)();
+#if defined(__i386__)
+ reinterpret_cast<fptr>(allocator.memory())();
+#endif
+ CHECK(CodeGenerator::CompileGraph(graph, kArm, &allocator));
+#if defined(__arm__)
+ reinterpret_cast<fptr>(allocator.memory())();
+#endif
+}
+
+TEST(CodegenTest, ReturnVoid) {
+ const uint16_t data[] = { Instruction::RETURN_VOID };
+ TestCode(data, sizeof(data) / sizeof(uint16_t));
+}
+
+TEST(PrettyPrinterTest, CFG1) {
+ const uint16_t data[] = {
+ Instruction::GOTO | 0x100,
+ Instruction::RETURN_VOID
+ };
+
+ TestCode(data, sizeof(data) / sizeof(uint16_t));
+}
+
+TEST(PrettyPrinterTest, CFG2) {
+ const uint16_t data[] = {
+ Instruction::GOTO | 0x100,
+ Instruction::GOTO | 0x100,
+ Instruction::RETURN_VOID
+ };
+
+ TestCode(data, sizeof(data) / sizeof(uint16_t));
+}
+
+TEST(PrettyPrinterTest, CFG3) {
+ const uint16_t data1[] = {
+ Instruction::GOTO | 0x200,
+ Instruction::RETURN_VOID,
+ Instruction::GOTO | 0xFF00
+ };
+
+ TestCode(data1, sizeof(data1) / sizeof(uint16_t));
+
+ const uint16_t data2[] = {
+ Instruction::GOTO_16, 3,
+ Instruction::RETURN_VOID,
+ Instruction::GOTO_16, 0xFFFF
+ };
+
+ TestCode(data2, sizeof(data2) / sizeof(uint16_t));
+
+ const uint16_t data3[] = {
+ Instruction::GOTO_32, 4, 0,
+ Instruction::RETURN_VOID,
+ Instruction::GOTO_32, 0xFFFF, 0xFFFF
+ };
+
+ TestCode(data3, sizeof(data3) / sizeof(uint16_t));
+}
+
+TEST(PrettyPrinterTest, CFG4) {
+ const uint16_t data[] = {
+ Instruction::RETURN_VOID,
+ Instruction::GOTO | 0x100,
+ Instruction::GOTO | 0xFE00
+ };
+
+ TestCode(data, sizeof(data) / sizeof(uint16_t));
+}
+
+} // namespace art