file(GLOB_RECURSE TESTS "src/*.test.cpp")
list(REMOVE_ITEM SOURCES ${TESTS})
-add_library(enco_core STATIC ${SOURCES})
-set_target_properties(enco_core PROPERTIES POSITION_INDEPENDENT_CODE ON)
+###
+### enco_core is built as a shared library to support "interactive debugging".
+###
+### interactive debugging helpers are stripped during linking when enco_core is
+### built as a static library
+###
+add_library(enco_core SHARED ${SOURCES})
target_include_directories(enco_core PRIVATE src)
target_include_directories(enco_core PUBLIC include)
target_link_libraries(enco_core enco_intf_cmdline)
--- /dev/null
+#include "Debugging.h"
+
+#include <pp/LinearDocument.h>
+#include <pp/MultiLineTextUtils.h>
+
+#include <iostream>
+
+#define DEBUGGING_API_P(NAME, TYPE, VAR) \
+ void NAME(const TYPE *); \
+ void NAME(long p) { NAME(reinterpret_cast<const TYPE *>(p)); } \
+ void NAME(const TYPE *VAR)
+
+/**
+ * SECTION: Op
+ */
+namespace
+{
+
+std::string op_kind(const coco::Op *op)
+{
+ struct OpKind : public coco::Op::Visitor<std::string>
+ {
+ std::string visit(const coco::Load *) override { return "Load"; }
+ std::string visit(const coco::Conv2D *) override { return "Conv2D"; }
+ std::string visit(const coco::MaxPool2D *) override { return "MaxPool2D"; }
+ std::string visit(const coco::AvgPool2D *) override { return "AvgPool2D"; }
+ std::string visit(const coco::PadF *) override { return "PadF"; }
+ std::string visit(const coco::ReLU *) override { return "ReLU"; }
+ std::string visit(const coco::Add *) override { return "Add"; }
+ std::string visit(const coco::Mul *) override { return "Mul"; }
+ std::string visit(const coco::ConcatF *) override { return "ConcatF"; }
+ };
+
+ OpKind v;
+
+ return op->accept(v);
+}
+
+pp::LinearDocument describe(const coco::Op *op)
+{
+ pp::LinearDocument doc;
+
+ doc.append("addr: ", op);
+ doc.append("kind: ", op_kind(op));
+ doc.append("parent(instr): ", op->parent());
+ doc.append("up(op): ", op->up());
+
+ return doc;
+}
+
+} // namespace
+
+DEBUGGING_API_P(enco_dump_op, coco::Op, op)
+{
+ if (op != nullptr)
+ {
+ std::cout << describe(op) << std::endl;
+ }
+ else
+ {
+ std::cout << "(nullptr)" << std::endl;
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * @file Debugging.h
+ * @brief This file includes various interactive debugging helpers
+ */
+
+#ifndef __ENCO_SUPPORT_DEBUGGING_H__
+#define __ENCO_SUPPORT_DEBUGGING_H__
+
+#include <coco/IR.h>
+
+static_assert(sizeof(long) == sizeof(void *), "sizeof(long) == sizeof(pointer)");
+
+/**
+ * Debugging API with a single pointer argument
+ */
+#define DEBUGGING_API_P(NAME, TYPE) \
+ void NAME(const TYPE *); \
+ void NAME(long);
+
+/**
+ * Print the details of coco::Op
+ *
+ * (gdb) call enco_dump_op(op)
+ * (gdb) call enco_dump_op(0x....)
+ */
+DEBUGGING_API_P(enco_dump_op, coco::Op);
+
+#undef DEBUGGING_API_P
+
+#endif // __ENCO_SUPPORT_DEBUGGING_H__
--- /dev/null
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Debugging.h"
+
+#include <gtest/gtest.h>
+
+// This test aims to check whether debugging API is actually defined
+TEST(DebuggingTest, defined) { enco_dump_op(nullptr); }