hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
IRLinker.hpp
Go to the documentation of this file.
1//
2// Created by XIaokang00010 on 2024/10/12.
3//
4
5#ifndef HOSHI_LANG_IRLINKER_HPP
6#define HOSHI_LANG_IRLINKER_HPP
7
8#include "compiler/ir/IR.h"
10#include <map>
11
12#define ENTRY_MODULE_ID_CONST 0xe1751a00
13
14namespace yoi {
15
16 class IRLinker {
17 public:
19
26 std::shared_ptr<IRObjectFile> link(const std::shared_ptr<compilerContext>& context, indexT entryModuleId);
27
28 private:
29 std::shared_ptr<compilerContext> compilerCtx;
30 std::shared_ptr<IRModule> finalModule;
32
33 // Remapping tables: map<old_module_id, map<old_index, new_index>>
34 std::map<indexT, std::map<indexT, indexT>> structRemapping;
35 std::map<indexT, std::map<indexT, indexT>> datastructRemapping;
36 std::map<indexT, std::map<indexT, indexT>> interfaceRemapping;
37 std::map<indexT, std::map<indexT, indexT>> interfaceImplRemapping;
38 std::map<indexT, std::map<indexT, indexT>> globalRemapping;
39 std::map<indexT, std::map<indexT, indexT>> functionRemapping;
40 std::map<indexT, std::map<indexT, indexT>> stringRemapping;
42
46 wstr mangleName(indexT moduleId, const wstr& originalName);
47
48 void linkStringLiterals();
50 void linkDataStructs();
52 void linkGlobals();
53 void linkFunctions();
54 void linkMetadata();
56 void patchIRFFITable();
57 std::tuple<IRValueType::valueType, indexT, indexT>
58 patchUniqueKey(const std::tuple<IRValueType::valueType, indexT, indexT> &key);
59
60 std::shared_ptr<IRValueType> patchType(const std::shared_ptr<IRValueType> &oldType);
61 IR patchInstruction(const IR& instr, indexT currentModuleId);
62 };
63
64} // namespace yoi
65
66#endif //HOSHI_LANG_IRLINKER_HPP
std::map< indexT, std::map< indexT, indexT > > datastructRemapping
Definition IRLinker.hpp:35
void patchIRFFITable()
Definition IRLinker.cpp:366
yoi::vec< yoi::indexT > globInitializerIndexes
Definition IRLinker.hpp:41
indexT entryModuleId
Definition IRLinker.hpp:31
void linkInterfaceImplementations()
Definition IRLinker.cpp:358
void linkGlobals()
Definition IRLinker.cpp:142
void linkStringLiterals()
Definition IRLinker.cpp:55
void linkStructsAndInterfaces()
Definition IRLinker.cpp:67
wstr mangleName(indexT moduleId, const wstr &originalName)
Mangles a symbol name with its module ID, unless it's the main function in the entry module.
Definition IRLinker.cpp:45
std::map< indexT, std::map< indexT, indexT > > structRemapping
Definition IRLinker.hpp:34
std::map< indexT, std::map< indexT, indexT > > globalRemapping
Definition IRLinker.hpp:38
void linkDataStructs()
Definition IRLinker.cpp:426
std::shared_ptr< IRObjectFile > link(const std::shared_ptr< compilerContext > &context, indexT entryModuleId)
Links all compiled modules from the context into a single IRObjectFile.
Definition IRLinker.cpp:18
std::map< indexT, std::map< indexT, indexT > > interfaceImplRemapping
Definition IRLinker.hpp:37
std::tuple< IRValueType::valueType, indexT, indexT > patchUniqueKey(const std::tuple< IRValueType::valueType, indexT, indexT > &key)
Definition IRLinker.cpp:387
std::map< indexT, std::map< indexT, indexT > > interfaceRemapping
Definition IRLinker.hpp:36
void createEntryFunction()
Definition IRLinker.cpp:332
void linkMetadata()
Definition IRLinker.cpp:412
std::shared_ptr< IRModule > finalModule
Definition IRLinker.hpp:30
IR patchInstruction(const IR &instr, indexT currentModuleId)
Definition IRLinker.cpp:214
std::shared_ptr< compilerContext > compilerCtx
Definition IRLinker.hpp:29
std::map< indexT, std::map< indexT, indexT > > functionRemapping
Definition IRLinker.hpp:39
void linkFunctions()
Definition IRLinker.cpp:156
std::shared_ptr< IRValueType > patchType(const std::shared_ptr< IRValueType > &oldType)
Definition IRLinker.cpp:292
std::map< indexT, std::map< indexT, indexT > > stringRemapping
Definition IRLinker.hpp:40
Definition IR.h:264
std::vector< t > vec
Definition def.hpp:53
std::wstring wstr
Definition def.hpp:48
uint64_t indexT
Definition def.hpp:51