1 /*
2  * Copyright (c) 2018, 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 
18 #ifndef DTYPEUTL_H_
19 #define DTYPEUTL_H_
20 
21 #include "gbldefs.h"
22 #include "error.h"
23 #include "global.h"
24 #include "symtab.h"
25 #include <stdio.h>
26 
27 /**
28    \brief ...
29  */
30 ISZ_T ad_val_of(int sym);
31 
32 /**
33    \brief ...
34  */
35 ISZ_T extent_of(DTYPE dtype);
36 
37 /// \brief Given a constant symbol, return its numerical value.
38 ISZ_T get_bnd_cval(int con);
39 
40 /**
41    \brief ...
42  */
43 ISZ_T size_of(DTYPE dtype);
44 
45 /**
46    \brief ...
47  */
48 ISZ_T size_of_sym(SPTR sym);
49 
50 /**
51    \brief ...
52  */
53 ISZ_T zsize_of(DTYPE dtype);
54 
55 /**
56  * \brief Return true if the data types for two functions are compatible.
57  *
58  * Two functions are compatible if a single local variable can be used to hold
59  * their return values and therefore implying that the same return mechanism can
60  * be used for the functions.
61  *
62  */
63 bool cmpat_func(DTYPE d1, DTYPE d2);
64 
65 /**
66    \brief ...
67  */
68 bool is_array_dtype(DTYPE dtype);
69 
70 /** Check for special case of empty typedef which has a size of 0
71  * but one member of type DT_NONE to indicate that the type is
72  * empty and not incomplete, a forward reference, etc.
73  */
74 bool is_empty_typedef(DTYPE dtype);
75 
76 /**
77    \brief ...
78  */
79 bool no_data_components(DTYPE dtype);
80 
81 /**
82    \brief if array datatype, returns the element dtype, else returns dtype
83  */
84 DTYPE array_element_dtype(DTYPE dtype);
85 
86 /**
87    \brief ...
88  */
89 DTYPE get_array_dtype(int numdim, DTYPE eltype);
90 
91 /**
92    \brief ...
93  */
94 DTYPE get_type(int n, TY_KIND v1, int v2);
95 
96 /**
97    \brief ...
98  */
99 DTYPE get_vector_dtype(DTYPE dtype, int n);
100 
101 /**
102    \brief ...
103  */
104 int alignment(DTYPE dtype);
105 
106 /**
107    \brief ...
108  */
109 int alignment_sym(SPTR sym);
110 
111 /**
112    \brief Support the alignof operator
113    \param dtype
114  */
115 int align_of(DTYPE dtype);
116 
117 /**
118    \brief ...
119  */
120 int align_unconstrained(DTYPE dtype);
121 
122 /**
123    \brief Return the length
124    \param dty
125    Length, in stb.dt_base words, of each type of datatype entry
126  */
127 int dlen(TY_KIND dty);
128 
129 /**
130    \brief ...
131  */
132 int dmp_dent(DTYPE dtypeind);
133 
134 /**
135  * \brief Get FVAL field of a data type
136  * \return 0 if reg, 1 if mem.
137  */
138 int fval_of(DTYPE dtype);
139 
140 /**
141    \brief Create a constant sym entry which reflects the type of an array
142    bound/extent.
143  */
144 int get_bnd_con(ISZ_T v);
145 
146 /**
147    \brief Extract necessary bytes from character string in order to return
148    integer (16-bit) representation of one kanji char.
149    \param p the character string
150    \param len number of bytes in string p
151    \return number of EUC bytes used up
152  */
153 int kanji_char(unsigned char *p, int len, int *bytes);
154 
155 /**
156    \brief Get number of kanji characters
157    \param length Length in bytes of character string
158  */
159 int kanji_len(unsigned char *p, int len);
160 
161 /**
162  * \brief Get number of bytes needed for kanji characters in string prefix
163  * \param p ptr to EUC string
164  * \param newlen number of kanji chars required from string prefix
165  * \param len total number of bytes in string
166  * \return number of bytes required for newlen chars
167  */
168 int kanji_prefix(unsigned char *p, int newlen, int len);
169 
170 /**
171  * \brief Compute the size of a data type
172  * \param dtype
173  * \param size    number of elements in the data type [output]
174  * \return number of bytes in each element, expressed as a power of two (scale)
175  *
176  * This machine dependent routine computes the size of a data type in terms of
177  * two quantities: the size and the scale
178  *
179  *  This routine will be used to take advantage of the machines that
180  *  have the ability to add a scaled expression (multiplied by a power
181  *  of two) to an address.  This is particularly useful for incrementing
182  *  a pointer variable and array subscripting.
183  *
184  *  Note that for those machines that do not have this feature, scale_of
185  *  returns a scale of 0 and size_of for size.
186  */
187 int Scale_Of(DTYPE dtype, ISZ_T *size);
188 
189 /**
190    \brief ...
191  */
192 int scale_of(DTYPE dtype, INT *size);
193 
194 /**
195    \brief ...
196  */
197 void dmp_dtype(void);
198 
199 /**
200  * \brief Put into the character array pointed to by ptr, the print
201  * representation of dtype.
202  */
203 void getdtype(DTYPE dtype, char *ptr);
204 
205 /**
206    \brief ...
207  */
208 void init_chartab(void);
209 
210 /**
211    \brief ...
212  */
213 void Restore_Chartab(FILE *fil);
214 
215 /**
216    \brief ...
217  */
218 void Save_Chartab(FILE *fil);
219 
220 int kanji_char(unsigned char*, int, int*);
221 int kanji_len(unsigned char *, int);
222 
223 #endif
224