blob: 3c4ae05eaa5c99898d97b36b312262368a501c69 [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#ifndef V8_COMPILER_CODE_STUB_ASSEMBLER_H_
6#define V8_COMPILER_CODE_STUB_ASSEMBLER_H_
7
8// Clients of this interface shouldn't depend on lots of compiler internals.
9// Do not include anything from src/compiler here!
10#include "src/allocation.h"
11#include "src/builtins.h"
12#include "src/runtime/runtime.h"
13
14namespace v8 {
15namespace internal {
16
17class CallInterfaceDescriptor;
18class Isolate;
19class Zone;
20
21namespace compiler {
22
23class CallDescriptor;
24class Graph;
25class Node;
26class Operator;
27class RawMachineAssembler;
28class Schedule;
29
30class CodeStubAssembler {
31 public:
32 CodeStubAssembler(Isolate* isolate, Zone* zone,
33 const CallInterfaceDescriptor& descriptor, Code::Kind kind,
34 const char* name);
35 virtual ~CodeStubAssembler();
36
37 Handle<Code> GenerateCode();
38
39 // Constants.
40 Node* Int32Constant(int value);
41 Node* IntPtrConstant(intptr_t value);
42 Node* NumberConstant(double value);
43 Node* HeapConstant(Handle<HeapObject> object);
44 Node* BooleanConstant(bool value);
45
46 Node* Parameter(int value);
47 void Return(Node* value);
48
49 // Tag and untag Smi values.
50 Node* SmiTag(Node* value);
51 Node* SmiUntag(Node* value);
52
53 // Basic arithmetic operations.
54 Node* IntPtrAdd(Node* a, Node* b);
55 Node* IntPtrSub(Node* a, Node* b);
56 Node* WordShl(Node* value, int shift);
57
58 // Load a field from an object on the heap.
59 Node* LoadObjectField(Node* object, int offset);
60
61 // Call runtime function.
62 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1);
63 Node* CallRuntime(Runtime::FunctionId function_id, Node* context, Node* arg1,
64 Node* arg2);
65
66 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
67 Node* arg1);
68 Node* TailCallRuntime(Runtime::FunctionId function_id, Node* context,
69 Node* arg1, Node* arg2);
70
71 private:
72 friend class CodeStubAssemblerTester;
73
74 Node* CallN(CallDescriptor* descriptor, Node* code_target, Node** args);
75 Node* TailCallN(CallDescriptor* descriptor, Node* code_target, Node** args);
76
77 Node* SmiShiftBitsConstant();
78
79 // Private helpers which delegate to RawMachineAssembler.
80 Graph* graph();
81 Isolate* isolate();
82 Zone* zone();
83
84 base::SmartPointer<RawMachineAssembler> raw_assembler_;
85 Code::Kind kind_;
86 const char* name_;
87 bool code_generated_;
88
89 DISALLOW_COPY_AND_ASSIGN(CodeStubAssembler);
90};
91
92} // namespace compiler
93} // namespace internal
94} // namespace v8
95
96#endif // V8_COMPILER_CODE_STUB_ASSEMBLER_H_