With this commit, Global is updated only inside CppCode.
- SubnetStructBuilder no longer updates Global.
Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
*/
for (uint32_t n = 0; n < _code->ann()->count(); ++n)
{
- const SubnetStructBuilder builder{&global};
+ SubnetStructBuilder builder;
auto subnet_binder = _code->ann()->nth(n);
auto subnet_struct_name = pp::fmt("Subnet_", subnet_ctx.size());
auto subnet_field_name = pp::fmt("_subnet_", subnet_ctx.size());
+
+ // Create global data variable
+ auto emit_weight = [&global, &builder](const ann::OperandID &id, const ann::Operand *info) {
+ if (info->weight())
+ {
+ auto base = info->weight()->base();
+ auto size = info->weight()->size();
+ auto gvar = global.constant(base, size);
+
+ auto base_exp = pp::fmt("reinterpret_cast<const void *>(&", gvar, ")");
+ auto size_exp = pp::fmt(size);
+
+ builder.expr(info, base_exp, size_exp);
+ }
+ };
+ subnet_binder->module()->operand()->each(emit_weight);
+
auto subnet_struct_content = builder.build(subnet_binder);
// Emit C++ declaration
throw std::runtime_error{"Unsupported"};
}
- if (info->weight())
+ if (_weighted.find(info) != _weighted.end())
{
- auto base = info->weight()->base();
- auto size = info->weight()->size();
- auto gvar = _global->constant(base, size);
-
- auto base_exp = pp::fmt("reinterpret_cast<const void *>(&", gvar, ")");
- auto size_exp = pp::fmt(size);
+ const auto &base_exp = _base_exprs.at(info);
+ const auto &size_exp = _size_exprs.at(info);
res->ctor() << WeightDecl{mname, id, base_exp, size_exp};
}
#define __ENCO_CPP_GEN_SUBNET_H__
#include "ANN/Binder.h"
-#include "CppGen/Global.h"
#include "CppGen/MemoryContext.h"
#include <pp/MultiLineText.h>
#include <map>
+#include <set>
namespace enco
{
class SubnetStructBuilder
{
public:
- SubnetStructBuilder(enco::Global *global) : _global{global}
- {
- // DO NOTHING
- }
+ std::unique_ptr<SubnetStruct> build(const ANNBinder *binder) const;
public:
- std::unique_ptr<SubnetStruct> build(const ANNBinder *binder) const;
+ void expr(const ann::Operand *oper, const std::string &base, const std::string &size)
+ {
+ _weighted.insert(oper);
+ _base_exprs[oper] = base;
+ _size_exprs[oper] = size;
+ }
private:
- enco::Global *_global;
+ std::set<const ann::Operand *> _weighted;
+ std::map<const ann::Operand *, std::string> _base_exprs;
+ std::map<const ann::Operand *, std::string> _size_exprs;
};
/**