Fixed tracker 717 to use the constructor/destructor according to the library's type.
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 5 Dec 2007 06:37:41 +0000 (06:37 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 5 Dec 2007 06:37:41 +0000 (06:37 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@907 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/AutoGen/GenC.py

index 3256cb9..392d2fa 100644 (file)
@@ -651,45 +651,55 @@ ${END}
 """\r
 ]\r
 \r
-## Library Constructor and Destructor Templates\r
-gLibraryString = [\r
-"""\r
-VOID\r
+gLibraryStructorPrototype = {\r
+'BASE'  : """${BEGIN}\r
+EFI_STATUS\r
 EFIAPI\r
-ProcessLibrary${Type}List (\r
+${Function} (\r
   VOID\r
-  )\r
-{\r
-}\r
+  );${END}\r
 """,\r
-"""\r
-VOID\r
+\r
+'PEI'   : """${BEGIN}\r
+EFI_STATUS\r
 EFIAPI\r
-ProcessLibrary${Type}List (\r
+${Function} (\r
   IN EFI_PEI_FILE_HANDLE       FileHandle,\r
   IN EFI_PEI_SERVICES          **PeiServices\r
-  )\r
-{\r
-}\r
+  );${END}\r
 """,\r
-"""\r
-VOID\r
+\r
+'DXE'   : """${BEGIN}\r
+EFI_STATUS\r
 EFIAPI\r
-ProcessLibrary${Type}List (\r
+${Function} (\r
   IN EFI_HANDLE        ImageHandle,\r
   IN EFI_SYSTEM_TABLE  *SystemTable\r
-  )\r
-{\r
+  );${END}\r
+""",\r
 }\r
+\r
+gLibraryStructorCall = {\r
+'BASE'  : """${BEGIN}\r
+  Status = ${Function} ();\r
+  ASSERT_EFI_ERROR (Status);${END}\r
 """,\r
-"""\r
-${BEGIN}\r
-RETURN_STATUS\r
-EFIAPI\r
-${Function} (\r
-  VOID\r
-  );\r
-${END}\r
+\r
+'PEI'   : """${BEGIN}\r
+  Status = ${Function} (FileHandle, PeiServices);\r
+  ASSERT_EFI_ERROR (Status);${END}\r
+""",\r
+\r
+'DXE'   : """${BEGIN}\r
+  Status = ${Function} (ImageHandle, SystemTable);\r
+  ASSERT_EFI_ERROR (Status);${END}\r
+""",\r
+}\r
+\r
+## Library Constructor and Destructor Templates\r
+gLibraryString = {\r
+'BASE'  :   """\r
+${BEGIN}${FunctionPrototype}${END}\r
 \r
 VOID\r
 EFIAPI\r
@@ -697,23 +707,13 @@ ProcessLibrary${Type}List (
   VOID\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-${BEGIN}\r
-  Status = ${Function} ();\r
-  ASSERT_EFI_ERROR (Status);\r
-${END}\r
+${BEGIN}  EFI_STATUS  Status;\r
+${FunctionCall}${END}\r
 }\r
 """,\r
-"""\r
-${BEGIN}\r
-EFI_STATUS\r
-EFIAPI\r
-${Function} (\r
-  IN EFI_PEI_FILE_HANDLE       FileHandle,\r
-  IN EFI_PEI_SERVICES          **PeiServices\r
-  );\r
-${END}\r
+\r
+'PEI'   :   """\r
+${BEGIN}${FunctionPrototype}${END}\r
 \r
 VOID\r
 EFIAPI\r
@@ -722,23 +722,13 @@ ProcessLibrary${Type}List (
   IN EFI_PEI_SERVICES          **PeiServices\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-${BEGIN}\r
-  Status = ${Function} (FileHandle, PeiServices);\r
-  ASSERT_EFI_ERROR (Status);\r
-${END}\r
+${BEGIN}  EFI_STATUS  Status;\r
+${FunctionCall}${END}\r
 }\r
 """,\r
-"""\r
-${BEGIN}\r
-EFI_STATUS\r
-EFIAPI\r
-${Function} (\r
-  IN EFI_HANDLE        ImageHandle,\r
-  IN EFI_SYSTEM_TABLE  *SystemTable\r
-  );\r
-${END}\r
+\r
+'DXE'   :   """\r
+${BEGIN}${FunctionPrototype}${END}\r
 \r
 VOID\r
 EFIAPI\r
@@ -747,15 +737,11 @@ ProcessLibrary${Type}List (
   IN EFI_SYSTEM_TABLE  *SystemTable\r
   )\r
 {\r
-  EFI_STATUS  Status;\r
-\r
-${BEGIN}\r
-  Status = ${Function} (ImageHandle, SystemTable);\r
-  ASSERT_EFI_ERROR (Status);\r
-${END}\r
+${BEGIN}  EFI_STATUS  Status;\r
+${FunctionCall}${END}\r
+}\r
+""",\r
 }\r
-"""\r
-]\r
 \r
 gSpecificationString = """\r
 ${BEGIN}\r
@@ -1329,28 +1315,42 @@ def CreateLibraryConstructorCode(Info, AutoGenC, AutoGenH):
     #\r
     # Library Constructors\r
     #\r
-    ConstructorList = []\r
+    ConstructorPrototypeString = TemplateString()\r
+    ConstructorCallingString = TemplateString()\r
     for Lib in Info.DependentLibraryList:\r
         if len(Lib.ConstructorList) <= 0:\r
             continue\r
-        ConstructorList.extend(Lib.ConstructorList)\r
+        Dict = {'Function':Lib.ConstructorList}\r
+        if Lib.ModuleType == 'BASE':\r
+            ConstructorPrototypeString.Append(gLibraryStructorPrototype['BASE'], Dict)\r
+            ConstructorCallingString.Append(gLibraryStructorCall['BASE'], Dict)\r
+        elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
+            ConstructorPrototypeString.Append(gLibraryStructorPrototype['PEI'], Dict)\r
+            ConstructorCallingString.Append(gLibraryStructorCall['PEI'], Dict)\r
+        elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION']:\r
+            ConstructorPrototypeString.Append(gLibraryStructorPrototype['DXE'], Dict)\r
+            ConstructorCallingString.Append(gLibraryStructorCall['DXE'], Dict)\r
+\r
+    if str(ConstructorPrototypeString) == '':\r
+        ConstructorPrototypeList = []\r
+    else:\r
+        ConstructorPrototypeList = [str(ConstructorPrototypeString)]\r
+    if str(ConstructorCallingString) == '':\r
+        ConstructorCallingList = []\r
+    else:\r
+        ConstructorCallingList = [str(ConstructorCallingString)]\r
 \r
-    Dict = {'Type':'Constructor', 'Function':ConstructorList}\r
+    Dict = {\r
+        'Type'              :   'Constructor',\r
+        'FunctionPrototype' :   ConstructorPrototypeList,\r
+        'FunctionCall'      :   ConstructorCallingList\r
+    }\r
     if Info.ModuleType == 'BASE':\r
-        if len(ConstructorList) == 0:\r
-            AutoGenC.Append(gLibraryString[0], Dict)\r
-        else:\r
-            AutoGenC.Append(gLibraryString[3], Dict)\r
+        AutoGenC.Append(gLibraryString['BASE'], Dict)\r
     elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
-        if len(ConstructorList) == 0:\r
-            AutoGenC.Append(gLibraryString[1], Dict)\r
-        else:\r
-            AutoGenC.Append(gLibraryString[4], Dict)\r
+        AutoGenC.Append(gLibraryString['PEI'], Dict)\r
     elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION']:\r
-        if len(ConstructorList) == 0:\r
-            AutoGenC.Append(gLibraryString[2], Dict)\r
-        else:\r
-            AutoGenC.Append(gLibraryString[5], Dict)\r
+        AutoGenC.Append(gLibraryString['DXE'], Dict)\r
 \r
 ## Create code for library destructor\r
 #\r
@@ -1364,18 +1364,43 @@ def CreateLibraryDestructorCode(Info, AutoGenC, AutoGenH):
     #\r
     # Library Destructors\r
     #\r
-    DestructorList = []\r
-    for Lib in Info.DependentLibraryList:\r
+    DestructorPrototypeString = TemplateString()\r
+    DestructorCallingString = TemplateString()\r
+    for Index in range(len(Info.DependentLibraryList)-1, -1, -1):\r
+        Lib = Info.DependentLibraryList[Index]\r
         if len(Lib.DestructorList) <= 0:\r
             continue\r
-        DestructorList.extend(Lib.DestructorList)\r
+        Dict = {'Function':Lib.DestructorList}\r
+        if Lib.ModuleType == 'BASE':\r
+            DestructorPrototypeString.Append(gLibraryStructorPrototype['BASE'], Dict)\r
+            DestructorCallingString.Append(gLibraryStructorCall['BASE'], Dict)\r
+        elif Lib.ModuleType in ['PEI_CORE','PEIM']:\r
+            DestructorPrototypeString.Append(gLibraryStructorPrototype['PEI'], Dict)\r
+            DestructorCallingString.Append(gLibraryStructorCall['PEI'], Dict)\r
+        elif Lib.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION']:\r
+            DestructorPrototypeString.Append(gLibraryStructorPrototype['DXE'], Dict)\r
+            DestructorCallingString.Append(gLibraryStructorCall['DXE'], Dict)\r
+\r
+    if str(DestructorPrototypeString) == '':\r
+        DestructorPrototypeList = []\r
+    else:\r
+        DestructorPrototypeList = [str(DestructorPrototypeString)]\r
+    if str(DestructorCallingString) == '':\r
+        DestructorCallingList = []\r
+    else:\r
+        DestructorCallingList = [str(DestructorCallingString)]\r
 \r
-    DestructorList.reverse()\r
-    if Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION']:\r
-        if len(DestructorList) == 0:\r
-            AutoGenC.Append(gLibraryString[2], {'Type':'Destructor','Function':DestructorList})\r
-        else:\r
-            AutoGenC.Append(gLibraryString[5], {'Type':'Destructor','Function':DestructorList})\r
+    Dict = {\r
+        'Type'              :   'Destructor',\r
+        'FunctionPrototype' :   DestructorPrototypeList,\r
+        'FunctionCall'      :   DestructorCallingList\r
+    }\r
+    if Info.ModuleType == 'BASE':\r
+        AutoGenC.Append(gLibraryString['BASE'], Dict)\r
+    elif Info.ModuleType in ['PEI_CORE','PEIM']:\r
+        AutoGenC.Append(gLibraryString['PEI'], Dict)\r
+    elif Info.ModuleType in ['DXE_CORE','DXE_DRIVER','DXE_SMM_DRIVER','DXE_RUNTIME_DRIVER','DXE_SAL_DRIVER','UEFI_DRIVER','UEFI_APPLICATION']:\r
+        AutoGenC.Append(gLibraryString['DXE'], Dict)\r
 \r
 \r
 ## Create code for ModuleEntryPoint\r