summaryrefslogtreecommitdiffstats
path: root/src/build/ifcompiler/initSymbols.H
blob: 68ba70718c3f98689670a6a1670f905f0233b7ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// IBM_PROLOG_BEGIN_TAG
// This is an automatically generated prolog.
//
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/ifcompiler/initSymbols.H,v $
//
// IBM CONFIDENTIAL
//
// COPYRIGHT International Business Machines Corp. 2010,2010
//
//UNDEFINED 
//
// Origin: UNDEFINED
//
// IBM_PROLOG_END_TAG
#if !defined(INITSYMBOLS_H)
#define INITSYMBOLS_H

// Change Log *************************************************************************************
//                                                                      
//  Flag Track     Userid   Date     Description                
//  ---- --------  -------- -------- -------------------------------------------------------------
//       D754106   dgilbert 06/14/10 Create
//                 andrewg  09/19/11 Updates based on review
// End Change Log *********************************************************************************

/**
 * @file initSymbols.H
 * @brief Definition of the initSymbols class. Handles all symbols for initfiles
 */

// Definitions:
// cini_id is the 32 bit symbol tag value of a CINI initfile literal or variable as defined in ciniIfSymbols.H
// rpn_id  is an internal representation used by the Rpn class for all numbers, symbols, Spy enums, etc. that is not an operator
// bin_id  is the 16 bit tag used to represet number, symbols, enums, etc. in the compiled initfile.


#include <stdint.h>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <initRpn.H>

using namespace std;


namespace init
{
    typedef set<string> FILELIST;

    class Symbols
    {
        public:

            enum
            {
                LIT_TYPE        = 0x4000,
                VAR_TYPE        = 0x8000,
                NUM_TYPE        = 0xC000,
                TYPE_MASK       = 0xFFFFC000,
                CINI_LIT_MASK   = 0xA0000000,
                INIT_ANY_LIT    = 0x07FFFFFE,
                INIT_EXPR_VAR   = 0x07FFFFFF,
            };

            enum
            {
                SYM_ATTR_UINT8_TYPE = 0x00,
                SYM_ATTR_UINT32_TYPE = 0x01,
                SYM_ATTR_UINT64_TYPE = 0x02,
                SYM_ATTR_UINT8_ARRAY_TYPE = 0x03,
                SYM_ATTR_UINT32_ARRAY_TYPE = 0x04,
                SYM_ATTR_UINT64_ARRAY_TYPE = 0x05,
            };

            enum 
            {
                NOT_FOUND       = 0x00000000,
                NOT_USED        = 0x00000000,
                CINI_ID_NOT_FOUND = 0x80000000,
            };

            /**
             * Build symbol map for list of files
             * @param List of files to open to build Symbols
             */
            Symbols(FILELIST & i_filenames);

            /**
             * Add a Symbol to the "used" symbol table if not already there
             * @param string Symbols name
             * @returns Symbols Rpn id
             * @post marks the id as 'USED'
             *
             */
            uint32_t use_symbol(string & i_symbol);

            /**
             * Lookup the tag id from the rpn_id provided by use_symbol()
             * @returns tag id
             * @param prn_id
             * @pre  all the symbols have been marked used (no new symbols)
             * @post tag table built if not already built.
             * @note  tag bits 0bttxxxxxx xxxxxxxx
             *               tt == 0b01 ->  enumerated literal
             *               tt == 0b10 ->  Variable name
             *               tt == 0b11 ->  Numeric constant
             *               xxxxxx xxxxxxxx assigned tag offset
             */
            uint16_t get_tag(uint32_t i_rpn_id);

            /**
             * Find the symbol name associated with an rpn_id
             * @param uint32_t rpn_id
             * @returns string Symbol name | "" if not found
             */
            string find_name(uint32_t i_rpn_id);

             /**
             * Find the tag for the numeric lit
             * @param data
             * @param number of significant bytes in the data [1-8]
             * @returns Rpn id
             */
            uint32_t find_numeric_lit(uint64_t i_data, int32_t byte_size);

             /**
             * Find the tag for the numeric array lit
             * @param data
             * @param number of significant bytes in the data [1-8]
             * @returns Rpn id
             */
            uint32_t find_numeric_array_lit(uint64_t i_data, int32_t byte_size);

            /**
             * Convert a numeric literal Rpn tag to an initfile tag
             * @param Rpn id returned by find_numeric_lit
             * @return tag
             * @pre Must not be called until find_numeric_lit() has been called for all numbers
             *      in the initfile.
             */
            uint16_t get_numeric_tag(uint32_t i_rpn_id);

