const ConsumerSet *user(void) const;
private:
+ // @brief Update the link to a producer
+ //
+ // WARN Only Def class is allowed to access this method
+ void def(Def *d);
+
+private:
Dep _dep;
+ Def *_def = nullptr;
};
// @brief Return the producer of a given object if it exists
virtual ~ObjectInfo() = default;
public:
- Def *def(void) const { return _def; }
- void def(Def *d);
-
-public:
Object::ConsumerSet *user(void) { return &_user; }
const Object::ConsumerSet *user(void) const { return &_user; }
#include "coco/IR/Def.h"
-#include "coco/IR/ObjectInfo.h"
#include <cassert>
{
if (_value)
{
- auto info = _value->info();
- assert(info != nullptr);
- info->def(nullptr);
-
+ _value->def(nullptr);
_value = nullptr;
}
if (value)
{
_value = value;
-
- auto info = _value->info();
- assert(info != nullptr);
- info->def(this);
+ _value->def(this);
}
assert(_value == value);
return res;
}
-Def *Object::def(void) const { return info()->def(); }
+Def *Object::def(void) const { return _def; }
+
+void Object::def(Def *d)
+{
+ // This assert enforces users to explicitly reset def before update.
+ //
+ // Let's consider an object o with def d0.
+ //
+ // The following code is allowed:
+ // o->def(nullptr);
+ // o->def(d1);
+ //
+ // However, the following code is not allowed:
+ // o->def(d1);
+ //
+ assert((_def == nullptr) || (d == nullptr));
+ _def = d;
+}
+
const UseSet *Object::uses(void) const { return info()->uses(); }
const Object::ConsumerSet *Object::user(void) const { return info()->user(); }
namespace coco
{
-void ObjectInfo::def(Def *d)
-{
- // This assert ensures that object cannot have multiple def.
- assert((_def == nullptr) || (d == nullptr));
- _def = d;
-}
-
} // namespace coco
{
coco::ObjectInfo info;
- ASSERT_EQ(info.def(), nullptr);
ASSERT_EQ(info.user()->size(), 0);
}