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.
5 #ifndef V8_COMPILER_INTERPRETER_ASSEMBLER_H_
6 #define V8_COMPILER_INTERPRETER_ASSEMBLER_H_
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/base/smart-pointers.h"
12 #include "src/builtins.h"
13 #include "src/frames.h"
14 #include "src/interpreter/bytecodes.h"
15 #include "src/runtime/runtime.h"
16 #include "src/zone-containers.h"
21 class CallInterfaceDescriptor;
31 class RawMachineAssembler;
34 class InterpreterAssembler {
36 InterpreterAssembler(Isolate* isolate, Zone* zone,
37 interpreter::Bytecode bytecode);
38 virtual ~InterpreterAssembler();
40 Handle<Code> GenerateCode();
42 // Returns the count immediate for bytecode operand |operand_index| in the
44 Node* BytecodeOperandCount(int operand_index);
45 // Returns the index immediate for bytecode operand |operand_index| in the
47 Node* BytecodeOperandIdx(int operand_index);
48 // Returns the Imm8 immediate for bytecode operand |operand_index| in the
50 Node* BytecodeOperandImm8(int operand_index);
51 // Returns the register index for bytecode operand |operand_index| in the
53 Node* BytecodeOperandReg(int operand_index);
56 Node* GetAccumulator();
57 void SetAccumulator(Node* value);
59 // Loads from and stores to the interpreter register file.
60 Node* LoadRegister(Node* reg_index);
61 Node* StoreRegister(Node* value, Node* reg_index);
63 // Returns the location in memory of the register |reg_index| in the
64 // interpreter register file.
65 Node* RegisterLocation(Node* reg_index);
68 Node* Int32Constant(int value);
69 Node* IntPtrConstant(intptr_t value);
70 Node* NumberConstant(double value);
71 Node* HeapConstant(Handle<HeapObject> object);
72 Node* BooleanConstant(bool value);
74 // Tag and untag Smi values.
75 Node* SmiTag(Node* value);
76 Node* SmiUntag(Node* value);
78 // Basic arithmetic operations.
79 Node* IntPtrAdd(Node* a, Node* b);
80 Node* IntPtrSub(Node* a, Node* b);
81 Node* WordShl(Node* value, int shift);
83 // Load constant at |index| in the constant pool.
84 Node* LoadConstantPoolEntry(Node* index);
86 // Load a field from an object on the heap.
87 Node* LoadObjectField(Node* object, int offset);
89 // Load |slot_index| from a context.
90 Node* LoadContextSlot(Node* context, int slot_index);
92 // Load |slot_index| from the current context.
93 Node* LoadContextSlot(int slot_index);
95 // Load the TypeFeedbackVector for the current function.
96 Node* LoadTypeFeedbackVector();
98 // Call JSFunction or Callable |function| with |arg_count| (not including
99 // receiver) and the first argument located at |first_arg|.
100 Node* CallJS(Node* function, Node* first_arg, Node* arg_count);
102 // Call an IC code stub.
103 Node* CallIC(CallInterfaceDescriptor descriptor, Node* target, Node* arg1,
104 Node* arg2, Node* arg3, Node* arg4);
105 Node* CallIC(CallInterfaceDescriptor descriptor, Node* target, Node* arg1,
106 Node* arg2, Node* arg3, Node* arg4, Node* arg5);
108 // Call runtime function.
109 Node* CallRuntime(Runtime::FunctionId function_id, Node* arg1);
110 Node* CallRuntime(Runtime::FunctionId function_id, Node* arg1, Node* arg2);
112 // Jump relative to the current bytecode by |jump_offset|.
113 void Jump(Node* jump_offset);
115 // Jump relative to the current bytecode by |jump_offset| if the
116 // word values |lhs| and |rhs| are equal.
117 void JumpIfWordEqual(Node* lhs, Node* rhs, Node* jump_offset);
119 // Returns from the function.
122 // Dispatch to the bytecode.
129 // Protected helpers (for testing) which delegate to RawMachineAssembler.
130 CallDescriptor* call_descriptor() const;
134 // Returns a raw pointer to start of the register file on the stack.
135 Node* RegisterFileRawPointer();
136 // Returns a tagged pointer to the current function's BytecodeArray object.
137 Node* BytecodeArrayTaggedPointer();
138 // Returns the offset from the BytecodeArrayPointer of the current bytecode.
139 Node* BytecodeOffset();
140 // Returns a raw pointer to first entry in the interpreter dispatch table.
141 Node* DispatchTableRawPointer();
142 // Returns a tagged pointer to the current context.
143 Node* ContextTaggedPointer();
145 // Returns the offset of register |index| relative to RegisterFilePointer().
146 Node* RegisterFrameOffset(Node* index);
148 Node* SmiShiftBitsConstant();
149 Node* BytecodeOperand(int operand_index);
150 Node* BytecodeOperandSignExtended(int operand_index);
152 Node* CallIC(CallInterfaceDescriptor descriptor, Node* target, Node** args);
153 Node* CallJSBuiltin(int context_index, Node* receiver, Node** js_args,
156 // Returns BytecodeOffset() advanced by delta bytecodes. Note: this does not
157 // update BytecodeOffset() itself.
158 Node* Advance(int delta);
159 Node* Advance(Node* delta);
161 // Starts next instruction dispatch at |new_bytecode_offset|.
162 void DispatchTo(Node* new_bytecode_offset);
164 // Adds an end node of the graph.
165 void AddEndInput(Node* input);
167 // Private helpers which delegate to RawMachineAssembler.
169 Schedule* schedule();
172 interpreter::Bytecode bytecode_;
173 base::SmartPointer<RawMachineAssembler> raw_assembler_;
174 ZoneVector<Node*> end_nodes_;
176 bool code_generated_;
178 DISALLOW_COPY_AND_ASSIGN(InterpreterAssembler);
181 } // namespace interpreter
182 } // namespace internal
185 #endif // V8_COMPILER_INTERPRETER_ASSEMBLER_H_