]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Misc - refactor RegEx to minimize multiple compiling
authorCarsey, Jaben <jaben.carsey@intel.com>
Fri, 20 Apr 2018 15:51:21 +0000 (23:51 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Thu, 26 Apr 2018 06:27:58 +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/Common/Misc.py

index 60ae98c550a8e940566b8e7e17157a32991b861b..641506a07d4ec8f95903820c650ebfb7cb8d4fa1 100644 (file)
@@ -84,6 +84,7 @@ def _parseForXcode(lines, efifilepath, varnames):
         if status == 1 and len(line) != 0:\r
             for varname in varnames:\r
                 if varname in line:\r
+                    # cannot pregenerate this RegEx since it uses varname from varnames.\r
                     m = re.match('^([\da-fA-FxX]+)([\s\S]*)([_]*%s)$' % varname, line)\r
                     if m is not None:\r
                         ret.append((varname, m.group(1)))\r
@@ -91,6 +92,8 @@ def _parseForXcode(lines, efifilepath, varnames):
 \r
 def _parseForGCC(lines, efifilepath, varnames):\r
     """ Parse map file generated by GCC linker """\r
+    valuePattern = re.compile('^([\w_\.]+) +([\da-fA-Fx]+) +([\da-fA-Fx]+)$')\r
+    pcdPattern = re.compile('^([\da-fA-Fx]+) +([\da-fA-Fx]+)')\r
     status = 0\r
     sections = []\r
     varoffset = []\r
@@ -109,7 +112,7 @@ def _parseForGCC(lines, efifilepath, varnames):
 \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
             for varname in varnames:\r
@@ -122,7 +125,7 @@ def _parseForGCC(lines, efifilepath, varnames):
                     else:\r
                         Str = line[len(".data.%s" % varname):]\r
                     if Str:\r
-                        m = re.match('^([\da-fA-Fx]+) +([\da-fA-Fx]+)', Str.strip())\r
+                        m = pcdPattern.match(Str.strip())\r
                         if m is not None:\r
                             varoffset.append((varname, int(m.groups(0)[0], 16) , int(sections[-1][1], 16), sections[-1][0]))\r
 \r
@@ -152,16 +155,18 @@ def _parseGeneral(lines, efifilepath, varnames):
     varoffset = []\r
     secRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\da-fA-F]+)[Hh]? +([.\w\$]+) +(\w+)', re.UNICODE)\r
     symRe = re.compile('^([\da-fA-F]+):([\da-fA-F]+) +([\.:\\\\\w\?@\$]+) +([\da-fA-F]+)', re.UNICODE)\r
+    startRe = re.compile("^Start[' ']+Length[' ']+Name[' ']+Class")\r
+    addressRe = re.compile("^Address[' ']+Publics by Value[' ']+Rva\+Base")\r
 \r
     for line in lines:\r
         line = line.strip()\r
-        if re.match("^Start[' ']+Length[' ']+Name[' ']+Class", line):\r
+        if startRe.match(line):\r
             status = 1\r
             continue\r
-        if re.match("^Address[' ']+Publics by Value[' ']+Rva\+Base", line):\r
+        if addressRe.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
@@ -177,6 +182,7 @@ def _parseGeneral(lines, efifilepath, varnames):
                 sec_no     = int(sec_no,     16)\r
                 sym_offset = int(sym_offset, 16)\r
                 vir_addr   = int(vir_addr,   16)\r
+                # cannot pregenerate this RegEx since it uses varname from varnames.\r
                 m2 = re.match('^[_]*(%s)' % varname, sym_name)\r
                 if m2 is not None:\r
                     # fond a binary pcd entry in map file\r