Mana
LocalAddressResolver.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "../runner/common/Setup.h"
10 #include "CodeBuffer.h"
11 #include "SyntaxNode.h"
12 #include "TypeDescriptor.h"
13 #include <array>
14 
15 namespace mana
16 {
17  class CodeGenerator;
18 
19  /*
20  ローカルアドレスを解決します
21  */
23  {
24  public:
25  enum class JumpChainStatus : uint8_t
26  {
27  Switch,
28  While,
29  Do,
30  For,
31  Loop,
32  Lock,
33  };
34 
35  public:
36  explicit LocalAddressResolver(const std::shared_ptr<CodeBuffer>& codeBuffer);
37  ~LocalAddressResolver() = default;
38 
40  void OpenChain(const JumpChainStatus status);
41 
43  int32_t Break(const int32_t newPc);
44 
46  int32_t Continue(const int32_t newPc);
47 
49  void CloseContinueOnly();
50 
52  void CloseChain();
53 
55  void OpenSwitchBlock(const std::shared_ptr<TypeDescriptor>& type);
56 
58  void RegistSwitchCase(const std::shared_ptr<SyntaxNode>& node);
59 
61  void RegistSwitchDefault();
62 
64  void ResolveSwitchBlock(const std::shared_ptr<CodeGenerator>& codeGenerator);
65 
67  void CloseSwitchBlock(void);
68 
69  private:
70  std::shared_ptr<CodeBuffer> mCodeBuffer;
71  std::shared_ptr<CodeGenerator> mCodeGenerator;
72 
73  static constexpr size_t JumpChainTableSize = 20;
74  static constexpr size_t JumpSwitchEntryStackSize = 256;
75  static constexpr size_t JumpSwitchStackSize = 256;
76 
78  struct JumpChainTable
79  {
80  JumpChainStatus status;
81  int32_t break_chain;
82  int32_t continue_chain;
83  int32_t start_address;
84  };
85  std::array<JumpChainTable, JumpChainTableSize> mJumpChainTable;
86  int32_t mJumpChainTablePointer;
89  struct JumpSwitchEntry
90  {
91  std::shared_ptr<SyntaxNode> node;
92  int32_t address;
93  };
94 
96  JumpSwitchEntry mJumpSwitchEntryStack[JumpSwitchEntryStackSize];
97 
99  JumpSwitchEntry* mJumpSwitchEntryStackPointer;
100 
102  struct JumpSwitchStack
103  {
104  JumpSwitchEntry* stack_pointer;
105  std::shared_ptr<TypeDescriptor> type;
106  int32_t default_address;
107  };
108  std::array<JumpSwitchStack, JumpSwitchStackSize> mJumpSwitchStack;
109 
111  int32_t mJumpSwitchStackPointer;
112  };
113 }
Definition: LocalAddressResolver.h:23
void CloseContinueOnly()
continueジャンプブロックの終了
Definition: LocalAddressResolver.cpp:69
int32_t Continue(const int32_t newPc)
continueの設定
Definition: LocalAddressResolver.cpp:49
void ResolveSwitchBlock(const std::shared_ptr< CodeGenerator > &codeGenerator)
switchブロックをバイナリーコードに変換
Definition: LocalAddressResolver.cpp:131
void RegistSwitchDefault()
defaultの登録
Definition: LocalAddressResolver.cpp:119
void OpenChain(const JumpChainStatus status)
ジャンプブロックの開始
Definition: LocalAddressResolver.cpp:23
void CloseSwitchBlock(void)
switchブロックの終了
Definition: LocalAddressResolver.cpp:180
JumpChainStatus
Definition: LocalAddressResolver.h:26
void RegistSwitchCase(const std::shared_ptr< SyntaxNode > &node)
caseの登録
Definition: LocalAddressResolver.cpp:99
void OpenSwitchBlock(const std::shared_ptr< TypeDescriptor > &type)
switchブロックの開始
Definition: LocalAddressResolver.cpp:91
void CloseChain()
ジャンプブロックの終了
Definition: LocalAddressResolver.cpp:78
LocalAddressResolver(const std::shared_ptr< CodeBuffer > &codeBuffer)
Definition: LocalAddressResolver.cpp:14
int32_t Break(const int32_t newPc)
breakの設定
Definition: LocalAddressResolver.cpp:32
Definition: CodeBuffer.cpp:12
Definition: Noncopyable.h:18