GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 21 / 3 / 24
Functions: 100.0% 3 / 0 / 3
Branches: 53.3% 16 / 14 / 44

src/objectemitter/ObjectEmitter.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "ObjectEmitter.h"
4
5 #include <SourceFile.h>
6 #include <driver/Driver.h>
7 #include <global/GlobalResourceManager.h>
8 #include <util/RawStringOStream.h>
9
10 #include <llvm/IR/LegacyPassManager.h>
11 #include <llvm/Support/CodeGen.h>
12 #include <llvm/Support/FileSystem.h>
13
14 namespace spice::compiler {
15
16 946 ObjectEmitter::ObjectEmitter(GlobalResourceManager &resourceManager, SourceFile *sourceFile)
17 : CompilerPass(resourceManager, sourceFile),
18
2/2
✓ Branch 3 → 4 taken 1 time.
✓ Branch 3 → 5 taken 945 times.
946 module(cliOptions.useLTO ? *resourceManager.ltoModule : *sourceFile->llvmModule) {}
19
20 946 void ObjectEmitter::emit(const std::filesystem::path &objectPath) const {
21
1/2
✓ Branch 2 → 3 taken 946 times.
✗ Branch 2 → 58 not taken.
946 const std::string objectPathString = objectPath.string();
22
23 // Open file output stream
24 946 std::error_code errorCode;
25
1/2
✓ Branch 5 → 6 taken 946 times.
✗ Branch 5 → 33 not taken.
946 llvm::raw_fd_ostream stream(objectPathString, errorCode, llvm::sys::fs::OF_None);
26
1/2
✗ Branch 7 → 8 not taken.
✓ Branch 7 → 15 taken 946 times.
946 if (errorCode)
27 throw CompilerError(CANT_OPEN_OUTPUT_FILE, "File '" + objectPathString + "' could not be opened"); // GCOV_EXCL_LINE
28
29
1/2
✓ Branch 15 → 16 taken 946 times.
✗ Branch 15 → 54 not taken.
946 llvm::legacy::PassManager passManager;
30 946 constexpr auto fileType = llvm::CodeGenFileType::ObjectFile;
31
2/4
✓ Branch 17 → 18 taken 946 times.
✗ Branch 17 → 52 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 27 taken 946 times.
946 if (sourceFile->targetMachine->addPassesToEmitFile(passManager, stream, nullptr, fileType, cliOptions.disableVerifier))
32 throw CompilerError(WRONG_OUTPUT_TYPE, "Target machine can't emit a file of this type"); // GCOV_EXCL_LINE
33
34 // Emit object file
35
1/2
✓ Branch 27 → 28 taken 946 times.
✗ Branch 27 → 52 not taken.
946 passManager.run(module);
36
1/2
✓ Branch 28 → 29 taken 946 times.
✗ Branch 28 → 52 not taken.
946 stream.flush();
37 946 }
38
39 902 void ObjectEmitter::getASMString(std::string &output) const {
40
1/2
✓ Branch 2 → 3 taken 902 times.
✗ Branch 2 → 33 not taken.
902 RawStringOStream ostream(output);
41
1/2
✓ Branch 3 → 4 taken 902 times.
✗ Branch 3 → 31 not taken.
902 llvm::legacy::PassManager passManager;
42 902 constexpr auto fileType = llvm::CodeGenFileType::AssemblyFile;
43
2/4
✓ Branch 5 → 6 taken 902 times.
✗ Branch 5 → 29 not taken.
✗ Branch 6 → 7 not taken.
✓ Branch 6 → 15 taken 902 times.
902 if (sourceFile->targetMachine->addPassesToEmitFile(passManager, ostream, nullptr, fileType, cliOptions.disableVerifier))
44 throw CompilerError(WRONG_OUTPUT_TYPE, "Target machine can't emit a file of this type"); // GCOV_EXCL_LINE
45
46 // Emit object file
47
1/2
✓ Branch 15 → 16 taken 902 times.
✗ Branch 15 → 29 not taken.
902 passManager.run(module);
48
1/2
✓ Branch 16 → 17 taken 902 times.
✗ Branch 16 → 29 not taken.
902 ostream.flush();
49 902 }
50
51 } // namespace spice::compiler
52