hoshi-lang dev
Yet another programming language
Loading...
Searching...
No Matches
compilerContext.h
Go to the documentation of this file.
1//
2// Created by XIaokang00010 on 2024/9/6.
3//
4
5#ifndef HOSHI_LANG_COMPILERCONTEXT_H
6#define HOSHI_LANG_COMPILERCONTEXT_H
7
8static const char *__yoi_builtin_module_hoshi =
9#include <compiler/builtinModule.hoshi>
10 ;
11
12#include "share/def.hpp"
15#include <map>
16#include <memory>
17#include <set>
18
19namespace yoi {
20 class moduleContext;
21
22 class IRObjectFile;
23
24 class IRStructDefinition;
25
26 class IRValueType;
27
28 class IRModule;
29
30 class IRBuildConfig;
31
32 class IRFFITable;
33
34 class BuiltinModuleBuilder;
35
36 class compilerContext : public std::enable_shared_from_this<compilerContext> {
39
40 std::map<yoi::indexT, std::shared_ptr<IRModule>> moduleImported;
41 std::shared_ptr<IRObjectFile> irObjectFile;
42 std::shared_ptr<IRBuildConfig> buildConfig;
43 std::shared_ptr<IRFFITable> irFFITable;
44 std::shared_ptr<BuiltinModuleBuilder> builtinModuleBuilder;
45 std::set<hoshiModule *> astToFinalize;
46 std::shared_ptr<moduleContext> builtinModuleContext;
47 std::shared_ptr<DiagnosticEngine> diagnosticEngine;
48
49 public:
50 compilerContext() = default;
51
52 compilerContext(const compilerContext &context) = default;
53
59 std::shared_ptr<IRModule> getImportedModule(yoi::indexT index);
60
66 std::shared_ptr<yoi::moduleContext> getModuleContext(yoi::indexT index);
67
73 std::shared_ptr<IRModule> getImportedModule(const yoi::wstr &modRealPath);
74
79 const std::map<yoi::indexT, std::shared_ptr<IRModule>> &getCompiledModules() const;
80
88
89 yoi::indexT compileModule(const yoi::wstr &filepath);
90
91 const std::shared_ptr<IRObjectFile> &getIRObjectFile() const;
92
93 void setIRObjectFile(const std::shared_ptr<IRObjectFile> &irObjectFile);
94
96
97 std::shared_ptr<yoi::IRValueType> getIntObjectType(bool forceRawAttr = false);
98
99 std::shared_ptr<yoi::IRValueType> getBoolObjectType(bool forceRawAttr = false);
100
101 std::shared_ptr<yoi::IRValueType> getDeciObjectType(bool forceRawAttr = false);
102
103 std::shared_ptr<yoi::IRValueType> getStrObjectType(bool forceRawAttr = false);
104
105 std::shared_ptr<yoi::IRValueType> getCharObjectType(bool forceRawAttr = false);
106
107 std::shared_ptr<yoi::IRValueType> getShortObjectType(bool forceRawAttr = false);
108
109 std::shared_ptr<yoi::IRValueType> getUnsignedObjectType(bool forceRawAttr = false);
110
111 std::shared_ptr<yoi::IRValueType> getNoneObjectType();
112
113 std::shared_ptr<yoi::IRValueType> getForeignInt32ObjectType();
114
115 std::shared_ptr<yoi::IRValueType> getForeignFloatObjectType();
116
117 std::shared_ptr<yoi::IRValueType> getPointerType();
118
119 std::shared_ptr<yoi::IRValueType> getNullInterfaceType();
120
121 yoi::IRValueType normalizeForeignBasicType(const std::shared_ptr<yoi::IRValueType> &type, bool handlePointer = true);
122
123 // i figured it out, all wrapper struct type should save in IRFFITable independently, they are not import type
124 // or export type. they are just wrapper types. as for import function wrapper and export function wrapper, ofc
125 // we need to treat it differently or in another word, the differentiation of import and export struct type
126 // should not even exist. cuz you can declare a struct object and export it as foreign type which can be used in
127 // import function wrapper too.
128
129 std::shared_ptr<IRBuildConfig> getBuildConfig() const;
130
131 void setBuildConfig(const std::shared_ptr<IRBuildConfig> &buildConfig);
132
133 std::shared_ptr<DiagnosticEngine> getDiagnosticEngine() const;
134
135 void setDiagnosticEngine(const std::shared_ptr<DiagnosticEngine> &engine);
136
137 std::shared_ptr<IRFFITable> getIRFFITable();
138
139 bool isInitialized() const;
140
141 void registerModule(yoi::indexT idx, std::shared_ptr<IRModule> mod);
142
143 void runOptimizer();
144
146 };
147
148} // namespace yoi
149
150#endif // HOSHI_LANG_COMPILERCONTEXT_H
std::shared_ptr< IRBuildConfig > buildConfig
std::shared_ptr< yoi::IRValueType > getForeignFloatObjectType()
std::map< yoi::indexT, std::shared_ptr< IRModule > > moduleImported
const std::map< yoi::indexT, std::shared_ptr< IRModule > > & getCompiledModules() const
std::shared_ptr< moduleContext > builtinModuleContext
void setIRObjectFile(const std::shared_ptr< IRObjectFile > &irObjectFile)
compilerContext()=default
yoi::indexTable< yoi::wstr, std::shared_ptr< yoi::moduleContext > > modules
std::shared_ptr< yoi::moduleContext > getModuleContext(yoi::indexT index)
get module context by index
std::shared_ptr< yoi::IRValueType > getCharObjectType(bool forceRawAttr=false)
void registerModule(yoi::indexT idx, std::shared_ptr< IRModule > mod)
std::shared_ptr< yoi::IRValueType > getNullInterfaceType()
void setBuildConfig(const std::shared_ptr< IRBuildConfig > &buildConfig)
std::set< hoshiModule * > astToFinalize
std::shared_ptr< yoi::IRValueType > getPointerType()
const std::shared_ptr< IRObjectFile > & getIRObjectFile() const
std::shared_ptr< yoi::IRValueType > getBoolObjectType(bool forceRawAttr=false)
std::shared_ptr< DiagnosticEngine > getDiagnosticEngine() const
yoi::indexT getModuleIndexByRealPath(const yoi::wstr &modRealPath)
std::shared_ptr< yoi::IRValueType > getUnsignedObjectType(bool forceRawAttr=false)
std::shared_ptr< IRFFITable > getIRFFITable()
std::shared_ptr< yoi::IRValueType > getForeignInt32ObjectType()
std::shared_ptr< yoi::IRValueType > getShortObjectType(bool forceRawAttr=false)
std::shared_ptr< yoi::IRValueType > getNoneObjectType()
yoi::indexT compileModule(const yoi::wstr &filepath)
std::shared_ptr< yoi::IRValueType > getIntObjectType(bool forceRawAttr=false)
std::shared_ptr< IRObjectFile > irObjectFile
std::shared_ptr< IRFFITable > irFFITable
std::shared_ptr< IRModule > getImportedModule(yoi::indexT index)
std::shared_ptr< BuiltinModuleBuilder > builtinModuleBuilder
void setDiagnosticEngine(const std::shared_ptr< DiagnosticEngine > &engine)
std::shared_ptr< IRBuildConfig > getBuildConfig() const
compilerContext(const compilerContext &context)=default
yoi::indexTable< yoi::wstr, std::shared_ptr< IRValueType > > sharedValueType
std::shared_ptr< yoi::IRValueType > getDeciObjectType(bool forceRawAttr=false)
yoi::IRValueType normalizeForeignBasicType(const std::shared_ptr< yoi::IRValueType > &type, bool handlePointer=true)
std::shared_ptr< yoi::IRValueType > getStrObjectType(bool forceRawAttr=false)
std::shared_ptr< DiagnosticEngine > diagnosticEngine
static const char * __yoi_builtin_module_hoshi
std::wstring wstr
Definition def.hpp:51
uint64_t indexT
Definition def.hpp:54