Przeglądaj źródła

reworked error reporting

Nicolas Winkler 6 lat temu
rodzic
commit
f839bba157

+ 11 - 5
src/CodegenVisitor.cpp

@@ -139,7 +139,7 @@ llvm::Value* ExpressionCodegenVisitor::visit(sem::MethodCallExpression& call, ll
     if (call.target != nullptr) {
         auto* target = call.target->accept(fg.lvalueVisitor, builder);
         
-        Logger::getInstance().debug() << "creating 'this' argument";
+        Printer::getInstance().debug() << "creating 'this' argument";
         if (llvm::LoadInst* li = llvm::dyn_cast<llvm::LoadInst>(target); li) {
             llvm::Value* ptr = builder.CreateLoad(call.target->type->getLlvmType(builder.getContext())->getPointerTo(), li, "ptrload");
             arguments.push_back(ptr);
@@ -380,7 +380,7 @@ llvm::Value* StatementVisitor::visit(sem::WhileBlock& whileBlock,
 llvm::Value* StatementVisitor::visit(sem::AssignmentStatement& assignment,
         qlow::gen::FunctionGenerator& fg)
 {
-    Logger& logger = Logger::getInstance();
+    Printer& printer = Printer::getInstance();
     llvm::IRBuilder<> builder(fg.getContext());
     builder.SetInsertPoint(fg.getCurrentBlock());
     
@@ -391,13 +391,17 @@ llvm::Value* StatementVisitor::visit(sem::AssignmentStatement& assignment,
     
     if (auto* targetVar =
         dynamic_cast<sem::LocalVariableExpression*>(assignment.target.get()); targetVar) {
-        logger.debug() << "assigning to LocalVariableExpression" << std::endl;
+#ifdef DEBUGGING
+        printer << "assigning to LocalVariableExpression" << std::endl;
+#endif
         builder.CreateStore(val, targetVar->var->allocaInst);
     }
     else if (auto* targetVar =
         dynamic_cast<sem::FieldAccessExpression*>(assignment.target.get()); targetVar) {
         
-        logger.debug() << "assigning to FieldAccessExpression" << std::endl;
+#ifdef DEBUGGING
+        printer << "assigning to FieldAccessExpression" << std::endl;
+#endif
         if (targetVar->target) {
             llvm::Value* target = targetVar->target->accept(fg.expressionVisitor, builder);
             
@@ -411,7 +415,9 @@ llvm::Value* StatementVisitor::visit(sem::AssignmentStatement& assignment,
         }
     }
     else {
-        logger.debug() << "assigning to instance of " << assignment.target->toString() << std::endl;
+#ifdef DEBUGGING
+        printer << "assigning to instance of " << assignment.target->toString() << std::endl;
+#endif
         throw "only local variables are assignable at the moment";
     }
     

+ 27 - 18
src/Driver.cpp

@@ -5,7 +5,8 @@
 #include "Builtin.h"
 #include "CodeGeneration.h"
 
-#include "Logging.h"
+#include "Printer.h"
+#include "ErrorReporting.h"
 
 #include <cstdio>
 
@@ -70,27 +71,31 @@ Driver::Driver(int argc, char** argv) :
 
 int Driver::run(void)
 {
-    Logger& logger = Logger::getInstance();
+    Printer& printer = Printer::getInstance();
     
-    logger.debug() << "starting parser" << std::endl;
-    //logger.logError("driver not yet implemented", {options.emitAssembly ? "asm" : "noasm", 10, 11, 12, 13});
+#ifdef DEBUGGING
+    printer << "starting parser" << std::endl;
+#endif
+    //printer.logError("driver not yet implemented", {options.emitAssembly ? "asm" : "noasm", 10, 11, 12, 13});
     bool errorOccurred = parseStage();
     
     if (errorOccurred) {
-        logger << "Aborting due to syntax errors." << std::endl;
+        printer << "Aborting due to syntax errors." << std::endl;
         return 1;
     }
     
     errorOccurred = semanticStage();
     
     if (errorOccurred) {
-        logger << "Aborting due to semantic errors." << std::endl;
+        printer << "Aborting due to semantic errors." << std::endl;
         return 1;
     }
     
 
     for (auto& [a, b] : semClasses->classes) {
-        logger.debug() << a << ": " << b->toString() << std::endl;
+#ifdef DEBUGGING
+        printer << a << ": " << b->toString() << std::endl;
+#endif
     }
     
     
@@ -98,7 +103,7 @@ int Driver::run(void)
     /*auto main = semClasses->classes.find("Main");
     qlow::sem::Class* mainClass = nullptr;
     if (main == semClasses->classes.end()) {
-        logger.logError("No Main class found");
+        printer.logError("No Main class found");
         return 1;
     }
     else {
@@ -108,11 +113,13 @@ int Driver::run(void)
     auto* mainMethod = semClasses->getMethod("main");
     if (mainMethod == nullptr && false) {
         // TODO handle main ckeck well
-        logger.logError("no main method found");
+        qlow::printError(printer, "no main method found");
         return 1;
     }
     
-    logger.debug() << "starting code generation!" << std::endl;
+#ifdef DEBUGGING
+    printer << "starting code generation!" << std::endl;
+#endif
 
     std::unique_ptr<llvm::Module> mod = nullptr;
     
@@ -124,7 +131,7 @@ int Driver::run(void)
         return 1;
     }
     catch (SemanticError& err) {
-        err.print(logger);
+        err.print(printer);
         return 1;
     }
     catch (...) {
@@ -136,16 +143,18 @@ int Driver::run(void)
         qlow::gen::generateObjectFile(options.outfile, std::move(mod), options.optLevel);
     }
     catch (const char* msg) {
-        logger.logError(msg);
+        printError(printer, msg);
         return 1;
     }
     catch (...) {
-        logger.logError("unknown error during object file creation");
+        printError(printer, "unknown error during object file creation");
         reportError("unknown error during object file creation");
         return 1;
     }
     
-    logger.debug() << "object exported!" << std::endl;
+#ifdef DEBUGGING
+    printer << "object exported!" << std::endl;
+#endif
     
     return 0;
 }
@@ -154,7 +163,7 @@ int Driver::run(void)
 bool Driver::parseStage(void)
 {
     using namespace std::literals;
-    Logger& logger = Logger::getInstance();
+    Printer& printer = Printer::getInstance();
 
     this->ast = std::make_unique<ast::Ast>();
     bool errorOccurred = false;
@@ -172,7 +181,7 @@ bool Driver::parseStage(void)
             this->ast->merge(parseFile(file, filename));
         }
         catch (const CompileError& ce) {
-            ce.print(logger);
+            ce.print(printer);
             errorOccurred = true;
         }
         catch (const char* errMsg) {
@@ -193,14 +202,14 @@ bool Driver::parseStage(void)
 
 bool Driver::semanticStage(void)
 {
-    Logger& logger = Logger::getInstance();
+    Printer& printer = Printer::getInstance();
     bool errorOccurred = false;
 
     try {
         std::tie(this->context, this->semClasses) = qlow::sem::createFromAst(*this->ast);
     }
     catch(SemanticError& se) {
-        se.print(logger);
+        se.print(printer);
         errorOccurred = true;
     }
     catch(const char* err) {

+ 68 - 47
src/ErrorReporting.cpp

@@ -12,24 +12,45 @@ namespace qlow
 {
     void reportError(const CompileError& ce)
     {
-        Logger& logger = Logger::getInstance();
+        Printer& printer = Printer::getInstance();
         
-        ce.print(logger);
+        ce.print(printer);
     }
     
     
     void reportError(const std::string& msg)
     {
-        Logger& logger = Logger::getInstance();
+        Printer& printer = Printer::getInstance();
         
-        logger.logError(msg);
+        printError(printer, msg);
         
-        logger.info() <<
+        printer <<
             "\n"
             "This kind of error isn't supposed to happen.\n\n"
             "Please submit a bug report to nicolas.winkler@gmx.ch\n"
         ;
     }
+
+
+    void printError(Printer& printer, const std::string& msg)
+    {
+        printer.bold();
+        printer.foreground(Printer::RED, true);
+        printer << "error: ";
+        printer.removeFormatting();
+        printer << msg << std::endl;
+    }
+
+
+    void printError(Printer& printer, const std::string& msg, const CodePosition& cp)
+    {
+        printer.bold();
+        printer << cp.filename << ":" << cp.first_line << ":" << cp.first_column << ": ";
+        printer.foreground(Printer::RED, true);
+        printer << "error: ";
+        printer.removeFormatting();
+        printer << msg << std::endl;
+    }
 }
 
 
@@ -40,7 +61,7 @@ CompileError::~CompileError(void)
 
 
 // TODO rewrite more compact and more readable
-void CompileError::underlineError(Logger& logger) const
+void CompileError::underlineError(Printer& printer) const
 {
     std::ifstream file(where.filename);
     
@@ -48,7 +69,7 @@ void CompileError::underlineError(Logger& logger) const
         return;
     
     if (where.isMultiline()) {
-        size_t lineNr = 1;
+        int lineNr = 1;
         while (lineNr < where.first_line) {
             if (file.get() == '\n') {
                 lineNr++;
@@ -59,19 +80,19 @@ void CompileError::underlineError(Logger& logger) const
         
         int lineNrLength = std::to_string(lineNr).size();
         
-        logger.err() << "from here:" << std::endl;
-        logger.foreground(Logger::Color::YELLOW, true);
-        logger.err() << lineNr;
-        logger.removeFormatting();
-        logger.err() << ": " << line << std::endl;
-        for (size_t i = 0; i < where.first_column + lineNrLength + 2; i++) {
-            logger.err() << ' ';
+        printer << "from here:" << std::endl;
+        printer.foreground(Printer::Color::YELLOW, true);
+        printer << lineNr;
+        printer.removeFormatting();
+        printer << ": " << line << std::endl;
+        for (int i = 0; i < where.first_column + lineNrLength + 2; i++) {
+            printer << ' ';
         }
-        logger.foreground(Logger::Color::RED, true);
+        printer.foreground(Printer::Color::RED, true);
         for (size_t i = where.first_column; i < line.size(); i++) {
-            logger.err() << '^';
+            printer << '^';
         }
-        logger.removeFormatting();
+        printer.removeFormatting();
         
         lineNr++;
         while (lineNr < where.last_line) {
@@ -82,25 +103,25 @@ void CompileError::underlineError(Logger& logger) const
         
         std::getline(file, line);
         lineNrLength = std::to_string(lineNr).size();
-        logger.err() << std::endl << "to here:" << std::endl;
+        printer << std::endl << "to here:" << std::endl;
         
-        logger.foreground(Logger::Color::YELLOW, true);
-        logger.err() << lineNr;
-        logger.removeFormatting();
-        logger.err() << ": " << line << std::endl;
-        for (size_t i = 0; i < lineNrLength + 2; i++) {
-            logger.err() << ' ';
+        printer.foreground(Printer::Color::YELLOW, true);
+        printer << lineNr;
+        printer.removeFormatting();
+        printer << ": " << line << std::endl;
+        for (int i = 0; i < lineNrLength + 2; i++) {
+            printer << ' ';
         }
-        logger.foreground(Logger::Color::RED, true);
-        for (size_t i = 0; i < where.last_column; i++) {
-            logger.err() << '^';
+        printer.foreground(Printer::Color::RED, true);
+        for (int i = 0; i < where.last_column; i++) {
+            printer << '^';
         }
-        logger.removeFormatting();
-        logger.err() << std::endl;
+        printer.removeFormatting();
+        printer << std::endl;
         
     }
     else {
-        size_t lineNr = 1;
+        int lineNr = 1;
         while (lineNr < where.first_line) {
             if (file.get() == '\n') {
                 lineNr++;
@@ -108,42 +129,42 @@ void CompileError::underlineError(Logger& logger) const
         }
         std::string line;
         std::getline(file, line);
-        logger.err() << line << std::endl;
-        for (size_t i = 0; i < where.first_column; i++) {
-            logger.err() << ' ';
+        printer << line << std::endl;
+        for (int i = 0; i < where.first_column; i++) {
+            printer << ' ';
         }
-        logger.foreground(Logger::Color::RED, true);
-        for (size_t i = where.first_column; i < where.last_column; i++) {
-            logger.err() << '^';
+        printer.foreground(Printer::Color::RED, true);
+        for (int i = where.first_column; i < where.last_column; i++) {
+            printer << '^';
         }
-        logger.removeFormatting();
-        logger.err() << std::endl;
+        printer.removeFormatting();
+        printer << std::endl;
     }
 }
 
 
-void SyntaxError::print(Logger& logger) const
+void SyntaxError::print(Printer& printer) const
 {
     using namespace std::literals;
     if (message == "")
-        logger.logError("Syntax error", where);
+        printError(printer, "Syntax error", where);
     else
-        logger.logError("Syntax error: "s + message, where);
-    underlineError(logger);
+        printError(printer, "Syntax error: "s + message, where);
+    underlineError(printer);
 }
 
 
-void SemanticError::print(Logger& logger) const
+void SemanticError::print(Printer& printer) const
 {
     std::string errMsg = getMessage();
-    logger.logError(errMsg + (errMsg != "" ?  ": " : "") + message, where);
-    underlineError(logger);
+    printError(printer, errMsg + (errMsg != "" ?  ": " : "") + message, where);
+    underlineError(printer);
 }
 
 
 std::string SemanticError::getMessage(void) const
 {
-    static std::map<ErrorCode, std::string> error = {
+    static const std::map<ErrorCode, std::string> error = {
         {UNKNOWN_TYPE, "unknown type"},
         {FEATURE_NOT_FOUND, "method or variable not found"},
         {DUPLICATE_CLASS_DEFINITION, "duplicate class definition"},
@@ -152,7 +173,7 @@ std::string SemanticError::getMessage(void) const
         {OPERATOR_NOT_FOUND, ""},
         {WRONG_NUMBER_OF_ARGUMENTS, "wrong number of arguments passed"},
     };
-    return error[errorCode];
+    return error.at(errorCode);
 }
 
 

+ 7 - 5
src/ErrorReporting.h

@@ -1,7 +1,7 @@
 #ifndef QLOW_ERROR_REPORTING
 #define QLOW_ERROR_REPORTING
 
-#include "Logging.h"
+#include "Printer.h"
 
 
 namespace qlow
@@ -17,6 +17,8 @@ namespace qlow
     
     void reportError(const CompileError& ce);
     void reportError(const std::string& message);
+    void printError(Printer& printer, const std::string& message);
+    void printError(Printer& printer, const std::string& message, const CodePosition& where);
 }
 
 
@@ -46,9 +48,9 @@ public:
     }
     
     virtual ~CompileError(void);
-    virtual void print(Logger& logger) const = 0;
+    virtual void print(Printer& printer = Printer::getInstance()) const = 0;
     
-    void underlineError(Logger& logger) const;
+    void underlineError(Printer& printer = Printer::getInstance()) const;
 };
 
 
@@ -67,7 +69,7 @@ public:
     {
     }
     
-    virtual void print(Logger&) const override;
+    virtual void print(Printer&) const override;
 };
 
 
@@ -105,7 +107,7 @@ public:
     {
     }
 
-    virtual void print(Logger&) const override;
+    virtual void print(Printer& p = Printer::getInstance()) const override;
     virtual std::string getMessage(void) const;
 };
 

+ 0 - 116
src/Logging.cpp

@@ -1,116 +0,0 @@
-#include "Logging.h"
-
-#include "Ast.h"
-
-using qlow::Logger;
-
-
-Logger Logger::instance(std::cout);
-
-
-Logger::Logger(std::ostream& target) :
-    std::ostream{ this },
-    target{ target },
-    indentVal{ 0 },
-    firstChar{ true }
-{
-}
-
-
-void Logger::foreground(Color color, bool bright)
-{
-    using std::string;
-    string cchar = string(1, '0' + color);
-    string isbright = bright ? "9" : "3";
-    *this << "\033[" << isbright << cchar << "m";
-}
-
-
-void Logger::background(Color color, bool bright)
-{
-    using std::string;
-    string cchar = string(1, '0' + color);
-    string isbright = bright ? "10" : "4";
-    *this << "\033[" << isbright << cchar << "m"; 
-}
-
-
-void Logger::bold(void)
-{
-    *this << "\033[1m";
-}
-
-
-void Logger::removeFormatting(void)
-{
-    *this << "\033[0m";
-}
-
-
-void Logger::logError(const std::string& errMsg)
-{
-    bold();
-    foreground(RED, true);
-    *this << "error: ";
-    removeFormatting();
-    *this << errMsg << std::endl;
-}
-
-
-void Logger::logError(const std::string& errMsg, const qlow::CodePosition& cp)
-{
-    bold();
-    *this << cp.filename << ":" << cp.first_line << ":" << cp.first_column << ": ";
-    foreground(RED, true);
-    *this << "error: ";
-    removeFormatting();
-    *this << errMsg << std::endl;
-}
-
-
-int Logger::overflow(int c)
-{
-    target.put(char(c));
-    return 0;
-}
-
-
-std::ostream& operator << (std::ostream& o, qlow::LogLevel l)
-{
-    switch(l)
-    {
-        case qlow::LogLevel::WARNING:
-            try {
-                dynamic_cast<qlow::Logger&>(o).setLogType(l);
-            }
-            catch(...) {}
-            return o << "\033[33m";
-    }
-    return o;
-}
-
-
-/*std::streamsize Logger::xsputn(const char* s, std::streamsize n)
-{
-    target.write(s, n);
-}*/
-
-
-/*int main()
-{
-    qlow::Logger& l = Logger::stdout;
-    l << "aha" << std::endl;
-    l.indent(10);
-    l << "aha" << std::endl;
-    l << qlow::LogLevel::WARNING << "ee";
-    l.unindent(10);
-    l << "aha" << std::endl;
-}*/
-
-
-
-
-
-
-
-

+ 0 - 119
src/Logging.h

@@ -1,119 +0,0 @@
-#ifndef QLOW_LOGGING_H
-#define QLOW_LOGGING_H
-
-#include <iostream>
-
-
-namespace qlow
-{
-    class Logger;
-
-    enum class LogLevel
-    {
-        NONE,
-        ERROR,
-        WARNING,
-        INFO,
-        DEBUG,
-        TRACE,
-        OFF,
-    };
-    
-    struct CodePosition;
-}
-
-
-class qlow::Logger :
-    public std::ostream,
-    private std::streambuf
-{
-protected:
-    
-    class NullStream :
-        public std::ostream,
-        public std::streambuf
-    {
-    public:
-        NullStream(void) : std::ostream{ this } {}
-        inline int overflow(int c) override { return c; }
-    };
-    
-public:
-    enum Color {
-        BLACK = 0,
-        RED,
-        GREEN,
-        YELLOW,
-        BLUE,
-        MAGENTA,
-        CYAN,
-        WHITE
-    };
-private:
-
-    std::ostream& target;
-    NullStream nullStream;
-    bool firstChar;
-    int indentVal;
-
-    // type of current logging
-    LogLevel logType = LogLevel::OFF;
-    
-#ifdef DEBUGGING
-    LogLevel logLevel = LogLevel::DEBUG;
-#else
-    LogLevel logLevel = LogLevel::WARNING;
-#endif
-
-    static Logger instance;
-
-public:
-    void foreground(Color color, bool bright);
-    void background(Color color, bool bright);
-    void bold(void);
-    void removeFormatting(void);
-
-public:
-    explicit Logger(std::ostream& target);
-    ~Logger(void) = default;
-
-    void logError(const std::string& errMsg);
-    void logError(const std::string& errMsg, const qlow::CodePosition& cp);
-
-    inline std::ostream& operator()(LogLevel ll)
-    {
-        if (logLevel <= ll) {
-            return *this;
-        }
-        else {
-            return nullStream;
-        }
-    }
-    
-    inline std::ostream& none (void) { return (*this)(LogLevel::NONE); }
-    inline std::ostream& err  (void) { return (*this)(LogLevel::ERROR); }
-    inline std::ostream& warn (void) { return (*this)(LogLevel::WARNING); }
-    inline std::ostream& info (void) { return (*this)(LogLevel::INFO); }
-    inline std::ostream& debug(void) { return (*this)(LogLevel::DEBUG); }
-    inline std::ostream& trace(void) { return (*this)(LogLevel::TRACE); }
-
-    inline void setLogType(LogLevel l) { logType = l; }
-
-    inline static Logger& getInstance(void) { return instance; }
-
-protected:
-    int overflow(int c) override;
-    //virtual std::streamsize xsputn (const char* s, std::streamsize n);
-};
-
-
-std::ostream& operator << (std::ostream& o, qlow::LogLevel l);
-
-inline void shouldbe()
-{
-    qlow::Logger& logger = qlow::Logger::getInstance();
-    logger.err() << "something happened" << std::endl;
-}
-
-#endif // QLOW_LOGGING_H
-

+ 52 - 0
src/Printer.cpp

@@ -0,0 +1,52 @@
+#include "Printer.h"
+
+#include "Ast.h"
+#include <cstdio>
+
+using qlow::Printer;
+
+
+#ifdef _WIN32
+#include <io.h>
+Printer Printer::instance(std::cout, _isatty(_fileno(stdout)));
+#else
+#include <unistd.h>
+Printer Printer::instance(std::cout, isatty(fileno(stdout)));
+#endif
+
+
+void Printer::foreground(Color color, bool bright)
+{
+    using std::string;
+    string cchar = string(1, '0' + color);
+    string isbright = bright ? "9" : "3";
+    target << "\033[" << isbright << cchar << "m";
+}
+
+
+void Printer::background(Color color, bool bright)
+{
+    using std::string;
+    string cchar = string(1, '0' + color);
+    string isbright = bright ? "10" : "4";
+    target << "\033[" << isbright << cchar << "m"; 
+}
+
+
+void Printer::bold(void)
+{
+    target << "\033[1m";
+}
+
+
+void Printer::removeFormatting(void)
+{
+    target << "\033[0m";
+}
+
+
+int Printer::overflow(int c)
+{
+    target.put(char(c));
+    return 0;
+}

+ 50 - 0
src/Printer.h

@@ -0,0 +1,50 @@
+#ifndef QLOW_LOGGING_H
+#define QLOW_LOGGING_H
+
+#include <iostream>
+
+namespace qlow
+{
+    class Printer;
+}
+
+
+class qlow::Printer :
+    public std::ostream,
+    private std::streambuf
+{
+    std::ostream& target;
+    bool isTty;
+
+    static Printer instance;
+public:
+    inline Printer(std::ostream& target, bool isTty) :
+        target{ target }, isTty{ isTty } {}
+
+    enum Color {
+        BLACK = 0,
+        RED,
+        GREEN,
+        YELLOW,
+        BLUE,
+        MAGENTA,
+        CYAN,
+        WHITE
+    };
+
+    void foreground(Color color, bool bright);
+    void background(Color color, bool bright);
+    void bold(void);
+    void removeFormatting(void);
+
+    inline static Printer& getInstance(void) { return instance; }
+protected:
+    int overflow(int c) override;
+};
+
+
+
+
+
+#endif // QLOW_LOGGING_H
+

+ 3 - 3
src/ast/AstVisitor.cpp

@@ -244,11 +244,11 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::FeatureCall& a
             auto* thisExpr = scope.getVariable("this");
             if (!thisExpr)
                 throw "no this found";
-            Logger::getInstance().debug() << "feature call " << var->toString() << " is a field\n";
+            //Printer::getInstance().debug() << "feature call " << var->toString() << " is a field\n";
             return std::make_unique<sem::FieldAccessExpression>(std::make_unique<sem::LocalVariableExpression>(thisExpr), field);
         }
         else {
-            Logger::getInstance().debug() << "feature call " << var->toString() << " is not a field\n";
+            //Printer::getInstance().debug() << "feature call " << var->toString() << " is not a field\n";
             return std::make_unique<sem::LocalVariableExpression>(var);
         }
     }
@@ -393,7 +393,7 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::BinaryOperatio
         ast.opString, { rightEval->type }
     );
     
-    Logger::getInstance().debug() << "looked for operation method for operator " <<
+    Printer::getInstance().debug() << "looked for operation method for operator " <<
     ast.opString << std::endl;
     if (!operationMethod) {
         throw SemanticError(SemanticError::OPERATOR_NOT_FOUND,

+ 17 - 11
src/sem/CodeGeneration.cpp

@@ -37,7 +37,7 @@ std::unique_ptr<llvm::Module> generateModule(const sem::GlobalScope& semantic)
     using llvm::Value;
     using llvm::IRBuilder;
     
-    Logger& logger = Logger::getInstance();
+    Printer& printer = Printer::getInstance();
     
 #ifdef DEBUGGING
         printf("creating llvm module\n"); 
@@ -79,7 +79,7 @@ std::unique_ptr<llvm::Module> generateModule(const sem::GlobalScope& semantic)
     
     
     std::vector<llvm::Function*> functions;
-    auto verifyStream = llvm::raw_os_ostream(logger.debug());
+    auto verifyStream = llvm::raw_os_ostream(printer);
     
     // create all llvm functions
     for (const auto& [name, cl] : semantic.getClasses()) {
@@ -107,10 +107,12 @@ std::unique_ptr<llvm::Module> generateModule(const sem::GlobalScope& semantic)
             
             FunctionGenerator fg(*method, module.get(), as);
             Function* f = fg.generate();
-            logger.debug() << "verifying function: " << method->name << std::endl;
+//            printer << "verifying function: " << method->name << std::endl;
             bool corrupt = llvm::verifyFunction(*f, &verifyStream);
             if (corrupt) {
+#ifdef DEBUGGING
                 module->print(verifyStream, nullptr);
+#endif
                 throw "corrupt llvm function";
             }
 #ifdef DEBUGGING
@@ -124,7 +126,7 @@ std::unique_ptr<llvm::Module> generateModule(const sem::GlobalScope& semantic)
         
         FunctionGenerator fg(*method, module.get(), as);
         Function* f = fg.generate();
-        logger.debug() << "verifying function: " << method->name << std::endl;
+        //printer.debug() << "verifying function: " << method->name << std::endl;
         bool corrupt = llvm::verifyFunction(*f, &verifyStream);
         if (corrupt) {
             module->print(verifyStream, nullptr);
@@ -179,7 +181,9 @@ llvm::Function* generateFunction(llvm::Module* module, sem::Method* method)
     auto argIterator = func->arg_begin();
     if (method->thisExpression != nullptr) {
         method->thisExpression->allocaInst = &*argIterator;
-        Logger::getInstance().debug() << "allocaInst of this";
+#ifdef DEBUGGING
+        Printer::getInstance() << "allocaInst of this";
+#endif
         argIterator++;
     }
     
@@ -209,9 +213,11 @@ void generateObjectFile(const std::string& filename, std::unique_ptr<llvm::Modul
     using llvm::TargetRegistry;
     using llvm::TargetOptions;
 
-    Logger& logger = Logger::getInstance();
-    logger.debug() << "verifying mod" << std::endl;
-    auto ostr = llvm::raw_os_ostream(logger.debug());
+    Printer& printer = Printer::getInstance();
+#ifdef DEBUGGING
+    printer << "verifying mod" << std::endl;
+#endif
+    auto ostr = llvm::raw_os_ostream(printer);
 #ifdef DEBUGGING
     module->print(ostr, nullptr);
 #endif
@@ -220,8 +226,6 @@ void generateObjectFile(const std::string& filename, std::unique_ptr<llvm::Modul
     if (broken)
         throw "invalid llvm module";
     
-    logger.debug() << "mod verified" << std::endl;
-
     llvm::InitializeAllTargetInfos();
     llvm::InitializeAllTargets();
     llvm::InitializeAllTargetMCs();
@@ -251,7 +255,9 @@ void generateObjectFile(const std::string& filename, std::unique_ptr<llvm::Modul
     const Target* target = TargetRegistry::lookupTarget(targetTriple, error);
 
     if (!target) {
-        logger.debug() << "could not create target: " << error << std::endl;
+#ifdef DEBUGGING
+        printer << "could not create target: " << error << std::endl;
+#endif
         throw "internal error";
     }
 

+ 1 - 1
src/sem/Semantic.cpp

@@ -20,7 +20,7 @@ std::pair<std::unique_ptr<Context>, std::unique_ptr<GlobalScope>>
     createFromAst(const qlow::ast::Ast& ast)
 {
     std::unique_ptr<Context> context = std::make_unique<Context>();
-    Logger& logger = Logger::getInstance();
+    Printer& printer = Printer::getInstance();
     auto& objects = ast.getObjects();
 
 #ifdef DEBUGGING