finish up comments
This commit is contained in:
@@ -11,9 +11,28 @@
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The LLVM context.
|
||||
*
|
||||
*/
|
||||
static std::unique_ptr<llvm::LLVMContext> TheContext;
|
||||
|
||||
/**
|
||||
* @brief The LLVM module.
|
||||
*
|
||||
*/
|
||||
static std::unique_ptr<llvm::Module> TheModule;
|
||||
|
||||
/**
|
||||
* @brief The LLVM IR builder.
|
||||
*
|
||||
*/
|
||||
static std::unique_ptr<llvm::IRBuilder<>> Builder;
|
||||
|
||||
/**
|
||||
* @brief The LLVM named values.
|
||||
*
|
||||
*/
|
||||
static std::map<std::string, llvm::Value *> NamedValues;
|
||||
} // namespace obelisk
|
||||
|
||||
|
||||
@@ -9,25 +9,71 @@
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The call AST expression node used to call functions.
|
||||
*
|
||||
*/
|
||||
class CallExpressionAST : public ExpressionAST
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief The function being called.
|
||||
*
|
||||
*/
|
||||
std::string callee_;
|
||||
|
||||
/**
|
||||
* @brief The arguments passed to the function.
|
||||
*
|
||||
*/
|
||||
std::vector<std::unique_ptr<ExpressionAST>> args_;
|
||||
|
||||
/**
|
||||
* @brief Get the callee.
|
||||
*
|
||||
* @return std::string Returns the name of the function being called.
|
||||
*/
|
||||
std::string getCallee();
|
||||
|
||||
/**
|
||||
* @brief Set the callee.
|
||||
*
|
||||
* @param[in] callee The name of the function.
|
||||
*/
|
||||
void setCallee(std::string callee);
|
||||
|
||||
/**
|
||||
* @brief Get the arguments being used by the function.
|
||||
*
|
||||
* @return std::vector<std::unique_ptr<ExpressionAST>> Returns an AST expression containing the args.
|
||||
*/
|
||||
std::vector<std::unique_ptr<ExpressionAST>> getArgs();
|
||||
|
||||
/**
|
||||
* @brief Set the arguments to be used by the function.
|
||||
*
|
||||
* @param[in] args The args to set.
|
||||
*/
|
||||
void setArgs(std::vector<std::unique_ptr<ExpressionAST>> args);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new CallExpressionAST object.
|
||||
*
|
||||
* @param[in] callee The function to call.
|
||||
* @param[in] args The args to pass into the function.
|
||||
*/
|
||||
CallExpressionAST(const std::string &callee, std::vector<std::unique_ptr<ExpressionAST>> args) :
|
||||
callee_(callee),
|
||||
args_(std::move(args))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate the calle IR code.
|
||||
*
|
||||
* @return llvm::Value*
|
||||
*/
|
||||
llvm::Value *codegen() override;
|
||||
};
|
||||
} // namespace obelisk
|
||||
|
||||
@@ -7,8 +7,21 @@
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
std::unique_ptr<ExpressionAST> LogError(const char *Str);
|
||||
llvm::Value *LogErrorV(const char *Str);
|
||||
/**
|
||||
* @brief Log an AST expression error.
|
||||
*
|
||||
* @param[in] str The error message.
|
||||
* @return std::unique_ptr<ExpressionAST> Returns the AST expression that caused the error.
|
||||
*/
|
||||
std::unique_ptr<ExpressionAST> LogError(const char *str);
|
||||
|
||||
/**
|
||||
* @brief Log an AST value error.
|
||||
*
|
||||
* @param[in] str The error message.
|
||||
* @return llvm::Value* Returns the AST value that caused the error.
|
||||
*/
|
||||
llvm::Value *LogErrorV(const char *str);
|
||||
} // namespace obelisk
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,10 +5,24 @@
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief A generic AST expression which other expression will inherit from.
|
||||
*
|
||||
*/
|
||||
class ExpressionAST
|
||||
{
|
||||
public:
|
||||
virtual ~ExpressionAST() = default;
|
||||
/**
|
||||
* @brief Destroy the ExpressionAST object.
|
||||
*
|
||||
*/
|
||||
virtual ~ExpressionAST() = default;
|
||||
|
||||
/**
|
||||
* @brief Generate LLVM IR code based on the AST expression.
|
||||
*
|
||||
* @return llvm::Value* Returns the LLVM code value from the expression.
|
||||
*/
|
||||
virtual llvm::Value *codegen() = 0;
|
||||
};
|
||||
} // namespace obelisk
|
||||
|
||||
@@ -8,22 +8,57 @@
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief A Funcion AST node.
|
||||
*
|
||||
*/
|
||||
class FunctionAST
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief The prototype of the function.
|
||||
*
|
||||
*/
|
||||
std::unique_ptr<PrototypeAST> prototype_;
|
||||
|
||||
/**
|
||||
* @brief The body of the function.
|
||||
*
|
||||
*/
|
||||
std::unique_ptr<ExpressionAST> body_;
|
||||
|
||||
/**
|
||||
* @brief Get the prototype.
|
||||
*
|
||||
* @return std::unique_ptr<PrototypeAST> Returns the prototype AST.
|
||||
*/
|
||||
std::unique_ptr<PrototypeAST> getPrototype();
|
||||
|
||||
/**
|
||||
* @brief Set the prototype.
|
||||
*
|
||||
* @param[in] prototype Set the prototype.
|
||||
*/
|
||||
void setPrototype(std::unique_ptr<PrototypeAST> prototype);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new FunctionAST object.
|
||||
*
|
||||
* @param[in] prototype The prototype of the function.
|
||||
* @param[in] body The body of the function.
|
||||
*/
|
||||
FunctionAST(std::unique_ptr<PrototypeAST> prototype, std::unique_ptr<ExpressionAST> body) :
|
||||
prototype_(std::move(prototype)),
|
||||
body_(std::move(body))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate LLVM IR code.
|
||||
*
|
||||
* @return llvm::Function* Returns the LLVM IR function code.
|
||||
*/
|
||||
llvm::Function *codegen();
|
||||
};
|
||||
} // namespace obelisk
|
||||
|
||||
@@ -5,20 +5,49 @@
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief A number expression AST node.
|
||||
*
|
||||
*/
|
||||
class NumberExpressionAST : public ExpressionAST
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief The number.
|
||||
*
|
||||
*/
|
||||
double number_;
|
||||
|
||||
/**
|
||||
* @brief Get the number.
|
||||
*
|
||||
* @return double Returns the number.
|
||||
*/
|
||||
double getNumber();
|
||||
|
||||
/**
|
||||
* @brief Set the number.
|
||||
*
|
||||
* @param[in] number The number.
|
||||
*/
|
||||
void setNumber(double number);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new NumberExpressionAST object.
|
||||
*
|
||||
* @param[in] number The number.
|
||||
*/
|
||||
NumberExpressionAST(double number) :
|
||||
number_(number)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate LLVM IR code for the number.
|
||||
*
|
||||
* @return llvm::Value* Returns the genrated IR code.
|
||||
*/
|
||||
llvm::Value *codegen() override;
|
||||
};
|
||||
} // namespace obelisk
|
||||
|
||||
@@ -8,30 +8,75 @@
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The prototype AST node.
|
||||
*
|
||||
*/
|
||||
class PrototypeAST
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief The name of the prototype.
|
||||
*
|
||||
*/
|
||||
std::string name_;
|
||||
/**
|
||||
* @brief The arguments the protype accepts.
|
||||
*
|
||||
*/
|
||||
std::vector<std::string> args_;
|
||||
|
||||
/**
|
||||
* @brief Set the name of the prototype.
|
||||
*
|
||||
* @param[in] name The name.
|
||||
*/
|
||||
void setName(const std::string& name);
|
||||
|
||||
/**
|
||||
* @brief Get the arguments the prototype accepts.
|
||||
*
|
||||
* @return std::vector<std::string> Returns the arguments.
|
||||
*/
|
||||
std::vector<std::string> getArgs();
|
||||
|
||||
/**
|
||||
* @brief Set the arguments the prototype accepts.
|
||||
*
|
||||
* @param[in] args The arguments.
|
||||
*/
|
||||
void setArgs(std::vector<std::string> args);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new PrototypeAST object.
|
||||
*
|
||||
* @param[in] name The name of the prototype.
|
||||
* @param[in] args The arguments the prototype accepts.
|
||||
*/
|
||||
PrototypeAST(const std::string& name, std::vector<std::string> args) :
|
||||
name_(name),
|
||||
args_(std::move(args))
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get the name of the prototype.
|
||||
*
|
||||
* @return const std::string& Returns the name of the prototype.
|
||||
*/
|
||||
const std::string& getName() const
|
||||
{
|
||||
return name_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate LLVM IR code for the prototype.
|
||||
*
|
||||
* @return llvm::Function* Returns IR code for the prototype.
|
||||
*/
|
||||
llvm::Function* codegen();
|
||||
};
|
||||
} //namespace obelisk
|
||||
} // namespace obelisk
|
||||
|
||||
#endif
|
||||
|
||||
@@ -7,21 +7,51 @@
|
||||
|
||||
namespace obelisk
|
||||
{
|
||||
/**
|
||||
* @brief The variable expression AST node.
|
||||
*
|
||||
*/
|
||||
class VariableExpressionAST : public ExpressionAST
|
||||
{
|
||||
private:
|
||||
/**
|
||||
* @brief The name of the variable.
|
||||
*
|
||||
*/
|
||||
std::string name_;
|
||||
|
||||
/**
|
||||
* @brief Get the name of the variable.
|
||||
*
|
||||
* @return std::string Returns the name of the variable.
|
||||
*/
|
||||
std::string getName();
|
||||
|
||||
/**
|
||||
* @brief Set the name of the variable.
|
||||
*
|
||||
* @param[in] name The name of the variable.
|
||||
*/
|
||||
void setName(const std::string name);
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief Construct a new VariableExpressionAST object.
|
||||
*
|
||||
* @param[in] name The name of the variable.
|
||||
*/
|
||||
VariableExpressionAST(const std::string &name) :
|
||||
name_(name)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Generate the variable LLVM IR code.
|
||||
*
|
||||
* @return llvm::Value* Returns the generated IR code.
|
||||
*/
|
||||
llvm::Value *codegen() override;
|
||||
};
|
||||
} //namespace obelisk
|
||||
} // namespace obelisk
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user