diff options
author | Kinney, Michael D <michael.d.kinney@intel.com> | 2018-02-20 20:08:32 -0800 |
---|---|---|
committer | Yonghong Zhu <yonghong.zhu@intel.com> | 2018-02-25 16:03:14 +0800 |
commit | 8bd72d7c05ff820ee7826809a033fda9b007d18f (patch) | |
tree | d3fab27586f5950534cc971734b520845be7a86a /BaseTools/Source/Python/Common | |
parent | ebfca258f5d7ab59cd1b72ad56f1de0e7a138ba9 (diff) | |
download | edk2-8bd72d7c05ff820ee7826809a033fda9b007d18f.tar.gz edk2-8bd72d7c05ff820ee7826809a033fda9b007d18f.tar.bz2 edk2-8bd72d7c05ff820ee7826809a033fda9b007d18f.zip |
BaseTools/Expression: Use 2nd passes on PCD values
Use 2 passes when evaluating PCD values to discover
all the LABEL() operators and compute the byte offset
of each LABEL(). The 2nd pass then has the information
to replace the OFFSET_OF() operator with the computed
byte offset. The 2 passes allows OFFSET_OF() to be used
before a LABEL() is declared.
fixes:https://bugzilla.tianocore.org/show_bug.cgi?id=880
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
Diffstat (limited to 'BaseTools/Source/Python/Common')
-rw-r--r-- | BaseTools/Source/Python/Common/Expression.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/BaseTools/Source/Python/Common/Expression.py b/BaseTools/Source/Python/Common/Expression.py index 74d1b08f76..28320d78a9 100644 --- a/BaseTools/Source/Python/Common/Expression.py +++ b/BaseTools/Source/Python/Common/Expression.py @@ -827,6 +827,30 @@ class ValueExpressionEx(ValueExpression): LabelDict = {}
ReLabel = re.compile('LABEL\((\w+)\)')
ReOffset = re.compile('OFFSET_OF\((\w+)\)')
+ LabelOffset = 0
+ for Index, Item in enumerate(ListItem):
+ # compute byte offset of every LABEL
+ Item = Item.strip()
+ try:
+ LabelList = ReLabel.findall(Item)
+ for Label in LabelList:
+ if Label not in LabelDict.keys():
+ LabelDict[Label] = str(LabelOffset)
+ Item = ReLabel.sub('', Item)
+ except:
+ pass
+ if Item.startswith('UINT8'):
+ LabelOffset = LabelOffset + 1
+ elif Item.startswith('UINT16'):
+ LabelOffset = LabelOffset + 2
+ elif Item.startswith('UINT32'):
+ LabelOffset = LabelOffset + 4
+ elif Item.startswith('UINT64'):
+ LabelOffset = LabelOffset + 8
+ else:
+ ItemValue, ItemSize = ParseFieldValue(Item)
+ LabelOffset = LabelOffset + ItemSize
+
for Index, Item in enumerate(ListItem):
# for LABEL parse
Item = Item.strip()
@@ -847,7 +871,7 @@ class ValueExpressionEx(ValueExpression): Re = re.compile('OFFSET_OF\(%s\)'% Offset)
Item = Re.sub(LabelDict[Offset], Item)
else:
- raise BadExpression('%s not defined before use' % Offset)
+ raise BadExpression('%s not defined' % Offset)
ValueType = ""
if Item.startswith('UINT8'):
ItemSize = 1
|