1 // Copyright 2020 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/torque/torque-code-generator.h"
6
7 #include "src/torque/global-context.h"
8
9 namespace v8 {
10 namespace internal {
11 namespace torque {
12
IsEmptyInstruction(const Instruction & instruction)13 bool TorqueCodeGenerator::IsEmptyInstruction(const Instruction& instruction) {
14 switch (instruction.kind()) {
15 case InstructionKind::kPeekInstruction:
16 case InstructionKind::kPokeInstruction:
17 case InstructionKind::kDeleteRangeInstruction:
18 case InstructionKind::kPushUninitializedInstruction:
19 case InstructionKind::kPushBuiltinPointerInstruction:
20 case InstructionKind::kUnsafeCastInstruction:
21 return true;
22 default:
23 return false;
24 }
25 }
26
EmitInstruction(const Instruction & instruction,Stack<std::string> * stack)27 void TorqueCodeGenerator::EmitInstruction(const Instruction& instruction,
28 Stack<std::string>* stack) {
29 #ifdef DEBUG
30 if (!IsEmptyInstruction(instruction)) {
31 EmitSourcePosition(instruction->pos);
32 }
33 #endif
34
35 switch (instruction.kind()) {
36 #define ENUM_ITEM(T) \
37 case InstructionKind::k##T: \
38 if (GlobalContext::annotate_ir()) { \
39 EmitIRAnnotation(instruction.Cast<T>(), stack); \
40 } \
41 return EmitInstruction(instruction.Cast<T>(), stack);
42 TORQUE_INSTRUCTION_LIST(ENUM_ITEM)
43 #undef ENUM_ITEM
44 }
45 }
46
EmitInstruction(const PeekInstruction & instruction,Stack<std::string> * stack)47 void TorqueCodeGenerator::EmitInstruction(const PeekInstruction& instruction,
48 Stack<std::string>* stack) {
49 stack->Push(stack->Peek(instruction.slot));
50 }
51
EmitInstruction(const PokeInstruction & instruction,Stack<std::string> * stack)52 void TorqueCodeGenerator::EmitInstruction(const PokeInstruction& instruction,
53 Stack<std::string>* stack) {
54 stack->Poke(instruction.slot, stack->Top());
55 stack->Pop();
56 }
57
EmitInstruction(const DeleteRangeInstruction & instruction,Stack<std::string> * stack)58 void TorqueCodeGenerator::EmitInstruction(
59 const DeleteRangeInstruction& instruction, Stack<std::string>* stack) {
60 stack->DeleteRange(instruction.range);
61 }
62
63 } // namespace torque
64 } // namespace internal
65 } // namespace v8
66