#ifndef __AST_HPP__ #define __AST_HPP__ 1 #include #include #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Module.h" #include "llvm/IR/Verifier.h" using namespace std; using namespace llvm; class ExprAST { public: virtual Value* codegen() const = 0; virtual ~ExprAST() {} }; class NumberExprAST : public ExprAST { public: NumberExprAST(double val) :_val(val) {} Value* codegen() const; private: double _val; }; class VariableExprAST : public ExprAST { public: VariableExprAST(string name) :_name(name) {} Value* codegen() const; private: string _name; }; class BinaryExprAST : public ExprAST { public: BinaryExprAST(char op, ExprAST *lhs, ExprAST *rhs) :_op(op), _lhs(lhs), _rhs(rhs) {} Value* codegen() const; ~BinaryExprAST() { delete _lhs; delete _rhs; } private: BinaryExprAST(const BinaryExprAST&); BinaryExprAST& operator=(const BinaryExprAST&); char _op; ExprAST *_lhs, *_rhs; }; class CallExprAST : public ExprAST { public: CallExprAST(string name, vector exps) :_name(name), _exps(exps) {} ~CallExprAST() { for (auto e : _exps) delete e; } Value* codegen() const; private: CallExprAST(const CallExprAST&); CallExprAST& operator=(const CallExprAST&); string _name; vector _exps; }; class PrototypeAST { public: PrototypeAST(string name, vector args) :_name(name), _args(args) {} string getName() const { return _name; } Value* codegen() const; private: string _name; vector _args; }; class FunctionAST { public: FunctionAST(PrototypeAST proto, ExprAST* definition) : _proto(proto), _definition(definition) { } ~FunctionAST() { delete _definition; } Value* codegen() const; private: FunctionAST(const FunctionAST&); FunctionAST& operator=(const FunctionAST&); PrototypeAST _proto; ExprAST* _definition; }; #endif