2022-10-17 22:26:36 -03:00
|
|
|
#ifndef OBELISK_AST_PROTOTYPE_AST_H
|
|
|
|
#define OBELISK_AST_PROTOTYPE_AST_H
|
|
|
|
|
2022-11-21 21:24:44 -03:00
|
|
|
#include <llvm/IR/Function.h>
|
|
|
|
|
2022-10-17 22:26:36 -03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace obelisk
|
|
|
|
{
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief The prototype AST node.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
class PrototypeAST
|
|
|
|
{
|
|
|
|
private:
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief The name of the prototype.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::string name_;
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief The arguments the protype accepts.
|
|
|
|
*
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::vector<std::string> args_;
|
|
|
|
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Set the name of the prototype.
|
|
|
|
*
|
|
|
|
* @param[in] name The name.
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
void setName(const std::string& name);
|
2023-02-20 22:01:14 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the arguments the prototype accepts.
|
|
|
|
*
|
|
|
|
* @return std::vector<std::string> Returns the arguments.
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
std::vector<std::string> getArgs();
|
2023-02-20 22:01:14 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the arguments the prototype accepts.
|
|
|
|
*
|
|
|
|
* @param[in] args The arguments.
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
void setArgs(std::vector<std::string> args);
|
|
|
|
|
|
|
|
public:
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Construct a new PrototypeAST object.
|
|
|
|
*
|
|
|
|
* @param[in] name The name of the prototype.
|
|
|
|
* @param[in] args The arguments the prototype accepts.
|
|
|
|
*/
|
2023-02-20 22:05:57 -03:00
|
|
|
PrototypeAST(const std::string& name,
|
|
|
|
std::vector<std::string> args) :
|
2022-10-17 22:26:36 -03:00
|
|
|
name_(name),
|
|
|
|
args_(std::move(args))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Get the name of the prototype.
|
|
|
|
*
|
|
|
|
* @return const std::string& Returns the name of the prototype.
|
|
|
|
*/
|
2022-10-17 22:26:36 -03:00
|
|
|
const std::string& getName() const
|
|
|
|
{
|
|
|
|
return name_;
|
|
|
|
}
|
2022-11-21 21:24:44 -03:00
|
|
|
|
2023-02-20 22:01:14 -03:00
|
|
|
/**
|
|
|
|
* @brief Generate LLVM IR code for the prototype.
|
|
|
|
*
|
|
|
|
* @return llvm::Function* Returns IR code for the prototype.
|
|
|
|
*/
|
2022-11-21 21:24:44 -03:00
|
|
|
llvm::Function* codegen();
|
2022-10-17 22:26:36 -03:00
|
|
|
};
|
2023-02-20 22:01:14 -03:00
|
|
|
} // namespace obelisk
|
2022-10-17 22:26:36 -03:00
|
|
|
|
|
|
|
#endif
|