[intermediate representation] improved skeleton
This commit is contained in:
@@ -2,22 +2,73 @@
|
||||
#define TDL_INCLUDE_IR_VALUE_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
|
||||
namespace tdl{
|
||||
namespace ir{
|
||||
|
||||
class type;
|
||||
class use;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// value class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
/* Value */
|
||||
class value {
|
||||
public:
|
||||
// constructor
|
||||
value(type *ty, const std::string &name = "");
|
||||
// uses
|
||||
void add_use(use *arg);
|
||||
// name
|
||||
void set_name(const std::string &name);
|
||||
type* get_type();
|
||||
type* get_type() { return ty_; }
|
||||
|
||||
private:
|
||||
type *ty_;
|
||||
std::string name_;
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// use class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class use {
|
||||
public:
|
||||
// Implicit conversions to/from value
|
||||
friend class value;
|
||||
operator value *() const { return val_; }
|
||||
value *get() const { return val_; }
|
||||
value *operator->() { return val_; }
|
||||
const value *operator->() const { return val_; }
|
||||
inline void set(value *val);
|
||||
inline value *operator=(value *rhs);
|
||||
inline const use &operator=(const use &rhs);
|
||||
|
||||
private:
|
||||
value *val_;
|
||||
};
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// user class
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
class user: public value{
|
||||
public:
|
||||
// Constructor
|
||||
user(type *ty, unsigned num_ops, const std::string &name = "")
|
||||
: value(ty, name), ops_(num_ops){ }
|
||||
|
||||
// Operands
|
||||
void set_operand(unsigned i, value *x);
|
||||
value *get_operand(unsigned i);
|
||||
unsigned get_num_operands();
|
||||
|
||||
private:
|
||||
std::vector<use> ops_;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user