summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h1
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp22
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h7
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp22
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h6
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp22
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h9
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp19
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h12
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h8
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp29
-rw-r--r--examples/Kaleidoscope/Chapter2/toy.cpp6
-rw-r--r--examples/Kaleidoscope/Chapter3/toy.cpp13
-rw-r--r--examples/Kaleidoscope/Chapter4/toy.cpp13
-rw-r--r--examples/Kaleidoscope/Chapter5/toy.cpp15
-rw-r--r--examples/Kaleidoscope/Chapter6/toy.cpp16
-rw-r--r--examples/Kaleidoscope/Chapter7/toy.cpp19
-rw-r--r--examples/Kaleidoscope/Chapter8/toy.cpp33
18 files changed, 216 insertions, 56 deletions
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
index 1a410aafbc45..22716b2b5215 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
@@ -93,7 +93,6 @@ public:
void removeModule(ModuleHandle H) {
CompileLayer.removeModuleSet(H);
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
index 22b0819cd71a..50912109e811 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
@@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +186,7 @@ public:
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;
};
@@ -194,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +282,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
index cf480aacef80..91d903029a00 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
@@ -25,10 +25,13 @@
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
-#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
#include <memory>
#include <string>
@@ -105,7 +108,6 @@ public:
}
private:
-
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
// Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
@@ -124,7 +126,6 @@ private:
return M;
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
index 22b0819cd71a..50912109e811 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
@@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +186,7 @@ public:
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;
};
@@ -194,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +282,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index 62c61aac6e69..5ecc869f80f5 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
@@ -26,12 +26,16 @@
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
#include <memory>
+#include <set>
#include <string>
#include <vector>
@@ -116,7 +120,6 @@ public:
}
private:
-
std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) {
// Create a function pass manager.
auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get());
@@ -135,7 +138,6 @@ private:
return M;
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
index 22b0819cd71a..50912109e811 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
@@ -7,15 +7,13 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +133,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +186,7 @@ public:
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;
};
@@ -194,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +282,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index 6d94c8f9bcdb..527d4be09f0f 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
@@ -26,11 +26,17 @@
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
+#include <cassert>
+#include <cstdlib>
#include <memory>
#include <string>
#include <vector>
@@ -47,6 +53,7 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
const PrototypeAST& getProto() const;
const std::string& getName() const;
llvm::Function *codegen();
@@ -197,7 +204,6 @@ public:
}
private:
-
std::string mangle(const std::string &Name) {
std::string MangledName;
raw_string_ostream MangledNameStream(MangledName);
@@ -223,7 +229,6 @@ private:
return M;
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
index ddce0dc35b25..07981a8f79b7 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
@@ -7,16 +7,15 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -140,7 +139,8 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -150,6 +150,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -159,8 +160,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -171,6 +173,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -183,6 +186,7 @@ public:
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;
};
@@ -195,6 +199,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -206,6 +211,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -220,6 +226,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -233,6 +240,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -250,6 +258,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
index f11f0369c42c..d1ef3c9549ff 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
@@ -15,11 +15,12 @@
#define LLVM_EXECUTIONENGINE_ORC_KALEIDOSCOPEJIT_H
#include "RemoteJITUtils.h"
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/Triple.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/JITSymbol.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
-#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
@@ -28,11 +29,17 @@
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h"
#include "llvm/IR/DataLayout.h"
+#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Mangler.h"
#include "llvm/Support/DynamicLibrary.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Target/TargetMachine.h"
+#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/GVN.h"
#include <algorithm>
+#include <cassert>
+#include <cstdlib>
#include <memory>
#include <string>
#include <vector>
@@ -49,6 +56,7 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
const PrototypeAST& getProto() const;
const std::string& getName() const;
llvm::Function *codegen();
@@ -229,7 +237,6 @@ public:
}
private:
-
std::string mangle(const std::string &Name) {
std::string MangledName;
raw_string_ostream MangledNameStream(MangledName);
@@ -255,7 +262,6 @@ private:
return M;
}
-
};
} // end namespace orc
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h b/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
index 718b99e4b24c..48a19385596f 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/RemoteJITUtils.h
@@ -15,8 +15,10 @@
#define LLVM_TOOLS_LLI_REMOTEJITUTILS_H
#include "llvm/ExecutionEngine/Orc/RawByteChannel.h"
-#include "llvm/ExecutionEngine/RTDyldMemoryManager.h"
-#include <mutex>
+#include "llvm/Support/Error.h"
+#include <cassert>
+#include <cerrno>
+#include <system_error>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
@@ -71,4 +73,4 @@ private:
int InFD, OutFD;
};
-#endif
+#endif // LLVM_TOOLS_LLI_REMOTEJITUTILS_H
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
index f5a06cf2bf49..aa08df9ceb53 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
@@ -7,29 +7,30 @@
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
-#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
+#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
-#include "llvm/Transforms/Scalar.h"
-#include "llvm/Transforms/Scalar/GVN.h"
#include "KaleidoscopeJIT.h"
+#include "RemoteJITUtils.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
+#include <cstring>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
-
#include <netdb.h>
-#include <unistd.h>
#include <netinet/in.h>
#include <sys/socket.h>
@@ -155,7 +156,8 @@ static int gettok() {
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -165,6 +167,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -174,8 +177,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -186,6 +190,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -198,6 +203,7 @@ public:
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;
};
@@ -210,6 +216,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -221,6 +228,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -235,6 +243,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -248,6 +257,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -265,6 +275,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -1229,9 +1240,9 @@ std::unique_ptr<FDRPCChannel> connect() {
}
sockaddr_in servAddr;
- bzero(&servAddr, sizeof(servAddr));
+ memset(&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = PF_INET;
- bcopy(server->h_addr, &servAddr.sin_addr.s_addr, server->h_length);
+ memcpy(&servAddr.sin_addr.s_addr, server->h_addr, server->h_length);
servAddr.sin_port = htons(Port);
if (connect(sockfd, reinterpret_cast<sockaddr*>(&servAddr),
sizeof(servAddr)) < 0) {
diff --git a/examples/Kaleidoscope/Chapter2/toy.cpp b/examples/Kaleidoscope/Chapter2/toy.cpp
index bab34adefdec..8357c5b63fb7 100644
--- a/examples/Kaleidoscope/Chapter2/toy.cpp
+++ b/examples/Kaleidoscope/Chapter2/toy.cpp
@@ -1,4 +1,5 @@
#include "llvm/ADT/STLExtras.h"
+#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
@@ -82,11 +83,13 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
};
/// NumberExprAST - Expression class for numeric literals like "1.0".
@@ -149,6 +152,7 @@ public:
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter3/toy.cpp b/examples/Kaleidoscope/Chapter3/toy.cpp
index cdf0d6c8cdb2..fdefb50cc209 100644
--- a/examples/Kaleidoscope/Chapter3/toy.cpp
+++ b/examples/Kaleidoscope/Chapter3/toy.cpp
@@ -9,6 +9,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
+#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
@@ -94,11 +95,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -108,6 +112,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -117,6 +122,7 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
+
Value *codegen() override;
};
@@ -129,6 +135,7 @@ public:
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;
};
@@ -141,6 +148,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -154,6 +162,7 @@ class PrototypeAST {
public:
PrototypeAST(const std::string &Name, std::vector<std::string> Args)
: Name(Name), Args(std::move(Args)) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
};
@@ -167,8 +176,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter4/toy.cpp b/examples/Kaleidoscope/Chapter4/toy.cpp
index 836a2053cbe9..39b9563bc287 100644
--- a/examples/Kaleidoscope/Chapter4/toy.cpp
+++ b/examples/Kaleidoscope/Chapter4/toy.cpp
@@ -15,6 +15,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "../include/KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -103,11 +104,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -117,6 +121,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -126,6 +131,7 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
+
Value *codegen() override;
};
@@ -138,6 +144,7 @@ public:
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;
};
@@ -150,6 +157,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -163,6 +171,7 @@ class PrototypeAST {
public:
PrototypeAST(const std::string &Name, std::vector<std::string> Args)
: Name(Name), Args(std::move(Args)) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
};
@@ -176,8 +185,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter5/toy.cpp b/examples/Kaleidoscope/Chapter5/toy.cpp
index a080bd00cb58..568ec8de5c30 100644
--- a/examples/Kaleidoscope/Chapter5/toy.cpp
+++ b/examples/Kaleidoscope/Chapter5/toy.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "../include/KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -121,11 +122,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -135,6 +139,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -144,6 +149,7 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
+
Value *codegen() override;
};
@@ -156,6 +162,7 @@ public:
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;
};
@@ -168,6 +175,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -179,6 +187,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -193,6 +202,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -206,6 +216,7 @@ class PrototypeAST {
public:
PrototypeAST(const std::string &Name, std::vector<std::string> Args)
: Name(Name), Args(std::move(Args)) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
};
@@ -219,8 +230,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter6/toy.cpp b/examples/Kaleidoscope/Chapter6/toy.cpp
index 85d953b0c756..0fa128d2e557 100644
--- a/examples/Kaleidoscope/Chapter6/toy.cpp
+++ b/examples/Kaleidoscope/Chapter6/toy.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "../include/KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -129,11 +130,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -143,6 +147,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -152,6 +157,7 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
+
Value *codegen() override;
};
@@ -163,6 +169,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -175,6 +182,7 @@ public:
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;
};
@@ -187,6 +195,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -198,6 +207,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -212,6 +222,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -229,6 +240,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -252,8 +264,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter7/toy.cpp b/examples/Kaleidoscope/Chapter7/toy.cpp
index 3206ca8c5d7b..58b7ce1ceda2 100644
--- a/examples/Kaleidoscope/Chapter7/toy.cpp
+++ b/examples/Kaleidoscope/Chapter7/toy.cpp
@@ -16,6 +16,7 @@
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "../include/KaleidoscopeJIT.h"
+#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
@@ -135,11 +136,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -149,6 +153,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -158,8 +163,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -170,6 +176,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -182,6 +189,7 @@ public:
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;
};
@@ -194,6 +202,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -205,6 +214,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -219,6 +229,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -232,6 +243,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -249,6 +261,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -272,8 +285,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//
diff --git a/examples/Kaleidoscope/Chapter8/toy.cpp b/examples/Kaleidoscope/Chapter8/toy.cpp
index f880bb8ea0f0..f7bb814da775 100644
--- a/examples/Kaleidoscope/Chapter8/toy.cpp
+++ b/examples/Kaleidoscope/Chapter8/toy.cpp
@@ -1,26 +1,33 @@
#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
-#include "llvm/Analysis/Passes.h"
+#include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
-#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Host.h"
+#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetOptions.h"
-#include "llvm/Transforms/Scalar.h"
+#include <algorithm>
+#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
+#include <system_error>
#include <utility>
#include <vector>
@@ -132,11 +139,14 @@ static int gettok() {
//===----------------------------------------------------------------------===//
// Abstract Syntax Tree (aka Parse Tree)
//===----------------------------------------------------------------------===//
+
namespace {
+
/// ExprAST - Base class for all expression nodes.
class ExprAST {
public:
- virtual ~ExprAST() {}
+ virtual ~ExprAST() = default;
+
virtual Value *codegen() = 0;
};
@@ -146,6 +156,7 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
+
Value *codegen() override;
};
@@ -155,8 +166,9 @@ class VariableExprAST : public ExprAST {
public:
VariableExprAST(const std::string &Name) : Name(Name) {}
- const std::string &getName() const { return Name; }
+
Value *codegen() override;
+ const std::string &getName() const { return Name; }
};
/// UnaryExprAST - Expression class for a unary operator.
@@ -167,6 +179,7 @@ class UnaryExprAST : public ExprAST {
public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
+
Value *codegen() override;
};
@@ -179,6 +192,7 @@ public:
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;
};
@@ -191,6 +205,7 @@ public:
CallExprAST(const std::string &Callee,
std::vector<std::unique_ptr<ExprAST>> Args)
: Callee(Callee), Args(std::move(Args)) {}
+
Value *codegen() override;
};
@@ -202,6 +217,7 @@ public:
IfExprAST(std::unique_ptr<ExprAST> Cond, std::unique_ptr<ExprAST> Then,
std::unique_ptr<ExprAST> Else)
: Cond(std::move(Cond)), Then(std::move(Then)), Else(std::move(Else)) {}
+
Value *codegen() override;
};
@@ -216,6 +232,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -229,6 +246,7 @@ public:
std::vector<std::pair<std::string, std::unique_ptr<ExprAST>>> VarNames,
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
+
Value *codegen() override;
};
@@ -246,6 +264,7 @@ public:
bool IsOperator = false, unsigned Prec = 0)
: Name(Name), Args(std::move(Args)), IsOperator(IsOperator),
Precedence(Prec) {}
+
Function *codegen();
const std::string &getName() const { return Name; }
@@ -269,8 +288,10 @@ public:
FunctionAST(std::unique_ptr<PrototypeAST> Proto,
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
+
Function *codegen();
};
+
} // end anonymous namespace
//===----------------------------------------------------------------------===//