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

Unified Diff: test/unittests/compiler/test-instruction-selector.h

Issue 439863004: Initial import of unittests using GTest/GMock. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: test/unittests/compiler/test-instruction-selector.h
diff --git a/test/unittests/compiler/test-instruction-selector.h b/test/unittests/compiler/test-instruction-selector.h
new file mode 100644
index 0000000000000000000000000000000000000000..a0603dc4af315896fbd3699271c39687d402541a
--- /dev/null
+++ b/test/unittests/compiler/test-instruction-selector.h
@@ -0,0 +1,88 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
+#define V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
+
+#include <deque>
+
+#include "src/compiler/instruction-selector.h"
+#include "src/compiler/raw-machine-assembler.h"
+#include "test/unittests/test-zone.h"
+
+namespace v8 {
+namespace internal {
+namespace compiler {
+
+class InstructionSelectorTest : public ContextTest, public ZoneTest {
+ public:
+ InstructionSelectorTest() {}
+
+ protected:
+ class Stream;
+
+ enum StreamBuilderMode { kAllInstructions, kTargetInstructions };
+
+ class StreamBuilder : public RawMachineAssembler {
+ public:
+ StreamBuilder(InstructionSelectorTest* test,
+ MachineRepresentation return_type)
+ : RawMachineAssembler(new (test->zone()) Graph(test->zone()),
+ CallDescriptorBuilder(test->zone(), return_type)),
+ test_(test) {}
+
+ Stream Build(StreamBuilderMode mode = kTargetInstructions);
+
+ private:
+ MachineCallDescriptorBuilder* CallDescriptorBuilder(
+ Zone* zone, MachineRepresentation return_type) {
+ return new (zone) MachineCallDescriptorBuilder(return_type, 0, NULL);
+ }
+
+ private:
+ InstructionSelectorTest* test_;
+ };
+
+ class Stream {
+ public:
+ size_t size() const { return instructions_.size(); }
+ const Instruction* operator[](size_t index) const {
+ EXPECT_LT(index, size());
+ return instructions_[index];
+ }
+
+ int32_t ToInt32(const InstructionOperand* operand) const {
+ return ToConstant(operand).ToInt32();
+ }
+
+ private:
+ Constant ToConstant(const InstructionOperand* operand) const {
+ ConstantMap::const_iterator i;
+ if (operand->IsConstant()) {
+ i = constants_.find(operand->index());
+ EXPECT_NE(constants_.end(), i);
+ } else {
+ EXPECT_EQ(InstructionOperand::IMMEDIATE, operand->kind());
+ i = immediates_.find(operand->index());
+ EXPECT_NE(immediates_.end(), i);
+ }
+ EXPECT_EQ(operand->index(), i->first);
+ return i->second;
+ }
+
+ friend class StreamBuilder;
+
+ typedef std::map<int, Constant> ConstantMap;
+
+ ConstantMap constants_;
+ ConstantMap immediates_;
+ std::deque<Instruction*> instructions_;
+ };
+};
+
+} // namespace compiler
+} // namespace internal
+} // namespace v8
+
+#endif // V8_UNITTESTS_COMPILER_INSTRUCTION_SELECTOR_TEST_H_
« no previous file with comments | « test/unittests/compiler/arm/test-instruction-selector-arm.cc ('k') | test/unittests/compiler/test-instruction-selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698