3 #include "llvm/IR/Value.h"
4 #include "llvm/IR/Function.h"
10 virtual ~ExprAST() = default;
11 virtual Value *codegen() = 0;
14 class NumberExprAST: public ExprAST {
18 NumberExprAST(double Val): Val(Val) {}
19 virtual Value *codegen();
22 class VariableExprAST: public ExprAST {
26 VariableExprAST(const std::string &Name): Name(Name) {}
27 virtual Value *codegen();
30 class BinaryExprAST: public ExprAST {
32 std::unique_ptr<ExprAST> LHS, RHS;
35 BinaryExprAST(char op, std::unique_ptr<ExprAST> LHS,
36 std::unique_ptr<ExprAST> RHS)
37 : Op(op), LHS(std::move(LHS)), RHS(std::move(RHS)) {}
38 virtual Value *codegen();
41 class CallExprAST: public ExprAST {
43 std::vector<std::unique_ptr<ExprAST>> Args;
46 CallExprAST(std::string &Callee, std::vector<std::unique_ptr<ExprAST>> Args)
47 : Callee(Callee), Args(std::move(Args)) {}
48 virtual Value *codegen();
52 Captures the prototype for a function
53 which is basically its name and arguments
57 std::vector<std::string> Args;
60 virtual ~PrototypeAST() = default;
61 PrototypeAST(std::string Name, std::vector<std::string> Args)
62 : Name(Name), Args(std::move(Args)) {}
64 const std::string &getName() const { return Name; }
65 virtual Function *codegen();
69 std::unique_ptr<PrototypeAST> Prototype;
70 std::unique_ptr<ExprAST> Body;
73 virtual ~FunctionAST() = default;
74 FunctionAST(std::unique_ptr<PrototypeAST> Prototype, std::unique_ptr<ExprAST> Body)
75 : Prototype(std::move(Prototype)), Body(std::move(Body)) {}
76 virtual Function *codegen();
79 std::unique_ptr<ExprAST> LogError(const char *Str);