summaryrefslogtreecommitdiffstats
path: root/src/build/ifcompiler/initScom.H
blob: fa80871164aea267d59e7164c7eb272ec3357f99 (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
// IBM_PROLOG_BEGIN_TAG
// This is an automatically generated prolog.
//
// $Source: /afs/awd/projects/eclipz/KnowledgeBase/.cvsroot/eclipz/ifcompiler/initScom.H,v $
//
// IBM CONFIDENTIAL
//
// COPYRIGHT International Business Machines Corp. 2010,2010
//
//UNDEFINED
//
// Origin: UNDEFINED
//
// IBM_PROLOG_END_TAG
#if !defined(INITSPY_H)
#define INITSPY_H

// Change Log *************************************************************************************
//
//  Flag Track     Userid   Date     Description
//  ----- -------- -------- -------- -------------------------------------------------------------
//         D754106 dgilbert 06/14/10 Create
//  dg002 SW039868 dgilbert 10/15/10 Add support to filter unneeded inits by EC
//  dg003 SW047506 dgilbert 12/09/10 More filtering enhancements
//                 andrewg  05/24/11 Port over for VPL/PgP
//                 andrewg  09/19/11 Updates based on review
// End Change Log *********************************************************************************

/**
 * @file initSpy.H
 * @brief Declairation of the initSpy Class. Represents the information parsed from an initfile spy
 *        statement.
 */

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


using namespace std;

namespace init
{
    typedef vector<string> SCOM_ADDR;
    typedef vector<Rpn> RPN_LIST;
    typedef vector<RPN_LIST> COL_LIST;
    typedef vector<uint32_t> VAR_LIST;
    typedef pair<uint32_t,uint32_t> RANGE;
    typedef vector<RANGE> RANGE_LIST;

    enum SCOM_WHEN
    {
        NONE                = 0x00000000,

        // WHEN= types
        LONG_SCAN           = 0x00000001,
        SCOM                = 0x00000002,
        DRAMINIT            = 0x00000003,
        CFAMINIT            = 0x00000004,
        LAST_WHEN_TYPE      = CFAMINIT,
        WHEN_MASK           = 0x000000FF,

        // WHEN= sub types
        SUBTYPE_MASK        = 0x0000F000,
        HOT_ADD_NODE        = 0x00004000,
        AFTER_HOT_ADD_NODE  = 0x00006000,
        HOT_ADD_GX          = 0x00008000,
        HOT_ADD_GX0         = 0x00007000,
        HOT_ADD_GX1         = 0x00005000,
        AFTER_HOT_ADD_GX    = 0x0000A000,
        AFTER_HOT_ADD_GX0   = 0x00003000,
        AFTER_HOT_ADD_GX1   = 0x00002000,
    };

    const char when_char[] = { '@','L','S','D','C' };

    class Scom
    {
        public:

            enum SPY_TYPE
            {
                NOTYPE,
                ISPY,
                ESPY,
                ARRAY
            };


            Scom(Symbols * i_symbols,uint32_t i_line = 0) :
                iv_symbols(i_symbols),
                iv_line(i_line),
                iv_scom_length(0),
                iv_scom_offset(0),
                iv_when(NONE)        {}

            // Build from binary sequence
            Scom(BINSEQ::const_iterator & bli, Symbols * i_symbols);

            bool compare(Scom & that);
            uint32_t get_when(void)              { return(iv_when); }
            void set_when(SCOM_WHEN i_when)              { iv_when |= (uint32_t)i_when; }
            void set_when(const string * when_str);
            bool do_when(SCOM_WHEN i_when)      { return ((uint32_t)i_when == (WHEN_MASK & iv_when)); }
            void set_sub_when(SCOM_WHEN i_when)          { iv_when |= i_when; }
            void set_when_rpn(const Rpn * i_rpn)        { iv_when_rpn = *i_rpn; delete i_rpn; }
            uint32_t get_line() { return iv_line; }
            void add_scom_rpn(const Rpn * i_rpn)        { iv_scom_rpn.push_back(*i_rpn); delete i_rpn; }



            /**
             * Is when statement valid for this spy
             * @param stats: ostream to print debug information
             * @param ec restriction - true if valid for this ec, 0xffffffff means ANY ec
             * @return false if Rpn for when statement resolves to false, otherwise true
             */
            bool valid_when(ostream & stats, uint32_t i_ec = 0xffffffff);

            void add_col(const string & i_colname);

            /**
             * Add a row rpn to the current column
             * @param pointer to Rpn object
             * @pre add_col()
             */
            void add_row_rpn(Rpn * i_rpn);

            void add_bit_range(uint32_t start, uint32_t end);
            void add_target_range(uint32_t r1, uint32_t r2);
            void make_target(const char * i_symbol);


            uint64_t get_address(void) {return(strtoul(iv_scom_addr[0].c_str(),NULL,16));}
            // string name();
            string listing();

            /**
             * Append binary listing of this Spy
             * @param when [init::LONG_SCAN | init::SCOM]
             * @param BINSEQ binary listing to append
             * @returns uint32_t number of spies added
             */
            uint32_t bin_listing(BINSEQ & blist);

            void set_scom_address(const string & i_scom_addr);
            void dup_scom_address(const string & i_scom_addr);
            void set_scom_suffix(const string & i_scom_addr);

        private:  // functions

            string list_one(RANGE range);
            void bin_list_one(BINSEQ & blist,uint64_t i_addr, RANGE range);

            /**
             * Optimize the row RPNs
             * @note Remove any rows that resolve to unconditionally false.
             */
            void row_optimize();

        private:  // data

          typedef map<string,SCOM_WHEN> WHEN_SUBTYPE_MAP;

            SCOM_ADDR   iv_scom_addr;
            uint64_t    iv_scom_addr_hex;
            uint32_t    iv_scom_length;
            uint32_t    iv_scom_offset;
            RPN_LIST    iv_scom_rpn;            ///< spyv - for each row
            RPN_LIST    iv_col_vars;            ///< RPNs of column name for each column
            COL_LIST    iv_cols_rpn;            ///< A list of row rpn segments one rpn list for each column
            RPN_LIST    iv_row_rpn;             ///< row rpns for current column being parsed.
            RANGE_LIST  iv_range_list;          ///< bit range list
            RANGE_LIST  iv_target_ranges;       ///< target range for current target begin parsed.
            Symbols   * iv_symbols;
            uint32_t    iv_line;                ///< line # in the initfile
            uint32_t    iv_when;
            Rpn         iv_when_rpn;


            static WHEN_SUBTYPE_MAP  cv_when_subtypes;

    };


    //=================================================================================================
    //  SpyList Class declarations
    //=================================================================================================
    // Container to track scoms
    typedef map<uint64_t, init::Scom *> SCOM_LIST;

    class ScomList
    {
        public:
            ScomList(const string & initfile, FILELIST & defines, ostream & stats, uint32_t i_ec = 0xFFFFFFFF);
            ~ScomList();
            //size_t size() { return iv_spy_list.size(); }
            //SPY_LIST::iterator begin() { return iv_spy_list.begin(); }
            //SPY_LIST::iterator end() { return iv_spy_list.end(); }
            void clear();
            void insert(Scom * i_scom);

            void compile(BINSEQ & bin_seq);

            void listing(BINSEQ & bin_seq, ostream & out);

            /**
             * Compare two spylists for equivalance
             * @returns true if equal
             * @note Both spylists should have been built from a binary sequence
             *    not directly from an initfile
             */
            bool compare(ScomList & that);



            void set_cvs_versions(const string * s) { iv_cvs_versions = *s; }
            void set_syntax_version(uint32_t v);
            size_t get_syntax_version() { return iv_syntax_version; }
            void clear_defines() { iv_symbols->clear_defines(); }
            void add_define(const string * name, const Rpn * rpn)
                    { iv_symbols->add_define(name,rpn); }

            Symbols * get_symbols() { return iv_symbols; }

        private: // functions

            string fmt8(uint32_t val);

        private:

              SCOM_LIST iv_scom_list;
              string iv_cvs_versions;
              uint32_t iv_syntax_version;
              Symbols * iv_symbols;
              ostream & iv_stats;
              uint32_t iv_ec;
    };
};
#endif
OpenPOWER on IntegriCloud