]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/AutoGen/AutoGen.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / AutoGen.py
... / ...
CommitLineData
1## @file\r
2# Generate AutoGen.h, AutoGen.c and *.depex files\r
3#\r
4# Copyright (c) 2007 - 2019, Intel Corporation. All rights reserved.<BR>\r
5# Copyright (c) 2018, Hewlett Packard Enterprise Development, L.P.<BR>\r
6# Copyright (c) 2019, American Megatrends, Inc. All rights reserved.<BR>\r
7#\r
8# SPDX-License-Identifier: BSD-2-Clause-Patent\r
9#\r
10\r
11## Import Modules\r
12#\r
13from __future__ import print_function\r
14from __future__ import absolute_import\r
15from Common.DataType import TAB_STAR\r
16## Base class for AutoGen\r
17#\r
18# This class just implements the cache mechanism of AutoGen objects.\r
19#\r
20class AutoGen(object):\r
21 # database to maintain the objects in each child class\r
22 __ObjectCache = {} # (BuildTarget, ToolChain, ARCH, platform file): AutoGen object\r
23\r
24 ## Factory method\r
25 #\r
26 # @param Class class object of real AutoGen class\r
27 # (WorkspaceAutoGen, ModuleAutoGen or PlatformAutoGen)\r
28 # @param Workspace Workspace directory or WorkspaceAutoGen object\r
29 # @param MetaFile The path of meta file\r
30 # @param Target Build target\r
31 # @param Toolchain Tool chain name\r
32 # @param Arch Target arch\r
33 # @param *args The specific class related parameters\r
34 # @param **kwargs The specific class related dict parameters\r
35 #\r
36\r
37 def __new__(cls, Workspace, MetaFile, Target, Toolchain, Arch, *args, **kwargs):\r
38 # check if the object has been created\r
39 Key = (Target, Toolchain, Arch, MetaFile)\r
40 if Key in cls.__ObjectCache:\r
41 # if it exists, just return it directly\r
42 return cls.__ObjectCache[Key]\r
43 # it didnt exist. create it, cache it, then return it\r
44 RetVal = cls.__ObjectCache[Key] = super(AutoGen, cls).__new__(cls)\r
45 return RetVal\r
46\r
47\r
48 ## hash() operator\r
49 #\r
50 # The file path of platform file will be used to represent hash value of this object\r
51 #\r
52 # @retval int Hash value of the file path of platform file\r
53 #\r
54 def __hash__(self):\r
55 return hash(self.MetaFile)\r
56\r
57 ## str() operator\r
58 #\r
59 # The file path of platform file will be used to represent this object\r
60 #\r
61 # @retval string String of platform file path\r
62 #\r
63 def __str__(self):\r
64 return str(self.MetaFile)\r
65\r
66 ## "==" operator\r
67 def __eq__(self, Other):\r
68 return Other and self.MetaFile == Other\r
69\r
70 @classmethod\r
71 def Cache(cls):\r
72 return cls.__ObjectCache\r
73\r
74#\r
75# The priority list while override build option\r
76#\r
77PrioList = {"0x11111" : 16, # TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest)\r
78 "0x01111" : 15, # ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
79 "0x10111" : 14, # TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
80 "0x00111" : 13, # ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE\r
81 "0x11011" : 12, # TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
82 "0x01011" : 11, # ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE\r
83 "0x10011" : 10, # TARGET_*********_****_COMMANDTYPE_ATTRIBUTE\r
84 "0x00011" : 9, # ******_*********_****_COMMANDTYPE_ATTRIBUTE\r
85 "0x11101" : 8, # TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
86 "0x01101" : 7, # ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE\r
87 "0x10101" : 6, # TARGET_*********_ARCH_***********_ATTRIBUTE\r
88 "0x00101" : 5, # ******_*********_ARCH_***********_ATTRIBUTE\r
89 "0x11001" : 4, # TARGET_TOOLCHAIN_****_***********_ATTRIBUTE\r
90 "0x01001" : 3, # ******_TOOLCHAIN_****_***********_ATTRIBUTE\r
91 "0x10001" : 2, # TARGET_*********_****_***********_ATTRIBUTE\r
92 "0x00001" : 1} # ******_*********_****_***********_ATTRIBUTE (Lowest)\r
93## Calculate the priority value of the build option\r
94#\r
95# @param Key Build option definition contain: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE\r
96#\r
97# @retval Value Priority value based on the priority list.\r
98#\r
99def CalculatePriorityValue(Key):\r
100 Target, ToolChain, Arch, CommandType, Attr = Key.split('_')\r
101 PriorityValue = 0x11111\r
102 if Target == TAB_STAR:\r
103 PriorityValue &= 0x01111\r
104 if ToolChain == TAB_STAR:\r
105 PriorityValue &= 0x10111\r
106 if Arch == TAB_STAR:\r
107 PriorityValue &= 0x11011\r
108 if CommandType == TAB_STAR:\r
109 PriorityValue &= 0x11101\r
110 if Attr == TAB_STAR:\r
111 PriorityValue &= 0x11110\r
112\r
113 return PrioList["0x%0.5x" % PriorityValue]\r