1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

Fix some Clang-tidy modernize-use-bool-literals and Include What You Use warnings in examples; other minor fixes.

Differential revision: http://reviews.llvm.org/D20397

llvm-svn: 270008
This commit is contained in:
Eugene Zelenko 2016-05-19 01:08:04 +00:00
parent 8833a2ff67
commit 7ecab2b09a
11 changed files with 249 additions and 100 deletions

View File

@ -1,5 +1,6 @@
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
@ -15,7 +16,7 @@ static
make_unique(Args &&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
}
} // end namespace helper
//===----------------------------------------------------------------------===//
// Lexer
@ -234,7 +235,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
if (auto Arg = ParseExpression())
Args.push_back(std::move(Arg));
else
@ -277,7 +278,7 @@ static std::unique_ptr<ExprAST> ParsePrimary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -407,7 +408,7 @@ static void HandleTopLevelExpression() {
/// top ::= definition | external | expression | ';'
static void MainLoop() {
while (1) {
while (true) {
fprintf(stderr, "ready> ");
switch (CurTok) {
case tok_eof:

View File

@ -1,11 +1,19 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <vector>
@ -237,7 +245,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
if (auto Arg = ParseExpression())
Args.push_back(std::move(Arg));
else
@ -280,7 +288,7 @@ static std::unique_ptr<ExprAST> ParsePrimary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -538,7 +546,7 @@ static void HandleTopLevelExpression() {
/// top ::= definition | external | expression | ';'
static void MainLoop() {
while (1) {
while (true) {
fprintf(stderr, "ready> ");
switch (CurTok) {
case tok_eof:

View File

@ -1,19 +1,29 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.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/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 "../include/KaleidoscopeJIT.h"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "../include/KaleidoscopeJIT.h"
using namespace llvm;
using namespace llvm::orc;
@ -244,7 +254,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
if (auto Arg = ParseExpression())
Args.push_back(std::move(Arg));
else
@ -287,7 +297,7 @@ static std::unique_ptr<ExprAST> ParsePrimary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -577,7 +587,6 @@ static void HandleTopLevelExpression() {
// Evaluate a top-level expression into an anonymous function.
if (auto FnAST = ParseTopLevelExpr()) {
if (FnAST->codegen()) {
// JIT the module containing the anonymous expression, keeping a handle so
// we can free it later.
auto H = TheJIT->addModule(std::move(TheModule));
@ -603,7 +612,7 @@ static void HandleTopLevelExpression() {
/// top ::= definition | external | expression | ';'
static void MainLoop() {
while (1) {
while (true) {
fprintf(stderr, "ready> ");
switch (CurTok) {
case tok_eof:

View File

@ -1,19 +1,30 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.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/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 "../include/KaleidoscopeJIT.h"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "../include/KaleidoscopeJIT.h"
using namespace llvm;
using namespace llvm::orc;
@ -286,7 +297,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
if (auto Arg = ParseExpression())
Args.push_back(std::move(Arg));
else
@ -411,7 +422,7 @@ static std::unique_ptr<ExprAST> ParsePrimary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -680,7 +691,7 @@ Value *ForExprAST::codegen() {
// Start the PHI node with an entry for Start.
PHINode *Variable =
Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName.c_str());
Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName);
Variable->addIncoming(StartVal, PreheaderBB);
// Within the loop, the variable is defined equal to the PHI node. If it
@ -848,7 +859,6 @@ static void HandleTopLevelExpression() {
// Evaluate a top-level expression into an anonymous function.
if (auto FnAST = ParseTopLevelExpr()) {
if (FnAST->codegen()) {
// JIT the module containing the anonymous expression, keeping a handle so
// we can free it later.
auto H = TheJIT->addModule(std::move(TheModule));
@ -874,7 +884,7 @@ static void HandleTopLevelExpression() {
/// top ::= definition | external | expression | ';'
static void MainLoop() {
while (1) {
while (true) {
fprintf(stderr, "ready> ");
switch (CurTok) {
case tok_eof:

View File

@ -1,19 +1,30 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.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/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 "../include/KaleidoscopeJIT.h"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "../include/KaleidoscopeJIT.h"
using namespace llvm;
using namespace llvm::orc;
@ -319,7 +330,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
if (auto Arg = ParseExpression())
Args.push_back(std::move(Arg));
else
@ -460,7 +471,7 @@ static std::unique_ptr<ExprAST> ParseUnary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -791,7 +802,7 @@ Value *ForExprAST::codegen() {
// Start the PHI node with an entry for Start.
PHINode *Variable =
Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName.c_str());
Builder.CreatePHI(Type::getDoubleTy(TheContext), 2, VarName);
Variable->addIncoming(StartVal, PreheaderBB);
// Within the loop, the variable is defined equal to the PHI node. If it
@ -966,7 +977,6 @@ static void HandleTopLevelExpression() {
// Evaluate a top-level expression into an anonymous function.
if (auto FnAST = ParseTopLevelExpr()) {
if (FnAST->codegen()) {
// JIT the module containing the anonymous expression, keeping a handle so
// we can free it later.
auto H = TheJIT->addModule(std::move(TheModule));
@ -992,7 +1002,7 @@ static void HandleTopLevelExpression() {
/// top ::= definition | external | expression | ';'
static void MainLoop() {
while (1) {
while (true) {
fprintf(stderr, "ready> ");
switch (CurTok) {
case tok_eof:

View File

@ -1,19 +1,31 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.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/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 <cctype>
#include <cstdio>
#include <map>
#include <string>
#include <vector>
#include "../include/KaleidoscopeJIT.h"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
using namespace llvm::orc;
@ -338,7 +350,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
if (auto Arg = ParseExpression())
Args.push_back(std::move(Arg));
else
@ -446,7 +458,7 @@ static std::unique_ptr<ExprAST> ParseVarExpr() {
if (CurTok != tok_identifier)
return LogError("expected identifier after var");
while (1) {
while (true) {
std::string Name = IdentifierStr;
getNextToken(); // eat identifier.
@ -530,7 +542,7 @@ static std::unique_ptr<ExprAST> ParseUnary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -706,8 +718,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr,
VarName.c_str());
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName);
}
Value *NumberExprAST::codegen() {
@ -1132,7 +1143,6 @@ static void HandleTopLevelExpression() {
// Evaluate a top-level expression into an anonymous function.
if (auto FnAST = ParseTopLevelExpr()) {
if (FnAST->codegen()) {
// JIT the module containing the anonymous expression, keeping a handle so
// we can free it later.
auto H = TheJIT->addModule(std::move(TheModule));
@ -1158,7 +1168,7 @@ static void HandleTopLevelExpression() {
/// top ::= definition | external | expression | ';'
static void MainLoop() {
while (1) {
while (true) {
fprintf(stderr, "ready> ");
switch (CurTok) {
case tok_eof:

View File

@ -1,20 +1,36 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Analysis/BasicAliasAnalysis.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DebugInfoMetadata.h"
#include "llvm/IR/DebugLoc.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DIBuilder.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/Host.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Target/TargetMachine.h"
#include "../include/KaleidoscopeJIT.h"
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "../include/KaleidoscopeJIT.h"
using namespace llvm;
using namespace llvm::orc;
@ -84,9 +100,9 @@ std::string getTokName(int Tok) {
}
namespace {
class PrototypeAST;
class ExprAST;
}
} // end anonymous namespace
static LLVMContext TheContext;
static IRBuilder<> Builder(TheContext);
struct DebugInfo {
@ -207,6 +223,7 @@ public:
virtual Value *codegen() = 0;
int getLine() const { return Loc.Line; }
int getCol() const { return Loc.Col; }
virtual raw_ostream &dump(raw_ostream &out, int ind) {
return out << ':' << getLine() << ':' << getCol() << '\n';
}
@ -218,10 +235,11 @@ class NumberExprAST : public ExprAST {
public:
NumberExprAST(double Val) : Val(Val) {}
Value *codegen() override;
raw_ostream &dump(raw_ostream &out, int ind) override {
return ExprAST::dump(out << Val, ind);
}
Value *codegen() override;
};
/// VariableExprAST - Expression class for referencing a variable, like "a".
@ -233,6 +251,7 @@ public:
: ExprAST(Loc), Name(Name) {}
const std::string &getName() const { return Name; }
Value *codegen() override;
raw_ostream &dump(raw_ostream &out, int ind) override {
return ExprAST::dump(out << Name, ind);
}
@ -247,6 +266,7 @@ public:
UnaryExprAST(char Opcode, std::unique_ptr<ExprAST> Operand)
: Opcode(Opcode), Operand(std::move(Operand)) {}
Value *codegen() override;
raw_ostream &dump(raw_ostream &out, int ind) override {
ExprAST::dump(out << "unary" << Opcode, ind);
Operand->dump(out, ind + 1);
@ -264,6 +284,7 @@ public:
std::unique_ptr<ExprAST> RHS)
: ExprAST(Loc), Op(Op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
Value *codegen() override;
raw_ostream &dump(raw_ostream &out, int ind) override {
ExprAST::dump(out << "binary" << Op, ind);
LHS->dump(indent(out, ind) << "LHS:", ind + 1);
@ -282,6 +303,7 @@ public:
std::vector<std::unique_ptr<ExprAST>> Args)
: ExprAST(Loc), Callee(Callee), Args(std::move(Args)) {}
Value *codegen() override;
raw_ostream &dump(raw_ostream &out, int ind) override {
ExprAST::dump(out << "call " << Callee, ind);
for (const auto &Arg : Args)
@ -300,6 +322,7 @@ public:
: ExprAST(Loc), Cond(std::move(Cond)), Then(std::move(Then)),
Else(std::move(Else)) {}
Value *codegen() override;
raw_ostream &dump(raw_ostream &out, int ind) override {
ExprAST::dump(out << "if", ind);
Cond->dump(indent(out, ind) << "Cond:", ind + 1);
@ -321,6 +344,7 @@ public:
: VarName(VarName), Start(std::move(Start)), End(std::move(End)),
Step(std::move(Step)), Body(std::move(Body)) {}
Value *codegen() override;
raw_ostream &dump(raw_ostream &out, int ind) override {
ExprAST::dump(out << "for", ind);
Start->dump(indent(out, ind) << "Cond:", ind + 1);
@ -342,6 +366,7 @@ public:
std::unique_ptr<ExprAST> Body)
: VarNames(std::move(VarNames)), Body(std::move(Body)) {}
Value *codegen() override;
raw_ostream &dump(raw_ostream &out, int ind) override {
ExprAST::dump(out << "var", ind);
for (const auto &NamedVar : VarNames)
@ -392,6 +417,7 @@ public:
std::unique_ptr<ExprAST> Body)
: Proto(std::move(Proto)), Body(std::move(Body)) {}
Function *codegen();
raw_ostream &dump(raw_ostream &out, int ind) {
indent(out, ind) << "FunctionAST\n";
++ind;
@ -477,7 +503,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
if (auto Arg = ParseExpression())
Args.push_back(std::move(Arg));
else
@ -587,7 +613,7 @@ static std::unique_ptr<ExprAST> ParseVarExpr() {
if (CurTok != tok_identifier)
return LogError("expected identifier after var");
while (1) {
while (true) {
std::string Name = IdentifierStr;
getNextToken(); // eat identifier.
@ -671,7 +697,7 @@ static std::unique_ptr<ExprAST> ParseUnary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -887,8 +913,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
const std::string &VarName) {
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr,
VarName.c_str());
return TmpB.CreateAlloca(Type::getDoubleTy(TheContext), nullptr, VarName);
}
Value *NumberExprAST::codegen() {
@ -1355,7 +1380,7 @@ static void HandleTopLevelExpression() {
/// top ::= definition | external | expression | ';'
static void MainLoop() {
while (1) {
while (true) {
switch (CurTok) {
case tok_eof:
return;
@ -1430,7 +1455,7 @@ int main() {
// Currently down as "fib.ks" as a filename since we're redirecting stdin
// but we'd like actual source locations.
KSDbgInfo.TheCU = DBuilder->createCompileUnit(
dwarf::DW_LANG_C, "fib.ks", ".", "Kaleidoscope Compiler", 0, "", 0);
dwarf::DW_LANG_C, "fib.ks", ".", "Kaleidoscope Compiler", false, "", 0);
// Run the main "interpreter loop" now.
MainLoop();

View File

@ -1,25 +1,44 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IndirectionUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/OrcABISupport.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
@ -304,7 +323,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
auto Arg = ParseExpression();
if (!Arg) return nullptr;
Args.push_back(std::move(Arg));
@ -430,7 +449,7 @@ static std::unique_ptr<VarExprAST> ParseVarExpr() {
if (CurTok != tok_identifier)
return ErrorU<VarExprAST>("expected identifier after var");
while (1) {
while (true) {
std::string Name = IdentifierStr;
getNextToken(); // eat identifier.
@ -506,7 +525,7 @@ static std::unique_ptr<ExprAST> ParseUnary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -688,6 +707,7 @@ public:
TargetMachine& getTarget() { return *TM; }
void addPrototypeAST(std::unique_ptr<PrototypeAST> P);
PrototypeAST* getPrototypeAST(const std::string &Name);
private:
typedef std::map<std::string, std::unique_ptr<PrototypeAST>> PrototypeMap;
@ -710,7 +730,6 @@ PrototypeAST* SessionContext::getPrototypeAST(const std::string &Name) {
class IRGenContext {
public:
IRGenContext(SessionContext &S)
: Session(S),
M(new Module(GenerateUniqueName("jit_module_"),
@ -727,6 +746,7 @@ public:
Function* getPrototype(const std::string &Name);
std::map<std::string, AllocaInst*> NamedValues;
private:
SessionContext &Session;
std::unique_ptr<Module> M;
@ -748,7 +768,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()),
nullptr, VarName.c_str());
nullptr, VarName);
}
Value *NumberExprAST::IRGen(IRGenContext &C) const {
@ -1227,7 +1247,6 @@ public:
}
private:
// This method searches the FunctionDefs map for a definition of 'Name'. If it
// finds one it generates a stub for it and returns the address of the stub.
RuntimeDyld::SymbolInfo searchFunctionASTs(const std::string &Name) {
@ -1371,7 +1390,7 @@ static void MainLoop() {
SessionContext S(TheContext);
KaleidoscopeJIT J(S);
while (1) {
while (true) {
switch (CurTok) {
case tok_eof: return;
case ';': getNextToken(); continue; // ignore top-level semicolons.

View File

@ -1,24 +1,41 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
@ -177,6 +194,7 @@ struct IfExprAST : public ExprAST {
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 *IRGen(IRGenContext &C) const override;
std::unique_ptr<ExprAST> Cond, Then, Else;
@ -303,7 +321,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
auto Arg = ParseExpression();
if (!Arg) return nullptr;
Args.push_back(std::move(Arg));
@ -429,7 +447,7 @@ static std::unique_ptr<VarExprAST> ParseVarExpr() {
if (CurTok != tok_identifier)
return ErrorU<VarExprAST>("expected identifier after var");
while (1) {
while (true) {
std::string Name = IdentifierStr;
getNextToken(); // eat identifier.
@ -505,7 +523,7 @@ static std::unique_ptr<ExprAST> ParseUnary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -687,6 +705,7 @@ public:
TargetMachine& getTarget() { return *TM; }
void addPrototypeAST(std::unique_ptr<PrototypeAST> P);
PrototypeAST* getPrototypeAST(const std::string &Name);
private:
typedef std::map<std::string, std::unique_ptr<PrototypeAST>> PrototypeMap;
@ -709,7 +728,6 @@ PrototypeAST* SessionContext::getPrototypeAST(const std::string &Name) {
class IRGenContext {
public:
IRGenContext(SessionContext &S)
: Session(S),
M(new Module(GenerateUniqueName("jit_module_"),
@ -726,6 +744,7 @@ public:
Function* getPrototype(const std::string &Name);
std::map<std::string, AllocaInst*> NamedValues;
private:
SessionContext &Session;
std::unique_ptr<Module> M;
@ -747,7 +766,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()),
nullptr, VarName.c_str());
nullptr, VarName);
}
Value *NumberExprAST::IRGen(IRGenContext &C) const {
@ -1266,7 +1285,7 @@ static void MainLoop() {
SessionContext S(TheContext);
KaleidoscopeJIT J(S);
while (1) {
while (true) {
switch (CurTok) {
case tok_eof: return;
case ';': getNextToken(); continue; // ignore top-level semicolons.

View File

@ -1,24 +1,42 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
@ -177,6 +195,7 @@ struct IfExprAST : public ExprAST {
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 *IRGen(IRGenContext &C) const override;
std::unique_ptr<ExprAST> Cond, Then, Else;
@ -303,7 +322,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
auto Arg = ParseExpression();
if (!Arg) return nullptr;
Args.push_back(std::move(Arg));
@ -429,7 +448,7 @@ static std::unique_ptr<VarExprAST> ParseVarExpr() {
if (CurTok != tok_identifier)
return ErrorU<VarExprAST>("expected identifier after var");
while (1) {
while (true) {
std::string Name = IdentifierStr;
getNextToken(); // eat identifier.
@ -505,7 +524,7 @@ static std::unique_ptr<ExprAST> ParseUnary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -687,6 +706,7 @@ public:
TargetMachine& getTarget() { return *TM; }
void addPrototypeAST(std::unique_ptr<PrototypeAST> P);
PrototypeAST* getPrototypeAST(const std::string &Name);
private:
typedef std::map<std::string, std::unique_ptr<PrototypeAST>> PrototypeMap;
@ -709,7 +729,6 @@ PrototypeAST* SessionContext::getPrototypeAST(const std::string &Name) {
class IRGenContext {
public:
IRGenContext(SessionContext &S)
: Session(S),
M(new Module(GenerateUniqueName("jit_module_"),
@ -726,6 +745,7 @@ public:
Function* getPrototype(const std::string &Name);
std::map<std::string, AllocaInst*> NamedValues;
private:
SessionContext &Session;
std::unique_ptr<Module> M;
@ -747,7 +767,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()),
nullptr, VarName.c_str());
nullptr, VarName);
}
Value *NumberExprAST::IRGen(IRGenContext &C) const {
@ -1270,7 +1290,7 @@ static void MainLoop() {
SessionContext S(TheContext);
KaleidoscopeJIT J(S);
while (1) {
while (true) {
switch (CurTok) {
case tok_eof: return;
case ';': getNextToken(); continue; // ignore top-level semicolons.

View File

@ -1,24 +1,41 @@
#include "llvm/Analysis/Passes.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/RuntimeDyld.h"
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
#include "llvm/ExecutionEngine/Orc/CompileUtils.h"
#include "llvm/ExecutionEngine/Orc/IRCompileLayer.h"
#include "llvm/ExecutionEngine/Orc/JITSymbol.h"
#include "llvm/ExecutionEngine/Orc/LambdaResolver.h"
#include "llvm/ExecutionEngine/Orc/LazyEmittingLayer.h"
#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.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/LegacyPassManager.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Mangler.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Target/TargetMachine.h"
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace llvm;
@ -177,6 +194,7 @@ struct IfExprAST : public ExprAST {
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 *IRGen(IRGenContext &C) const override;
std::unique_ptr<ExprAST> Cond, Then, Else;
@ -303,7 +321,7 @@ static std::unique_ptr<ExprAST> ParseIdentifierExpr() {
getNextToken(); // eat (
std::vector<std::unique_ptr<ExprAST>> Args;
if (CurTok != ')') {
while (1) {
while (true) {
auto Arg = ParseExpression();
if (!Arg) return nullptr;
Args.push_back(std::move(Arg));
@ -429,7 +447,7 @@ static std::unique_ptr<VarExprAST> ParseVarExpr() {
if (CurTok != tok_identifier)
return ErrorU<VarExprAST>("expected identifier after var");
while (1) {
while (true) {
std::string Name = IdentifierStr;
getNextToken(); // eat identifier.
@ -505,7 +523,7 @@ static std::unique_ptr<ExprAST> ParseUnary() {
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) {
// If this is a binop, find its precedence.
while (1) {
while (true) {
int TokPrec = GetTokPrecedence();
// If this is a binop that binds at least as tightly as the current binop,
@ -687,6 +705,7 @@ public:
TargetMachine& getTarget() { return *TM; }
void addPrototypeAST(std::unique_ptr<PrototypeAST> P);
PrototypeAST* getPrototypeAST(const std::string &Name);
private:
typedef std::map<std::string, std::unique_ptr<PrototypeAST>> PrototypeMap;
@ -709,7 +728,6 @@ PrototypeAST* SessionContext::getPrototypeAST(const std::string &Name) {
class IRGenContext {
public:
IRGenContext(SessionContext &S)
: Session(S),
M(new Module(GenerateUniqueName("jit_module_"),
@ -726,6 +744,7 @@ public:
Function* getPrototype(const std::string &Name);
std::map<std::string, AllocaInst*> NamedValues;
private:
SessionContext &Session;
std::unique_ptr<Module> M;
@ -747,7 +766,7 @@ static AllocaInst *CreateEntryBlockAlloca(Function *TheFunction,
IRBuilder<> TmpB(&TheFunction->getEntryBlock(),
TheFunction->getEntryBlock().begin());
return TmpB.CreateAlloca(Type::getDoubleTy(TheFunction->getContext()),
nullptr, VarName.c_str());
nullptr, VarName);
}
Value *NumberExprAST::IRGen(IRGenContext &C) const {
@ -1216,7 +1235,6 @@ public:
}
private:
// This method searches the FunctionDefs map for a definition of 'Name'. If it
// finds one it generates a stub for it and returns the address of the stub.
RuntimeDyld::SymbolInfo searchFunctionASTs(const std::string &Name) {
@ -1301,7 +1319,7 @@ static void MainLoop() {
SessionContext S(TheContext);
KaleidoscopeJIT J(S);
while (1) {
while (true) {
switch (CurTok) {
case tok_eof: return;
case ';': getNextToken(); continue; // ignore top-level semicolons.