|
@@ -7,7 +7,8 @@
|
|
|
|
|
|
namespace ast{
|
|
|
// attributes added from chapter 3 of the tutorial
|
|
|
-std::unique_ptr<Module> AstObjects::TheModule = std::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;
|
|
|
|
|
@@ -44,8 +45,8 @@ Value *BinaryExprAST::codegen() {
|
|
|
case '<':
|
|
|
L = AstObjects::Builder.CreateFCmpULT(L, R, "cmptmp");
|
|
|
// Convert bool 0/1 to double 0.0 or 1.0
|
|
|
- return AstObjects::Builder.CreateUIToFP(L, Type::getDoubleTy(getGlobalContext()),
|
|
|
- "booltmp");
|
|
|
+ return AstObjects::Builder.CreateUIToFP(L,
|
|
|
+ Type::getDoubleTy(getGlobalContext()), "booltmp");
|
|
|
default:
|
|
|
return ErrorV("invalid binary operator");
|
|
|
}
|
|
@@ -72,10 +73,13 @@ 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;
|
|
@@ -90,7 +94,8 @@ const std::string &PrototypeAST::getName() const { return Name; }
|
|
|
Function *FunctionAST::codegen() {
|
|
|
|
|
|
// First, check for an existing function from a previous 'extern' declaration.
|
|
|
- Function *TheFunction = AstObjects::TheModule->getFunction(Proto->getName());
|
|
|
+ Function *TheFunction =
|
|
|
+ AstObjects::TheModule->getFunction(Proto->getName());
|
|
|
|
|
|
if (!TheFunction)
|
|
|
TheFunction = Proto->codegen();
|
|
@@ -102,7 +107,8 @@ Function *FunctionAST::codegen() {
|
|
|
return (Function*)ErrorV("Function cannot be redefined.");
|
|
|
|
|
|
// Create a new basic block to start insertion into.
|
|
|
- BasicBlock *BB = BasicBlock::Create(getGlobalContext(), "entry", TheFunction);
|
|
|
+ BasicBlock *BB = BasicBlock::Create(getGlobalContext(),
|
|
|
+ "entry", TheFunction);
|
|
|
AstObjects::Builder.SetInsertPoint(BB);
|
|
|
|
|
|
// Record the function arguments in the NamedValues map.
|