-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
GlobalResourceManager.h
73 lines (61 loc) · 2.62 KB
/
GlobalResourceManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) 2021-2024 ChilliBits. All rights reserved.
#pragma once
#include <exception/ErrorManager.h>
#include <global/CacheManager.h>
#include <global/RuntimeModuleManager.h>
#include <linker/ExternalLinkerInterface.h>
#include <util/BlockAllocator.h>
#include <util/CodeLoc.h>
#include <util/Timer.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Target/TargetMachine.h>
#include "../../lib/thread-pool/thread-pool-utils.hpp"
#include "../../lib/thread-pool/thread-pool.hpp"
namespace spice::compiler {
// Forward declarations
struct CliOptions;
class SourceFile;
// Constants
const char *const MAIN_FILE_NAME = "root";
const char *const LTO_FILE_NAME = "lto-module";
/**
* The GlobalResourceManager is instantiated at startup of the compiler and serves as distribution point for globally used assets.
* This component owns all SourceFile instances and AST nodes and therefore is the resource root of the compiler.
* Other components of the compiler can request the required global resources from the GlobalResourceManager.
*/
class GlobalResourceManager {
public:
// Constructors
explicit GlobalResourceManager(const CliOptions &cliOptions);
GlobalResourceManager(const GlobalResourceManager &) = delete; // Global resource manager can only exist exactly once
~GlobalResourceManager();
// Public methods
SourceFile *createSourceFile(SourceFile *parent, const std::string &depName, const std::filesystem::path &path, bool isStdFile);
uint64_t getNextCustomTypeId();
size_t getTotalLineCount() const;
// Public members
llvm::LLVMContext context;
llvm::IRBuilder<> builder = llvm::IRBuilder<>(context);
std::unique_ptr<llvm::Module> ltoModule;
std::unique_ptr<llvm::TargetMachine> targetMachine;
DefaultMemoryManager memoryManager;
std::vector<std::string> compileTimeStringValues;
BlockAllocator<ASTNode> astNodeAlloc = BlockAllocator<ASTNode>(memoryManager); // Used to allocate all AST nodes
std::unordered_map<std::string, std::unique_ptr<SourceFile>> sourceFiles; // The GlobalResourceManager owns all source files
std::vector<ASTNode *> astNodes;
const CliOptions &cliOptions;
ExternalLinkerInterface linker;
CacheManager cacheManager;
RuntimeModuleManager runtimeModuleManager;
Timer totalTimer;
BS::thread_pool threadPool = BS::thread_pool(cliOptions.compileJobCount);
BS::synced_stream tout;
ErrorManager errorManager;
bool abortCompilation = false;
private:
// Private members
std::atomic<uint64_t> nextCustomTypeId = UINT8_MAX + 1; // Start at 256 because all primitive types come first
};
} // namespace spice::compiler