blob: b1303c9f6ab47665e82d8caafa5bd85982a07376 [file] [log] [blame]
Ben Murdochc5610432016-08-08 18:44:38 +01001// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_INTERPRETER_BYTECODE_ARRAY_WRITER_H_
6#define V8_INTERPRETER_BYTECODE_ARRAY_WRITER_H_
7
8#include "src/interpreter/bytecode-pipeline.h"
9
10namespace v8 {
11namespace internal {
12namespace interpreter {
13
14class SourcePositionTableBuilder;
15
16// Class for emitting bytecode as the final stage of the bytecode
17// generation pipeline.
18class BytecodeArrayWriter final : public BytecodePipelineStage {
19 public:
20 BytecodeArrayWriter(
21 Zone* zone, SourcePositionTableBuilder* source_position_table_builder);
22 virtual ~BytecodeArrayWriter();
23
24 void Write(BytecodeNode* node) override;
25 size_t FlushForOffset() override;
26 void FlushBasicBlock() override;
27
28 // Get the bytecode vector.
29 ZoneVector<uint8_t>* bytecodes() { return &bytecodes_; }
30
31 // Returns the size in bytes of the frame associated with the
32 // bytecode written.
33 int GetMaximumFrameSizeUsed();
34
35 private:
36 void EmitBytecode(const BytecodeNode* const node);
37 void UpdateSourcePositionTable(const BytecodeNode* const node);
38
39 ZoneVector<uint8_t> bytecodes_;
40 int max_register_count_;
41 SourcePositionTableBuilder* source_position_table_builder_;
42
43 DISALLOW_COPY_AND_ASSIGN(BytecodeArrayWriter);
44};
45
46} // namespace interpreter
47} // namespace internal
48} // namespace v8
49
50#endif // V8_INTERPRETER_BYTECODE_ARRAY_WRITER_H_