Browse Source

80 char limi

Andrea Gussoni 8 years ago
parent
commit
32416e5010
3 changed files with 25 additions and 13 deletions
  1. 14 8
      source/Ast.cpp
  2. 9 4
      source/Ast.h
  3. 2 1
      source/Parser.cpp

+ 14 - 8
source/Ast.cpp

@@ -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.

+ 9 - 4
source/Ast.h

@@ -53,7 +53,8 @@ class BinaryExprAST : public ExprAST {
   std::unique_ptr<ExprAST> LHS, RHS;
 
 public:
-  BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS, std::unique_ptr<ExprAST> RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
+  BinaryExprAST(char Op, std::unique_ptr<ExprAST> LHS,
+      std::unique_ptr<ExprAST> RHS) : Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
   Value *codegen() override;
 };
 
@@ -64,7 +65,8 @@ class CallExprAST : public ExprAST {
   std::vector<std::unique_ptr<ExprAST>> Args;
 
 public:
-  CallExprAST(const std::string &Callee, std::vector<std::unique_ptr<ExprAST>> Args) : Callee(Callee), Args(std::move(Args)) {}
+  CallExprAST(const std::string &Callee,
+      std::vector<std::unique_ptr<ExprAST>> Args) : Callee(Callee), Args(std::move(Args)) {}
     Value *codegen() override;
   };
 
@@ -76,7 +78,8 @@ class PrototypeAST {
   std::vector<std::string> Args;
 
 public:
-  PrototypeAST(const std::string &Name, std::vector<std::string> Args) : Name(Name), Args(std::move(Args)) {}
+  PrototypeAST(const std::string &Name,
+      std::vector<std::string> Args) : Name(Name), Args(std::move(Args)) {}
   Function *codegen();
   const std::string &getName() const;
 };
@@ -87,7 +90,9 @@ class FunctionAST {
   std::unique_ptr<ExprAST> Body;
 
 public:
-  FunctionAST(std::unique_ptr<PrototypeAST> Proto, std::unique_ptr<ExprAST> Body) : Proto(std::move(Proto)), Body(std::move(Body)) {}
+  FunctionAST(std::unique_ptr<PrototypeAST> Proto,
+      std::unique_ptr<ExprAST> Body)
+      : Proto(std::move(Proto)), Body(std::move(Body)) {}
   Function *codegen();
 };
 

+ 2 - 1
source/Parser.cpp

@@ -206,7 +206,8 @@ static std::unique_ptr<FunctionAST> ParseDefinition() {
 static std::unique_ptr<FunctionAST> ParseTopLevelExpr() {
   if (auto E = ParseExpression()) {
     // Make an anonymous proto.
-    auto Proto = llvm::make_unique<PrototypeAST>("__anon_expr", std::vector<std::string>());
+    auto Proto = llvm::make_unique<PrototypeAST>("__anon_expr",
+        std::vector<std::string>());
     return llvm::make_unique<FunctionAST>(std::move(Proto), std::move(E));
   }
   return nullptr;