Debian Codegraph @

visa/iga/GEDLibrary/GED_external/Source/ged/xcoder/ged_interpreters.cpp

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2017-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #include "common/ged_base.h"
10 #include "xcoder/ged_internal_api.h"
11 #include "xcoder/ged_restrictions_handler.h"
12 #include "xcoder/ged_interpreters.h"
13
14
15 /*************************************************************************************************
16 * class GEDInterpreter static API functions
17 *************************************************************************************************/
18
19 uint64_t GEDInterpreter::InterpretPositionInternal(uint64_t value, /* GED_PSEUDO_FIELD */ const uint32_t interpId,
20 const /* GED_MODEL */ uint8_t modelId, const GED_VALUE_TYPE valueType,
21 GED_RETURN_VALUE& ret)
22 {
23 const ModelData& modelData = ModelsArray[modelId];
24 if ((NULL == modelData.pseudoFields) || (interpId >= modelData.numberOfPseudoFields))
25 {
26 ret = GED_RETURN_VALUE_INVALID_INTERPRETER;
27 return value;
28 }
29 const ged_ins_field_entry_t& dataEntry = modelData.pseudoFields[interpId];
30 if (GED_TABLE_ENTRY_TYPE_NOT_SUPPORTED == dataEntry._entryType)
31 {
32 ret = GED_RETURN_VALUE_INVALID_INTERPRETER;
33 return value;
34 }
35 ret = GED_RETURN_VALUE_SUCCESS; // if the interpreter is valid, extracting the value is bound to succeed
36 GEDASSERT(GED_TABLE_ENTRY_TYPE_CONSECUTIVE == dataEntry._entryType);
37 value &= dataEntry._consecutive._position._bitMask;
38 GEDASSERT(dataEntry._consecutive._position._shift >= 0);
39 value >>= dataEntry._consecutive._position._shift;
40 if (GED_VALUE_TYPE_ENCODED == valueType) return value;
41 GEDASSERT(GED_VALUE_TYPE_PROCESSED == valueType);
42 value = GEDRestrictionsHandler::HandleDecodingRestrictions(&dataEntry, value, ret);
43 return value;
44 }
45
46
47 GED_RETURN_VALUE GEDInterpreter::SetInterpretedPositionInternal(uint64_t& writeTo, /* GED_PSEUDO_FIELD */ const uint32_t interpId,
48 const /* GED_MODEL */ uint8_t modelId, const GED_VALUE_TYPE valueType,
49 uint64_t valueToWrite)
50 {
51 const ModelData& modelData = ModelsArray[modelId];
52 GEDASSERT(interpId < modelData.numberOfPseudoFields);
53 if (NULL == modelData.pseudoFields) return GED_RETURN_VALUE_INVALID_INTERPRETER;
54
55 const ged_ins_field_entry_t& dataEntry = modelData.pseudoFields[interpId];
56 if (GED_TABLE_ENTRY_TYPE_NOT_SUPPORTED == dataEntry._entryType) return GED_RETURN_VALUE_INVALID_INTERPRETER;
57 GEDASSERT(GED_TABLE_ENTRY_TYPE_CONSECUTIVE == dataEntry._entryType);
58 GEDASSERT(dataEntry._consecutive._position._shift >= 0);
59
60 if (!GEDRestrictionsHandler::HandleEncodingRestrictions(&dataEntry, valueType, valueToWrite))
61 {
62 return GED_RETURN_VALUE_INVALID_VALUE;
63 }
64 // Shift the value into position.
65 valueToWrite <<= dataEntry._consecutive._position._shift;
66
67 // Clear the field in the destination.
68 writeTo &= ~dataEntry._consecutive._position._bitMask;
69
70 // No need to apply mask to valueToWrite, as it's always unsigned. If was signed, applying the mask was required (for negatives)
71
72 // Now set the field with the value itself.
73 writeTo |= valueToWrite;
74 return GED_RETURN_VALUE_SUCCESS;
75 }
76
77
78 /*************************************************************************************************
79 * class GEDInterpreter API functions
80 *************************************************************************************************/
81
82 uint32_t GEDInterpreter::ReinterpretEnum(uint32_t value, /* GED_REINTERPRETED_ENUM */ const uint32_t interpId,
83 const /* GED_MODEL */ uint8_t modelId, GED_RETURN_VALUE& ret)
84 {
85 const ModelData& modelData = ModelsArray[modelId];
86 GEDASSERT(interpId < modelData.numberOfReinterpretedEnums);
87 GEDASSERT(NULL != modelData.reinterpretedEnums);
88 if (NULL == modelData.reinterpretedEnums[interpId])
89 {
90 ret = GED_RETURN_VALUE_INVALID_INTERPRETER;
91 return value;
92 }
93 if (NULL == modelData.reinterpretedEnums[interpId][value])
94 {
95 ret = GED_RETURN_VALUE_INVALID_VALUE;
96 return value;
97 }
98 ret = GED_RETURN_VALUE_SUCCESS;
99 return *(modelData.reinterpretedEnums[interpId][value]);
100 }
101
102
103 uint32_t GEDInterpreter::CollectFields(GEDIns& ins, /* GED_COLLECTOR */ const uint32_t interpId, GED_RETURN_VALUE& ret)
104 {
105 const ModelData& modelData = ModelsArray[ins.GetCurrentModel()];
106 GEDASSERT(interpId < modelData.numberOfCollectors);
107 if (NULL == modelData.collectionTables || NULL == modelData.collectionTables[interpId]._table)
108 {
109 ret = GED_RETURN_VALUE_INVALID_INTERPRETER;
110 return MAX_UINT32_T;
111 }
112
113 GEDASSERT(0 != modelData.collectionTables[interpId]._numberOfFields);
114 uint32_t collectedValue = 0; // this will hold the collected value
115 for (unsigned int m = 0; m < modelData.collectionTables[interpId]._numberOfFields; ++m)
116 {
117 const ged_compact_mapping_entry_t& entry = modelData.collectionTables[interpId]._table[m];
118 if (GED_MAPPING_TABLE_ENTRY_TYPE_VALUE_MAPPING_CONSECUTIVE == entry._entryType)
119 {
120 uint32_t fieldRawValue = ins.GetRawField(entry._field, ret); // get the current field-raw-value to be collected
121 if (GED_RETURN_VALUE_SUCCESS != ret) return MAX_UINT32_T;
122 fieldRawValue &= entry._consecutive._fromMask;
123 GEDASSERT(0 == entry._consecutive._to._dwordIndex); // only 32-bit values are allowed
124 GEDASSERT(0 <= entry._consecutive._to._shift); // only left shifts are expected since the source is right-shifted to zero
125 fieldRawValue <<= entry._consecutive._to._shift;
126 collectedValue |= fieldRawValue;
127 }
128 else if (GED_MAPPING_TABLE_ENTRY_TYPE_VALUE_MAPPING_FRAGMENTED == entry._entryType)
129 {
130 const uint32_t fieldRawValue = ins.GetRawField(entry._field, ret); // get the current field-raw-value to be collected
131 if (GED_RETURN_VALUE_SUCCESS != ret) return MAX_UINT32_T;
132 for (uint32_t f = 0; f < entry._fragmented._numOfMappingFragments; ++f)
133 {
134 const ged_compact_mapping_fragment_t& fragment = entry._fragmented._fragments[f];
135 GEDASSERT(GED_COMPACT_MAPPING_TYPE_1x1 == fragment._mappingType);
136 GEDASSERT(0 == fragment._from._dwordIndex); // only 32-bit values are allowed
137 GEDASSERT(0 == fragment._to._dwordIndex); // only 32-bit values are allowed
138 uint32_t fragmentRawValue = fieldRawValue & fragment._from._bitMask;
139 const int8_t shift = fragment._from._shift - fragment._to._shift;
140 if (shift > 0)
141 {
142 fragmentRawValue >>= shift;
143 }
144 else
145 {
146 fragmentRawValue <<= shift;
147 }
148 collectedValue |= fragmentRawValue;
149 }
150 }
151 else
152 {
153 GEDASSERT(0); // only explicit mappings are allowed
154 }
155 }
156 return collectedValue;
157 }