• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2 * Copyright (C) 2015-2017 Intel Corporation.   All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * @file ${filename}.h
24 *
25 * @brief Dynamic Knobs for Core.
26 *
27 * ======================= AUTO GENERATED: DO NOT EDIT !!! ====================
28 *
29 * Generation Command Line:
30 *  ${'\n*    '.join(cmdline)}
31 *
32 ******************************************************************************/
33 <% calc_max_knob_len(knobs) %>
34 #pragma once
35 #include <string>
36 
37 struct KnobBase
38 {
39 private:
40     // Update the input string.
41     static void autoExpandEnvironmentVariables(std::string &text);
42 
43 protected:
44     // Leave input alone and return new string.
expandEnvironmentVariablesKnobBase45     static std::string expandEnvironmentVariables(std::string const &input)
46     {
47         std::string text = input;
48         autoExpandEnvironmentVariables(text);
49         return text;
50     }
51 
52     template <typename T>
expandEnvironmentVariablesKnobBase53     static T expandEnvironmentVariables(T const &input)
54     {
55         return input;
56     }
57 };
58 
59 template <typename T>
60 struct Knob : KnobBase
61 {
62 public:
ValueKnob63     const   T&  Value() const               { return m_Value; }
ValueKnob64     const   T&  Value(T const &newValue)
65     {
66         m_Value = expandEnvironmentVariables(newValue);
67         return Value();
68     }
69 
70 private:
71     T m_Value;
72 };
73 
74 #define DEFINE_KNOB(_name, _type, _default)                     \\
75 
76     struct Knob_##_name : Knob<_type>                           \\
77 
78     {                                                           \\
79 
Name_name80         static const char* Name() { return "KNOB_" #_name; }    \\
81 
DefaultValue_name82         static _type DefaultValue() { return (_default); }      \\
83 
84     } _name;
85 
86 #define GET_KNOB(_name)             g_GlobalKnobs._name.Value()
87 #define SET_KNOB(_name, _newValue)  g_GlobalKnobs._name.Value(_newValue)
88 
89 struct GlobalKnobs
90 {
91     % for knob in knobs:
92     //-----------------------------------------------------------
93     // KNOB_${knob[0]}
94     //
95     % for line in knob[1]['desc']:
96     // ${line}
97     % endfor
98     % if knob[1].get('choices'):
99     <%
100     choices = knob[1].get('choices')
101     _max_len = calc_max_name_len(choices) %>//
102     % for i in range(len(choices)):
103     //     ${choices[i]['name']}${space_name(choices[i]['name'], _max_len)} = ${format(choices[i]['value'], '#010x')}
104     % endfor
105     % endif
106     //
107     % if knob[1]['type'] == 'std::string':
108     DEFINE_KNOB(${knob[0]}, ${knob[1]['type']}, "${repr(knob[1]['default'])[1:-1]}");
109     % else:
110     DEFINE_KNOB(${knob[0]}, ${knob[1]['type']}, ${knob[1]['default']});
111     % endif
112 
113     % endfor
114 
115     std::string ToString(const char* optPerLinePrefix="");
116     GlobalKnobs();
117 };
118 extern GlobalKnobs g_GlobalKnobs;
119 
120 #undef DEFINE_KNOB
121 
122 % for knob in knobs:
123 #define KNOB_${knob[0]}${space_knob(knob[0])} GET_KNOB(${knob[0]})
124 % endfor
125 
126 <%!
127     # Globally available python
128     max_len = 0
129     def calc_max_knob_len(knobs):
130         global max_len
131         max_len = 0
132         for knob in knobs:
133             if len(knob[0]) > max_len: max_len = len(knob[0])
134         max_len += len('KNOB_ ')
135         if max_len % 4: max_len += 4 - (max_len % 4)
136 
137     def space_knob(knob):
138         knob_len = len('KNOB_' + knob)
139         return ' '*(max_len - knob_len)
140 
141     def calc_max_name_len(choices_array):
142         _max_len = 0
143         for choice in choices_array:
144             if len(choice['name']) > _max_len: _max_len = len(choice['name'])
145 
146         if _max_len % 4: _max_len += 4 - (_max_len % 4)
147         return _max_len
148 
149     def space_name(name, max_len):
150         name_len = len(name)
151         return ' '*(max_len - name_len)
152 %>
153