| Index: src/interpreter/control-flow-builders.h
|
| diff --git a/src/interpreter/control-flow-builders.h b/src/interpreter/control-flow-builders.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..97f771f3e9ed76bea01ddcb35b40e873fa2ffc1f
|
| --- /dev/null
|
| +++ b/src/interpreter/control-flow-builders.h
|
| @@ -0,0 +1,69 @@
|
| +// Copyright 2015 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_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
|
| +#define V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
|
| +
|
| +#include "src/interpreter/bytecode-array-builder.h"
|
| +
|
| +#include "src/zone-containers.h"
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +namespace interpreter {
|
| +
|
| +class ControlFlowBuilder BASE_EMBEDDED {
|
| + public:
|
| + explicit ControlFlowBuilder(BytecodeArrayBuilder* builder)
|
| + : builder_(builder) {}
|
| + virtual ~ControlFlowBuilder() {}
|
| +
|
| + protected:
|
| + BytecodeArrayBuilder* builder() const { return builder_; }
|
| +
|
| + private:
|
| + BytecodeArrayBuilder* builder_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ControlFlowBuilder);
|
| +};
|
| +
|
| +// A class to help with co-ordinating break and continue statements with
|
| +// their loop.
|
| +// TODO(oth): add support for TF branch/merge info.
|
| +class LoopBuilder : public ControlFlowBuilder {
|
| + public:
|
| + explicit LoopBuilder(BytecodeArrayBuilder* builder)
|
| + : ControlFlowBuilder(builder),
|
| + continue_sites_(builder->zone()),
|
| + break_sites_(builder->zone()) {}
|
| + ~LoopBuilder();
|
| +
|
| + // These methods should be called by the LoopBuilder owner before
|
| + // destruction to update sites that emit jumps for break/continue.
|
| + void SetContinueTarget(const BytecodeLabel* const continue_target);
|
| + void SetBreakTarget(const BytecodeLabel* const break_target);
|
| +
|
| + // These methods are called when visiting break and continue
|
| + // statements in the AST. Inserts a jump to a unbound label that is
|
| + // patched when the corresponding SetContinueTarget/SetBreakTarget
|
| + // is called.
|
| + void Break() { EmitJump(&break_sites_); }
|
| + void Continue() { EmitJump(&continue_sites_); }
|
| +
|
| + private:
|
| + void BindLabels(const BytecodeLabel* const target,
|
| + ZoneVector<BytecodeLabel>* labels);
|
| + void EmitJump(ZoneVector<BytecodeLabel>* labels);
|
| +
|
| + // Unbound labels that identify jumps for continue/break statements
|
| + // in the code.
|
| + ZoneVector<BytecodeLabel> continue_sites_;
|
| + ZoneVector<BytecodeLabel> break_sites_;
|
| +};
|
| +
|
| +} // namespace interpreter
|
| +} // namespace internal
|
| +} // namespace v8
|
| +
|
| +#endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
|
|
|