#include "../include/KaleidoscopeJIT.h"
#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/Instructions.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Passes/PassBuilder.h"
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/Scalar/Reassociate.h"
#include "llvm/Transforms/Scalar/SimplifyCFG.h"
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <memory>
#include <string>
#include <vector>
usingnamespacellvm;
usingnamespacellvm::orc;
enum Token { … };
static std::string IdentifierStr;
static double NumVal;
static int gettok() { … }
namespace {
class ExprAST { … };
class NumberExprAST : public ExprAST { … };
class VariableExprAST : public ExprAST { … };
class UnaryExprAST : public ExprAST { … };
class BinaryExprAST : public ExprAST { … };
class CallExprAST : public ExprAST { … };
class IfExprAST : public ExprAST { … };
class ForExprAST : public ExprAST { … };
class PrototypeAST { … };
class FunctionAST { … };
}
static int CurTok;
static int getNextToken() { … }
static std::map<char, int> BinopPrecedence;
static int GetTokPrecedence() { … }
std::unique_ptr<ExprAST> LogError(const char *Str) { … }
std::unique_ptr<PrototypeAST> LogErrorP(const char *Str) { … }
static std::unique_ptr<ExprAST> ParseExpression();
static std::unique_ptr<ExprAST> ParseNumberExpr() { … }
static std::unique_ptr<ExprAST> ParseParenExpr() { … }
static std::unique_ptr<ExprAST> ParseIdentifierExpr() { … }
static std::unique_ptr<ExprAST> ParseIfExpr() { … }
static std::unique_ptr<ExprAST> ParseForExpr() { … }
static std::unique_ptr<ExprAST> ParsePrimary() { … }
static std::unique_ptr<ExprAST> ParseUnary() { … }
static std::unique_ptr<ExprAST> ParseBinOpRHS(int ExprPrec,
std::unique_ptr<ExprAST> LHS) { … }
static std::unique_ptr<ExprAST> ParseExpression() { … }
static std::unique_ptr<PrototypeAST> ParsePrototype() { … }
static std::unique_ptr<FunctionAST> ParseDefinition() { … }
static std::unique_ptr<FunctionAST> ParseTopLevelExpr() { … }
static std::unique_ptr<PrototypeAST> ParseExtern() { … }
static std::unique_ptr<LLVMContext> TheContext;
static std::unique_ptr<Module> TheModule;
static std::unique_ptr<IRBuilder<>> Builder;
static std::map<std::string, Value *> NamedValues;
static std::unique_ptr<KaleidoscopeJIT> TheJIT;
static std::unique_ptr<FunctionPassManager> TheFPM;
static std::unique_ptr<LoopAnalysisManager> TheLAM;
static std::unique_ptr<FunctionAnalysisManager> TheFAM;
static std::unique_ptr<CGSCCAnalysisManager> TheCGAM;
static std::unique_ptr<ModuleAnalysisManager> TheMAM;
static std::unique_ptr<PassInstrumentationCallbacks> ThePIC;
static std::unique_ptr<StandardInstrumentations> TheSI;
static std::map<std::string, std::unique_ptr<PrototypeAST>> FunctionProtos;
static ExitOnError ExitOnErr;
Value *LogErrorV(const char *Str) { … }
Function *getFunction(std::string Name) { … }
Value *NumberExprAST::codegen() { … }
Value *VariableExprAST::codegen() { … }
Value *UnaryExprAST::codegen() { … }
Value *BinaryExprAST::codegen() { … }
Value *CallExprAST::codegen() { … }
Value *IfExprAST::codegen() { … }
Value *ForExprAST::codegen() { … }
Function *PrototypeAST::codegen() { … }
Function *FunctionAST::codegen() { … }
static void InitializeModuleAndManagers() { … }
static void HandleDefinition() { … }
static void HandleExtern() { … }
static void HandleTopLevelExpression() { … }
static void MainLoop() { … }
#ifdef _WIN32
#define DLLEXPORT …
#else
#define DLLEXPORT
#endif
extern "C" DLLEXPORT double putchard(double X) { … }
extern "C" DLLEXPORT double printd(double X) { … }
int main() { … }