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

Side by Side Diff: src/interpreter/bytecode-array-builder.cc

Issue 1266713004: [Intepreter] Addition of BytecodeArrayBuilder and accumulator based bytecodes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Tweak BytecodeArray::Disassemble(). Created 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // 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 #include "src/ast.h"
6 #include "src/interpreter/bytecode-array-builder.h"
rmcilroy 2015/07/30 10:12:25 always have header on it's own line first (which m
oth 2015/07/30 15:38:42 Done.
7
8 namespace v8 {
9 namespace internal {
10 namespace interpreter {
11
12 BytecodeArrayBuilder::BytecodeArrayBuilder(Isolate* isolate)
13 : isolate_(isolate), max_registers_(-1), scratch_register_(-1) {}
14
15
16 void BytecodeArrayBuilder::set_stack_slots(int slots) {
rmcilroy 2015/07/30 10:12:24 nit - this would be clearer to me as this be set_
oth 2015/07/30 15:38:42 Done.
17 scratch_register_ = slots;
rmcilroy 2015/07/30 10:12:24 local_register_count_
oth 2015/07/30 15:38:42 Done.
18 max_registers_ = slots;
rmcilroy 2015/07/30 10:12:24 max_temporary_register_count_
oth 2015/07/30 15:38:42 Done.
19 }
20
21
22 Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() const {
rmcilroy 2015/07/30 10:12:24 add a "bytecodes_generated_" bool and DCHECK here
oth 2015/07/30 15:38:42 Done.
23 int bytecode_size = static_cast<int>(bytecodes_.size());
24 int frame_size = max_registers_ * sizeof(intptr_t);
25 return isolate_->factory()->NewBytecodeArray(bytecode_size,
26 &bytecodes_.front(), frame_size);
27 }
28
29
30 void BytecodeArrayBuilder::BinaryOperation(Token::Value binop, int reg) {
31 Output(BytecodeFor(binop), reg);
32 }
33
34
35 void BytecodeArrayBuilder::LoadLiteral(v8::internal::Smi* smi) {
36 int32_t raw_smi = smi->value();
37 if (raw_smi == 0) {
38 Output(Bytecode::kLoadLiteral0);
39 } else if (raw_smi > -128 && raw_smi <= 128) {
40 Output(Bytecode::kLoadSmi8, static_cast<uint8_t>(raw_smi));
41 } else {
42 // TODO(oth): Put Smi in constant pool.
43 UNIMPLEMENTED();
44 }
45 }
46
47
48 void BytecodeArrayBuilder::LoadUndefined() { Output(Bytecode::kLdaUndefined); }
49
50
51 void BytecodeArrayBuilder::LoadNull() { Output(Bytecode::kLdaNull); }
52
53
54 void BytecodeArrayBuilder::LoadTheHole() { Output(Bytecode::kLdaTheHole); }
55
56
57 void BytecodeArrayBuilder::LoadTrue() { Output(Bytecode::kLdaTrue); }
58
59
60 void BytecodeArrayBuilder::LoadFalse() { Output(Bytecode::kLdaFalse); }
61
62
63 void BytecodeArrayBuilder::LoadAccumulatorWithRegister(int reg) {
64 Output(Bytecode::kLdar, reg);
65 }
66
67
68 void BytecodeArrayBuilder::StoreAccumulatorInRegister(int reg) {
69 Output(Bytecode::kStra, reg);
70 }
71
72
73 void BytecodeArrayBuilder::Return() { Output(Bytecode::kReturn); }
74
75
76 int BytecodeArrayBuilder::AllocateScratchRegister() {
rmcilroy 2015/07/30 10:12:24 These should be Pop/PushScratchRegister if they re
oth 2015/07/30 15:38:42 Done.
rmcilroy 2015/07/31 09:56:19 Missed rename to Push/Pop?
77 int reg = scratch_register_++;
rmcilroy 2015/07/30 10:12:24 nit - add CHECK(locals_register_count_ >= 0)
oth 2015/07/30 15:38:42 Done.
78 if (scratch_register_ > max_registers_) {
79 max_registers_ = scratch_register_;
80 }
81 return reg;
82 }
83
84
85 void BytecodeArrayBuilder::FreeScratchRegister(int reg) {
86 DCHECK(reg == scratch_register_ - 1);
87 scratch_register_ = reg;
88 }
89
90
91 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t r0, uint8_t r1,
rmcilroy 2015/07/30 10:12:24 nit - operand0, operand1, etc. (instead of r0, r1.
oth 2015/07/30 15:38:42 Done.
92 uint8_t r2) {
93 CHECK(Bytecodes::NumberOfOperands(bytecode) == 3);
94 bytecodes_.push_back(Bytecodes::ToByte(bytecode));
95 bytecodes_.push_back(r0);
96 bytecodes_.push_back(r1);
97 bytecodes_.push_back(r2);
98 }
99
100
101 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t r0, uint8_t r1) {
102 CHECK(Bytecodes::NumberOfOperands(bytecode) == 2);
103 bytecodes_.push_back(Bytecodes::ToByte(bytecode));
104 bytecodes_.push_back(r0);
105 bytecodes_.push_back(r1);
106 }
107
108
109 void BytecodeArrayBuilder::Output(Bytecode bytecode, uint8_t r0) {
110 CHECK(Bytecodes::NumberOfOperands(bytecode) == 1);
111 bytecodes_.push_back(Bytecodes::ToByte(bytecode));
112 bytecodes_.push_back(r0);
113 }
114
115
116 void BytecodeArrayBuilder::Output(Bytecode bytecode) {
117 CHECK(Bytecodes::NumberOfOperands(bytecode) == 0);
118 bytecodes_.push_back(Bytecodes::ToByte(bytecode));
119 }
120
121
122 // static
123 Bytecode BytecodeArrayBuilder::BytecodeFor(Token::Value op) {
rmcilroy 2015/07/30 10:12:24 Let's make this BytecodeForBinaryOp and remove the
oth 2015/07/30 15:38:42 Done.
124 switch (op) {
125 case Token::Value::ASSIGN:
126 return Bytecode::kStra;
127 case Token::Value::ADD:
128 return Bytecode::kAdd;
129 case Token::Value::SUB:
130 return Bytecode::kSub;
131 case Token::Value::MUL:
132 return Bytecode::kMul;
133 case Token::Value::DIV:
134 return Bytecode::kDiv;
135 default:
136 UNIMPLEMENTED();
137 return static_cast<Bytecode>(-1);
138 }
139 }
140
141 } // namespace interpreter
142 } // namespace internal
143 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698