[neurun] Add assertion for Graph building methods (#2340)
author이한종/동작제어Lab(SR)/Engineer/삼성전자 <hanjoung.lee@samsung.com>
Mon, 20 Aug 2018 02:09:24 +0000 (11:09 +0900)
committer오형석/동작제어Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 20 Aug 2018 02:09:24 +0000 (11:09 +0900)
Add assertions for Graph building method which must be called only in
`BUILDING` phase.

Signed-off-by: Hanjoung Lee <hanjoung.lee@samsung.com>
runtimes/neurun/src/graph/Graph.cc

index b0c73b0..16d16aa 100644 (file)
@@ -13,25 +13,35 @@ namespace graph
 
 operand::Index Graph::addOperand(const ::internal::tflite::operand::Shape &shape)
 {
+  assert(_phase == Phase::BUILDING);
   return _operands.append(shape);
 }
 
 operation::Index Graph::addOperation(std::unique_ptr<operation::Node> &&node)
 {
-
+  assert(_phase == Phase::BUILDING);
   return _operations.append(std::move(node));
 }
 
 void Graph::setOperandValue(const operand::Index &ind,
                             std::unique_ptr<::internal::tflite::operand::Data> &&data)
 {
+  assert(_phase == Phase::BUILDING);
   assert(_operands.exist(ind));
   _operands.at(ind).data(std::move(data));
 }
 
-void Graph::addInput(const operand::Index &ind) { _inputs.append(ind); }
+void Graph::addInput(const operand::Index &ind)
+{
+  assert(_phase == Phase::BUILDING);
+  _inputs.append(ind);
+}
 
-void Graph::addOutput(const operand::Index &ind) { _outputs.append(ind); }
+void Graph::addOutput(const operand::Index &ind)
+{
+  assert(_phase == Phase::BUILDING);
+  _outputs.append(ind);
+}
 
 void Graph::finishBuilding(void)
 {