• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rieske / trans / 29993228457

23 Jul 2026 08:57AM UTC coverage: 91.09% (-0.6%) from 91.733%
29993228457

push

github

web-flow
Harden process invocation, exit codes, and ownership (#57)

Replace shell system() with an argv-based Process helper that drains
stdout/stderr concurrently and fails hard on non-zero tool exits.
Propagate compile failures from Driver to main, move parsing/scanner
factories to unique_ptr, and throw from unfinished array codegen.
Add focused util/driver/codegen tests; keep production free of coverage
tooling hooks.

130 of 202 new or added lines in 9 files covered. (64.36%)

5643 of 6195 relevant lines covered (91.09%)

186846.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.83
/src/driver/Compiler.cpp
1
#include "Compiler.h"
2

3
#include <fstream>
4
#include <stdexcept>
5

6
#include "CompilerComponentsFactory.h"
7
#include "codegen/AssemblyGenerator.h"
8
#include "codegen/GlobalVariable.h"
9
#include "codegen/QuadrupleGenerator.h"
10
#include "parser/SyntaxTreeBuilder.h"
11
#include "scanner/Scanner.h"
12
#include "semantic_analyzer/SemanticAnalyzer.h"
13
#include "codegen/quadruples/Quadruple.h"
14
#include "util/Logger.h"
15
#include "util/LogManager.h"
16
#include "util/Process.h"
17

18
static Logger& out = LogManager::getOutputLogger();
19

20
namespace {
21

22
void assemble(const std::string& assemblyFileName) {
211✔
23
    util::runProcessOrThrow({ "nasm", "-O1", "-f", "elf64", assemblyFileName });
1,900✔
24
}
843✔
25

26
void link(const std::string& sourceFileName) {
210✔
27
    util::runProcessOrThrow({
2,100✔
28
            "gcc", "-m64", "-no-pie",
29
            "-o", sourceFileName + ".out",
30
            sourceFileName + ".o"
31
    });
32
}
840✔
33

34
} // namespace
35

36
Compiler::Compiler(Configuration configuration) :
234✔
37
        configuration { configuration },
234✔
38
        compilerComponentsFactory { configuration },
234✔
39
        grammar { compilerComponentsFactory.makeGrammar() },
234✔
40
        parser { compilerComponentsFactory.makeParser(&grammar) }
234✔
41
{
42
}
234✔
43

44
void Compiler::compile(std::string sourceFileName) const {
235✔
45
    out << "Compiling " << sourceFileName << "...\n";
235✔
46

47
    std::unique_ptr<scanner::Scanner> scanner = compilerComponentsFactory.makeScannerForSourceFile(sourceFileName);
239✔
48
    std::unique_ptr<parser::SyntaxTreeBuilder> syntaxTreeBuilder = compilerComponentsFactory.makeSyntaxTreeBuilder(sourceFileName, &grammar);
231✔
49
    std::unique_ptr<parser::SyntaxTree> syntaxTree = parser->parse(*scanner, *syntaxTreeBuilder);
231✔
50

51
    semantic_analyzer::SemanticAnalyzer semanticAnalyzer;
227✔
52
    semanticAnalyzer.analyze(*syntaxTree);
227✔
53

54
    std::vector<codegen::GlobalVariable> globalVariables;
211✔
55
    for (const auto& global : semanticAnalyzer.getGlobalVariables()) {
267✔
56
        globalVariables.push_back({
56✔
57
                global.getName(),
58
                global.getType().getSize(),
112✔
59
                std::to_string(global.getConstantInitializer().value_or(0))
56✔
60
        });
61
    }
211✔
62

63
    codegen::QuadrupleGenerator quadrupleGenerator;
211✔
64
    // TODO: encapsulate quadruples behind intermediate form object
65
    std::vector<std::unique_ptr<codegen::Quadruple>> quadruples = quadrupleGenerator.generateQuadruplesFrom(*syntaxTree);
211✔
66

67
    if (configuration.isOutputIntermediateForms()) {
211✔
68
        out << "\nsymbol table\n";
208✔
69
        semanticAnalyzer.printSymbolTable();
208✔
70
        out << "symbol table end\n";
208✔
71
        out << "\nquadruples\n";
208✔
72
        for (auto &quadruple : quadruples) {
1,517✔
73
            out << *quadruple;
1,309✔
74
        }
75
        out << "quadruples end\n\n";
208✔
76
    }
77

78
    std::string assemblyFileName { sourceFileName + ".S" };
211✔
79
    std::ofstream assemblyFile { assemblyFileName };
211✔
80
    if (!assemblyFile) {
211✔
NEW
81
        throw std::runtime_error { "Unable to open assembly output file " + assemblyFileName };
×
82
    }
83
    std::unique_ptr<codegen::AssemblyGenerator> assemblyGenerator = compilerComponentsFactory.makeAssemblyGenerator(&assemblyFile);
211✔
84
    assemblyGenerator->generateAssemblyCode(std::move(quadruples), semanticAnalyzer.getConstants(), globalVariables);
211✔
85
    assemblyFile.close();
211✔
86

87
    assemble(assemblyFileName);
211✔
88
    link(sourceFileName);
210✔
89
    out << "Successfully compiled and linked\n";
210✔
90
}
404✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc