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