[enco] Global as local helper class (#1766)
author박종현/동작제어Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 8 Oct 2018 00:21:25 +0000 (09:21 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 8 Oct 2018 00:21:25 +0000 (09:21 +0900)
Now, only Global Data Generation pass accesses the internal of 'Global'
class.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
contrib/enco/core/src/CppCode.cpp
contrib/enco/core/src/CppGen/Global.cpp [deleted file]
contrib/enco/core/src/CppGen/Global.h [deleted file]
contrib/enco/core/src/CppGen/Global.test.cpp [deleted file]
contrib/enco/core/src/Transforms/GlobalDataGeneration.cpp
contrib/enco/core/src/Transforms/GlobalDataGeneration.h

index 4eb98f9..db984b4 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "Transforms/GlobalDataGeneration.h"
 
-#include "CppGen/Global.h"
 #include "CppGen/MemoryContext.h"
 
 #include "CppGen/Host.h"
diff --git a/contrib/enco/core/src/CppGen/Global.cpp b/contrib/enco/core/src/CppGen/Global.cpp
deleted file mode 100644 (file)
index d8ee646..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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 "Global.h"
-
-#include <cassert>
-
-namespace enco
-{
-
-GlobalOffset Global::constant(const std::string &s)
-{
-  auto const base = reinterpret_cast<const uint8_t *>(s.c_str());
-  auto const size = s.size() + 1 /* NUL */;
-  return constant(base, size);
-}
-
-template <> GlobalOffset Global::constant(const std::vector<uint32_t> &values)
-{
-  auto const base = reinterpret_cast<const uint8_t *>(values.data());
-  auto const size = sizeof(uint32_t) * values.size();
-  return constant(base, size);
-}
-
-GlobalOffset Global::constant(const uint8_t *base, uint32_t size)
-{
-  auto pos = _os.tellp();
-  assert(pos != -1);
-
-  _os.write(reinterpret_cast<const char *>(base), size);
-
-  return static_cast<GlobalOffset>(pos);
-}
-
-} // namespace enco
diff --git a/contrib/enco/core/src/CppGen/Global.h b/contrib/enco/core/src/CppGen/Global.h
deleted file mode 100644 (file)
index c3b4fff..0000000
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.
- */
-
-#ifndef __ENCO_GLOBAL_H__
-#define __ENCO_GLOBAL_H__
-
-#include <cstdint>
-#include <string>
-#include <vector>
-#include <ostream>
-
-namespace enco
-{
-
-using GlobalOffset = uint32_t;
-
-/**
- * @brief Manage global variable declarations
- */
-class Global
-{
-public:
-  Global(std::ostream &os) : _os(os)
-  {
-    // DO NOTHING
-  }
-
-public:
-  // @brief Create a global constant string (const char *) literal, and return variable name
-  GlobalOffset constant(const std::string &value);
-
-  // @brief Create a global constant array variable of type T
-  template <typename T> GlobalOffset constant(const std::vector<T> &values);
-
-  // @brief Create a global constant array variable of byte (uint8_t) type
-  GlobalOffset constant(const uint8_t *base, uint32_t size);
-
-private:
-  uint32_t _offset = 0;
-  std::ostream &_os;
-};
-
-} // namespace enco
-
-#endif // __ENCO_GLOBAL_H__
diff --git a/contrib/enco/core/src/CppGen/Global.test.cpp b/contrib/enco/core/src/CppGen/Global.test.cpp
deleted file mode 100644 (file)
index bd4e444..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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 "Global.h"
-
-#include <set>
-
-#include <gtest/gtest.h>
-
-// TODO Rewrite this test
-#if 0
-TEST(GLOBAL, distinct_id)
-{
-  enco::Global global;
-
-  std::set<std::string> ids;
-
-  ids.insert(global.constant("Hello"));
-  ids.insert(global.constant("Nice to meet you"));
-
-  ASSERT_EQ(ids.size(), 2);
-}
-#endif
index b244f8a..123f466 100644 (file)
@@ -26,6 +26,61 @@ using nncc::foundation::make_unique;
 namespace
 {
 
+/**
+ * @brief Manage global variable declarations
+ */
+class Global
+{
+public:
+  Global(std::ostream &os) : _os(os)
+  {
+    // DO NOTHING
+  }
+
+public:
+  // @brief Create a global constant string (const char *) literal, and return variable name
+  enco::GlobalOffset constant(const std::string &value);
+
+  // @brief Create a global constant array variable of type T
+  template <typename T> enco::GlobalOffset constant(const std::vector<T> &values);
+
+  // @brief Create a global constant array variable of byte (uint8_t) type
+  enco::GlobalOffset constant(const uint8_t *base, uint32_t size);
+
+private:
+  uint32_t _offset = 0;
+  std::ostream &_os;
+};
+
+enco::GlobalOffset Global::constant(const std::string &s)
+{
+  auto const base = reinterpret_cast<const uint8_t *>(s.c_str());
+  auto const size = s.size() + 1 /* NUL */;
+  return constant(base, size);
+}
+
+template <> enco::GlobalOffset Global::constant(const std::vector<uint32_t> &values)
+{
+  auto const base = reinterpret_cast<const uint8_t *>(values.data());
+  auto const size = sizeof(uint32_t) * values.size();
+  return constant(base, size);
+}
+
+enco::GlobalOffset Global::constant(const uint8_t *base, uint32_t size)
+{
+  auto pos = _os.tellp();
+  assert(pos != -1);
+
+  _os.write(reinterpret_cast<const char *>(base), size);
+
+  return static_cast<enco::GlobalOffset>(pos);
+}
+
+} // namespace
+
+namespace
+{
+
 std::map<const ann::Operand *, enco::GlobalOffset> data_offset_ctx;
 std::map<const coco::Arg *, enco::GlobalOffset> name_offset_ctx;
 std::map<const coco::Arg *, enco::GlobalOffset> dims_offset_ctx;
index 6298e15..fd7b382 100644 (file)
 #ifndef __ENCO_TRANSFORM_GLOBAL_DATA_GENERATION_H__
 #define __ENCO_TRANSFORM_GLOBAL_DATA_GENERATION_H__
 
-#include "CppGen/Global.h"
 #include "Code.h"
 
+#include <ostream>
+
 namespace enco
 {
 
+using GlobalOffset = uint32_t;
+
 struct GlobalData
 {
   static GlobalOffset data_offset(const ann::Operand *);