Browse Source

fixing llvm compat errors

Nicolas Winkler 4 years ago
parent
commit
5f3b47ca22
6 changed files with 13 additions and 3 deletions
  1. 1 1
      src/Driver.cpp
  2. 1 0
      src/ErrorReporting.cpp
  3. 2 0
      src/ErrorReporting.h
  4. 1 1
      src/ast/AstVisitor.cpp
  5. 4 1
      src/sem/CodeGeneration.cpp
  6. 4 0
      src/util/Path.cpp

+ 1 - 1
src/Driver.cpp

@@ -125,7 +125,7 @@ int Driver::run(void) try
     }*/
     }*/
     
     
     auto* mainMethod = semClasses->getMethod("main");
     auto* mainMethod = semClasses->getMethod("main");
-    if (mainMethod == nullptr && false) {
+    if (mainMethod == nullptr) {
         // TODO handle main ckeck well
         // TODO handle main ckeck well
         qlow::printError(printer, "no main method found");
         qlow::printError(printer, "no main method found");
         return 1;
         return 1;

+ 1 - 0
src/ErrorReporting.cpp

@@ -219,6 +219,7 @@ std::string SemanticError::getMessage(void) const noexcept
         {OPERATOR_NOT_FOUND, ""},
         {OPERATOR_NOT_FOUND, ""},
         {WRONG_NUMBER_OF_ARGUMENTS, "wrong number of arguments passed"},
         {WRONG_NUMBER_OF_ARGUMENTS, "wrong number of arguments passed"},
         {INVALID_RETURN_TYPE, "invalid return type"},
         {INVALID_RETURN_TYPE, "invalid return type"},
+        {NO_MAIN_METHOD, "no main method specified"},
     };
     };
     if (errors.find(errorCode) != errors.end())
     if (errors.find(errorCode) != errors.end())
         return errors.at(errorCode);
         return errors.at(errorCode);

+ 2 - 0
src/ErrorReporting.h

@@ -134,6 +134,8 @@ public:
         TYPE_MISMATCH,
         TYPE_MISMATCH,
         INVALID_RETURN_TYPE,
         INVALID_RETURN_TYPE,
         NEW_FOR_NON_CLASS,
         NEW_FOR_NON_CLASS,
+
+        NO_MAIN_METHOD,
     };
     };
     
     
     
     

+ 1 - 1
src/ast/AstVisitor.cpp

@@ -300,7 +300,7 @@ std::unique_ptr<sem::SemanticObject> StructureVisitor::visit(ast::AssignmentStat
         throw SemanticError(
         throw SemanticError(
             SemanticError::TYPE_MISMATCH,
             SemanticError::TYPE_MISMATCH,
             "Can't assign expression of type '" + as->value->type->asString() +
             "Can't assign expression of type '" + as->value->type->asString() +
-            "' to value of type '" + as->target->type->asString() + "'.",
+            "' to variable of type '" + as->target->type->asString() + "'.",
             ast.pos
             ast.pos
         );
         );
     }
     }

+ 4 - 1
src/sem/CodeGeneration.cpp

@@ -121,7 +121,10 @@ std::unique_ptr<llvm::Module> generateModule(sem::GlobalScope& semantic)
         printf("verified function: %s\n", method->name.c_str());
         printf("verified function: %s\n", method->name.c_str());
 #endif
 #endif
     }
     }
-    generateStartFunction(module.get(), semantic.getMethod("main")->llvmNode);
+    auto mainMethod = semantic.getMethod("main");
+    if (mainMethod != nullptr) {
+        generateStartFunction(module.get(), mainMethod->llvmNode);
+    }
     return module;
     return module;
 }
 }
 
 

+ 4 - 0
src/util/Path.cpp

@@ -31,6 +31,10 @@ Path Path::parentPath(void) const
         return parent;
         return parent;
     }
     }
 
 
+    if (parent.path.find(defaultDirSeparator) == std::string::npos) {
+        return "";
+    }
+
     while (!parent.endsWithSeparator()) {
     while (!parent.endsWithSeparator()) {
         parent.path.pop_back();
         parent.path.pop_back();
     }
     }