From e53e059fe88ce011a5829a3dffae96ba516da03e Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EB=B0=95=EC=A2=85=ED=98=84/=EB=8F=99=EC=9E=91=EC=A0=9C?= =?utf8?q?=EC=96=B4Lab=28SR=29/Staff=20Engineer/=EC=82=BC=EC=84=B1?= =?utf8?q?=EC=A0=84=EC=9E=90?= Date: Wed, 29 Aug 2018 12:02:46 +0900 Subject: [PATCH] [enco] Declare subnet field (#1226) Now, Network struct has a dedicated field for each subnet. Signed-off-by: Jonghyun Park --- contrib/enco/core/src/CppCode.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contrib/enco/core/src/CppCode.cpp b/contrib/enco/core/src/CppCode.cpp index 9678a8d..e008649 100644 --- a/contrib/enco/core/src/CppCode.cpp +++ b/contrib/enco/core/src/CppCode.cpp @@ -22,6 +22,14 @@ namespace struct SubnetInfo { std::string struct_name; + + // @brief The field name (in Network struct) for this subnet + std::string field_name; +}; + +struct NetworkStruct +{ + pp::LinearDocument def; }; struct InvokeFunction @@ -67,6 +75,7 @@ void CppCode::dump(std::ostream &os) const auto m = _code->module(); Global global; + NetworkStruct network; InvokeFunction invoke; pp::LinearDocument internal; @@ -98,6 +107,7 @@ void CppCode::dump(std::ostream &os) const 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()); auto subnet_struct_content = builder.build(subnet_binder); // Emit C++ declaration @@ -124,10 +134,14 @@ void CppCode::dump(std::ostream &os) const internal.unindent(); internal.append("};"); + // Declare subnet field + network.def.append(subnet_struct_name, " ", subnet_field_name, ";"); + // Update subnet context SubnetInfo subnet_info; subnet_info.struct_name = subnet_struct_name; + subnet_info.field_name = subnet_field_name; assert(subnet_ctx.find(subnet_binder) == subnet_ctx.end()); subnet_ctx[subnet_binder] = subnet_info; @@ -229,6 +243,8 @@ void CppCode::dump(std::ostream &os) const net_def.append("~", name, "();"); net_def.append(); + net_def.append(network.def); + net_def.append(); net_def.append("std::arrayinput()->size(), "> inputs;"); net_def.append("std::arrayoutput()->size(), "> outputs;"); -- 2.7.4