blob: b2a05b64f86074bd877ece99deb15c815f33f82b [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// 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
23namespace v8 {
24namespace internal {
25namespace compiler {
26
27
28CodeStubAssembler::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
40CodeStubAssembler::~CodeStubAssembler() {}
41
42
43Handle<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
56Node* CodeStubAssembler::Int32Constant(int value) {
57 return raw_assembler_->Int32Constant(value);
58}
59
60
61Node* CodeStubAssembler::IntPtrConstant(intptr_t value) {
62 return raw_assembler_->IntPtrConstant(value);
63}
64
65
66Node* CodeStubAssembler::NumberConstant(double value) {
67 return raw_assembler_->NumberConstant(value);
68}
69
70
71Node* CodeStubAssembler::HeapConstant(Handle<HeapObject> object) {
72 return raw_assembler_->HeapConstant(object);
73}
74
75
76Node* CodeStubAssembler::BooleanConstant(bool value) {
77 return raw_assembler_->BooleanConstant(value);
78}
79
80
81Node* CodeStubAssembler::Parameter(int value) {
82 return raw_assembler_->Parameter(value);
83}
84
85
86void CodeStubAssembler::Return(Node* value) {
87 return raw_assembler_->Return(value);
88}
89
90
91Node* CodeStubAssembler::SmiShiftBitsConstant() {
92 return Int32Constant(kSmiShiftSize + kSmiTagSize);
93}
94
95
96Node* CodeStubAssembler::SmiTag(Node* value) {
97 return raw_assembler_->WordShl(value, SmiShiftBitsConstant());
98}
99
100
101Node* CodeStubAssembler::SmiUntag(Node* value) {
102 return raw_assembler_->WordSar(value, SmiShiftBitsConstant());
103}
104
105
106Node* CodeStubAssembler::IntPtrAdd(Node* a, Node* b) {
107 return raw_assembler_->IntPtrAdd(a, b);
108}
109
110
111Node* CodeStubAssembler::IntPtrSub(Node* a, Node* b) {
112 return raw_assembler_->IntPtrSub(a, b);
113}
114
115
116Node* CodeStubAssembler::WordShl(Node* value, int shift) {
117 return raw_assembler_->WordShl(value, Int32Constant(shift));
118}
119
120
121Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) {
122 return raw_assembler_->Load(MachineType::AnyTagged(), object,
123 IntPtrConstant(offset - kHeapObjectTag));
124}
125
126
127Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target,
128 Node** args) {
129 return raw_assembler_->CallN(descriptor, code_target, args);
130}
131
132
133Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor,
134 Node* code_target, Node** args) {
135 return raw_assembler_->TailCallN(descriptor, code_target, args);
136}
137
138
139Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id,
140 Node* context, Node* arg1) {
141 return raw_assembler_->CallRuntime1(function_id, arg1, context);
142}
143
144
145Node* 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
151Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id,
152 Node* context, Node* arg1) {
153 return raw_assembler_->TailCallRuntime1(function_id, arg1, context);
154}
155
156
157Node* 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:
165Isolate* CodeStubAssembler::isolate() { return raw_assembler_->isolate(); }
166
167
168Graph* CodeStubAssembler::graph() { return raw_assembler_->graph(); }
169
170
171Zone* CodeStubAssembler::zone() { return raw_assembler_->zone(); }
172
173
174} // namespace compiler
175} // namespace internal
176} // namespace v8