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"
14#include <map>
15#include <memory>
16#include <set>
17
18namespace yoi {
19 class moduleContext;
20
21 class IRObjectFile;
22
23 class IRStructDefinition;
24
25 class IRValueType;
26
27 class IRModule;
28
29 class IRBuildConfig;
30
31 class IRFFITable;
32
33 class BuiltinModuleBuilder;
34
35 class compilerContext : public std::enable_shared_from_this<compilerContext> {
38
39 std::map<yoi::indexT, std::shared_ptr<IRModule>> moduleImported;
40 std::shared_ptr<IRObjectFile> irObjectFile;
41 std::shared_ptr<IRBuildConfig> buildConfig;
42 std::shared_ptr<IRFFITable> irFFITable;
43 std::shared_ptr<BuiltinModuleBuilder> builtinModuleBuilder;
44 std::set<hoshiModule *> astToFinalize;
45 std::shared_ptr<moduleContext> builtinModuleContext;
46
47 public:
48 compilerContext() = default;
49
50 compilerContext(const compilerContext &context) = default;
51
57 std::shared_ptr<IRModule> getImportedModule(yoi::indexT index);
58
64 std::shared_ptr<yoi::moduleContext> getModuleContext(yoi::indexT index);
65
71 std::shared_ptr<IRModule> getImportedModule(const yoi::wstr &modRealPath);
72
77 const std::map<yoi::indexT, std::shared_ptr<IRModule>> &getCompiledModules() const;
78
86
87 yoi::indexT compileModule(const yoi::wstr &filepath);
88
89 const std::shared_ptr<IRObjectFile> &getIRObjectFile() const;
90
91 void setIRObjectFile(const std::shared_ptr<IRObjectFile> &irObjectFile);
92
94
95 std::shared_ptr<yoi::IRValueType> getIntObjectType(bool forceRawAttr = false);
96
97 std::shared_ptr<yoi::IRValueType> getBoolObjectType(bool forceRawAttr = false);
98
99 std::shared_ptr<yoi::IRValueType> getDeciObjectType(bool forceRawAttr = false);
100
101 std::shared_ptr<yoi::IRValueType> getStrObjectType(bool forceRawAttr = false);
102
103 std::shared_ptr<yoi::IRValueType> getCharObjectType(bool forceRawAttr = false);
104
105 std::shared_ptr<yoi::IRValueType> getShortObjectType(bool forceRawAttr = false);
106
107 std::shared_ptr<yoi::IRValueType> getUnsignedObjectType(bool forceRawAttr = false);
108
109 std::shared_ptr<yoi::IRValueType> getNoneObjectType();
110
111 std::shared_ptr<yoi::IRValueType> getForeignInt32ObjectType();
112
113 std::shared_ptr<yoi::IRValueType> getForeignFloatObjectType();
114
115 std::shared_ptr<yoi::IRValueType> getPointerType();
116
117 std::shared_ptr<yoi::IRValueType> getNullInterfaceType();
118
119 yoi::IRValueType normalizeForeignBasicType(const std::shared_ptr<yoi::IRValueType> &type, bool handlePointer = true);
120
121 // i figured it out, all wrapper struct type should save in IRFFITable independently, they are not import type
122 // or export type. they are just wrapper types. as for import function wrapper and export function wrapper, ofc
123 // we need to treat it differently or in another word, the differentiation of import and export struct type
124 // should not even exist. cuz you can declare a struct object and export it as foreign type which can be used in
125 // import function wrapper too.
126
127 std::shared_ptr<IRBuildConfig> getBuildConfig() const;
128
129 void setBuildConfig(const std::shared_ptr<IRBuildConfig> &buildConfig);
130
131 std::shared_ptr<IRFFITable> getIRFFITable();
132
133 void runOptimizer();
134
136 };
137
138} // namespace yoi
139
140#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)
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)
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
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)
static const char * __yoi_builtin_module_hoshi
std::wstring wstr
Definition def.hpp:48
uint64_t indexT
Definition def.hpp:51