Mana
CodeGenerator.h
Go to the documentation of this file.
1 
8 #pragma once
9 #include "../runner/common/Setup.h"
10 #include "CodeBuffer.h"
11 #include "DataBuffer.h"
12 #include "GlobalAddressResolver.h"
13 #include "GlobalSemanticAnalyzer.h"
14 #include "LocalAddressResolver.h"
15 #include "LocalSemanticAnalyzer.h"
16 #include "SymbolFactory.h"
17 #include "SyntaxNode.h"
18 #include "TypeDescriptorFactory.h"
19 #include <memory>
20 
21 namespace mana
22 {
26  class CodeGenerator final : Noncopyable, public std::enable_shared_from_this<CodeGenerator>
27  {
28  public:
29  CodeGenerator() = delete;
30  explicit CodeGenerator(
31  const std::shared_ptr<CodeBuffer>& codeBuffer,
32  const std::shared_ptr<DataBuffer>& dataBuffer,
33  const std::shared_ptr<GlobalSemanticAnalyzer>& globalSemanticAnalyzer,
34  const std::shared_ptr<LocalSemanticAnalyzer>& localSemanticAnalyzer,
35  const std::shared_ptr<SymbolFactory>& symbolFactory,
36  const std::shared_ptr<TypeDescriptorFactory>& typeDescriptorFactory);
37 
43  void GenerateCode(std::shared_ptr<SyntaxNode> node, const int32_t enableLoad);
44 
48  void Expression(const std::shared_ptr<SyntaxNode>& tree, const int32_t enableAssign);
49 
53  const std::shared_ptr<GlobalAddressResolver>& GetGlobalAddressResolver();
54 
58  const std::shared_ptr<LocalAddressResolver>& GetLocalAddressResolver();
59 
60  void Dump(std::ofstream& output) const;
61 
62  private:
63  void ResolveLoad(const std::shared_ptr<SyntaxNode>& node) const;
64  void ResolveStore(const std::shared_ptr<SyntaxNode>& node) const;
65  void Return(const std::shared_ptr<Symbol>& function, const std::shared_ptr<SyntaxNode>& tree);
66  void Rollback(const std::shared_ptr<SyntaxNode>& tree);
67  int32_t Argument(int32_t count, const std::shared_ptr<Symbol>& param, std::shared_ptr<SyntaxNode> arg);
68  static int32_t CallArgumentSize(int32_t address, const std::shared_ptr<Symbol>& param, std::shared_ptr<SyntaxNode> arg);
69  int32_t CallArgument(int32_t address, const std::shared_ptr<Symbol>& param, std::shared_ptr<SyntaxNode> arg);
70  void Call(const std::shared_ptr<SyntaxNode>& node);
71  int32_t CallPrintGenerateArgument(int32_t argc, const std::shared_ptr<SyntaxNode>& node);
72  void CallPrint(const std::shared_ptr<SyntaxNode>& node);
73  void ConditionCheck(const std::shared_ptr<SyntaxNode>& tree);
74  address_t ConditionCore(const std::shared_ptr<SyntaxNode>& tree);
75  address_t Condition(const std::shared_ptr<SyntaxNode>& tree, const bool match);
76  void GenerateConstantInteger(const TypeDescriptor::Id typeId, const int32_t value) const;
77  void GenerateConstantFloat(const TypeDescriptor::Id typeId, const float value) const;
78 
79  private:
80  std::shared_ptr<CodeBuffer> mCodeBuffer;
81  std::shared_ptr<DataBuffer> mDataBuffer;
82  std::shared_ptr<GlobalAddressResolver> mGlobalAddressResolver;
83  std::shared_ptr<GlobalSemanticAnalyzer> mGlobalSemanticAnalyzer;
84  std::shared_ptr<LocalAddressResolver> mLocalAddressResolver;
85  std::shared_ptr<LocalSemanticAnalyzer> mLocalSemanticAnalyzer;
86  std::shared_ptr<StringPool> mStringPool;
87  std::shared_ptr<SymbolFactory> mSymbolFactory;
88  std::shared_ptr<TypeDescriptorFactory> mTypeDescriptorFactory;
89 
90  std::shared_ptr<Symbol> mActorSymbolEntryPointer;
91  std::shared_ptr<Symbol> mFunctionSymbolEntryPointer;
92  };
93 }
Definition: CodeGenerator.h:27
void GenerateCode(std::shared_ptr< SyntaxNode > node, const int32_t enableLoad)
Definition: CodeGenerator.cpp:555
const std::shared_ptr< GlobalAddressResolver > & GetGlobalAddressResolver()
Definition: CodeGenerator.cpp:1419
void Expression(const std::shared_ptr< SyntaxNode > &tree, const int32_t enableAssign)
Definition: CodeGenerator.cpp:500
void Dump(std::ofstream &output) const
Definition: CodeGenerator.cpp:1429
const std::shared_ptr< LocalAddressResolver > & GetLocalAddressResolver()
Definition: CodeGenerator.cpp:1424
Id
type identifier
Definition: TypeDescriptor.h:30
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:31
Definition: Noncopyable.h:18