visibility = [ ":*" ] # Only targets in this file can depend on this.
sources = [
+ "src/base/adapters.h",
"src/base/atomicops.h",
"src/base/atomicops_internals_arm64_gcc.h",
"src/base/atomicops_internals_arm_gcc.h",
--- /dev/null
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Slightly adapted for inclusion in V8.
+// Copyright 2014 the V8 project authors. All rights reserved.
+
+#ifndef V8_BASE_ADAPTERS_H_
+#define V8_BASE_ADAPTERS_H_
+
+#include "src/base/macros.h"
+
+namespace v8 {
+namespace base {
+
+// Internal adapter class for implementing base::Reversed.
+template <typename T>
+class ReversedAdapter {
+ public:
+ typedef decltype(static_cast<T*>(nullptr)->rbegin()) Iterator;
+
+ explicit ReversedAdapter(T& t) : t_(t) {}
+ ReversedAdapter(const ReversedAdapter& ra) : t_(ra.t_) {}
+
+ Iterator begin() const { return t_.rbegin(); }
+ Iterator end() const { return t_.rend(); }
+
+ private:
+ T& t_;
+
+ DISALLOW_ASSIGN(ReversedAdapter);
+};
+
+// Reversed returns a container adapter usable in a range-based "for" statement
+// for iterating a reversible container in reverse order.
+//
+// Example:
+//
+// std::vector<int> v = ...;
+// for (int i : base::Reversed(v)) {
+// // iterates through v from back to front
+// }
+template <typename T>
+ReversedAdapter<T> Reversed(T& t) {
+ return ReversedAdapter<T>(t);
+}
+
+} // namespace base
+} // namespace v8
+
+#endif // V8_BASE_ADAPTERS_H_
}
+// Put this in the private: declarations for a class to be unassignable.
+#define DISALLOW_ASSIGN(TypeName) void operator=(const TypeName&)
+
+
// A macro to disallow the evil copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "src/base/adapters.h"
#include "src/base/bits.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
// TODO(dcarney): might be possible to use claim/poke instead
// Push any stack arguments.
- for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
- ++i) {
- Emit(kArmPush, g.NoOutput(), g.UseRegister(*i));
+ for (Node* node : base::Reversed(buffer.pushed_nodes)) {
+ Emit(kArmPush, g.NoOutput(), g.UseRegister(node));
}
// Pass label of exception handler block.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
InitializeCallBuffer(node, &buffer, true, true);
// Push any stack arguments.
- for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
- ++i) {
+ for (Node* node : base::Reversed(buffer.pushed_nodes)) {
// TODO(titzer): handle pushing double parameters.
InstructionOperand value =
- g.CanBeImmediate(*i) ? g.UseImmediate(*i) : IsSupported(ATOM)
- ? g.UseRegister(*i)
- : g.Use(*i);
+ g.CanBeImmediate(node)
+ ? g.UseImmediate(node)
+ : IsSupported(ATOM) ? g.UseRegister(node) : g.Use(node);
Emit(kIA32Push, g.NoOutput(), value);
}
#include <limits>
+#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
// Visit code in reverse control flow order, because architecture-specific
// matching may cover more than one node at a time.
- for (BasicBlock::reverse_iterator i = block->rbegin(); i != block->rend();
- ++i) {
- Node* node = *i;
+ for (auto node : base::Reversed(*block)) {
// Skip nodes that are unused or already defined.
if (!IsUsed(node) || IsDefined(node)) continue;
// Generate code for this node "top down", but schedule the code "bottom
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "src/compiler/liveness-analyzer.h"
+#include "src/base/adapters.h"
#include "src/compiler/js-graph.h"
+#include "src/compiler/liveness-analyzer.h"
#include "src/compiler/node.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/state-values-utils.h"
// Copy the bitvector to the target bit vector.
result->CopyFrom(live_);
- for (auto i = entries_.rbegin(); i != entries_.rend(); i++) {
- auto entry = *i;
+ for (auto entry : base::Reversed(entries_)) {
switch (entry.kind()) {
case Entry::kLookup:
result->Add(entry.var());
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "src/base/adapters.h"
#include "src/base/bits.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
g.TempImmediate(push_count << kPointerSizeLog2));
}
int slot = buffer.pushed_nodes.size() - 1;
- for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
- ++i) {
- Emit(kMipsStoreToStackSlot, g.NoOutput(), g.UseRegister(*i),
+ for (Node* node : base::Reversed(buffer.pushed_nodes)) {
+ Emit(kMipsStoreToStackSlot, g.NoOutput(), g.UseRegister(node),
g.TempImmediate(slot << kPointerSizeLog2));
slot--;
}
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "src/base/adapters.h"
#include "src/base/bits.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
g.TempImmediate(push_count << kPointerSizeLog2));
}
int slot = buffer.pushed_nodes.size() - 1;
- for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
- ++i) {
- Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(*i),
+ for (Node* node : base::Reversed(buffer.pushed_nodes)) {
+ Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(node),
g.TempImmediate(slot << kPointerSizeLog2));
slot--;
}
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
// Push any stack arguments.
// TODO(mbrandy): reverse order and use push only for first
- for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
- i++) {
- Emit(kPPC_Push, g.NoOutput(), g.UseRegister(*i));
+ for (Node* node : base::Reversed(buffer.pushed_nodes)) {
+ Emit(kPPC_Push, g.NoOutput(), g.UseRegister(node));
}
// Pass label of exception handler block.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "src/base/adapters.h"
#include "src/compiler/linkage.h"
#include "src/compiler/register-allocator.h"
#include "src/string-stream.h"
void LiveRangeBuilder::ResolvePhis() {
// Process the blocks in reverse order.
- for (auto i = code()->instruction_blocks().rbegin();
- i != code()->instruction_blocks().rend(); ++i) {
- ResolvePhis(*i);
+ for (InstructionBlock* block : base::Reversed(code()->instruction_blocks())) {
+ ResolvePhis(block);
}
}
#include <iomanip>
+#include "src/base/adapters.h"
#include "src/bit-vector.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/control-equivalence.h"
for (NodeVector& nodes : scheduled_nodes_) {
BasicBlock::Id id = BasicBlock::Id::FromInt(block_num++);
BasicBlock* block = schedule_->GetBlockById(id);
- for (auto i = nodes.rbegin(); i != nodes.rend(); ++i) {
- schedule_->AddNode(block, *i);
+ for (Node* node : base::Reversed(nodes)) {
+ schedule_->AddNode(block, node);
}
}
}
#include <algorithm>
+#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
InitializeCallBuffer(node, &buffer, true, true);
// Push any stack arguments.
- for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
- ++i) {
+ for (Node* node : base::Reversed(buffer.pushed_nodes)) {
// TODO(titzer): handle pushing double parameters.
InstructionOperand value =
- g.CanBeImmediate(*i) ? g.UseImmediate(*i) : IsSupported(ATOM)
- ? g.UseRegister(*i)
- : g.Use(*i);
+ g.CanBeImmediate(node)
+ ? g.UseImmediate(node)
+ : IsSupported(ATOM) ? g.UseRegister(node) : g.Use(node);
Emit(kX64Push, g.NoOutput(), value);
}
};
-template <class C>
-class ContainerPointerWrapper {
- public:
- typedef typename C::iterator iterator;
- typedef typename C::reverse_iterator reverse_iterator;
- explicit ContainerPointerWrapper(C* container) : container_(container) {}
- iterator begin() { return container_->begin(); }
- iterator end() { return container_->end(); }
- reverse_iterator rbegin() { return container_->rbegin(); }
- reverse_iterator rend() { return container_->rend(); }
- private:
- C* container_;
-};
-
-
// ----------------------------------------------------------------------------
// I/O support.
'../..',
],
'sources': [
+ '../../src/base/adapters.h',
'../../src/base/atomicops.h',
'../../src/base/atomicops_internals_arm64_gcc.h',
'../../src/base/atomicops_internals_arm_gcc.h',