2018-12-31 22:47:31 -05:00
|
|
|
#ifndef TDL_INCLUDE_IR_FUNCTION_H
|
|
|
|
#define TDL_INCLUDE_IR_FUNCTION_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "value.h"
|
2019-01-03 15:32:22 -05:00
|
|
|
#include "constant.h"
|
2018-12-31 22:47:31 -05:00
|
|
|
|
|
|
|
namespace tdl{
|
|
|
|
namespace ir{
|
|
|
|
|
2019-01-03 15:32:22 -05:00
|
|
|
class function;
|
2018-12-31 22:47:31 -05:00
|
|
|
class function_type;
|
|
|
|
class module;
|
|
|
|
|
|
|
|
/* Argument */
|
|
|
|
class argument: public value{
|
2019-01-03 15:32:22 -05:00
|
|
|
argument(type *ty, const std::string &name, function *parent, unsigned arg_no);
|
2018-12-31 22:47:31 -05:00
|
|
|
|
2019-01-03 15:32:22 -05:00
|
|
|
public:
|
|
|
|
static argument* create(type *ty, const std::string &name,
|
|
|
|
function *parent = nullptr, unsigned arg_no = 0);
|
|
|
|
|
|
|
|
private:
|
|
|
|
function *parent_;
|
|
|
|
unsigned arg_no_;
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Function */
|
2019-01-03 15:32:22 -05:00
|
|
|
class function: public global_object{
|
|
|
|
typedef std::vector<argument*> args_t;
|
|
|
|
typedef args_t::iterator arg_iterator;
|
|
|
|
typedef args_t::const_iterator const_arg_iterator;
|
|
|
|
private:
|
|
|
|
function(function_type *ty, linkage_types_t linkage,
|
|
|
|
const std::string &name = "", module *parent = nullptr);
|
2018-12-31 22:47:31 -05:00
|
|
|
|
|
|
|
public:
|
2019-01-03 15:32:22 -05:00
|
|
|
arg_iterator arg_begin() { return args_.begin(); }
|
|
|
|
arg_iterator arg_end() { return args_.end(); }
|
|
|
|
const_arg_iterator arg_begin() const { return args_.begin(); }
|
|
|
|
const_arg_iterator arg_end() const { return args_.end(); }
|
|
|
|
// Accessors
|
|
|
|
function_type* get_function_ty() const;
|
2018-12-31 22:47:31 -05:00
|
|
|
// Factory methods
|
2019-01-03 15:32:22 -05:00
|
|
|
static function *create(function_type *ty, linkage_types_t linkage,
|
|
|
|
const std::string &name, module *mod);
|
2018-12-31 22:47:31 -05:00
|
|
|
|
|
|
|
private:
|
2019-01-03 15:32:22 -05:00
|
|
|
module *parent_;
|
|
|
|
args_t args_;
|
|
|
|
bool init_;
|
2018-12-31 22:47:31 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|