GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 74.3% 26 / 4 / 39
Functions: 66.7% 4 / 0 / 6
Branches: 35.9% 28 / 8 / 86

src/global/GlobalResourceManager.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "GlobalResourceManager.h"
4
5 #include <SourceFile.h>
6 #include <driver/Driver.h>
7 #include <global/TypeRegistry.h>
8 #include <symboltablebuilder/Scope.h> // IWYU pragma: keep - Scope
9 #include <typechecker/FunctionManager.h>
10 #include <typechecker/InterfaceManager.h>
11 #include <typechecker/StructManager.h>
12 #include <util/FileUtil.h>
13
14 #include <llvm/IR/Module.h>
15 #include <llvm/Support/ManagedStatic.h>
16 #include <llvm/Support/TargetSelect.h>
17 #include <llvm/TargetParser/Host.h>
18 #include <llvm/TargetParser/SubtargetFeature.h>
19
20 namespace spice::compiler {
21
22 467 GlobalResourceManager::GlobalResourceManager(const CliOptions &cliOptions)
23
6/12
✓ Branch 4 → 5 taken 467 times.
✗ Branch 4 → 87 not taken.
✓ Branch 8 → 9 taken 467 times.
✗ Branch 8 → 81 not taken.
✓ Branch 9 → 10 taken 467 times.
✗ Branch 9 → 81 not taken.
✓ Branch 12 → 13 taken 467 times.
✗ Branch 12 → 75 not taken.
✓ Branch 13 → 14 taken 467 times.
✗ Branch 13 → 73 not taken.
✓ Branch 15 → 16 taken 467 times.
✗ Branch 15 → 71 not taken.
467 : cliOptions(cliOptions), linker(cliOptions), cacheManager(cliOptions), runtimeModuleManager(*this) {
24 // Initialize the required LLVM targets
25
2/2
✓ Branch 18 → 19 taken 462 times.
✓ Branch 18 → 22 taken 5 times.
467 if (cliOptions.isNativeTarget) {
26
1/2
✓ Branch 19 → 20 taken 462 times.
✗ Branch 19 → 69 not taken.
462 llvm::InitializeNativeTarget();
27
1/2
✓ Branch 20 → 21 taken 462 times.
✗ Branch 20 → 69 not taken.
462 llvm::InitializeNativeTargetAsmPrinter();
28
1/2
✓ Branch 21 → 26 taken 462 times.
✗ Branch 21 → 69 not taken.
462 llvm::InitializeNativeTargetAsmParser();
29 } else { // GCOV_EXCL_START
30 llvm::InitializeAllTargets();
31 llvm::InitializeAllTargetMCs();
32 llvm::InitializeAllAsmPrinters();
33 llvm::InitializeAllAsmParsers();
34 } // GCOV_EXCL_STOP
35
36 // Create cpu name and features strings
37
1/2
✓ Branch 26 → 27 taken 467 times.
✗ Branch 26 → 69 not taken.
467 cpuName = "generic";
38
3/4
✓ Branch 27 → 28 taken 462 times.
✓ Branch 27 → 51 taken 5 times.
✗ Branch 28 → 29 not taken.
✓ Branch 28 → 51 taken 462 times.
467 if (cliOptions.isNativeTarget && cliOptions.useCPUFeatures) {
39 // Retrieve native CPU name and the supported CPU features
40 cpuName = llvm::sys::getHostCPUName();
41 llvm::SubtargetFeatures features;
42 for (const auto &[feature, isEnabled] : llvm::sys::getHostCPUFeatures())
43 features.AddFeature(feature, isEnabled);
44 cpuFeatures = features.getString();
45 }
46
47
2/2
✓ Branch 51 → 52 taken 1 time.
✓ Branch 51 → 57 taken 466 times.
467 if (cliOptions.useLTO) {
48 // Discard value names if not required
49
1/2
✓ Branch 52 → 53 taken 1 time.
✗ Branch 52 → 69 not taken.
1 ltoContext.setDiscardValueNames(!cliOptions.namesForIRValues);
50 // Create lto module
51
1/2
✓ Branch 53 → 54 taken 1 time.
✗ Branch 53 → 68 not taken.
1 ltoModule = std::make_unique<llvm::Module>(LTO_FILE_NAME, ltoContext);
52 }
53 467 }
54
55 467 GlobalResourceManager::~GlobalResourceManager() {
56 // Notify all global components to prepare to destroy
57 467 TypeRegistry::clear();
58 467 FunctionManager::cleanup();
59 467 StructManager::cleanup();
60 467 InterfaceManager::cleanup();
61 // Cleanup all LLVM statics
62 467 llvm::llvm_shutdown();
63 467 }
64
65 1537 SourceFile *GlobalResourceManager::createSourceFile(SourceFile *parent, const std::string &depName,
66 const std::filesystem::path &path, bool isStdFile) {
67 // Check if the source file was already added (e.g. by another source file that imports it)
68
3/6
✓ Branch 2 → 3 taken 1537 times.
✗ Branch 2 → 22 not taken.
✓ Branch 3 → 4 taken 1537 times.
✗ Branch 3 → 20 not taken.
✓ Branch 4 → 5 taken 1537 times.
✗ Branch 4 → 18 not taken.
1537 const std::string filePathStr = weakly_canonical(absolute(path)).string();
69
70 // Create the new source file if it does not exist yet
71
3/4
✓ Branch 7 → 8 taken 1537 times.
✗ Branch 7 → 27 not taken.
✓ Branch 8 → 9 taken 1308 times.
✓ Branch 8 → 13 taken 229 times.
1537 if (!sourceFiles.contains(filePathStr))
72
2/4
✓ Branch 9 → 10 taken 1308 times.
✗ Branch 9 → 26 not taken.
✓ Branch 10 → 11 taken 1308 times.
✗ Branch 10 → 24 not taken.
1308 sourceFiles.emplace(filePathStr, std::make_unique<SourceFile>(*this, parent, depName, path, isStdFile));
73
74
1/2
✓ Branch 13 → 14 taken 1537 times.
✗ Branch 13 → 27 not taken.
3074 return sourceFiles.at(filePathStr).get();
75 1537 }
76
77 1101 uint64_t GlobalResourceManager::getNextCustomTypeId() { return nextCustomTypeId++; }
78
79 size_t GlobalResourceManager::getTotalLineCount() const {
80 const auto acc = [](size_t sum, const auto &sourceFile) { return sum + FileUtil::getLineCount(sourceFile.second->filePath); };
81 return std::accumulate(sourceFiles.begin(), sourceFiles.end(), 0, acc);
82 }
83
84 } // namespace spice::compiler
85