9 #include "../runner/common/Setup.h"
16 #include <unordered_map>
27 class TypeDescriptorFactory;
36 bool IsValid(std::shared_ptr<Symbol> symbolEntry);
40 const std::shared_ptr<CodeBuffer>& codeBuffer,
41 const std::shared_ptr<DataBuffer>& dataBuffer,
42 const std::shared_ptr<StringPool>& stringPool,
43 const std::shared_ptr<TypeDescriptorFactory>& typeDescriptorFactory
48 std::shared_ptr<Symbol>
CreateConstInt(
const std::string_view name,
const int32_t value);
49 std::shared_ptr<Symbol>
CreateConstFloat(
const std::string_view name,
const float value);
50 std::shared_ptr<Symbol>
CreateConstString(
const std::string_view name,
const std::string_view text);
51 std::shared_ptr<Symbol>
CreateVariable(
const std::string_view name,
const std::shared_ptr<TypeDescriptor>& type,
const bool staticVariable,
const bool isBlockOpened,
const bool isFunctionOpened);
52 std::shared_ptr<Symbol>
CreateLabel(
const std::string_view name);
53 std::shared_ptr<Symbol>
CreateFunction(
const std::string_view name,
const bool isActorOrStructOpened);
54 std::shared_ptr<Symbol>
CreateType(
const std::string_view name,
const std::shared_ptr<TypeDescriptor>& type);
55 void Destroy(
const std::string_view name);
57 bool Each(std::function<
bool(
const std::shared_ptr<Symbol>&)>
function)
59 for (
auto& symbol : mSymbolEntries)
61 if (!
function(symbol))
67 bool Each(std::function<
bool(
const std::shared_ptr<const Symbol>&)>
function)
const
69 for (
auto& symbol : mSymbolEntries)
71 if (!
function(symbol))
78 std::shared_ptr<Symbol>
Lookup(
const std::string_view name)
const;
81 void Define(
const std::string_view name, std::shared_ptr<Symbol> symbolEntry);
82 void Define(std::shared_ptr<Symbol> symbolEntry);
83 void Undefine(
const std::string_view name);
84 void Undefine(std::shared_ptr<Symbol> symbolEntry);
90 void EachBlock(std::function<
void(
const std::shared_ptr<Symbol>&)>
function);
94 void ExtendModule(
const std::shared_ptr<Symbol>& symbol);
97 void RegisterToBlock(
const std::shared_ptr<TypeDescriptor>& typeDescriptor);
105 int32_t
OpenBlock(
const bool resetMaxFrameMemoryAddress);
110 void OpenFunction(
const std::shared_ptr<SyntaxNode>& node,
const bool is_action);
111 void OpenFunction2(
const std::shared_ptr<const Symbol>&
function)
const;
112 void CloseFunction(
const std::shared_ptr<SyntaxNode>& node,
const bool is_action);
116 void CloseNativeFunction(
const std::shared_ptr<Symbol>&
function,
const std::shared_ptr<TypeDescriptor>& type);
128 void CommitRegistrationActor(
const std::string_view name,
const std::string_view parent,
const std::shared_ptr<TypeDescriptor>& type,
const bool phantom);
131 void OpenActor(
const std::string_view name);
140 void OpenModule(
const std::shared_ptr<Symbol>& symbolEntry);
151 return mBlockTypeDescriptor.top();
156 void AddRequest(
const std::shared_ptr<CodeGenerator>& codeGenerator,
const IntermediateLanguage opcode,
const std::shared_ptr<SyntaxNode>& level,
const std::shared_ptr<SyntaxNode>& actor,
const std::string_view action)
const;
157 void AddJoin(
const std::shared_ptr<CodeGenerator>& codeGenerator,
const std::shared_ptr<SyntaxNode>& level,
const std::shared_ptr<SyntaxNode>& actor)
const;
186 return mReturnAddressList;
191 mReturnAddressList = returnAddressList;
196 void Dump(std::ofstream& output)
const;
202 void PrintFooter(
const std::string_view,
const std::shared_ptr<TypeDescriptor>& type);
203 void PrintEntry(
const std::shared_ptr<Symbol>& symbolEntry,
const std::shared_ptr<TypeDescriptor>& type);
207 std::shared_ptr<Symbol> CreateSymbol(
const std::string_view name,
const Symbol::ClassTypeId class_type);
208 std::shared_ptr<Symbol> CreateSymbolWithAddress(
const std::string_view name,
const Symbol::ClassTypeId class_type,
const int32_t address);
209 std::shared_ptr<Symbol> CreateSymbolWithLevel(
const std::string_view name,
Symbol::ClassTypeId class_type,
const size_t blockLevel);
212 bool GenerateActorEntity(
OutputStream& stream,
const std::shared_ptr<const Symbol>& symbol,
const std::shared_ptr<const TypeDescriptor>& type)
const;
214 static int32_t symbol_align_size(
const int32_t X,
const int32_t Y)
216 return (X + Y - 1) / Y * Y;
221 std::shared_ptr<CodeBuffer> mCodeBuffer;
222 std::shared_ptr<DataBuffer> mDataBuffer;
223 std::shared_ptr<StringPool> mStringPool;
224 std::shared_ptr<TypeDescriptorFactory> mTypeDescriptorFactory;
226 std::unordered_map<std::string_view, std::shared_ptr<Symbol>> mHashChainTable;
227 std::vector<std::shared_ptr<Symbol>> mSymbolEntries;
229 struct BlockEntry final
231 BlockEntry() =
default;
232 void Set(
const std::shared_ptr<Symbol>& symbolEntry)
234 mSymbolEntry = symbolEntry;
236 void Set(
const std::shared_ptr<TypeDescriptor>& typeDescriptor)
238 mTypeDescriptor = typeDescriptor;
241 std::shared_ptr<Symbol> mSymbolEntry;
242 std::shared_ptr<TypeDescriptor> mTypeDescriptor;
245 struct BlockTable final
250 explicit BlockTable(
const int32_t allocp)
254 std::stack<std::unique_ptr<BlockTable>> mBlockTable;
256 std::stack<std::shared_ptr<TypeDescriptor>> mBlockTypeDescriptor;
259 ssize_t mActorOrStructureLevel = 0;
260 size_t mFunctionBlockLevel = 0;
261 bool mIsFunctionOpened =
false;
262 bool mModuleBlockOpened =
false;
265 int32_t mStaticMemoryAddress = 0;
266 int32_t mGlobalMemoryAddress = 0;
267 int32_t mActorMemoryAddress = 0;
268 int32_t mLocalMemoryAddress = 0;
269 int32_t mMaxLocalMemoryAddress = 0;
271 int32_t mFrameSizeList = 0;
272 address_t mReturnAddressList = InvalidAddress;
Definition: OutputStream.h:15
Definition: SymbolFactory.h:33
int32_t GetGlobalMemoryAddress() const
Definition: SymbolFactory.cpp:1286
bool Each(std::function< bool(const std::shared_ptr< const Symbol > &)> function) const
Definition: SymbolFactory.h:67
void DumpFunctionNameFromAddress(std::ofstream &output, const int32_t address) const
Definition: SymbolFactory.cpp:412
void AllocateMemory(const std::shared_ptr< Symbol > &symbolEntry, std::shared_ptr< TypeDescriptor > type, Symbol::MemoryTypeId)
Definition: SymbolFactory.cpp:1207
void OpenFunction(const std::shared_ptr< SyntaxNode > &node, const bool is_action)
Definition: SymbolFactory.cpp:474
void PrintFooter(const std::string_view, const std::shared_ptr< TypeDescriptor > &type)
Definition: SymbolFactory.cpp:1364
void PrintEntry(const std::shared_ptr< Symbol > &symbolEntry, const std::shared_ptr< TypeDescriptor > &type)
Definition: SymbolFactory.cpp:1399
void BeginNativeFunction()
Definition: SymbolFactory.cpp:651
void AddRequest(const std::shared_ptr< CodeGenerator > &codeGenerator, const IntermediateLanguage opcode, const std::shared_ptr< SyntaxNode > &level, const std::shared_ptr< SyntaxNode > &actor, const std::string_view action) const
Definition: SymbolFactory.cpp:1137
std::shared_ptr< TypeDescriptor > GetLastTypeDescriptorInBlock() const
Definition: SymbolFactory.cpp:393
std::shared_ptr< TypeDescriptor > GetCurrentBlockTypeDescriptor() const
Definition: SymbolFactory.h:149
void BeginRegistrationActor(const std::shared_ptr< Symbol > &symbolEntry)
Definition: SymbolFactory.cpp:819
void Destroy(const std::string_view name)
Definition: SymbolFactory.cpp:231
void OpenFunction2(const std::shared_ptr< const Symbol > &function) const
Definition: SymbolFactory.cpp:550
void SetGlobalMemoryAddress(const int32_t size)
Definition: SymbolFactory.cpp:1291
std::shared_ptr< Symbol > CreateLabel(const std::string_view name)
Definition: SymbolFactory.cpp:162
void CloseNativeFunction(const std::shared_ptr< Symbol > &function, const std::shared_ptr< TypeDescriptor > &type)
Definition: SymbolFactory.cpp:669
void CloseModule(const std::string_view name)
Definition: SymbolFactory.cpp:1093
address_t GetReturnAddressList() const
Definition: SymbolFactory.h:184
void RegisterToBlock(const std::shared_ptr< Symbol > &symbolEntry)
Definition: SymbolFactory.cpp:375
void CommitRegistrationModule(const std::string_view name)
Definition: SymbolFactory.cpp:1036
void OpenBlock(const int32_t address)
Definition: SymbolFactory.cpp:301
void SetStaticMemoryAddress(const int32_t size)
Definition: SymbolFactory.cpp:1280
void BeginRegistrationStructure()
Definition: SymbolFactory.cpp:690
void Define(const std::string_view name, std::shared_ptr< Symbol > symbolEntry)
Definition: SymbolFactory.cpp:281
bool GenerateActorInformation(OutputStream &stream) const
Definition: SymbolFactory.cpp:1433
size_t GetNumberOfActors() const
Definition: SymbolFactory.cpp:1297
void EachBlock(std::function< void(const std::shared_ptr< Symbol > &)> function)
Definition: SymbolFactory.cpp:344
void PrintHeader()
Definition: SymbolFactory.cpp:1347
void PrintDummyGlobalVariable(size_t size)
Definition: SymbolFactory.cpp:1414
void OpenStructure(const std::string_view name)
Definition: SymbolFactory.cpp:754
bool Each(std::function< bool(const std::shared_ptr< Symbol > &)> function)
Definition: SymbolFactory.h:57
void AddJoin(const std::shared_ptr< CodeGenerator > &codeGenerator, const std::shared_ptr< SyntaxNode > &level, const std::shared_ptr< SyntaxNode > &actor) const
Definition: SymbolFactory.cpp:1183
bool IsOpenBlock() const
Definition: SymbolFactory.cpp:468
int32_t CloseBlock()
Definition: SymbolFactory.cpp:306
void CloseStructure()
Definition: SymbolFactory.cpp:794
bool IsValid(std::shared_ptr< Symbol > symbolEntry)
Definition: SymbolFactory.cpp:240
bool IsActorOrStructerOpened() const
Definition: SymbolFactory.cpp:921
void Dump(std::ofstream &output) const
Definition: SymbolFactory.cpp:403
void CheckUndefine()
Definition: SymbolFactory.cpp:1333
void ExtendModule(const std::shared_ptr< Symbol > &symbol)
Definition: SymbolFactory.cpp:359
void CommitRegistrationStructure(const std::string_view name)
Definition: SymbolFactory.cpp:705
int32_t GetStaticMemoryAddress() const
Definition: SymbolFactory.cpp:1275
void OpenModule(const std::shared_ptr< Symbol > &symbolEntry)
Definition: SymbolFactory.cpp:1063
void CloseActor()
Definition: SymbolFactory.cpp:968
std::shared_ptr< Symbol > Lookup(const std::string_view name) const
Definition: SymbolFactory.cpp:260
void OpenActor(const std::string_view name)
Definition: SymbolFactory.cpp:926
SymbolFactory(const std::shared_ptr< CodeBuffer > &codeBuffer, const std::shared_ptr< DataBuffer > &dataBuffer, const std::shared_ptr< StringPool > &stringPool, const std::shared_ptr< TypeDescriptorFactory > &typeDescriptorFactory)
Definition: SymbolFactory.cpp:20
void Undefine(const std::string_view name)
Definition: SymbolFactory.cpp:291
size_t GetBlockDepth() const
Definition: SymbolFactory.cpp:339
void symbol_open_actor_register_member(const std::shared_ptr< Symbol > &symbol)
Definition: SymbolFactory.cpp:805
void BeginRegistrationModule(const std::shared_ptr< Symbol > &symbolEntry)
Definition: SymbolFactory.cpp:997
bool IsModuleOpened() const
Definition: SymbolFactory.h:142
void SetReturnAddressList(const address_t returnAddressList)
Definition: SymbolFactory.h:189
std::shared_ptr< Symbol > CreateConstInt(const std::string_view name, const int32_t value)
Definition: SymbolFactory.cpp:66
bool IsFunctionOpened() const
Definition: SymbolFactory.h:113
std::shared_ptr< Symbol > CreateConstString(const std::string_view name, const std::string_view text)
Definition: SymbolFactory.cpp:108
void CommitRegistrationActor(const std::string_view name, const std::string_view parent, const std::shared_ptr< TypeDescriptor > &type, const bool phantom)
Definition: SymbolFactory.cpp:857
std::shared_ptr< Symbol > CreateType(const std::string_view name, const std::shared_ptr< TypeDescriptor > &type)
Definition: SymbolFactory.cpp:194
std::shared_ptr< Symbol > CreateVariable(const std::string_view name, const std::shared_ptr< TypeDescriptor > &type, const bool staticVariable, const bool isBlockOpened, const bool isFunctionOpened)
Definition: SymbolFactory.cpp:131
std::shared_ptr< Symbol > CreateFunction(const std::string_view name, const bool isActorOrStructOpened)
Definition: SymbolFactory.cpp:175
std::shared_ptr< Symbol > GetLastSymbolEntryInBlock() const
Definition: SymbolFactory.cpp:386
std::shared_ptr< Symbol > CreateConstFloat(const std::string_view name, const float value)
Definition: SymbolFactory.cpp:87
void CloseFunction(const std::shared_ptr< SyntaxNode > &node, const bool is_action)
Definition: SymbolFactory.cpp:587
ClassTypeId
Definition: Symbol.h:25
MemoryTypeId
Definition: Symbol.h:62
Definition: CodeBuffer.cpp:12
std::uint32_t address_t
Definition: Type.h:31
IntermediateLanguage
Definition: FileFormat.h:80
Definition: Noncopyable.h:18