]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: GenPatchPcdTable - refactor RegEx to minimize multiple compiling
authorCarsey, Jaben <jaben.carsey@intel.com>
Fri, 20 Apr 2018 15:51:22 +0000 (23:51 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Thu, 26 Apr 2018 06:27:59 +0000 (14:27 +0800)
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
BaseTools/Source/Python/GenPatchPcdTable/GenPatchPcdTable.py

index dc2ceaf775d88c5a179930c4430ee74212aa5307..59748763a553d2711470f4b06879767a95055330 100644 (file)
@@ -63,6 +63,7 @@ def parsePcdInfoFromMapFile(mapfilepath, efifilepath):
     return _parseGeneral(lines, efifilepath)\r
 \r
 def _parseForXcode(lines, efifilepath):\r
+    valuePattern = re.compile('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))')\r
     status = 0\r
     pcds = []\r
     for line in lines:\r
@@ -72,13 +73,16 @@ def _parseForXcode(lines, efifilepath):
             continue\r
         if status == 1 and len(line) != 0:\r
             if '_gPcd_BinaryPatch_' in line:\r
-                m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*_gPcd_BinaryPatch_([\w]+))', line)\r
+                m = valuePattern.match(line)\r
                 if m is not None:\r
                     pcds.append((m.groups(0)[3], int(m.groups(0)[0], 16)))\r
     return pcds\r
 \r
 def _parseForGCC(lines, efifilepath):\r
     """ Parse map file generated by GCC linker """\r
+    valuePattern = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')\r
+    dataPattern = re.compile('^.data._gPcd_BinaryPatch_([\w_\d]+)$')\r
+    pcdPattern = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')\r
     status = 0\r
     imageBase = -1\r
     sections = []\r
@@ -98,15 +102,15 @@ def _parseForGCC(lines, efifilepath):
 \r
         # status handler\r
         if status == 3:\r
-            m = re.match('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$', line)\r
+            m = valuePattern.match(line)\r
             if m is not None:\r
                 sections.append(m.groups(0))\r
         if status == 3:\r
-            m = re.match('^.data._gPcd_BinaryPatch_([\w_\d]+)$', line)\r
+            m = dataPattern.match(line)\r
             if m is not None:\r
                 if lines[index + 1]:\r
                     PcdName = m.groups(0)[0]\r
-                    m = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', lines[index + 1].strip())\r
+                    m = pcdPattern.match(lines[index + 1].strip())\r
                     if m is not None:\r
                         bpcds.append((PcdName, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))\r
                 \r
@@ -137,17 +141,19 @@ def _parseGeneral(lines, efifilepath):
     status = 0    #0 - beginning of file; 1 - PE section definition; 2 - symbol table\r
     secs = []    # key = section name\r
     bPcds = []\r
-\r
+    startPattern = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")\r
+    addressPattern = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")\r
+    symPattern = re.compile('^[_]+gPcd_BinaryPatch_([\w]+)')\r
 \r
     for line in lines:\r
         line = line.strip()\r
-        if re.match("^Start[' ']+Length[' ']+Name[' ']+Class", line):\r
+        if startPattern.match(line):\r
             status = 1\r
             continue\r
-        if re.match("^Address[' ']+Publics by Value[' ']+Rva\+Base", line):\r
+        if addressPattern.match(line):\r
             status = 2\r
             continue\r
-        if re.match("^entry point at", line):\r
+        if line.startswith("entry point at"):\r
             status = 3\r
             continue\r
         if status == 1 and len(line) != 0:\r
@@ -162,7 +168,7 @@ def _parseGeneral(lines, efifilepath):
             sec_no = int(sec_no, 16)\r
             sym_offset = int(sym_offset, 16)\r
             vir_addr = int(vir_addr, 16)\r
-            m2 = re.match('^[_]+gPcd_BinaryPatch_([\w]+)', sym_name)\r
+            m2 = symPattern.match(sym_name)\r
             if m2 is not None:\r
                 # fond a binary pcd entry in map file\r
                 for sec in secs:\r