|
@@ -1,21 +1,14 @@
|
|
|
#include "Ast.h"
|
|
|
+#include "Parser.h"
|
|
|
|
|
|
-using namespace ast;
|
|
|
-
|
|
|
+namespace ast{
|
|
|
// attributes added from chapter 3 of the tutorial
|
|
|
-std::unique_ptr<Module> AstObjects::TheModule = make_unique<Module>("my cool jit", getGlobalContext());;
|
|
|
+std::unique_ptr<Module> AstObjects::TheModule = std::make_unique<Module>("my cool jit", getGlobalContext());
|
|
|
IRBuilder<> AstObjects::Builder(getGlobalContext());
|
|
|
-std::map<std::string, Value *> AstObjects::NamedValues;
|
|
|
-
|
|
|
-// error method from chapter 3
|
|
|
-// HACK: duplicated function already present in example
|
|
|
-std::unique_ptr<ExprAST> Error_Ast(const char *Str) {
|
|
|
- fprintf(stderr, "Error: %s\n", Str);
|
|
|
- return nullptr;
|
|
|
-}
|
|
|
+std::map<std::string, Value *> AstObjects::NamedValues{};
|
|
|
|
|
|
Value *ErrorV(const char *Str) {
|
|
|
- Error_Ast(Str);
|
|
|
+ parser::Error(Str);
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
@@ -75,13 +68,10 @@ Value *CallExprAST::codegen() {
|
|
|
|
|
|
Function *PrototypeAST::codegen() {
|
|
|
// Make the function type: double(double,double) etc.
|
|
|
- std::vector<Type *> Doubles(Args.size(),
|
|
|
- Type::getDoubleTy(getGlobalContext()));
|
|
|
- FunctionType *FT =
|
|
|
- FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
|
|
+ std::vector<Type *> Doubles(Args.size(), Type::getDoubleTy(getGlobalContext()));
|
|
|
+ FunctionType *FT = FunctionType::get(Type::getDoubleTy(getGlobalContext()), Doubles, false);
|
|
|
|
|
|
- Function *F =
|
|
|
- Function::Create(FT, Function::ExternalLinkage, Name, AstObjects::TheModule.get());
|
|
|
+ Function *F = Function::Create(FT, Function::ExternalLinkage, Name, AstObjects::TheModule.get());
|
|
|
|
|
|
// Set names for all arguments.
|
|
|
unsigned Idx = 0;
|
|
@@ -91,7 +81,10 @@ Function *PrototypeAST::codegen() {
|
|
|
return F;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
Function *FunctionAST::codegen() {
|
|
|
+
|
|
|
// First, check for an existing function from a previous 'extern' declaration.
|
|
|
Function *TheFunction = AstObjects::TheModule->getFunction(Proto->getName());
|
|
|
|
|
@@ -127,3 +120,5 @@ Function *FunctionAST::codegen() {
|
|
|
TheFunction->eraseFromParent();
|
|
|
return nullptr;
|
|
|
}
|
|
|
+
|
|
|
+}
|