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/compiler/code-stub-assembler.h"
6
7 #include <ostream>
8
9 #include "src/code-factory.h"
10 #include "src/compiler/graph.h"
11 #include "src/compiler/instruction-selector.h"
12 #include "src/compiler/linkage.h"
13 #include "src/compiler/pipeline.h"
14 #include "src/compiler/raw-machine-assembler.h"
15 #include "src/compiler/schedule.h"
16 #include "src/frames.h"
17 #include "src/interface-descriptors.h"
18 #include "src/interpreter/bytecodes.h"
19 #include "src/machine-type.h"
20 #include "src/macro-assembler.h"
21 #include "src/zone.h"
22
23 namespace v8 {
24 namespace internal {
25 namespace compiler {
26
27
CodeStubAssembler(Isolate * isolate,Zone * zone,const CallInterfaceDescriptor & descriptor,Code::Kind kind,const char * name)28 CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone,
29 const CallInterfaceDescriptor& descriptor,
30 Code::Kind kind, const char* name)
31 : raw_assembler_(new RawMachineAssembler(
32 isolate, new (zone) Graph(zone),
33 Linkage::GetStubCallDescriptor(isolate, zone, descriptor, 0,
34 CallDescriptor::kNoFlags))),
35 kind_(kind),
36 name_(name),
37 code_generated_(false) {}
38
39
~CodeStubAssembler()40 CodeStubAssembler::~CodeStubAssembler() {}
41
42
GenerateCode()43 Handle<Code> CodeStubAssembler::GenerateCode() {
44 DCHECK(!code_generated_);
45
46 Schedule* schedule = raw_assembler_->Export();
47 Handle<Code> code = Pipeline::GenerateCodeForCodeStub(
48 isolate(), raw_assembler_->call_descriptor(), graph(), schedule, kind_,
49 name_);
50
51 code_generated_ = true;
52 return code;
53 }
54
55
Int32Constant(int value)56 Node* CodeStubAssembler::Int32Constant(int value) {
57 return raw_assembler_->Int32Constant(value);
58 }
59
60
IntPtrConstant(intptr_t value)61 Node* CodeStubAssembler::IntPtrConstant(intptr_t value) {
62 return raw_assembler_->IntPtrConstant(value);
63 }
64
65
NumberConstant(double value)66 Node* CodeStubAssembler::NumberConstant(double value) {
67 return raw_assembler_->NumberConstant(value);
68 }
69
70
HeapConstant(Handle<HeapObject> object)71 Node* CodeStubAssembler::HeapConstant(Handle<HeapObject> object) {
72 return raw_assembler_->HeapConstant(object);
73 }
74
75
BooleanConstant(bool value)76 Node* CodeStubAssembler::BooleanConstant(bool value) {
77 return raw_assembler_->BooleanConstant(value);
78 }
79
80
Parameter(int value)81 Node* CodeStubAssembler::Parameter(int value) {
82 return raw_assembler_->Parameter(value);
83 }
84
85
Return(Node * value)86 void CodeStubAssembler::Return(Node* value) {
87 return raw_assembler_->Return(value);
88 }
89
90
SmiShiftBitsConstant()91 Node* CodeStubAssembler::SmiShiftBitsConstant() {
92 return Int32Constant(kSmiShiftSize + kSmiTagSize);
93 }
94
95
SmiTag(Node * value)96 Node* CodeStubAssembler::SmiTag(Node* value) {
97 return raw_assembler_->WordShl(value, SmiShiftBitsConstant());
98 }
99
100
SmiUntag(Node * value)101 Node* CodeStubAssembler::SmiUntag(Node* value) {
102 return raw_assembler_->WordSar(value, SmiShiftBitsConstant());
103 }
104
105
IntPtrAdd(Node * a,Node * b)106 Node* CodeStubAssembler::IntPtrAdd(Node* a, Node* b) {
107 return raw_assembler_->IntPtrAdd(a, b);
108 }
109
110
IntPtrSub(Node * a,Node * b)111 Node* CodeStubAssembler::IntPtrSub(Node* a, Node* b) {
112 return raw_assembler_->IntPtrSub(a, b);
113 }
114
115
WordShl(Node * value,int shift)116 Node* CodeStubAssembler::WordShl(Node* value, int shift) {
117 return raw_assembler_->WordShl(value, Int32Constant(shift));
118 }
119
120
LoadObjectField(Node * object,int offset)121 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) {
122 return raw_assembler_->Load(MachineType::AnyTagged(), object,
123 IntPtrConstant(offset - kHeapObjectTag));
124 }
125
126
CallN(CallDescriptor * descriptor,Node * code_target,Node ** args)127 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target,
128 Node** args) {
129 return raw_assembler_->CallN(descriptor, code_target, args);
130 }
131
132
TailCallN(CallDescriptor * descriptor,Node * code_target,Node ** args)133 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor,
134 Node* code_target, Node** args) {
135 return raw_assembler_->TailCallN(descriptor, code_target, args);
136 }
137
138
CallRuntime(Runtime::FunctionId function_id,Node * context,Node * arg1)139 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
140 Node* context, Node* arg1) {
141 return raw_assembler_->CallRuntime1(function_id, arg1, context);
142 }
143
144
CallRuntime(Runtime::FunctionId function_id,Node * context,Node * arg1,Node * arg2)145 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
146 Node* context, Node* arg1, Node* arg2) {
147 return raw_assembler_->CallRuntime2(function_id, arg1, arg2, context);
148 }
149
150
TailCallRuntime(Runtime::FunctionId function_id,Node * context,Node * arg1)151 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
152 Node* context, Node* arg1) {
153 return raw_assembler_->TailCallRuntime1(function_id, arg1, context);
154 }
155
156
TailCallRuntime(Runtime::FunctionId function_id,Node * context,Node * arg1,Node * arg2)157 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
158 Node* context, Node* arg1,
159 Node* arg2) {
160 return raw_assembler_->TailCallRuntime2(function_id, arg1, arg2, context);
161 }
162
163
164 // RawMachineAssembler delegate helpers:
isolate()165 Isolate* CodeStubAssembler::isolate() { return raw_assembler_->isolate(); }
166
167
graph()168 Graph* CodeStubAssembler::graph() { return raw_assembler_->graph(); }
169
170
zone()171 Zone* CodeStubAssembler::zone() { return raw_assembler_->zone(); }
172
173
174 } // namespace compiler
175 } // namespace internal
176 } // namespace v8
177