MatchLib
UIntOrEmpty.h
1 /*
2  * Copyright (c) 2017-2019, NVIDIA CORPORATION. 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 #ifndef _UINTOREMPTY_H_
18 #define _UINTOREMPTY_H_
19 
20 #include <systemc>
21 #include <nvhls_int.h>
22 #include <nvhls_types.h>
23 #include <nvhls_assert.h>
24 #include <nvhls_message.h>
25 
27 // Provides an NVUINT field that can also be of width = 0
28 // May eventually integrate this more into Connections marshaller
29 
30 namespace nvhls {
31 
35 struct EmptyField : public nvhls_message {
36  template <typename T>
37  EmptyField operator=(T const &) {
38  NVHLS_ASSERT_MSG(true,"EmptyField should never be assigned or accessed"); // If an assignment actually occurs during runtime
39  // you've done something wrong
40  return EmptyField();
41  }
42  uint64 to_uint64() { return 0; }
43  const sc_bit operator[](std::size_t idx) const { return static_cast<sc_bit>(0); }
44 };
45 
46 /* Operator << for EmptyField. */
47 inline std::ostream &operator<<(ostream &os, const EmptyField &empty) {
48  return os << "EMPTYFIELD";
49 }
50 
51 /* Operator & for Marshaller and EmptyField. */
52 template <unsigned int Size>
53 Marshaller<Size> &operator&(Marshaller<Size> &m, EmptyField &rhs) {
54  return m; // just do nothing
55 }
56 
60 template <bool, int W>
62 
66 template <int W>
67 class UIntOrEmptywCheck<true, W> {
68  public:
69  typedef NVUINTW(W) T;
70 };
71 
75 template <int W>
76 class UIntOrEmptywCheck<false, W> {
77  public:
78  typedef EmptyField T;
79 };
80 
92 template <int W>
93 class UIntOrEmpty {
94  public:
95  typedef typename UIntOrEmptywCheck<(W > 0), W>::T T;
96 };
97 
98 };
99 
101 
102 #endif
103 
NVUINTW(Wrapped< T >::width) TypeToNVUINT(T in)
Convert Type to NVUINT.
Definition: TypeToBits.h:115
A class to determine whether to instantiate an NVUINT or an EmptyField.
Definition: UIntOrEmpty.h:61
The EmptyField class is used for rudimentary support for members of a struct that can be configured t...
Definition: UIntOrEmpty.h:35
#define NVHLS_ASSERT_MSG(X, MSG)
Definition: nvhls_assert.h:116
The UIntOrEmpty class is used to define a bitvector that can have a bitwidth of 0.
Definition: UIntOrEmpty.h:93