90760e95bd2ab73fd43d3ca126e83efcfab5274d
[platform/core/ml/nnfw.git] / compiler / luci / pass / src / helpers / TypeMapper.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <loco/IR/DataType.h>
18
19 #include <cstdint>
20
21 namespace luci
22 {
23
24 /**
25  * @brief TypeMapper maps between c++ primitive data type and loco::DataType.
26  */
27 template <typename T> struct TypeMapper
28 {
29   static constexpr loco::DataType get() { return loco::DataType::Unknown; }
30 };
31
32 template <> struct TypeMapper<float>
33 {
34   static constexpr loco::DataType get() { return loco::DataType::FLOAT32; }
35 };
36
37 template <> struct TypeMapper<uint8_t>
38 {
39   static constexpr loco::DataType get() { return loco::DataType::U8; }
40 };
41
42 template <> struct TypeMapper<uint16_t>
43 {
44   static constexpr loco::DataType get() { return loco::DataType::U16; }
45 };
46
47 template <> struct TypeMapper<uint32_t>
48 {
49   static constexpr loco::DataType get() { return loco::DataType::U32; }
50 };
51
52 template <> struct TypeMapper<uint64_t>
53 {
54   static constexpr loco::DataType get() { return loco::DataType::U64; }
55 };
56
57 template <> struct TypeMapper<int8_t>
58 {
59   static constexpr loco::DataType get() { return loco::DataType::S8; }
60 };
61
62 template <> struct TypeMapper<int16_t>
63 {
64   static constexpr loco::DataType get() { return loco::DataType::S16; }
65 };
66
67 template <> struct TypeMapper<int32_t>
68 {
69   static constexpr loco::DataType get() { return loco::DataType::S32; }
70 };
71
72 template <> struct TypeMapper<int64_t>
73 {
74   static constexpr loco::DataType get() { return loco::DataType::S64; }
75 };
76
77 } // namespace luci