public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] BaseTools/Expression: Use 2nd passes on PCD values
@ 2018-02-24  2:13 Yonghong Zhu
  2018-02-24  7:24 ` Zhu, Yonghong
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Zhu @ 2018-02-24  2:13 UTC (permalink / raw)
  To: edk2-devel; +Cc: Kinney, Michael D

From: "Kinney, Michael D" <michael.d.kinney@intel.com>

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.
---
 BaseTools/Source/Python/Common/Expression.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

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
-- 
2.14.2.windows.3



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] BaseTools/Expression: Use 2nd passes on PCD values
  2018-02-24  2:13 [PATCH] BaseTools/Expression: Use 2nd passes on PCD values Yonghong Zhu
@ 2018-02-24  7:24 ` Zhu, Yonghong
  0 siblings, 0 replies; 2+ messages in thread
From: Zhu, Yonghong @ 2018-02-24  7:24 UTC (permalink / raw)
  To: Zhu, Yonghong, edk2-devel@lists.01.org; +Cc: Kinney, Michael D, Zhu, Yonghong

Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com> 

Best Regards,
Zhu Yonghong


-----Original Message-----
From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Yonghong Zhu
Sent: Saturday, February 24, 2018 10:14 AM
To: edk2-devel@lists.01.org
Cc: Kinney, Michael D <michael.d.kinney@intel.com>
Subject: [edk2] [PATCH] BaseTools/Expression: Use 2nd passes on PCD values

From: "Kinney, Michael D" <michael.d.kinney@intel.com>

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.
---
 BaseTools/Source/Python/Common/Expression.py | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

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
--
2.14.2.windows.3

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-24  7:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-02-24  2:13 [PATCH] BaseTools/Expression: Use 2nd passes on PCD values Yonghong Zhu
2018-02-24  7:24 ` Zhu, Yonghong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox