2022-10-17 22:26:36 -03:00
|
|
|
#ifndef OBELISK_AST_FUNCTION_AST_H
|
|
|
|
#define OBELISK_AST_FUNCTION_AST_H
|
|
|
|
|
|
|
|
#include "ast/expression_ast.h"
|
|
|
|
#include "ast/prototype_ast.h"
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
namespace obelisk
|
|
|
|
{
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief A Funcion AST node.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
class FunctionAST
|
|
|
|
{
|
|
|
|
private:
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief The prototype of the function.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::unique_ptr<PrototypeAST> prototype_;
|
2023-02-20 22:01:14 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The body of the function.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::unique_ptr<ExpressionAST> body_;
|
|
|
|
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Get the prototype.
|
|
|
|
*
|
|
|
|
* @return std::unique_ptr<PrototypeAST> Returns the prototype AST.
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::unique_ptr<PrototypeAST> getPrototype();
|
2023-02-20 22:01:14 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the prototype.
|
|
|
|
*
|
|
|
|
* @param[in] prototype Set the prototype.
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
void setPrototype(std::unique_ptr<PrototypeAST> prototype);
|
|
|
|
|
|
|
|
public:
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new FunctionAST object.
|
|
|
|
*
|
|
|
|
* @param[in] prototype The prototype of the function.
|
|
|
|
* @param[in] body The body of the function.
|
|
|
|
*/
|
2023-02-20 22:05:57 -03:00
|
|
|
FunctionAST(std::unique_ptr<PrototypeAST> prototype,
|
|
|
|
std::unique_ptr<ExpressionAST> body) :
|
2022-10-17 22:26:36 -03:00
|
|
|
prototype_(std::move(prototype)),
|
|
|
|
body_(std::move(body))
|
|
|
|
{
|
|
|
|
}
|
2022-11-21 21:24:44 -03:00
|
|
|
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Generate LLVM IR code.
|
|
|
|
*
|
|
|
|
* @return llvm::Function* Returns the LLVM IR function code.
|
|
|
|
*/
|
2022-11-21 21:24:44 -03:00
|
|
|
llvm::Function *codegen();
|
2022-10-17 22:26:36 -03:00
|
|
|
};
|
|
|
|
} // namespace obelisk
|
|
|
|
|
|
|
|
#endif
|