            /**
             * Convert a numeric array literal Rpn tag to an initfile tag
             * @param Rpn id returned by find_numeric_lit
             * @return tag
             * @pre Must not be called until find_numeric_array_lit() has been called for all numbers
             *      in the initfile.
             */
            uint16_t get_numeric_array_tag(uint32_t i_rpn_id);

            /**
             * Get the literal data value from the Rpn id returned by find_numeric_lit()
             * @param uint32_t Rpn id
             * @param uint32_t for returned byte size
             * @returns uint64_t data
             */
            uint64_t get_numeric_data(uint32_t i_rpn_id, uint32_t & o_size);


            /**
             * Store enum name & return rpn_id
             */
            uint32_t use_enum(const string & enumname);
            uint32_t get_spy_enum_id(uint32_t i_rpn_id, const string & spyname);
            string get_enum_name(uint32_t i_rpn_id);

            string get_enumname(uint32_t spy_id);
            string get_spyname(uint32_t spy_id);

            /**
             * Return spy id
             */
            uint32_t get_spy_id(const string & spyname);

            void add_define(const string * name, const Rpn * rpn);
            Rpn get_define_rpn(uint32_t rpn_id);
            void clear_defines() { iv_defines.clear(); }


            string listing();              ///< listing of used vars & lits
            uint32_t bin_vars(BINSEQ & blist);  ///< binary byte output of used vars. ret # vars
            uint32_t bin_lits(BINSEQ & blist);  ///< binary byte sequence of used lits ret # lits

            string full_listing();         ///< listing of all vars & lits (debug)
            string not_found_listing();    ///< listing of all vars searched for, but not found

            /**
             * Get the rpn_id from an initfile binary tag
             */
            uint32_t get_rpn_id(uint32_t bin_tag);


            /**
             * Restore used symbol lists from binary sequence
             * @returns number of symbols
             */
            uint32_t restore_var_bseq(BINSEQ::const_iterator & bli);
            uint32_t restore_lit_bseq(BINSEQ::const_iterator & bli);

            /**
             * Test that all spies in this object are a subset of the object provided
             * @param Symbols object to compare against
             * @return string will all error messages. Empty string indicates success.
             */
            string spies_are_in(Symbols & i_full_list, const set<string> & i_ignore_spies);

            static void translate_spyname(string & s)
            { 
                for(string::iterator i = s.begin(); i != s.end(); ++i)
                    if((*i) == '.' || (*i) == '#' ||
                       (*i) == '=' || (*i) == '&' ||
                       (*i) == '<' || (*i) == '>' ||
                       (*i) == '!' || (*i) == '*' ||
                       (*i) == '/' || (*i) == '%' ||
                       (*i) == '$')                      *i = '_';
                    else *i = toupper(*i);
            }

        private:  // functions

            string find_text(uint32_t i_cini_id);
            uint32_t add_undefined(const string & s);
            uint32_t get_attr_type(const string &i_type, bool i_array);

        private: //data

            //   map | symbol name | (cini_id, usage flags) |
            typedef pair<uint32_t,uint32_t> MAP_DATA;
            typedef map<string,MAP_DATA > SYMBOL_MAP;
            typedef map<string,uint32_t> SPY_MAP;
            typedef map<string,uint32_t> SYMBOL_ATTR_TYPE;

            typedef pair<Rpn,uint32_t> DEF_DATA;
            typedef map<string,DEF_DATA> DEF_MAP;

            typedef pair<string,uint32_t>  RPN_DATA;
            typedef map<uint32_t,RPN_DATA> RPN_MAP;

            typedef vector<uint32_t>  SYMBOL_USED;

            typedef pair<uint64_t,uint32_t> LIT_DATA;
            typedef vector<LIT_DATA> LIT_LIST;

            SYMBOL_MAP  iv_symbols;     ///< From ciniIfSymbols.H all vars and enumerated lits
            SYMBOL_ATTR_TYPE iv_attr_type;
            SYMBOL_MAP  iv_not_found;   ///< List of symbols not found
            RPN_MAP     iv_rpn_map;     ///< Map rpn_id to symbol name/cini_id of used Symbols
            SYMBOL_USED iv_used_var;    ///< List of cini_ids of used vars ordered by name
            SYMBOL_USED iv_used_lit;    ///< List of cini_ids of used enum lits ordered by name

            LIT_LIST iv_lits;           ///< Numeric literals

            SPY_MAP iv_spymap;          ///< Spies & arrays & enum spies
            SPY_MAP iv_enums;           ///< Spy enums

            DEF_MAP iv_defines;         ///< defines

            uint32_t iv_used_var_count;
            uint32_t iv_used_lit_count;
            uint32_t iv_rpn_id;         ///< Current rpn offset assignment
    };
};


#endif
OpenPOWER on IntegriCloud