void CppCode::dump(std::ostream &os) const
{
+ auto m = _code->module();
+
//
// Generate full C++ source code with code snippet
//
{
net_def.append("struct ", name, " {");
net_def.indent();
+ net_def.append("struct Input {");
+ net_def.indent();
+ net_def.append("const uint8_t *ptr;");
+ net_def.append("unsigned len;");
+ net_def.unindent();
+ net_def.append("};");
+ net_def.append("struct Output {");
+ net_def.indent();
+ net_def.append("uint8_t *ptr;");
+ net_def.append("unsigned len;");
+ net_def.unindent();
+ net_def.append("};");
+ net_def.append();
net_def.append(name, "();");
net_def.append("~", name, "();");
+
+ net_def.append();
+
+ net_def.append("std::array<Input, ", m->input()->size(), "> inputs;");
+ net_def.append("std::array<Output, ", m->output()->size(), "> outputs;");
+
net_def.unindent();
net_def.append("};");
}
source.append();
- source.append("unsigned ", name, "_input_count(const ", name, " *net) { assert(\"NYI\"); }");
+ // Emit Network_input_count function
+ source.append("unsigned ", name, "_input_count(const ", name, " *net) {");
+ source.indent();
+ source.append("net->inputs.size();");
+ source.unindent();
+ source.append("}");
+
+ source.append();
+
source.append("const char *", name, "_input_name(const ", name,
" *net, unsigned n) { assert(\"NYI\"); }");
source.append("unsigned ", name, "_input_rank(const ", name,
" *net, unsigned n) { assert(\"NYI\"); }");
source.append("unsigned ", name, "_input_dim(const ", name,
" *net, unsigned n, unsigned axis) { assert(\"NYI\"); }");
+
+ // Emit Network_input_bind function
source.append("void ", name, "_input_bind(", name,
" *net, unsigned n, const void *ptr, unsigned len) {");
source.indent();
- source.append("assert(\"NYI\");");
+ source.append("net->inputs.at(n).ptr = reinterpret_cast<const uint8_t *>(ptr);");
+ source.append("net->inputs.at(n).len = len;");
+ source.unindent();
+ source.append("}");
+
+ source.append();
+
+ // Emit Network_output_count function
+ source.append("unsigned ", name, "_output_count(const ", name, " *net) {");
+ source.indent();
+ source.append("net->outputs.size();");
source.unindent();
source.append("}");
source.append();
- source.append("unsigned ", name, "_output_count(const ", name, " *net) { assert(\"NYI\"); }");
source.append("const char *", name, "_output_name(const ", name,
" *net, unsigned n) { assert(\"NYI\"); }");
source.append("unsigned ", name, "_output_rank(const ", name,
" *net, unsigned n) { assert(\"NYI\"); }");
source.append("unsigned ", name, "_output_dim(const ", name,
" *net, unsigned n, unsigned axis) { assert(\"NYI\"); }");
+
+ // Emit Network_output_bind function
source.append("void ", name, "_output_bind(", name,
" *net, unsigned n, void *ptr, unsigned len) {");
source.indent();
- source.append("assert(\"NYI\");");
+ source.append("net->outputs.at(n).ptr = reinterpret_cast<uint8_t *>(ptr);");
+ source.append("net->outputs.at(n).len = len;");
source.unindent();
source.append("}");