Sync EDKII BaseTools to BaseTools project r1903.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10123 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
4947
BaseTools/Source/Python/Eot/CLexer.py
Normal file
4947
BaseTools/Source/Python/Eot/CLexer.py
Normal file
File diff suppressed because it is too large
Load Diff
18844
BaseTools/Source/Python/Eot/CParser.py
Normal file
18844
BaseTools/Source/Python/Eot/CParser.py
Normal file
File diff suppressed because it is too large
Load Diff
185
BaseTools/Source/Python/Eot/CodeFragment.py
Normal file
185
BaseTools/Source/Python/Eot/CodeFragment.py
Normal file
@@ -0,0 +1,185 @@
|
||||
## @file
|
||||
# fragments of source file
|
||||
#
|
||||
# Copyright (c) 2007 ~ 2010, Intel Corporation
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
|
||||
## The description of comment contents and start & end position
|
||||
#
|
||||
#
|
||||
class Comment :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
# @param CommentType The type of comment (T_COMMENT_TWO_SLASH or T_COMMENT_SLASH_STAR).
|
||||
#
|
||||
def __init__(self, Str, Begin, End, CommentType):
|
||||
self.Content = Str
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
self.Type = CommentType
|
||||
|
||||
## The description of preprocess directives and start & end position
|
||||
#
|
||||
#
|
||||
class PP_Directive :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
#
|
||||
def __init__(self, Str, Begin, End):
|
||||
self.Content = Str
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
|
||||
## The description of assignment expression and start & end position
|
||||
#
|
||||
#
|
||||
class AssignmentExpression :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
#
|
||||
def __init__(self, Lvalue, Op, Exp, Begin, End):
|
||||
self.Name = Lvalue
|
||||
self.Operator = Op
|
||||
self.Value = Exp
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
|
||||
## The description of predicate expression and start & end position
|
||||
#
|
||||
#
|
||||
class PredicateExpression :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
#
|
||||
def __init__(self, Str, Begin, End):
|
||||
self.Content = Str
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
|
||||
## The description of function definition and start & end position
|
||||
#
|
||||
#
|
||||
class FunctionDefinition :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
# @param LBPos The left brace position tuple.
|
||||
#
|
||||
def __init__(self, ModifierStr, DeclStr, Begin, End, LBPos, NamePos):
|
||||
self.Modifier = ModifierStr
|
||||
self.Declarator = DeclStr
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
self.LeftBracePos = LBPos
|
||||
self.NamePos = NamePos
|
||||
|
||||
## The description of variable declaration and start & end position
|
||||
#
|
||||
#
|
||||
class VariableDeclaration :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
#
|
||||
def __init__(self, ModifierStr, DeclStr, Begin, End):
|
||||
self.Modifier = ModifierStr
|
||||
self.Declarator = DeclStr
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
|
||||
## The description of enum definition and start & end position
|
||||
#
|
||||
#
|
||||
class EnumerationDefinition :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
#
|
||||
def __init__(self, Str, Begin, End):
|
||||
self.Content = Str
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
|
||||
## The description of struct/union definition and start & end position
|
||||
#
|
||||
#
|
||||
class StructUnionDefinition :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
#
|
||||
def __init__(self, Str, Begin, End):
|
||||
self.Content = Str
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
|
||||
## The description of 'Typedef' definition and start & end position
|
||||
#
|
||||
#
|
||||
class TypedefDefinition :
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
#
|
||||
def __init__(self, FromStr, ToStr, Begin, End):
|
||||
self.FromType = FromStr
|
||||
self.ToType = ToStr
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
||||
|
||||
## The description of function calling definition and start & end position
|
||||
#
|
||||
#
|
||||
class FunctionCalling:
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param Begin The start position tuple.
|
||||
# @param End The end position tuple.
|
||||
#
|
||||
def __init__(self, Name, Param, Begin, End):
|
||||
self.FuncName = Name
|
||||
self.ParamList = Param
|
||||
self.StartPos = Begin
|
||||
self.EndPos = End
|
467
BaseTools/Source/Python/Eot/CodeFragmentCollector.py
Normal file
467
BaseTools/Source/Python/Eot/CodeFragmentCollector.py
Normal file
@@ -0,0 +1,467 @@
|
||||
## @file
|
||||
# preprocess source file
|
||||
#
|
||||
# Copyright (c) 2007 ~ 2010, Intel Corporation
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
|
||||
import antlr3
|
||||
from CLexer import CLexer
|
||||
from CParser import CParser
|
||||
|
||||
import FileProfile
|
||||
from CodeFragment import PP_Directive
|
||||
from ParserWarning import Warning
|
||||
|
||||
|
||||
##define T_CHAR_SPACE ' '
|
||||
##define T_CHAR_NULL '\0'
|
||||
##define T_CHAR_CR '\r'
|
||||
##define T_CHAR_TAB '\t'
|
||||
##define T_CHAR_LF '\n'
|
||||
##define T_CHAR_SLASH '/'
|
||||
##define T_CHAR_BACKSLASH '\\'
|
||||
##define T_CHAR_DOUBLE_QUOTE '\"'
|
||||
##define T_CHAR_SINGLE_QUOTE '\''
|
||||
##define T_CHAR_STAR '*'
|
||||
##define T_CHAR_HASH '#'
|
||||
|
||||
(T_CHAR_SPACE, T_CHAR_NULL, T_CHAR_CR, T_CHAR_TAB, T_CHAR_LF, T_CHAR_SLASH, \
|
||||
T_CHAR_BACKSLASH, T_CHAR_DOUBLE_QUOTE, T_CHAR_SINGLE_QUOTE, T_CHAR_STAR, T_CHAR_HASH) = \
|
||||
(' ', '\0', '\r', '\t', '\n', '/', '\\', '\"', '\'', '*', '#')
|
||||
|
||||
SEPERATOR_TUPLE = ('=', '|', ',', '{', '}')
|
||||
|
||||
(T_COMMENT_TWO_SLASH, T_COMMENT_SLASH_STAR) = (0, 1)
|
||||
|
||||
(T_PP_INCLUDE, T_PP_DEFINE, T_PP_OTHERS) = (0, 1, 2)
|
||||
|
||||
## The collector for source code fragments.
|
||||
#
|
||||
# PreprocessFile method should be called prior to ParseFile
|
||||
#
|
||||
# GetNext*** procedures mean these procedures will get next token first, then make judgement.
|
||||
# Get*** procedures mean these procedures will make judgement on current token only.
|
||||
#
|
||||
class CodeFragmentCollector:
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param FileName The file that to be parsed
|
||||
#
|
||||
def __init__(self, FileName):
|
||||
self.Profile = FileProfile.FileProfile(FileName)
|
||||
self.Profile.FileLinesList.append(T_CHAR_LF)
|
||||
self.FileName = FileName
|
||||
self.CurrentLineNumber = 1
|
||||
self.CurrentOffsetWithinLine = 0
|
||||
|
||||
self.__Token = ""
|
||||
self.__SkippedChars = ""
|
||||
|
||||
## __IsWhiteSpace() method
|
||||
#
|
||||
# Whether char at current FileBufferPos is whitespace
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Char The char to test
|
||||
# @retval True The char is a kind of white space
|
||||
# @retval False The char is NOT a kind of white space
|
||||
#
|
||||
def __IsWhiteSpace(self, Char):
|
||||
if Char in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_SPACE, T_CHAR_TAB, T_CHAR_LF):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
## __SkipWhiteSpace() method
|
||||
#
|
||||
# Skip white spaces from current char, return number of chars skipped
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @retval Count The number of chars skipped
|
||||
#
|
||||
def __SkipWhiteSpace(self):
|
||||
Count = 0
|
||||
while not self.__EndOfFile():
|
||||
Count += 1
|
||||
if self.__CurrentChar() in (T_CHAR_NULL, T_CHAR_CR, T_CHAR_LF, T_CHAR_SPACE, T_CHAR_TAB):
|
||||
self.__SkippedChars += str(self.__CurrentChar())
|
||||
self.__GetOneChar()
|
||||
|
||||
else:
|
||||
Count = Count - 1
|
||||
return Count
|
||||
|
||||
## __EndOfFile() method
|
||||
#
|
||||
# Judge current buffer pos is at file end
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @retval True Current File buffer position is at file end
|
||||
# @retval False Current File buffer position is NOT at file end
|
||||
#
|
||||
def __EndOfFile(self):
|
||||
NumberOfLines = len(self.Profile.FileLinesList)
|
||||
SizeOfLastLine = len(self.Profile.FileLinesList[-1])
|
||||
if self.CurrentLineNumber == NumberOfLines and self.CurrentOffsetWithinLine >= SizeOfLastLine - 1:
|
||||
return True
|
||||
elif self.CurrentLineNumber > NumberOfLines:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
## __EndOfLine() method
|
||||
#
|
||||
# Judge current buffer pos is at line end
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @retval True Current File buffer position is at line end
|
||||
# @retval False Current File buffer position is NOT at line end
|
||||
#
|
||||
def __EndOfLine(self):
|
||||
SizeOfCurrentLine = len(self.Profile.FileLinesList[self.CurrentLineNumber - 1])
|
||||
if self.CurrentOffsetWithinLine >= SizeOfCurrentLine - 1:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
## Rewind() method
|
||||
#
|
||||
# Reset file data buffer to the initial state
|
||||
#
|
||||
# @param self The object pointer
|
||||
#
|
||||
def Rewind(self):
|
||||
self.CurrentLineNumber = 1
|
||||
self.CurrentOffsetWithinLine = 0
|
||||
|
||||
## __UndoOneChar() method
|
||||
#
|
||||
# Go back one char in the file buffer
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @retval True Successfully go back one char
|
||||
# @retval False Not able to go back one char as file beginning reached
|
||||
#
|
||||
def __UndoOneChar(self):
|
||||
|
||||
if self.CurrentLineNumber == 1 and self.CurrentOffsetWithinLine == 0:
|
||||
return False
|
||||
elif self.CurrentOffsetWithinLine == 0:
|
||||
self.CurrentLineNumber -= 1
|
||||
self.CurrentOffsetWithinLine = len(self.__CurrentLine()) - 1
|
||||
else:
|
||||
self.CurrentOffsetWithinLine -= 1
|
||||
return True
|
||||
|
||||
## __GetOneChar() method
|
||||
#
|
||||
# Move forward one char in the file buffer
|
||||
#
|
||||
# @param self The object pointer
|
||||
#
|
||||
def __GetOneChar(self):
|
||||
if self.CurrentOffsetWithinLine == len(self.Profile.FileLinesList[self.CurrentLineNumber - 1]) - 1:
|
||||
self.CurrentLineNumber += 1
|
||||
self.CurrentOffsetWithinLine = 0
|
||||
else:
|
||||
self.CurrentOffsetWithinLine += 1
|
||||
|
||||
## __CurrentChar() method
|
||||
#
|
||||
# Get the char pointed to by the file buffer pointer
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @retval Char Current char
|
||||
#
|
||||
def __CurrentChar(self):
|
||||
CurrentChar = self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine]
|
||||
|
||||
return CurrentChar
|
||||
|
||||
## __NextChar() method
|
||||
#
|
||||
# Get the one char pass the char pointed to by the file buffer pointer
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @retval Char Next char
|
||||
#
|
||||
def __NextChar(self):
|
||||
if self.CurrentOffsetWithinLine == len(self.Profile.FileLinesList[self.CurrentLineNumber - 1]) - 1:
|
||||
return self.Profile.FileLinesList[self.CurrentLineNumber][0]
|
||||
else:
|
||||
return self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine + 1]
|
||||
|
||||
## __SetCurrentCharValue() method
|
||||
#
|
||||
# Modify the value of current char
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Value The new value of current char
|
||||
#
|
||||
def __SetCurrentCharValue(self, Value):
|
||||
self.Profile.FileLinesList[self.CurrentLineNumber - 1][self.CurrentOffsetWithinLine] = Value
|
||||
|
||||
## __SetCharValue() method
|
||||
#
|
||||
# Modify the value of current char
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Value The new value of current char
|
||||
#
|
||||
def __SetCharValue(self, Line, Offset, Value):
|
||||
self.Profile.FileLinesList[Line - 1][Offset] = Value
|
||||
|
||||
## __CurrentLine() method
|
||||
#
|
||||
# Get the list that contains current line contents
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @retval List current line contents
|
||||
#
|
||||
def __CurrentLine(self):
|
||||
return self.Profile.FileLinesList[self.CurrentLineNumber - 1]
|
||||
|
||||
## __InsertComma() method
|
||||
#
|
||||
# Insert ',' to replace PP
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @retval List current line contents
|
||||
#
|
||||
def __InsertComma(self, Line):
|
||||
|
||||
|
||||
if self.Profile.FileLinesList[Line - 1][0] != T_CHAR_HASH:
|
||||
BeforeHashPart = str(self.Profile.FileLinesList[Line - 1]).split(T_CHAR_HASH)[0]
|
||||
if BeforeHashPart.rstrip().endswith(T_CHAR_COMMA) or BeforeHashPart.rstrip().endswith(';'):
|
||||
return
|
||||
|
||||
if Line - 2 >= 0 and str(self.Profile.FileLinesList[Line - 2]).rstrip().endswith(','):
|
||||
return
|
||||
|
||||
if Line - 2 >= 0 and str(self.Profile.FileLinesList[Line - 2]).rstrip().endswith(';'):
|
||||
return
|
||||
|
||||
if str(self.Profile.FileLinesList[Line]).lstrip().startswith(',') or str(self.Profile.FileLinesList[Line]).lstrip().startswith(';'):
|
||||
return
|
||||
|
||||
self.Profile.FileLinesList[Line - 1].insert(self.CurrentOffsetWithinLine, ',')
|
||||
|
||||
## PreprocessFileWithClear() method
|
||||
#
|
||||
# Run a preprocess for the file to clean all comments
|
||||
#
|
||||
# @param self The object pointer
|
||||
#
|
||||
def PreprocessFileWithClear(self):
|
||||
|
||||
self.Rewind()
|
||||
InComment = False
|
||||
DoubleSlashComment = False
|
||||
HashComment = False
|
||||
PPExtend = False
|
||||
PPDirectiveObj = None
|
||||
# HashComment in quoted string " " is ignored.
|
||||
InString = False
|
||||
InCharLiteral = False
|
||||
|
||||
self.Profile.FileLinesList = [list(s) for s in self.Profile.FileLinesListFromFile]
|
||||
while not self.__EndOfFile():
|
||||
|
||||
if not InComment and self.__CurrentChar() == T_CHAR_DOUBLE_QUOTE:
|
||||
InString = not InString
|
||||
|
||||
if not InComment and self.__CurrentChar() == T_CHAR_SINGLE_QUOTE:
|
||||
InCharLiteral = not InCharLiteral
|
||||
# meet new line, then no longer in a comment for // and '#'
|
||||
if self.__CurrentChar() == T_CHAR_LF:
|
||||
if HashComment and PPDirectiveObj != None:
|
||||
if PPDirectiveObj.Content.rstrip(T_CHAR_CR).endswith(T_CHAR_BACKSLASH):
|
||||
PPDirectiveObj.Content += T_CHAR_LF
|
||||
PPExtend = True
|
||||
else:
|
||||
PPExtend = False
|
||||
|
||||
EndLinePos = (self.CurrentLineNumber, self.CurrentOffsetWithinLine)
|
||||
|
||||
if InComment and DoubleSlashComment:
|
||||
InComment = False
|
||||
DoubleSlashComment = False
|
||||
|
||||
if InComment and HashComment and not PPExtend:
|
||||
InComment = False
|
||||
HashComment = False
|
||||
PPDirectiveObj.Content += T_CHAR_LF
|
||||
PPDirectiveObj.EndPos = EndLinePos
|
||||
FileProfile.PPDirectiveList.append(PPDirectiveObj)
|
||||
PPDirectiveObj = None
|
||||
|
||||
if InString or InCharLiteral:
|
||||
CurrentLine = "".join(self.__CurrentLine())
|
||||
if CurrentLine.rstrip(T_CHAR_LF).rstrip(T_CHAR_CR).endswith(T_CHAR_BACKSLASH):
|
||||
SlashIndex = CurrentLine.rindex(T_CHAR_BACKSLASH)
|
||||
self.__SetCharValue(self.CurrentLineNumber, SlashIndex, T_CHAR_SPACE)
|
||||
|
||||
self.CurrentLineNumber += 1
|
||||
self.CurrentOffsetWithinLine = 0
|
||||
# check for */ comment end
|
||||
elif InComment and not DoubleSlashComment and not HashComment and self.__CurrentChar() == T_CHAR_STAR and self.__NextChar() == T_CHAR_SLASH:
|
||||
|
||||
self.__SetCurrentCharValue(T_CHAR_SPACE)
|
||||
self.__GetOneChar()
|
||||
self.__SetCurrentCharValue(T_CHAR_SPACE)
|
||||
self.__GetOneChar()
|
||||
InComment = False
|
||||
# set comments to spaces
|
||||
elif InComment:
|
||||
if HashComment:
|
||||
# // follows hash PP directive
|
||||
if self.__CurrentChar() == T_CHAR_SLASH and self.__NextChar() == T_CHAR_SLASH:
|
||||
InComment = False
|
||||
HashComment = False
|
||||
PPDirectiveObj.EndPos = (self.CurrentLineNumber, self.CurrentOffsetWithinLine - 1)
|
||||
FileProfile.PPDirectiveList.append(PPDirectiveObj)
|
||||
PPDirectiveObj = None
|
||||
continue
|
||||
else:
|
||||
PPDirectiveObj.Content += self.__CurrentChar()
|
||||
|
||||
self.__SetCurrentCharValue(T_CHAR_SPACE)
|
||||
self.__GetOneChar()
|
||||
# check for // comment
|
||||
elif self.__CurrentChar() == T_CHAR_SLASH and self.__NextChar() == T_CHAR_SLASH:
|
||||
InComment = True
|
||||
DoubleSlashComment = True
|
||||
|
||||
# check for '#' comment
|
||||
elif self.__CurrentChar() == T_CHAR_HASH and not InString and not InCharLiteral:
|
||||
InComment = True
|
||||
HashComment = True
|
||||
PPDirectiveObj = PP_Directive('', (self.CurrentLineNumber, self.CurrentOffsetWithinLine), None)
|
||||
# check for /* comment start
|
||||
elif self.__CurrentChar() == T_CHAR_SLASH and self.__NextChar() == T_CHAR_STAR:
|
||||
|
||||
self.__SetCurrentCharValue( T_CHAR_SPACE)
|
||||
self.__GetOneChar()
|
||||
self.__SetCurrentCharValue( T_CHAR_SPACE)
|
||||
self.__GetOneChar()
|
||||
InComment = True
|
||||
else:
|
||||
self.__GetOneChar()
|
||||
|
||||
EndLinePos = (self.CurrentLineNumber, self.CurrentOffsetWithinLine)
|
||||
|
||||
if InComment and HashComment and not PPExtend:
|
||||
PPDirectiveObj.EndPos = EndLinePos
|
||||
FileProfile.PPDirectiveList.append(PPDirectiveObj)
|
||||
self.Rewind()
|
||||
|
||||
## ParseFile() method
|
||||
#
|
||||
# Parse the file profile buffer to extract fd, fv ... information
|
||||
# Exception will be raised if syntax error found
|
||||
#
|
||||
# @param self The object pointer
|
||||
#
|
||||
def ParseFile(self):
|
||||
self.PreprocessFileWithClear()
|
||||
# restore from ListOfList to ListOfString
|
||||
self.Profile.FileLinesList = ["".join(list) for list in self.Profile.FileLinesList]
|
||||
FileStringContents = ''
|
||||
for fileLine in self.Profile.FileLinesList:
|
||||
FileStringContents += fileLine
|
||||
cStream = antlr3.StringStream(FileStringContents)
|
||||
lexer = CLexer(cStream)
|
||||
tStream = antlr3.CommonTokenStream(lexer)
|
||||
parser = CParser(tStream)
|
||||
parser.translation_unit()
|
||||
|
||||
## CleanFileProfileBuffer() method
|
||||
#
|
||||
# Reset all contents of the profile of a file
|
||||
#
|
||||
def CleanFileProfileBuffer(self):
|
||||
|
||||
FileProfile.PPDirectiveList = []
|
||||
FileProfile.AssignmentExpressionList = []
|
||||
FileProfile.FunctionDefinitionList = []
|
||||
FileProfile.VariableDeclarationList = []
|
||||
FileProfile.EnumerationDefinitionList = []
|
||||
FileProfile.StructUnionDefinitionList = []
|
||||
FileProfile.TypedefDefinitionList = []
|
||||
FileProfile.FunctionCallingList = []
|
||||
|
||||
## PrintFragments() method
|
||||
#
|
||||
# Print the contents of the profile of a file
|
||||
#
|
||||
def PrintFragments(self):
|
||||
|
||||
print '################# ' + self.FileName + '#####################'
|
||||
|
||||
print '/****************************************/'
|
||||
print '/*************** ASSIGNMENTS ***************/'
|
||||
print '/****************************************/'
|
||||
for asign in FileProfile.AssignmentExpressionList:
|
||||
print str(asign.StartPos) + asign.Name + asign.Operator + asign.Value
|
||||
|
||||
print '/****************************************/'
|
||||
print '/********* PREPROCESS DIRECTIVES ********/'
|
||||
print '/****************************************/'
|
||||
for pp in FileProfile.PPDirectiveList:
|
||||
print str(pp.StartPos) + pp.Content
|
||||
|
||||
print '/****************************************/'
|
||||
print '/********* VARIABLE DECLARATIONS ********/'
|
||||
print '/****************************************/'
|
||||
for var in FileProfile.VariableDeclarationList:
|
||||
print str(var.StartPos) + var.Modifier + ' '+ var.Declarator
|
||||
|
||||
print '/****************************************/'
|
||||
print '/********* FUNCTION DEFINITIONS *********/'
|
||||
print '/****************************************/'
|
||||
for func in FileProfile.FunctionDefinitionList:
|
||||
print str(func.StartPos) + func.Modifier + ' '+ func.Declarator + ' ' + str(func.NamePos)
|
||||
|
||||
print '/****************************************/'
|
||||
print '/************ ENUMERATIONS **************/'
|
||||
print '/****************************************/'
|
||||
for enum in FileProfile.EnumerationDefinitionList:
|
||||
print str(enum.StartPos) + enum.Content
|
||||
|
||||
print '/****************************************/'
|
||||
print '/*********** STRUCTS/UNIONS *************/'
|
||||
print '/****************************************/'
|
||||
for su in FileProfile.StructUnionDefinitionList:
|
||||
print str(su.StartPos) + su.Content
|
||||
|
||||
print '/****************************************/'
|
||||
print '/************** TYPEDEFS ****************/'
|
||||
print '/****************************************/'
|
||||
for typedef in FileProfile.TypedefDefinitionList:
|
||||
print str(typedef.StartPos) + typedef.ToType
|
||||
|
||||
##
|
||||
#
|
||||
# This acts like the main() function for the script, unless it is 'import'ed into another
|
||||
# script.
|
||||
#
|
||||
if __name__ == "__main__":
|
||||
|
||||
print "For Test."
|
255
BaseTools/Source/Python/Eot/Database.py
Normal file
255
BaseTools/Source/Python/Eot/Database.py
Normal file
@@ -0,0 +1,255 @@
|
||||
## @file
|
||||
# This file is used to create a database used by EOT tool
|
||||
#
|
||||
# Copyright (c) 2007 - 2010, Intel Corporation
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import sqlite3
|
||||
import os, time
|
||||
|
||||
import Common.EdkLogger as EdkLogger
|
||||
import CommonDataClass.DataClass as DataClass
|
||||
|
||||
from Table.TableDataModel import TableDataModel
|
||||
from Table.TableFile import TableFile
|
||||
from Table.TableFunction import TableFunction
|
||||
from Table.TableIdentifier import TableIdentifier
|
||||
from Table.TableEotReport import TableEotReport
|
||||
from Table.TableInf import TableInf
|
||||
from Table.TableDec import TableDec
|
||||
from Table.TableDsc import TableDsc
|
||||
from Table.TableFdf import TableFdf
|
||||
from Table.TableQuery import TableQuery
|
||||
|
||||
##
|
||||
# Static definitions
|
||||
#
|
||||
DATABASE_PATH = "Eot.db"
|
||||
|
||||
## Database class
|
||||
#
|
||||
# This class defined the EOT databse
|
||||
# During the phase of initialization, the database will create all tables and
|
||||
# insert all records of table DataModel
|
||||
#
|
||||
class Database(object):
|
||||
## The constructor
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param DbPath: The file path of the database
|
||||
#
|
||||
def __init__(self, DbPath):
|
||||
self.DbPath = DbPath
|
||||
self.Conn = None
|
||||
self.Cur = None
|
||||
self.TblDataModel = None
|
||||
self.TblFile = None
|
||||
self.TblFunction = None
|
||||
self.TblIdentifier = None
|
||||
self.TblReport = None
|
||||
self.TblInf = None
|
||||
self.TblDec = None
|
||||
self.TblDsc = None
|
||||
self.TblFdf = None
|
||||
self.TblQuery = None
|
||||
self.TblQuery2 = None
|
||||
|
||||
## InitDatabase() method
|
||||
# 1. Delete all old existing tables
|
||||
# 2. Create new tables
|
||||
# 3. Initialize table DataModel
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param NewDatabase: Check if it needs to create a new database
|
||||
#
|
||||
def InitDatabase(self, NewDatabase = True):
|
||||
EdkLogger.verbose("\nInitialize EOT database started ...")
|
||||
#
|
||||
# Drop all old existing tables
|
||||
#
|
||||
if NewDatabase:
|
||||
if os.path.exists(self.DbPath):
|
||||
os.remove(self.DbPath)
|
||||
self.Conn = sqlite3.connect(self.DbPath, isolation_level = 'DEFERRED')
|
||||
self.Conn.execute("PRAGMA page_size=8192")
|
||||
self.Conn.execute("PRAGMA synchronous=OFF")
|
||||
# to avoid non-ascii charater conversion error
|
||||
self.Conn.text_factory = str
|
||||
self.Cur = self.Conn.cursor()
|
||||
|
||||
self.TblDataModel = TableDataModel(self.Cur)
|
||||
self.TblFile = TableFile(self.Cur)
|
||||
self.TblFunction = TableFunction(self.Cur)
|
||||
self.TblIdentifier = TableIdentifier(self.Cur)
|
||||
self.TblReport = TableEotReport(self.Cur)
|
||||
self.TblInf = TableInf(self.Cur)
|
||||
self.TblDec = TableDec(self.Cur)
|
||||
self.TblDsc = TableDsc(self.Cur)
|
||||
self.TblFdf = TableFdf(self.Cur)
|
||||
self.TblQuery = TableQuery(self.Cur)
|
||||
self.TblQuery2 = TableQuery(self.Cur)
|
||||
self.TblQuery2.Table = 'Query2'
|
||||
|
||||
# Create new tables
|
||||
if NewDatabase:
|
||||
self.TblDataModel.Create()
|
||||
self.TblFile.Create()
|
||||
self.TblFunction.Create()
|
||||
self.TblReport.Create()
|
||||
self.TblInf.Create()
|
||||
self.TblDec.Create()
|
||||
self.TblDsc.Create()
|
||||
self.TblFdf.Create()
|
||||
self.TblQuery.Create()
|
||||
self.TblQuery2.Create()
|
||||
|
||||
# Init each table's ID
|
||||
self.TblDataModel.InitID()
|
||||
self.TblFile.InitID()
|
||||
self.TblFunction.InitID()
|
||||
self.TblReport.InitID()
|
||||
self.TblInf.InitID()
|
||||
self.TblDec.InitID()
|
||||
self.TblDsc.InitID()
|
||||
self.TblFdf.InitID()
|
||||
self.TblQuery.Drop()
|
||||
self.TblQuery.Create()
|
||||
self.TblQuery.InitID()
|
||||
self.TblQuery2.Drop()
|
||||
self.TblQuery2.Create()
|
||||
self.TblQuery2.InitID()
|
||||
|
||||
# Initialize table DataModel
|
||||
if NewDatabase:
|
||||
self.TblDataModel.InitTable()
|
||||
|
||||
EdkLogger.verbose("Initialize EOT database ... DONE!")
|
||||
|
||||
## QueryTable() method
|
||||
#
|
||||
# Query a table
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Table: The instance of the table to be queried
|
||||
#
|
||||
def QueryTable(self, Table):
|
||||
Table.Query()
|
||||
|
||||
## Close() method
|
||||
#
|
||||
# Commit all first
|
||||
# Close the connection and cursor
|
||||
#
|
||||
def Close(self):
|
||||
# Commit to file
|
||||
self.Conn.commit()
|
||||
|
||||
# Close connection and cursor
|
||||
self.Cur.close()
|
||||
self.Conn.close()
|
||||
|
||||
## InsertOneFile() method
|
||||
#
|
||||
# Insert one file's information to the database
|
||||
# 1. Create a record in TableFile
|
||||
# 2. Create functions one by one
|
||||
# 2.1 Create variables of function one by one
|
||||
# 2.2 Create pcds of function one by one
|
||||
# 3. Create variables one by one
|
||||
# 4. Create pcds one by one
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param File: The object of the file to be inserted
|
||||
#
|
||||
def InsertOneFile(self, File):
|
||||
# Insert a record for file
|
||||
FileID = self.TblFile.Insert(File.Name, File.ExtName, File.Path, File.FullPath, Model = File.Model, TimeStamp = File.TimeStamp)
|
||||
IdTable = TableIdentifier(self.Cur)
|
||||
IdTable.Table = "Identifier%s" % FileID
|
||||
IdTable.Create()
|
||||
|
||||
# Insert function of file
|
||||
for Function in File.FunctionList:
|
||||
FunctionID = self.TblFunction.Insert(Function.Header, Function.Modifier, Function.Name, Function.ReturnStatement, \
|
||||
Function.StartLine, Function.StartColumn, Function.EndLine, Function.EndColumn, \
|
||||
Function.BodyStartLine, Function.BodyStartColumn, FileID, \
|
||||
Function.FunNameStartLine, Function.FunNameStartColumn)
|
||||
|
||||
# Insert Identifier of function
|
||||
for Identifier in Function.IdentifierList:
|
||||
IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
|
||||
FileID, FunctionID, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
|
||||
# Insert Identifier of file
|
||||
for Identifier in File.IdentifierList:
|
||||
IdentifierID = IdTable.Insert(Identifier.Modifier, Identifier.Type, Identifier.Name, Identifier.Value, Identifier.Model, \
|
||||
FileID, -1, Identifier.StartLine, Identifier.StartColumn, Identifier.EndLine, Identifier.EndColumn)
|
||||
|
||||
EdkLogger.verbose("Insert information from file %s ... DONE!" % File.FullPath)
|
||||
|
||||
## UpdateIdentifierBelongsToFunction() method
|
||||
#
|
||||
# Update the field "BelongsToFunction" for each Indentifier
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def UpdateIdentifierBelongsToFunction(self):
|
||||
EdkLogger.verbose("Update 'BelongsToFunction' for Identifiers started ...")
|
||||
|
||||
SqlCommand = """select ID, BelongsToFile, StartLine, EndLine from Function"""
|
||||
Records = self.TblFunction.Exec(SqlCommand)
|
||||
Data1 = []
|
||||
Data2 = []
|
||||
for Record in Records:
|
||||
FunctionID = Record[0]
|
||||
BelongsToFile = Record[1]
|
||||
StartLine = Record[2]
|
||||
EndLine = Record[3]
|
||||
|
||||
SqlCommand = """Update Identifier%s set BelongsToFunction = %s where BelongsToFile = %s and StartLine > %s and EndLine < %s""" % \
|
||||
(BelongsToFile, FunctionID, BelongsToFile, StartLine, EndLine)
|
||||
self.TblIdentifier.Exec(SqlCommand)
|
||||
|
||||
SqlCommand = """Update Identifier%s set BelongsToFunction = %s, Model = %s where BelongsToFile = %s and Model = %s and EndLine = %s""" % \
|
||||
(BelongsToFile, FunctionID, DataClass.MODEL_IDENTIFIER_FUNCTION_HEADER, BelongsToFile, DataClass.MODEL_IDENTIFIER_COMMENT, StartLine - 1)
|
||||
self.TblIdentifier.Exec(SqlCommand)
|
||||
|
||||
|
||||
##
|
||||
#
|
||||
# This acts like the main() function for the script, unless it is 'import'ed into another
|
||||
# script.
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
EdkLogger.Initialize()
|
||||
EdkLogger.SetLevel(EdkLogger.DEBUG_0)
|
||||
EdkLogger.verbose("Start at " + time.strftime('%H:%M:%S', time.localtime()))
|
||||
|
||||
Db = Database(DATABASE_PATH)
|
||||
Db.InitDatabase()
|
||||
Db.QueryTable(Db.TblDataModel)
|
||||
|
||||
identifier1 = DataClass.IdentifierClass(-1, '', '', "i''1", 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 32, 43, 54, 43)
|
||||
identifier2 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 15, 43, 20, 43)
|
||||
identifier3 = DataClass.IdentifierClass(-1, '', '', 'i1', 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 55, 43, 58, 43)
|
||||
identifier4 = DataClass.IdentifierClass(-1, '', '', "i1'", 'aaa', DataClass.MODEL_IDENTIFIER_COMMENT, 1, -1, 77, 43, 88, 43)
|
||||
fun1 = DataClass.FunctionClass(-1, '', '', 'fun1', '', 21, 2, 60, 45, 1, 23, 0, [], [])
|
||||
file = DataClass.FileClass(-1, 'F1', 'c', 'C:\\', 'C:\\F1.exe', DataClass.MODEL_FILE_C, '2007-12-28', [fun1], [identifier1, identifier2, identifier3, identifier4], [])
|
||||
Db.InsertOneFile(file)
|
||||
|
||||
Db.QueryTable(Db.TblFile)
|
||||
Db.QueryTable(Db.TblFunction)
|
||||
Db.QueryTable(Db.TblIdentifier)
|
||||
|
||||
Db.Close()
|
||||
EdkLogger.verbose("End at " + time.strftime('%H:%M:%S', time.localtime()))
|
||||
|
BIN
BaseTools/Source/Python/Eot/EfiCompressor.pyd
Normal file
BIN
BaseTools/Source/Python/Eot/EfiCompressor.pyd
Normal file
Binary file not shown.
647
BaseTools/Source/Python/Eot/Eot.py
Normal file
647
BaseTools/Source/Python/Eot/Eot.py
Normal file
@@ -0,0 +1,647 @@
|
||||
## @file
|
||||
# This file is used to be the main entrance of EOT tool
|
||||
#
|
||||
# Copyright (c) 2008 - 2010, Intel Corporation
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import os, time, glob
|
||||
import Common.EdkLogger as EdkLogger
|
||||
import EotGlobalData
|
||||
from optparse import OptionParser
|
||||
from Common.String import NormPath
|
||||
from Common import BuildToolError
|
||||
from Common.Misc import GuidStructureStringToGuidString
|
||||
from InfParserLite import *
|
||||
import c
|
||||
import Database
|
||||
from FvImage import *
|
||||
from array import array
|
||||
from Report import Report
|
||||
from Common.Misc import ParseConsoleLog
|
||||
from Parser import ConvertGuid
|
||||
|
||||
## Class Eot
|
||||
#
|
||||
# This class is used to define Eot main entrance
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
class Eot(object):
|
||||
## The constructor
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def __init__(self, CommandLineOption=True, IsInit=True, SourceFileList=None, \
|
||||
IncludeDirList=None, DecFileList=None, GuidList=None, LogFile=None,
|
||||
FvFileList="", MapFileList="", Report='Report.html', Dispatch=None):
|
||||
# Version and Copyright
|
||||
self.VersionNumber = "0.02"
|
||||
self.Version = "%prog Version " + self.VersionNumber
|
||||
self.Copyright = "Copyright (c) 2008 - 2010, Intel Corporation All rights reserved."
|
||||
self.Report = Report
|
||||
|
||||
self.IsInit = IsInit
|
||||
self.SourceFileList = SourceFileList
|
||||
self.IncludeDirList = IncludeDirList
|
||||
self.DecFileList = DecFileList
|
||||
self.GuidList = GuidList
|
||||
self.LogFile = LogFile
|
||||
self.FvFileList = FvFileList
|
||||
self.MapFileList = MapFileList
|
||||
self.Dispatch = Dispatch
|
||||
|
||||
# Check workspace environment
|
||||
if "EFI_SOURCE" not in os.environ:
|
||||
if "EDK_SOURCE" not in os.environ:
|
||||
pass
|
||||
else:
|
||||
EotGlobalData.gEDK_SOURCE = os.path.normpath(os.getenv("EDK_SOURCE"))
|
||||
else:
|
||||
EotGlobalData.gEFI_SOURCE = os.path.normpath(os.getenv("EFI_SOURCE"))
|
||||
EotGlobalData.gEDK_SOURCE = os.path.join(EotGlobalData.gEFI_SOURCE, 'Edk')
|
||||
|
||||
if "WORKSPACE" not in os.environ:
|
||||
EdkLogger.error("EOT", BuildToolError.ATTRIBUTE_NOT_AVAILABLE, "Environment variable not found",
|
||||
ExtraData="WORKSPACE")
|
||||
else:
|
||||
EotGlobalData.gWORKSPACE = os.path.normpath(os.getenv("WORKSPACE"))
|
||||
|
||||
EotGlobalData.gMACRO['WORKSPACE'] = EotGlobalData.gWORKSPACE
|
||||
EotGlobalData.gMACRO['EFI_SOURCE'] = EotGlobalData.gEFI_SOURCE
|
||||
EotGlobalData.gMACRO['EDK_SOURCE'] = EotGlobalData.gEDK_SOURCE
|
||||
|
||||
# Parse the options and args
|
||||
if CommandLineOption:
|
||||
self.ParseOption()
|
||||
|
||||
if self.FvFileList:
|
||||
for FvFile in GetSplitValueList(self.FvFileList, ' '):
|
||||
FvFile = os.path.normpath(FvFile)
|
||||
if not os.path.isfile(FvFile):
|
||||
EdkLogger.error("Eot", EdkLogger.EOT_ERROR, "Can not find file %s " % FvFile)
|
||||
EotGlobalData.gFV_FILE.append(FvFile)
|
||||
else:
|
||||
EdkLogger.error("Eot", EdkLogger.EOT_ERROR, "The fv file list of target platform was not specified")
|
||||
|
||||
if self.MapFileList:
|
||||
for MapFile in GetSplitValueList(self.MapFileList, ' '):
|
||||
MapFile = os.path.normpath(MapFile)
|
||||
if not os.path.isfile(MapFile):
|
||||
EdkLogger.error("Eot", EdkLogger.EOT_ERROR, "Can not find file %s " % MapFile)
|
||||
EotGlobalData.gMAP_FILE.append(MapFile)
|
||||
|
||||
# Generate source file list
|
||||
self.GenerateSourceFileList(self.SourceFileList, self.IncludeDirList)
|
||||
|
||||
# Generate guid list of dec file list
|
||||
self.ParseDecFile(self.DecFileList)
|
||||
|
||||
# Generate guid list from GUID list file
|
||||
self.ParseGuidList(self.GuidList)
|
||||
|
||||
# Init Eot database
|
||||
EotGlobalData.gDb = Database.Database(Database.DATABASE_PATH)
|
||||
EotGlobalData.gDb.InitDatabase(self.IsInit)
|
||||
|
||||
# Build ECC database
|
||||
self.BuildDatabase()
|
||||
|
||||
# Parse Ppi/Protocol
|
||||
self.ParseExecutionOrder()
|
||||
|
||||
# Merge Identifier tables
|
||||
self.GenerateQueryTable()
|
||||
|
||||
# Generate report database
|
||||
self.GenerateReportDatabase()
|
||||
|
||||
# Load Fv Info
|
||||
self.LoadFvInfo()
|
||||
|
||||
# Load Map Info
|
||||
self.LoadMapInfo()
|
||||
|
||||
# Generate Report
|
||||
self.GenerateReport()
|
||||
|
||||
# Convert log file
|
||||
self.ConvertLogFile(self.LogFile)
|
||||
|
||||
# DONE
|
||||
EdkLogger.quiet("EOT FINISHED!")
|
||||
|
||||
# Close Database
|
||||
EotGlobalData.gDb.Close()
|
||||
|
||||
## ParseDecFile() method
|
||||
#
|
||||
# parse DEC file and get all GUID names with GUID values as {GuidName : GuidValue}
|
||||
# The Dict is stored in EotGlobalData.gGuidDict
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param DecFileList: A list of all DEC files
|
||||
#
|
||||
def ParseDecFile(self, DecFileList):
|
||||
if DecFileList:
|
||||
path = os.path.normpath(DecFileList)
|
||||
lfr = open(path, 'rb')
|
||||
for line in lfr:
|
||||
path = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line.strip()))
|
||||
if os.path.exists(path):
|
||||
dfr = open(path, 'rb')
|
||||
for line in dfr:
|
||||
line = CleanString(line)
|
||||
list = line.split('=')
|
||||
if len(list) == 2:
|
||||
EotGlobalData.gGuidDict[list[0].strip()] = GuidStructureStringToGuidString(list[1].strip())
|
||||
|
||||
|
||||
## ParseGuidList() method
|
||||
#
|
||||
# Parse Guid list and get all GUID names with GUID values as {GuidName : GuidValue}
|
||||
# The Dict is stored in EotGlobalData.gGuidDict
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param GuidList: A list of all GUID and its value
|
||||
#
|
||||
def ParseGuidList(self, GuidList):
|
||||
Path = os.path.join(EotGlobalData.gWORKSPACE, GuidList)
|
||||
if os.path.isfile(Path):
|
||||
for Line in open(Path):
|
||||
(GuidName, GuidValue) = Line.split()
|
||||
EotGlobalData.gGuidDict[GuidName] = GuidValue
|
||||
|
||||
## ConvertLogFile() method
|
||||
#
|
||||
# Parse a real running log file to get real dispatch order
|
||||
# The result is saved to old file name + '.new'
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param LogFile: A real running log file name
|
||||
#
|
||||
def ConvertLogFile(self, LogFile):
|
||||
newline = []
|
||||
lfr = None
|
||||
lfw = None
|
||||
if LogFile:
|
||||
lfr = open(LogFile, 'rb')
|
||||
lfw = open(LogFile + '.new', 'wb')
|
||||
for line in lfr:
|
||||
line = line.strip()
|
||||
line = line.replace('.efi', '')
|
||||
index = line.find("Loading PEIM at ")
|
||||
if index > -1:
|
||||
newline.append(line[index + 55 : ])
|
||||
continue
|
||||
index = line.find("Loading driver at ")
|
||||
if index > -1:
|
||||
newline.append(line[index + 57 : ])
|
||||
continue
|
||||
|
||||
for line in newline:
|
||||
lfw.write(line + '\r\n')
|
||||
|
||||
if lfr:
|
||||
lfr.close()
|
||||
if lfw:
|
||||
lfw.close()
|
||||
|
||||
## GenerateSourceFileList() method
|
||||
#
|
||||
# Generate a list of all source files
|
||||
# 1. Search the file list one by one
|
||||
# 2. Store inf file name with source file names under it like
|
||||
# { INF file name: [source file1, source file2, ...]}
|
||||
# 3. Search the include list to find all .h files
|
||||
# 4. Store source file list to EotGlobalData.gSOURCE_FILES
|
||||
# 5. Store INF file list to EotGlobalData.gINF_FILES
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param SourceFileList: A list of all source files
|
||||
# @param IncludeFileList: A list of all include files
|
||||
#
|
||||
def GenerateSourceFileList(self, SourceFileList, IncludeFileList):
|
||||
EdkLogger.quiet("Generating source files list ... ")
|
||||
mSourceFileList = []
|
||||
mInfFileList = []
|
||||
mDecFileList = []
|
||||
mFileList = {}
|
||||
mCurrentInfFile = ''
|
||||
mCurrentSourceFileList = []
|
||||
|
||||
if SourceFileList:
|
||||
sfl = open(SourceFileList, 'rb')
|
||||
for line in sfl:
|
||||
line = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line.strip()))
|
||||
if line[-2:].upper() == '.C' or line[-2:].upper() == '.H':
|
||||
if line not in mCurrentSourceFileList:
|
||||
mCurrentSourceFileList.append(line)
|
||||
mSourceFileList.append(line)
|
||||
EotGlobalData.gOP_SOURCE_FILES.write('%s\n' % line)
|
||||
if line[-4:].upper() == '.INF':
|
||||
if mCurrentInfFile != '':
|
||||
mFileList[mCurrentInfFile] = mCurrentSourceFileList
|
||||
mCurrentSourceFileList = []
|
||||
mCurrentInfFile = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line))
|
||||
EotGlobalData.gOP_INF.write('%s\n' % mCurrentInfFile)
|
||||
if mCurrentInfFile not in mFileList:
|
||||
mFileList[mCurrentInfFile] = mCurrentSourceFileList
|
||||
|
||||
# Get all include files from packages
|
||||
if IncludeFileList:
|
||||
ifl = open(IncludeFileList, 'rb')
|
||||
for line in ifl:
|
||||
if not line.strip():
|
||||
continue
|
||||
newline = os.path.normpath(os.path.join(EotGlobalData.gWORKSPACE, line.strip()))
|
||||
for Root, Dirs, Files in os.walk(str(newline)):
|
||||
for File in Files:
|
||||
FullPath = os.path.normpath(os.path.join(Root, File))
|
||||
if FullPath not in mSourceFileList and File[-2:].upper() == '.H':
|
||||
mSourceFileList.append(FullPath)
|
||||
EotGlobalData.gOP_SOURCE_FILES.write('%s\n' % FullPath)
|
||||
if FullPath not in mDecFileList and File.upper().find('.DEC') > -1:
|
||||
mDecFileList.append(FullPath)
|
||||
|
||||
EotGlobalData.gSOURCE_FILES = mSourceFileList
|
||||
EotGlobalData.gOP_SOURCE_FILES.close()
|
||||
|
||||
EotGlobalData.gINF_FILES = mFileList
|
||||
EotGlobalData.gOP_INF.close()
|
||||
|
||||
EotGlobalData.gDEC_FILES = mDecFileList
|
||||
|
||||
|
||||
## GenerateReport() method
|
||||
#
|
||||
# Generate final HTML report
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def GenerateReport(self):
|
||||
EdkLogger.quiet("Generating report file ... ")
|
||||
Rep = Report(self.Report, EotGlobalData.gFV, self.Dispatch)
|
||||
Rep.GenerateReport()
|
||||
|
||||
## LoadMapInfo() method
|
||||
#
|
||||
# Load map files and parse them
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def LoadMapInfo(self):
|
||||
if EotGlobalData.gMAP_FILE != []:
|
||||
EdkLogger.quiet("Parsing Map file ... ")
|
||||
EotGlobalData.gMap = ParseMapFile(EotGlobalData.gMAP_FILE)
|
||||
|
||||
## LoadFvInfo() method
|
||||
#
|
||||
# Load FV binary files and parse them
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def LoadFvInfo(self):
|
||||
EdkLogger.quiet("Parsing FV file ... ")
|
||||
EotGlobalData.gFV = MultipleFv(EotGlobalData.gFV_FILE)
|
||||
EotGlobalData.gFV.Dispatch(EotGlobalData.gDb)
|
||||
|
||||
for Protocol in EotGlobalData.gProtocolList:
|
||||
EotGlobalData.gOP_UN_MATCHED_IN_LIBRARY_CALLING.write('%s\n' %Protocol)
|
||||
|
||||
## GenerateReportDatabase() method
|
||||
#
|
||||
# Generate data for the information needed by report
|
||||
# 1. Update name, macro and value of all found PPI/PROTOCOL GUID
|
||||
# 2. Install hard coded PPI/PROTOCOL
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def GenerateReportDatabase(self):
|
||||
EdkLogger.quiet("Generating the cross-reference table of GUID for Ppi/Protocol ... ")
|
||||
|
||||
# Update Protocol/Ppi Guid
|
||||
SqlCommand = """select DISTINCT GuidName from Report"""
|
||||
RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
GuidName = Record[0]
|
||||
GuidMacro = ''
|
||||
GuidMacro2 = ''
|
||||
GuidValue = ''
|
||||
|
||||
# Find value for hardcode guid macro
|
||||
if GuidName in EotGlobalData.gGuidMacroDict:
|
||||
GuidMacro = EotGlobalData.gGuidMacroDict[GuidName][0]
|
||||
GuidValue = EotGlobalData.gGuidMacroDict[GuidName][1]
|
||||
SqlCommand = """update Report set GuidMacro = '%s', GuidValue = '%s' where GuidName = '%s'""" %(GuidMacro, GuidValue, GuidName)
|
||||
EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
continue
|
||||
|
||||
# Find guid value defined in Dec file
|
||||
if GuidName in EotGlobalData.gGuidDict:
|
||||
GuidValue = EotGlobalData.gGuidDict[GuidName]
|
||||
SqlCommand = """update Report set GuidMacro = '%s', GuidValue = '%s' where GuidName = '%s'""" %(GuidMacro, GuidValue, GuidName)
|
||||
EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
continue
|
||||
|
||||
# Search defined Macros for guid name
|
||||
SqlCommand ="""select DISTINCT Value, Modifier from Query where Name like '%s'""" % GuidName
|
||||
GuidMacroSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
# Ignore NULL result
|
||||
if not GuidMacroSet:
|
||||
continue
|
||||
GuidMacro = GuidMacroSet[0][0].strip()
|
||||
if not GuidMacro:
|
||||
continue
|
||||
# Find Guid value of Guid Macro
|
||||
SqlCommand ="""select DISTINCT Value from Query2 where Value like '%%%s%%' and Model = %s""" % (GuidMacro, MODEL_IDENTIFIER_MACRO_DEFINE)
|
||||
GuidValueSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
if GuidValueSet != []:
|
||||
GuidValue = GuidValueSet[0][0]
|
||||
GuidValue = GuidValue[GuidValue.find(GuidMacro) + len(GuidMacro) :]
|
||||
GuidValue = GuidValue.lower().replace('\\', '').replace('\r', '').replace('\n', '').replace('l', '').strip()
|
||||
GuidValue = GuidStructureStringToGuidString(GuidValue)
|
||||
SqlCommand = """update Report set GuidMacro = '%s', GuidValue = '%s' where GuidName = '%s'""" %(GuidMacro, GuidValue, GuidName)
|
||||
EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
continue
|
||||
|
||||
# Update Hard Coded Ppi/Protocol
|
||||
SqlCommand = """select DISTINCT GuidValue, ItemType from Report where ModuleID = -2 and ItemMode = 'Produced'"""
|
||||
RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
if Record[1] == 'Ppi':
|
||||
EotGlobalData.gPpiList[Record[0].lower()] = -2
|
||||
if Record[1] == 'Protocol':
|
||||
EotGlobalData.gProtocolList[Record[0].lower()] = -2
|
||||
|
||||
## GenerateQueryTable() method
|
||||
#
|
||||
# Generate two tables improve query performance
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def GenerateQueryTable(self):
|
||||
EdkLogger.quiet("Generating temp query table for analysis ... ")
|
||||
for Identifier in EotGlobalData.gIdentifierTableList:
|
||||
SqlCommand = """insert into Query (Name, Modifier, Value, Model)
|
||||
select Name, Modifier, Value, Model from %s where (Model = %s or Model = %s)""" \
|
||||
% (Identifier[0], MODEL_IDENTIFIER_VARIABLE, MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION)
|
||||
EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
SqlCommand = """insert into Query2 (Name, Modifier, Value, Model)
|
||||
select Name, Modifier, Value, Model from %s where Model = %s""" \
|
||||
% (Identifier[0], MODEL_IDENTIFIER_MACRO_DEFINE)
|
||||
EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
|
||||
## ParseExecutionOrder() method
|
||||
#
|
||||
# Get final execution order
|
||||
# 1. Search all PPI
|
||||
# 2. Search all PROTOCOL
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def ParseExecutionOrder(self):
|
||||
EdkLogger.quiet("Searching Ppi/Protocol ... ")
|
||||
for Identifier in EotGlobalData.gIdentifierTableList:
|
||||
ModuleID, ModuleName, ModuleGuid, SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, Enabled = \
|
||||
-1, '', '', -1, '', '', '', '', '', '', '', '', 0
|
||||
|
||||
SourceFileID = Identifier[0].replace('Identifier', '')
|
||||
SourceFileFullPath = Identifier[1]
|
||||
Identifier = Identifier[0]
|
||||
|
||||
# Find Ppis
|
||||
ItemMode = 'Produced'
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.InstallPpi', '->InstallPpi', 'PeiInstallPpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchPpi(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode)
|
||||
|
||||
ItemMode = 'Produced'
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.ReInstallPpi', '->ReInstallPpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchPpi(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 2)
|
||||
|
||||
SearchPpiCallFunction(Identifier, SourceFileID, SourceFileFullPath, ItemMode)
|
||||
|
||||
ItemMode = 'Consumed'
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.LocatePpi', '->LocatePpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchPpi(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode)
|
||||
|
||||
SearchFunctionCalling(Identifier, SourceFileID, SourceFileFullPath, 'Ppi', ItemMode)
|
||||
|
||||
ItemMode = 'Callback'
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.NotifyPpi', '->NotifyPpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchPpi(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode)
|
||||
|
||||
# Find Procotols
|
||||
ItemMode = 'Produced'
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%' or Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.InstallProtocolInterface', '.ReInstallProtocolInterface', '->InstallProtocolInterface', '->ReInstallProtocolInterface', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 1)
|
||||
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.InstallMultipleProtocolInterfaces', '->InstallMultipleProtocolInterfaces', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 2)
|
||||
|
||||
SearchFunctionCalling(Identifier, SourceFileID, SourceFileFullPath, 'Protocol', ItemMode)
|
||||
|
||||
ItemMode = 'Consumed'
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.LocateProtocol', '->LocateProtocol', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 0)
|
||||
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.HandleProtocol', '->HandleProtocol', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 1)
|
||||
|
||||
SearchFunctionCalling(Identifier, SourceFileID, SourceFileFullPath, 'Protocol', ItemMode)
|
||||
|
||||
ItemMode = 'Callback'
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' or Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, '.RegisterProtocolNotify', '->RegisterProtocolNotify', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
SearchProtocols(SqlCommand, Identifier, SourceFileID, SourceFileFullPath, ItemMode, 0)
|
||||
|
||||
SearchFunctionCalling(Identifier, SourceFileID, SourceFileFullPath, 'Protocol', ItemMode)
|
||||
|
||||
# Hard Code
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gEfiSecPlatformInformationPpiGuid', '', '', '', 0)
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gEfiNtLoadAsDllPpiGuid', '', '', '', 0)
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gNtPeiLoadFileGuid', '', '', '', 0)
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiNtAutoScanPpiGuid', '', '', '', 0)
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gNtFwhPpiGuid', '', '', '', 0)
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiNtThunkPpiGuid', '', '', '', 0)
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiPlatformTypePpiGuid', '', '', '', 0)
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiFrequencySelectionCpuPpiGuid', '', '', '', 0)
|
||||
EotGlobalData.gDb.TblReport.Insert(-2, '', '', -1, '', '', 'Ppi', 'Produced', 'gPeiCachePpiGuid', '', '', '', 0)
|
||||
|
||||
EotGlobalData.gDb.Conn.commit()
|
||||
|
||||
|
||||
## BuildDatabase() methoc
|
||||
#
|
||||
# Build the database for target
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def BuildDatabase(self):
|
||||
# Clean report table
|
||||
EotGlobalData.gDb.TblReport.Drop()
|
||||
EotGlobalData.gDb.TblReport.Create()
|
||||
|
||||
# Build database
|
||||
if self.IsInit:
|
||||
self.BuildMetaDataFileDatabase(EotGlobalData.gINF_FILES)
|
||||
EdkLogger.quiet("Building database for source code ...")
|
||||
c.CreateCCodeDB(EotGlobalData.gSOURCE_FILES)
|
||||
EdkLogger.quiet("Building database for source code done!")
|
||||
|
||||
EotGlobalData.gIdentifierTableList = GetTableList((MODEL_FILE_C, MODEL_FILE_H), 'Identifier', EotGlobalData.gDb)
|
||||
|
||||
## BuildMetaDataFileDatabase() method
|
||||
#
|
||||
# Build the database for meta data files
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Inf_Files: A list for all INF files
|
||||
#
|
||||
def BuildMetaDataFileDatabase(self, Inf_Files):
|
||||
EdkLogger.quiet("Building database for meta data files ...")
|
||||
for InfFile in Inf_Files:
|
||||
EdkLogger.quiet("Parsing %s ..." % str(InfFile))
|
||||
EdkInfParser(InfFile, EotGlobalData.gDb, Inf_Files[InfFile], '')
|
||||
|
||||
EotGlobalData.gDb.Conn.commit()
|
||||
EdkLogger.quiet("Building database for meta data files done!")
|
||||
|
||||
## ParseOption() method
|
||||
#
|
||||
# Parse command line options
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def ParseOption(self):
|
||||
(Options, Target) = self.EotOptionParser()
|
||||
|
||||
# Set log level
|
||||
self.SetLogLevel(Options)
|
||||
|
||||
if Options.FvFileList:
|
||||
self.FvFileList = Options.FvFileList
|
||||
|
||||
if Options.MapFileList:
|
||||
self.MapFileList = Options.FvMapFileList
|
||||
|
||||
if Options.SourceFileList:
|
||||
self.SourceFileList = Options.SourceFileList
|
||||
|
||||
if Options.IncludeDirList:
|
||||
self.IncludeDirList = Options.IncludeDirList
|
||||
|
||||
if Options.DecFileList:
|
||||
self.DecFileList = Options.DecFileList
|
||||
|
||||
if Options.GuidList:
|
||||
self.GuidList = Options.GuidList
|
||||
|
||||
if Options.LogFile:
|
||||
self.LogFile = Options.LogFile
|
||||
|
||||
if Options.keepdatabase:
|
||||
self.IsInit = False
|
||||
|
||||
## SetLogLevel() method
|
||||
#
|
||||
# Set current log level of the tool based on args
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Option: The option list including log level setting
|
||||
#
|
||||
def SetLogLevel(self, Option):
|
||||
if Option.verbose != None:
|
||||
EdkLogger.SetLevel(EdkLogger.VERBOSE)
|
||||
elif Option.quiet != None:
|
||||
EdkLogger.SetLevel(EdkLogger.QUIET)
|
||||
elif Option.debug != None:
|
||||
EdkLogger.SetLevel(Option.debug + 1)
|
||||
else:
|
||||
EdkLogger.SetLevel(EdkLogger.INFO)
|
||||
|
||||
## EotOptionParser() method
|
||||
#
|
||||
# Using standard Python module optparse to parse command line option of this tool.
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
# @retval Opt A optparse.Values object containing the parsed options
|
||||
# @retval Args Target of build command
|
||||
#
|
||||
def EotOptionParser(self):
|
||||
Parser = OptionParser(description = self.Copyright, version = self.Version, prog = "Eot.exe", usage = "%prog [options]")
|
||||
Parser.add_option("-m", "--makefile filename", action="store", type="string", dest='MakeFile',
|
||||
help="Specify a makefile for the platform.")
|
||||
Parser.add_option("-c", "--dsc filename", action="store", type="string", dest="DscFile",
|
||||
help="Specify a dsc file for the platform.")
|
||||
Parser.add_option("-f", "--fv filename", action="store", type="string", dest="FvFileList",
|
||||
help="Specify fv file list, quoted by \"\".")
|
||||
Parser.add_option("-a", "--map filename", action="store", type="string", dest="MapFileList",
|
||||
help="Specify map file list, quoted by \"\".")
|
||||
Parser.add_option("-s", "--source files", action="store", type="string", dest="SourceFileList",
|
||||
help="Specify source file list by a file")
|
||||
Parser.add_option("-i", "--include dirs", action="store", type="string", dest="IncludeDirList",
|
||||
help="Specify include dir list by a file")
|
||||
Parser.add_option("-e", "--dec files", action="store", type="string", dest="DecFileList",
|
||||
help="Specify dec file list by a file")
|
||||
Parser.add_option("-g", "--guid list", action="store", type="string", dest="GuidList",
|
||||
help="Specify guid file list by a file")
|
||||
Parser.add_option("-l", "--log filename", action="store", type="string", dest="LogFile",
|
||||
help="Specify real execution log file")
|
||||
|
||||
Parser.add_option("-k", "--keepdatabase", action="store_true", type=None, help="The existing Eot database will not be cleaned except report information if this option is specified.")
|
||||
|
||||
Parser.add_option("-q", "--quiet", action="store_true", type=None, help="Disable all messages except FATAL ERRORS.")
|
||||
Parser.add_option("-v", "--verbose", action="store_true", type=None, help="Turn on verbose output with informational messages printed, "\
|
||||
"including library instances selected, final dependency expression, "\
|
||||
"and warning messages, etc.")
|
||||
Parser.add_option("-d", "--debug", action="store", type="int", help="Enable debug messages at specified level.")
|
||||
|
||||
(Opt, Args)=Parser.parse_args()
|
||||
|
||||
return (Opt, Args)
|
||||
|
||||
##
|
||||
#
|
||||
# This acts like the main() function for the script, unless it is 'import'ed into another
|
||||
# script.
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
# Initialize log system
|
||||
EdkLogger.Initialize()
|
||||
EdkLogger.IsRaiseError = False
|
||||
EdkLogger.quiet(time.strftime("%H:%M:%S, %b.%d %Y ", time.localtime()) + "[00:00]" + "\n")
|
||||
|
||||
StartTime = time.clock()
|
||||
Eot = Eot()
|
||||
FinishTime = time.clock()
|
||||
|
||||
BuildDuration = time.strftime("%M:%S", time.gmtime(int(round(FinishTime - StartTime))))
|
||||
EdkLogger.quiet("\n%s [%s]" % (time.strftime("%H:%M:%S, %b.%d %Y", time.localtime()), BuildDuration))
|
138
BaseTools/Source/Python/Eot/EotGlobalData.py
Normal file
138
BaseTools/Source/Python/Eot/EotGlobalData.py
Normal file
@@ -0,0 +1,138 @@
|
||||
## @file
|
||||
# This file is used to save global datas
|
||||
#
|
||||
# Copyright (c) 2008 - 2010, Intel Corporation
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
from Common.Misc import sdict
|
||||
|
||||
gEFI_SOURCE = ''
|
||||
gEDK_SOURCE = ''
|
||||
gWORKSPACE = ''
|
||||
gSHELL_INF = 'Application\Shell'
|
||||
gMAKE_FILE = ''
|
||||
gDSC_FILE = ''
|
||||
gFV_FILE = []
|
||||
gFV = []
|
||||
gMAP_FILE = []
|
||||
gMap = {}
|
||||
|
||||
|
||||
gDb = ''
|
||||
gIdentifierTableList = []
|
||||
|
||||
# Global macro
|
||||
gMACRO = {}
|
||||
gMACRO['EFI_SOURCE'] = gEFI_SOURCE
|
||||
gMACRO['EDK_SOURCE'] = gEDK_SOURCE
|
||||
gMACRO['SHELL_INF'] = gSHELL_INF
|
||||
gMACRO['CAPSULE_INF'] = ''
|
||||
|
||||
gNOT_FOUND_FILES = []
|
||||
gSOURCE_FILES = []
|
||||
gINF_FILES = {}
|
||||
gDEC_FILES = []
|
||||
|
||||
# Log file for unmatched variables
|
||||
gUN_MATCHED_LOG = 'Log_UnMatched.log'
|
||||
gOP_UN_MATCHED = open(gUN_MATCHED_LOG, 'w+')
|
||||
|
||||
# Log file for all INF files
|
||||
gINF_FILES = 'Log_Inf_File.log'
|
||||
gOP_INF = open(gINF_FILES, 'w+')
|
||||
|
||||
# Log file for not dispatched PEIM/DRIVER
|
||||
gUN_DISPATCHED_LOG = 'Log_UnDispatched.log'
|
||||
gOP_UN_DISPATCHED = open(gUN_DISPATCHED_LOG, 'w+')
|
||||
|
||||
# Log file for unmatched variables in function calling
|
||||
gUN_MATCHED_IN_LIBRARY_CALLING_LOG = 'Log_UnMatchedInLibraryCalling.log'
|
||||
gOP_UN_MATCHED_IN_LIBRARY_CALLING = open(gUN_MATCHED_IN_LIBRARY_CALLING_LOG, 'w+')
|
||||
|
||||
# Log file for order of dispatched PEIM/DRIVER
|
||||
gDISPATCH_ORDER_LOG = 'Log_DispatchOrder.log'
|
||||
gOP_DISPATCH_ORDER = open(gDISPATCH_ORDER_LOG, 'w+')
|
||||
|
||||
# Log file for source files not found
|
||||
gUN_FOUND_FILES = 'Log_UnFoundSourceFiles.log'
|
||||
gOP_UN_FOUND_FILES = open(gUN_FOUND_FILES, 'w+')
|
||||
|
||||
# Log file for found source files
|
||||
gSOURCE_FILES = 'Log_SourceFiles.log'
|
||||
gOP_SOURCE_FILES = open(gSOURCE_FILES, 'w+')
|
||||
|
||||
# Dict for GUID found in DEC files
|
||||
gGuidDict = sdict()
|
||||
|
||||
# Dict for hard coded GUID Macros
|
||||
# {GuidName : [GuidMacro : GuidValue]}
|
||||
gGuidMacroDict = sdict()
|
||||
|
||||
# Dict for PPI
|
||||
gPpiList = {}
|
||||
|
||||
# Dict for PROTOCOL
|
||||
gProtocolList = {}
|
||||
|
||||
# Dict for consumed PPI function calling
|
||||
gConsumedPpiLibrary = sdict()
|
||||
gConsumedPpiLibrary['EfiCommonLocateInterface'] = 0
|
||||
gConsumedPpiLibrary['PeiServicesLocatePpi'] = 0
|
||||
|
||||
# Dict for produced PROTOCOL function calling
|
||||
gProducedProtocolLibrary = sdict()
|
||||
gProducedProtocolLibrary['RegisterEsalClass'] = 0
|
||||
gProducedProtocolLibrary['CoreInstallProtocolInterface'] = 1
|
||||
gProducedProtocolLibrary['CoreInstallMultipleProtocolInterfaces'] = -1
|
||||
gProducedProtocolLibrary['EfiInstallProtocolInterface'] = 1
|
||||
gProducedProtocolLibrary['EfiReinstallProtocolInterface'] = 1
|
||||
gProducedProtocolLibrary['EfiLibNamedEventSignal'] = 0
|
||||
gProducedProtocolLibrary['LibInstallProtocolInterfaces'] = 1
|
||||
gProducedProtocolLibrary['LibReinstallProtocolInterfaces'] = 1
|
||||
|
||||
# Dict for consumed PROTOCOL function calling
|
||||
gConsumedProtocolLibrary = sdict()
|
||||
gConsumedProtocolLibrary['EfiHandleProtocol'] = 0
|
||||
gConsumedProtocolLibrary['EfiLocateProtocolHandleBuffers'] = 0
|
||||
gConsumedProtocolLibrary['EfiLocateProtocolInterface'] = 0
|
||||
gConsumedProtocolLibrary['EfiHandleProtocol'] = 1
|
||||
|
||||
# Dict for callback PROTOCOL function callling
|
||||
gCallbackProtocolLibrary = sdict()
|
||||
gCallbackProtocolLibrary['EfiRegisterProtocolCallback'] = 2
|
||||
|
||||
# Dict for ARCH PROTOCOL
|
||||
gArchProtocols = ['gEfiBdsArchProtocolGuid',
|
||||
'gEfiCapsuleArchProtocolGuid',
|
||||
'gEfiCpuArchProtocolGuid', #5053697e-2cbc-4819-90d9-0580deee5754
|
||||
'gEfiMetronomeArchProtocolGuid',
|
||||
'gEfiMonotonicCounterArchProtocolGuid',
|
||||
'gEfiRealTimeClockArchProtocolGuid',
|
||||
'gEfiResetArchProtocolGuid',
|
||||
'gEfiRuntimeArchProtocolGuid',
|
||||
'gEfiSecurityArchProtocolGuid',
|
||||
'gEfiStatusCodeRuntimeProtocolGuid',
|
||||
'gEfiTimerArchProtocolGuid',
|
||||
'gEfiVariableArchProtocolGuid',
|
||||
'gEfiVariableWriteArchProtocolGuid',
|
||||
'gEfiWatchdogTimerArchProtocolGuid']
|
||||
gArchProtocolGuids = ['665e3ff6-46cc-11d4-9a38-0090273fc14d',
|
||||
'26baccb1-6f42-11d4-bce7-0080c73c8881',
|
||||
'26baccb2-6f42-11d4-bce7-0080c73c8881',
|
||||
'1da97072-bddc-4b30-99f1-72a0b56fff2a',
|
||||
'27cfac87-46cc-11d4-9a38-0090273fc14d',
|
||||
'27cfac88-46cc-11d4-9a38-0090273fc14d',
|
||||
'b7dfb4e1-052f-449f-87be-9818fc91b733',
|
||||
'a46423e3-4617-49f1-b9ff-d1bfa9115839',
|
||||
'd2b2b828-0826-48a7-b3df-983c006024f0',
|
||||
'26baccb3-6f42-11d4-bce7-0080c73c8881',
|
||||
'1e5668e2-8481-11d4-bcf1-0080c73c8881',
|
||||
'6441f818-6362-4e44-b570-7dba31dd2453',
|
||||
'665e3ff5-46cc-11d4-9a38-0090273fc14d']
|
21
BaseTools/Source/Python/Eot/EotToolError.py
Normal file
21
BaseTools/Source/Python/Eot/EotToolError.py
Normal file
@@ -0,0 +1,21 @@
|
||||
## @file
|
||||
# Standardized Error Handling infrastructures.
|
||||
#
|
||||
# Copyright (c) 2008 - 2010, Intel Corporation
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
# Error id
|
||||
ERROR_1 = 1000
|
||||
|
||||
# Error message
|
||||
gEccErrorMessage = {
|
||||
ERROR_1 : "RESERVED"
|
||||
}
|
||||
|
58
BaseTools/Source/Python/Eot/FileProfile.py
Normal file
58
BaseTools/Source/Python/Eot/FileProfile.py
Normal file
@@ -0,0 +1,58 @@
|
||||
## @file
|
||||
# fragments of source file
|
||||
#
|
||||
# Copyright (c) 2007 - 2010, Intel Corporation
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
|
||||
import re
|
||||
import os
|
||||
from ParserWarning import Warning
|
||||
|
||||
# Profile contents of a file
|
||||
PPDirectiveList = []
|
||||
AssignmentExpressionList = []
|
||||
PredicateExpressionList = []
|
||||
FunctionDefinitionList = []
|
||||
VariableDeclarationList = []
|
||||
EnumerationDefinitionList = []
|
||||
StructUnionDefinitionList = []
|
||||
TypedefDefinitionList = []
|
||||
FunctionCallingList = []
|
||||
|
||||
## Class FileProfile
|
||||
#
|
||||
# record file data when parsing source
|
||||
#
|
||||
# May raise Exception when opening file.
|
||||
#
|
||||
class FileProfile :
|
||||
|
||||
## The constructor
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param FileName: The file that to be parsed
|
||||
#
|
||||
def __init__(self, FileName):
|
||||
self.FileLinesList = []
|
||||
self.FileLinesListFromFile = []
|
||||
try:
|
||||
fsock = open(FileName, "rb", 0)
|
||||
try:
|
||||
self.FileLinesListFromFile = fsock.readlines()
|
||||
finally:
|
||||
fsock.close()
|
||||
|
||||
except IOError:
|
||||
raise Warning("Error when opening file %s" % FileName)
|
1453
BaseTools/Source/Python/Eot/FvImage.py
Normal file
1453
BaseTools/Source/Python/Eot/FvImage.py
Normal file
File diff suppressed because it is too large
Load Diff
171
BaseTools/Source/Python/Eot/InfParserLite.py
Normal file
171
BaseTools/Source/Python/Eot/InfParserLite.py
Normal file
@@ -0,0 +1,171 @@
|
||||
## @file
|
||||
# This file is used to parse INF file of EDK project
|
||||
#
|
||||
# Copyright (c) 2008 - 2010 Intel Corporation
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import os
|
||||
import Common.EdkLogger as EdkLogger
|
||||
from Common.DataType import *
|
||||
from CommonDataClass.DataClass import *
|
||||
from Common.Identification import *
|
||||
from Common.String import *
|
||||
from Parser import *
|
||||
import Database
|
||||
|
||||
## EdkInfParser() class
|
||||
#
|
||||
# This class defined basic INF object which is used by inheriting
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
class EdkInfParser(object):
|
||||
## The constructor
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Filename: INF file name
|
||||
# @param Database: Eot database
|
||||
# @param SourceFileList: A list for all source file belonging this INF file
|
||||
# @param SourceOverridePath: Override path for source file
|
||||
# @param Edk_Source: Envirnoment variable EDK_SOURCE
|
||||
# @param Efi_Source: Envirnoment variable EFI_SOURCE
|
||||
#
|
||||
def __init__(self, Filename = None, Database = None, SourceFileList = None, SourceOverridePath = None, Edk_Source = None, Efi_Source = None):
|
||||
self.Identification = Identification()
|
||||
self.Sources = []
|
||||
self.Macros = {}
|
||||
|
||||
self.Cur = Database.Cur
|
||||
self.TblFile = Database.TblFile
|
||||
self.TblInf = Database.TblInf
|
||||
self.FileID = -1
|
||||
self.SourceOverridePath = SourceOverridePath
|
||||
|
||||
# Load Inf file if filename is not None
|
||||
if Filename != None:
|
||||
self.LoadInfFile(Filename)
|
||||
|
||||
if SourceFileList:
|
||||
for Item in SourceFileList:
|
||||
self.TblInf.Insert(MODEL_EFI_SOURCE_FILE, Item, '', '', '', '', 'COMMON', -1, self.FileID, -1, -1, -1, -1, 0)
|
||||
|
||||
|
||||
## LoadInffile() method
|
||||
#
|
||||
# Load INF file and insert a record in database
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Filename: Input value for filename of Inf file
|
||||
#
|
||||
def LoadInfFile(self, Filename = None):
|
||||
# Insert a record for file
|
||||
Filename = NormPath(Filename)
|
||||
self.Identification.FileFullPath = Filename
|
||||
(self.Identification.FileRelativePath, self.Identification.FileName) = os.path.split(Filename)
|
||||
|
||||
self.FileID = self.TblFile.InsertFile(Filename, MODEL_FILE_INF)
|
||||
|
||||
self.ParseInf(PreProcess(Filename, False), self.Identification.FileRelativePath, Filename)
|
||||
|
||||
## ParserSource() method
|
||||
#
|
||||
# Parse Source section and insert records in database
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param CurrentSection: current section name
|
||||
# @param SectionItemList: the item belonging current section
|
||||
# @param ArchList: A list for arch for this section
|
||||
# @param ThirdList: A list for third item for this section
|
||||
#
|
||||
def ParserSource(self, CurrentSection, SectionItemList, ArchList, ThirdList):
|
||||
for Index in range(0, len(ArchList)):
|
||||
Arch = ArchList[Index]
|
||||
Third = ThirdList[Index]
|
||||
if Arch == '':
|
||||
Arch = TAB_ARCH_COMMON
|
||||
|
||||
for Item in SectionItemList:
|
||||
if CurrentSection.upper() == 'defines'.upper():
|
||||
(Name, Value) = AddToSelfMacro(self.Macros, Item[0])
|
||||
self.TblInf.Insert(MODEL_META_DATA_HEADER, Name, Value, Third, '', '', Arch, -1, self.FileID, Item[1], -1, Item[1], -1, 0)
|
||||
|
||||
## ParseInf() method
|
||||
#
|
||||
# Parse INF file and get sections information
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Lines: contents of INF file
|
||||
# @param FileRelativePath: relative path of the file
|
||||
# @param Filename: file name of INF file
|
||||
#
|
||||
def ParseInf(self, Lines = [], FileRelativePath = '', Filename = ''):
|
||||
IfDefList, SectionItemList, CurrentSection, ArchList, ThirdList, IncludeFiles = \
|
||||
[], [], TAB_UNKNOWN, [], [], []
|
||||
LineNo = 0
|
||||
|
||||
for Line in Lines:
|
||||
LineNo = LineNo + 1
|
||||
if Line == '':
|
||||
continue
|
||||
if Line.startswith(TAB_SECTION_START) and Line.endswith(TAB_SECTION_END):
|
||||
self.ParserSource(CurrentSection, SectionItemList, ArchList, ThirdList)
|
||||
|
||||
# Parse the new section
|
||||
SectionItemList = []
|
||||
ArchList = []
|
||||
ThirdList = []
|
||||
# Parse section name
|
||||
CurrentSection = ''
|
||||
LineList = GetSplitValueList(Line[len(TAB_SECTION_START):len(Line) - len(TAB_SECTION_END)], TAB_COMMA_SPLIT)
|
||||
for Item in LineList:
|
||||
ItemList = GetSplitValueList(Item, TAB_SPLIT)
|
||||
if CurrentSection == '':
|
||||
CurrentSection = ItemList[0]
|
||||
else:
|
||||
if CurrentSection != ItemList[0]:
|
||||
EdkLogger.error("Parser", PARSER_ERROR, "Different section names '%s' and '%s' are found in one section definition, this is not allowed." % (CurrentSection, ItemList[0]), File=Filename, Line=LineNo)
|
||||
ItemList.append('')
|
||||
ItemList.append('')
|
||||
if len(ItemList) > 5:
|
||||
RaiseParserError(Line, CurrentSection, Filename, '', LineNo)
|
||||
else:
|
||||
ArchList.append(ItemList[1].upper())
|
||||
ThirdList.append(ItemList[2])
|
||||
|
||||
continue
|
||||
|
||||
# Add a section item
|
||||
SectionItemList.append([Line, LineNo])
|
||||
# End of parse
|
||||
|
||||
self.ParserSource(CurrentSection, SectionItemList, ArchList, ThirdList)
|
||||
#End of For
|
||||
|
||||
##
|
||||
#
|
||||
# This acts like the main() function for the script, unless it is 'import'ed into another
|
||||
# script.
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
EdkLogger.Initialize()
|
||||
EdkLogger.SetLevel(EdkLogger.QUIET)
|
||||
|
||||
Db = Database.Database('Inf.db')
|
||||
Db.InitDatabase()
|
||||
P = EdkInfParser(os.path.normpath("C:\Framework\Edk\Sample\Platform\Nt32\Dxe\PlatformBds\PlatformBds.inf"), Db, '', '')
|
||||
for Inf in P.Sources:
|
||||
print Inf
|
||||
for Item in P.Macros:
|
||||
print Item, P.Macros[Item]
|
||||
|
||||
Db.Close()
|
BIN
BaseTools/Source/Python/Eot/LzmaCompressor.pyd
Normal file
BIN
BaseTools/Source/Python/Eot/LzmaCompressor.pyd
Normal file
Binary file not shown.
848
BaseTools/Source/Python/Eot/Parser.py
Normal file
848
BaseTools/Source/Python/Eot/Parser.py
Normal file
@@ -0,0 +1,848 @@
|
||||
## @file
|
||||
# This file is used to define common parsing related functions used in parsing
|
||||
# Inf/Dsc/Makefile process
|
||||
#
|
||||
# Copyright (c) 2008 - 2010, Intel Corporation
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import os, re
|
||||
import Common.EdkLogger as EdkLogger
|
||||
from Common.DataType import *
|
||||
from CommonDataClass.DataClass import *
|
||||
from Common.String import CleanString, GetSplitValueList, ReplaceMacro
|
||||
import EotGlobalData
|
||||
from Common.Misc import sdict
|
||||
|
||||
## PreProcess() method
|
||||
#
|
||||
# Pre process a file
|
||||
#
|
||||
# 1. Remove all comments
|
||||
# 2. Merge multiple lines code to one line
|
||||
#
|
||||
# @param Filename: Name of the file to be parsed
|
||||
# @param MergeMultipleLines: Switch for if merge multiple lines
|
||||
# @param LineNo: Default line no
|
||||
#
|
||||
# @return Lines: The file contents after remvoing comments
|
||||
#
|
||||
def PreProcess(Filename, MergeMultipleLines = True, LineNo = -1):
|
||||
Lines = []
|
||||
Filename = os.path.normpath(Filename)
|
||||
if not os.path.isfile(Filename):
|
||||
EdkLogger.error("Eot", EdkLogger.FILE_NOT_FOUND, ExtraData=Filename)
|
||||
|
||||
IsFindBlockComment = False
|
||||
IsFindBlockCode = False
|
||||
ReservedLine = ''
|
||||
ReservedLineLength = 0
|
||||
for Line in open(Filename, 'r'):
|
||||
Line = Line.strip()
|
||||
# Remove comment block
|
||||
if Line.find(TAB_COMMENT_R8_START) > -1:
|
||||
ReservedLine = GetSplitValueList(Line, TAB_COMMENT_R8_START, 1)[0]
|
||||
IsFindBlockComment = True
|
||||
if Line.find(TAB_COMMENT_R8_END) > -1:
|
||||
Line = ReservedLine + GetSplitValueList(Line, TAB_COMMENT_R8_END, 1)[1]
|
||||
ReservedLine = ''
|
||||
IsFindBlockComment = False
|
||||
if IsFindBlockComment:
|
||||
Lines.append('')
|
||||
continue
|
||||
|
||||
# Remove comments at tail and remove spaces again
|
||||
Line = CleanString(Line)
|
||||
if Line == '':
|
||||
Lines.append('')
|
||||
continue
|
||||
|
||||
if MergeMultipleLines:
|
||||
# Add multiple lines to one line
|
||||
if IsFindBlockCode and Line[-1] != TAB_SLASH:
|
||||
ReservedLine = (ReservedLine + TAB_SPACE_SPLIT + Line).strip()
|
||||
Lines.append(ReservedLine)
|
||||
for Index in (0, ReservedLineLength):
|
||||
Lines.append('')
|
||||
ReservedLine = ''
|
||||
ReservedLineLength = 0
|
||||
IsFindBlockCode = False
|
||||
continue
|
||||
if Line[-1] == TAB_SLASH:
|
||||
ReservedLine = ReservedLine + TAB_SPACE_SPLIT + Line[0:-1].strip()
|
||||
ReservedLineLength = ReservedLineLength + 1
|
||||
IsFindBlockCode = True
|
||||
continue
|
||||
|
||||
Lines.append(Line)
|
||||
|
||||
return Lines
|
||||
|
||||
## AddToGlobalMacro() method
|
||||
#
|
||||
# Add a macro to EotGlobalData.gMACRO
|
||||
#
|
||||
# @param Name: Name of the macro
|
||||
# @param Value: Value of the macro
|
||||
#
|
||||
def AddToGlobalMacro(Name, Value):
|
||||
Value = ReplaceMacro(Value, EotGlobalData.gMACRO, True)
|
||||
EotGlobalData.gMACRO[Name] = Value
|
||||
|
||||
## AddToSelfMacro() method
|
||||
#
|
||||
# Parse a line of macro definition and add it to a macro set
|
||||
#
|
||||
# @param SelfMacro: The self macro set
|
||||
# @param Line: The line of a macro definition
|
||||
#
|
||||
# @return Name: Name of macro
|
||||
# @return Value: Value of macro
|
||||
#
|
||||
def AddToSelfMacro(SelfMacro, Line):
|
||||
Name, Value = '', ''
|
||||
List = GetSplitValueList(Line, TAB_EQUAL_SPLIT, 1)
|
||||
if len(List) == 2:
|
||||
Name = List[0]
|
||||
Value = List[1]
|
||||
Value = ReplaceMacro(Value, EotGlobalData.gMACRO, True)
|
||||
Value = ReplaceMacro(Value, SelfMacro, True)
|
||||
SelfMacro[Name] = Value
|
||||
|
||||
return (Name, Value)
|
||||
|
||||
## GetIncludeListOfFile() method
|
||||
#
|
||||
# Get the include path list for a source file
|
||||
#
|
||||
# 1. Find the source file belongs to which INF file
|
||||
# 2. Find the inf's package
|
||||
# 3. Return the include path list of the package
|
||||
#
|
||||
# @param WorkSpace: WORKSPACE path
|
||||
# @param Filepath: File path
|
||||
# @param Db: Eot database
|
||||
#
|
||||
# @return IncludeList: A list of include directories
|
||||
#
|
||||
def GetIncludeListOfFile(WorkSpace, Filepath, Db):
|
||||
IncludeList = []
|
||||
Filepath = os.path.normpath(Filepath)
|
||||
SqlCommand = """
|
||||
select Value1 from Inf where Model = %s and BelongsToFile in(
|
||||
select distinct B.BelongsToFile from File as A left join Inf as B
|
||||
where A.ID = B.BelongsToFile and B.Model = %s and (A.Path || '%s' || B.Value1) = '%s')""" \
|
||||
% (MODEL_META_DATA_PACKAGE, MODEL_EFI_SOURCE_FILE, '\\', Filepath)
|
||||
RecordSet = Db.TblFile.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
DecFullPath = os.path.normpath(os.path.join(WorkSpace, Record[0]))
|
||||
(DecPath, DecName) = os.path.split(DecFullPath)
|
||||
SqlCommand = """select Value1 from Dec where BelongsToFile =
|
||||
(select ID from File where FullPath = '%s') and Model = %s""" \
|
||||
% (DecFullPath, MODEL_EFI_INCLUDE)
|
||||
NewRecordSet = Db.TblDec.Exec(SqlCommand)
|
||||
for NewRecord in NewRecordSet:
|
||||
IncludePath = os.path.normpath(os.path.join(DecPath, NewRecord[0]))
|
||||
if IncludePath not in IncludeList:
|
||||
IncludeList.append(IncludePath)
|
||||
|
||||
return IncludeList
|
||||
|
||||
## GetTableList() method
|
||||
#
|
||||
# Search table file and find all small tables
|
||||
#
|
||||
# @param FileModelList: Model code for the file list
|
||||
# @param Table: Table to insert records
|
||||
# @param Db: Eot database
|
||||
#
|
||||
# @return TableList: A list of tables
|
||||
#
|
||||
def GetTableList(FileModelList, Table, Db):
|
||||
TableList = []
|
||||
SqlCommand = """select ID, FullPath from File where Model in %s""" % str(FileModelList)
|
||||
RecordSet = Db.TblFile.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
TableName = Table + str(Record[0])
|
||||
TableList.append([TableName, Record[1]])
|
||||
|
||||
return TableList
|
||||
|
||||
## GetAllIncludeDir() method
|
||||
#
|
||||
# Find all Include directories
|
||||
#
|
||||
# @param Db: Eot database
|
||||
#
|
||||
# @return IncludeList: A list of include directories
|
||||
#
|
||||
def GetAllIncludeDirs(Db):
|
||||
IncludeList = []
|
||||
SqlCommand = """select distinct Value1 from Inf where Model = %s order by Value1""" % MODEL_EFI_INCLUDE
|
||||
RecordSet = Db.TblInf.Exec(SqlCommand)
|
||||
|
||||
for Record in RecordSet:
|
||||
IncludeList.append(Record[0])
|
||||
|
||||
return IncludeList
|
||||
|
||||
## GetAllIncludeFiles() method
|
||||
#
|
||||
# Find all Include files
|
||||
#
|
||||
# @param Db: Eot database
|
||||
#
|
||||
# @return IncludeFileList: A list of include files
|
||||
#
|
||||
def GetAllIncludeFiles(Db):
|
||||
IncludeList = GetAllIncludeDirs(Db)
|
||||
IncludeFileList = []
|
||||
|
||||
for Dir in IncludeList:
|
||||
if os.path.isdir(Dir):
|
||||
SubDir = os.listdir(Dir)
|
||||
for Item in SubDir:
|
||||
if os.path.isfile(Item):
|
||||
IncludeFileList.append(Item)
|
||||
|
||||
return IncludeFileList
|
||||
|
||||
## GetAllSourceFiles() method
|
||||
#
|
||||
# Find all source files
|
||||
#
|
||||
# @param Db: Eot database
|
||||
#
|
||||
# @return SourceFileList: A list of source files
|
||||
#
|
||||
def GetAllSourceFiles(Db):
|
||||
SourceFileList = []
|
||||
SqlCommand = """select distinct Value1 from Inf where Model = %s order by Value1""" % MODEL_EFI_SOURCE_FILE
|
||||
RecordSet = Db.TblInf.Exec(SqlCommand)
|
||||
|
||||
for Record in RecordSet:
|
||||
SourceFileList.append(Record[0])
|
||||
|
||||
return SourceFileList
|
||||
|
||||
## GetAllFiles() method
|
||||
#
|
||||
# Find all files, both source files and include files
|
||||
#
|
||||
# @param Db: Eot database
|
||||
#
|
||||
# @return FileList: A list of files
|
||||
#
|
||||
def GetAllFiles(Db):
|
||||
FileList = []
|
||||
IncludeFileList = GetAllIncludeFiles(Db)
|
||||
SourceFileList = GetAllSourceFiles(Db)
|
||||
for Item in IncludeFileList:
|
||||
if os.path.isfile(Item) and Item not in FileList:
|
||||
FileList.append(Item)
|
||||
for Item in SourceFileList:
|
||||
if os.path.isfile(Item) and Item not in FileList:
|
||||
FileList.append(Item)
|
||||
|
||||
return FileList
|
||||
|
||||
## ParseConditionalStatement() method
|
||||
#
|
||||
# Parse conditional statement
|
||||
#
|
||||
# @param Line: One line to be parsed
|
||||
# @param Macros: A set of all macro
|
||||
# @param StatusSet: A set of all status
|
||||
#
|
||||
# @retval True: Find keyword of conditional statement
|
||||
# @retval False: Not find keyword of conditional statement
|
||||
#
|
||||
def ParseConditionalStatement(Line, Macros, StatusSet):
|
||||
NewLine = Line.upper()
|
||||
if NewLine.find(TAB_IF_EXIST.upper()) > -1:
|
||||
IfLine = Line[NewLine.find(TAB_IF_EXIST) + len(TAB_IF_EXIST) + 1:].strip()
|
||||
IfLine = ReplaceMacro(IfLine, EotGlobalData.gMACRO, True)
|
||||
IfLine = ReplaceMacro(IfLine, Macros, True)
|
||||
IfLine = IfLine.replace("\"", '')
|
||||
IfLine = IfLine.replace("(", '')
|
||||
IfLine = IfLine.replace(")", '')
|
||||
Status = os.path.exists(os.path.normpath(IfLine))
|
||||
StatusSet.append([Status])
|
||||
return True
|
||||
if NewLine.find(TAB_IF_DEF.upper()) > -1:
|
||||
IfLine = Line[NewLine.find(TAB_IF_DEF) + len(TAB_IF_DEF) + 1:].strip()
|
||||
Status = False
|
||||
if IfLine in Macros or IfLine in EotGlobalData.gMACRO:
|
||||
Status = True
|
||||
StatusSet.append([Status])
|
||||
return True
|
||||
if NewLine.find(TAB_IF_N_DEF.upper()) > -1:
|
||||
IfLine = Line[NewLine.find(TAB_IF_N_DEF) + len(TAB_IF_N_DEF) + 1:].strip()
|
||||
Status = False
|
||||
if IfLine not in Macros and IfLine not in EotGlobalData.gMACRO:
|
||||
Status = True
|
||||
StatusSet.append([Status])
|
||||
return True
|
||||
if NewLine.find(TAB_IF.upper()) > -1:
|
||||
IfLine = Line[NewLine.find(TAB_IF) + len(TAB_IF) + 1:].strip()
|
||||
Status = ParseConditionalStatementMacros(IfLine, Macros)
|
||||
StatusSet.append([Status])
|
||||
return True
|
||||
if NewLine.find(TAB_ELSE_IF.upper()) > -1:
|
||||
IfLine = Line[NewLine.find(TAB_ELSE_IF) + len(TAB_ELSE_IF) + 1:].strip()
|
||||
Status = ParseConditionalStatementMacros(IfLine, Macros)
|
||||
StatusSet[-1].append(Status)
|
||||
return True
|
||||
if NewLine.find(TAB_ELSE.upper()) > -1:
|
||||
Status = False
|
||||
for Item in StatusSet[-1]:
|
||||
Status = Status or Item
|
||||
StatusSet[-1].append(not Status)
|
||||
return True
|
||||
if NewLine.find(TAB_END_IF.upper()) > -1:
|
||||
StatusSet.pop()
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
## ParseConditionalStatement() method
|
||||
#
|
||||
# Parse conditional statement with Macros
|
||||
#
|
||||
# @param Line: One line to be parsed
|
||||
# @param Macros: A set of macros
|
||||
#
|
||||
# @return Line: New line after replacing macros
|
||||
#
|
||||
def ParseConditionalStatementMacros(Line, Macros):
|
||||
if Line.upper().find('DEFINED(') > -1 or Line.upper().find('EXIST') > -1:
|
||||
return False
|
||||
Line = ReplaceMacro(Line, EotGlobalData.gMACRO, True)
|
||||
Line = ReplaceMacro(Line, Macros, True)
|
||||
Line = Line.replace("&&", "and")
|
||||
Line = Line.replace("||", "or")
|
||||
return eval(Line)
|
||||
|
||||
## GetConditionalStatementStatus() method
|
||||
#
|
||||
# 1. Assume the latest status as True
|
||||
# 2. Pop the top status of status set, previous status
|
||||
# 3. Compare the latest one and the previous one and get new status
|
||||
#
|
||||
# @param StatusSet: A set of all status
|
||||
#
|
||||
# @return Status: The final status
|
||||
#
|
||||
def GetConditionalStatementStatus(StatusSet):
|
||||
Status = True
|
||||
for Item in StatusSet:
|
||||
Status = Status and Item[-1]
|
||||
|
||||
return Status
|
||||
|
||||
## SearchBelongsToFunction() method
|
||||
#
|
||||
# Search all functions belong to the file
|
||||
#
|
||||
# @param BelongsToFile: File id
|
||||
# @param StartLine: Start line of search scope
|
||||
# @param EndLine: End line of search scope
|
||||
#
|
||||
# @return: The found function
|
||||
#
|
||||
def SearchBelongsToFunction(BelongsToFile, StartLine, EndLine):
|
||||
SqlCommand = """select ID, Name from Function where BelongsToFile = %s and StartLine <= %s and EndLine >= %s""" %(BelongsToFile, StartLine, EndLine)
|
||||
RecordSet = EotGlobalData.gDb.TblFunction.Exec(SqlCommand)
|
||||
if RecordSet != []:
|
||||
return RecordSet[0][0], RecordSet[0][1]
|
||||
else:
|
||||
return -1, ''
|
||||
|
||||
## SearchPpiCallFunction() method
|
||||
#
|
||||
# Search all used PPI calling function 'PeiServicesReInstallPpi' and 'PeiServicesInstallPpi'
|
||||
# Store the result to database
|
||||
#
|
||||
# @param Identifier: Table id
|
||||
# @param SourceFileID: Source file id
|
||||
# @param SourceFileFullPath: Source file full path
|
||||
# @param ItemMode: Mode of the item
|
||||
#
|
||||
def SearchPpiCallFunction(Identifier, SourceFileID, SourceFileFullPath, ItemMode):
|
||||
ItemName, ItemType, GuidName, GuidMacro, GuidValue = '', 'Ppi', '', '', ''
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' and Model = %s)""" \
|
||||
% (Identifier, 'PeiServicesReInstallPpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
BelongsToFunctionID, BelongsToFunction = -1, ''
|
||||
Db = EotGlobalData.gDb.TblReport
|
||||
RecordSet = Db.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
Index = 0
|
||||
BelongsToFile, StartLine, EndLine = Record[2], Record[3], Record[4]
|
||||
BelongsToFunctionID, BelongsToFunction = SearchBelongsToFunction(BelongsToFile, StartLine, EndLine)
|
||||
VariableList = Record[0].split(',')
|
||||
for Variable in VariableList:
|
||||
Variable = Variable.strip()
|
||||
# Get index of the variable
|
||||
if Variable.find('[') > -1:
|
||||
Index = int(Variable[Variable.find('[') + 1 : Variable.find(']')])
|
||||
Variable = Variable[:Variable.find('[')]
|
||||
# Get variable name
|
||||
if Variable.startswith('&'):
|
||||
Variable = Variable[1:]
|
||||
# Get variable value
|
||||
SqlCommand = """select Value from %s where (Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, Variable, MODEL_IDENTIFIER_VARIABLE)
|
||||
NewRecordSet = Db.Exec(SqlCommand)
|
||||
if NewRecordSet:
|
||||
NewRecord = NewRecordSet[0][0]
|
||||
VariableValueList = NewRecord.split('},')
|
||||
if len(VariableValueList) > Index:
|
||||
VariableValue = VariableValueList[Index]
|
||||
NewVariableValueList = VariableValue.split(',')
|
||||
if len(NewVariableValueList) > 1:
|
||||
NewVariableValue = NewVariableValueList[1].strip()
|
||||
if NewVariableValue.startswith('&'):
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, NewVariableValue[1:], GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
continue
|
||||
else:
|
||||
EotGlobalData.gOP_UN_MATCHED.write('%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, NewParameter))
|
||||
|
||||
ItemName, ItemType, GuidName, GuidMacro, GuidValue = '', 'Ppi', '', '', ''
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Value like '%%%s%%' and Model = %s)""" \
|
||||
% (Identifier, 'PeiServicesInstallPpi', MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION)
|
||||
BelongsToFunctionID, BelongsToFunction = -1, ''
|
||||
Db = EotGlobalData.gDb.TblReport
|
||||
RecordSet = Db.Exec(SqlCommand)
|
||||
|
||||
SqlCommand = """select Value, Name, BelongsToFile, StartLine, EndLine from %s
|
||||
where (Name like '%%%s%%' and Model = %s)""" \
|
||||
% (Identifier, 'PeiServicesInstallPpi', MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
Db = EotGlobalData.gDb.TblReport
|
||||
RecordSet2 = Db.Exec(SqlCommand)
|
||||
|
||||
for Record in RecordSet + RecordSet2:
|
||||
if Record == []:
|
||||
continue
|
||||
Index = 0
|
||||
BelongsToFile, StartLine, EndLine = Record[2], Record[3], Record[4]
|
||||
BelongsToFunctionID, BelongsToFunction = SearchBelongsToFunction(BelongsToFile, StartLine, EndLine)
|
||||
Variable = Record[0].replace('PeiServicesInstallPpi', '').replace('(', '').replace(')', '').replace('&', '').strip()
|
||||
Variable = Variable[Variable.find(',') + 1:].strip()
|
||||
# Get index of the variable
|
||||
if Variable.find('[') > -1:
|
||||
Index = int(Variable[Variable.find('[') + 1 : Variable.find(']')])
|
||||
Variable = Variable[:Variable.find('[')]
|
||||
# Get variable name
|
||||
if Variable.startswith('&'):
|
||||
Variable = Variable[1:]
|
||||
# Get variable value
|
||||
SqlCommand = """select Value from %s where (Name like '%%%s%%') and Model = %s""" \
|
||||
% (Identifier, Variable, MODEL_IDENTIFIER_VARIABLE)
|
||||
NewRecordSet = Db.Exec(SqlCommand)
|
||||
if NewRecordSet:
|
||||
NewRecord = NewRecordSet[0][0]
|
||||
VariableValueList = NewRecord.split('},')
|
||||
if len(VariableValueList) > Index:
|
||||
VariableValue = VariableValueList[Index]
|
||||
NewVariableValueList = VariableValue.split(',')
|
||||
if len(NewVariableValueList) > 1:
|
||||
NewVariableValue = NewVariableValueList[1].strip()
|
||||
if NewVariableValue.startswith('&'):
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, NewVariableValue[1:], GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
continue
|
||||
else:
|
||||
EotGlobalData.gOP_UN_MATCHED.write('%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, NewParameter))
|
||||
|
||||
## SearchPpis() method
|
||||
#
|
||||
# Search all used PPI calling function
|
||||
# Store the result to database
|
||||
#
|
||||
# @param SqlCommand: SQL command statement
|
||||
# @param Table: Table id
|
||||
# @param SourceFileID: Source file id
|
||||
# @param SourceFileFullPath: Source file full path
|
||||
# @param ItemMode: Mode of the item
|
||||
# @param PpiMode: Mode of PPI
|
||||
#
|
||||
def SearchPpi(SqlCommand, Table, SourceFileID, SourceFileFullPath, ItemMode, PpiMode = 1):
|
||||
ItemName, ItemType, GuidName, GuidMacro, GuidValue = '', 'Ppi', '', '', ''
|
||||
BelongsToFunctionID, BelongsToFunction = -1, ''
|
||||
Db = EotGlobalData.gDb.TblReport
|
||||
RecordSet = Db.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
Parameter = GetPpiParameter(Record[0], PpiMode)
|
||||
BelongsToFile, StartLine, EndLine = Record[2], Record[3], Record[4]
|
||||
# Get BelongsToFunction
|
||||
BelongsToFunctionID, BelongsToFunction = SearchBelongsToFunction(BelongsToFile, StartLine, EndLine)
|
||||
|
||||
# Default is Not Found
|
||||
IsFound = False
|
||||
|
||||
# For Consumed Ppi
|
||||
if ItemMode == 'Consumed':
|
||||
if Parameter.startswith('g'):
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, Parameter, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
else:
|
||||
EotGlobalData.gOP_UN_MATCHED.write('%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter))
|
||||
continue
|
||||
|
||||
# Direct Parameter.Guid
|
||||
SqlCommand = """select Value from %s where (Name like '%%%s.Guid%%' or Name like '%%%s->Guid%%') and Model = %s""" % (Table, Parameter, Parameter, MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION)
|
||||
NewRecordSet = Db.Exec(SqlCommand)
|
||||
for NewRecord in NewRecordSet:
|
||||
GuidName = GetParameterName(NewRecord[0])
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
IsFound = True
|
||||
|
||||
# Defined Parameter
|
||||
if not IsFound:
|
||||
Key = Parameter
|
||||
if Key.rfind(' ') > -1:
|
||||
Key = Key[Key.rfind(' ') : ].strip().replace('&', '')
|
||||
Value = FindKeyValue(EotGlobalData.gDb.TblFile, Table, Key)
|
||||
List = GetSplitValueList(Value.replace('\n', ''), TAB_COMMA_SPLIT)
|
||||
if len(List) > 1:
|
||||
GuidName = GetParameterName(List[1])
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
IsFound = True
|
||||
|
||||
# A list Parameter
|
||||
if not IsFound:
|
||||
Start = Parameter.find('[')
|
||||
End = Parameter.find(']')
|
||||
if Start > -1 and End > -1 and Start < End:
|
||||
try:
|
||||
Index = int(Parameter[Start + 1 : End])
|
||||
Parameter = Parameter[0 : Start]
|
||||
SqlCommand = """select Value from %s where Name = '%s' and Model = %s""" % (Table, Parameter, MODEL_IDENTIFIER_VARIABLE)
|
||||
NewRecordSet = Db.Exec(SqlCommand)
|
||||
for NewRecord in NewRecordSet:
|
||||
NewParameter = GetSplitValueList(NewRecord[0], '}')[Index]
|
||||
GuidName = GetPpiParameter(NewParameter[NewParameter.find('{') : ])
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
IsFound = True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# A External Parameter
|
||||
if not IsFound:
|
||||
SqlCommand = """select File.ID from Inf, File
|
||||
where BelongsToFile = (select BelongsToFile from Inf where Value1 = '%s')
|
||||
and Inf.Model = %s and Inf.Value1 = File.FullPath and File.Model = %s""" % (SourceFileFullPath, MODEL_EFI_SOURCE_FILE, MODEL_FILE_C)
|
||||
NewRecordSet = Db.Exec(SqlCommand)
|
||||
for NewRecord in NewRecordSet:
|
||||
Table = 'Identifier' + str(NewRecord[0])
|
||||
SqlCommand = """select Value from %s where Name = '%s' and Modifier = 'EFI_PEI_PPI_DESCRIPTOR' and Model = %s""" % (Table, Parameter, MODEL_IDENTIFIER_VARIABLE)
|
||||
PpiSet = Db.Exec(SqlCommand)
|
||||
if PpiSet != []:
|
||||
GuidName = GetPpiParameter(PpiSet[0][0])
|
||||
if GuidName != '':
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
IsFound = True
|
||||
break
|
||||
|
||||
if not IsFound:
|
||||
EotGlobalData.gOP_UN_MATCHED.write('%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter))
|
||||
|
||||
## SearchProtocols() method
|
||||
#
|
||||
# Search all used PROTOCOL calling function
|
||||
# Store the result to database
|
||||
#
|
||||
# @param SqlCommand: SQL command statement
|
||||
# @param Table: Table id
|
||||
# @param SourceFileID: Source file id
|
||||
# @param SourceFileFullPath: Source file full path
|
||||
# @param ItemMode: Mode of the item
|
||||
# @param ProtocolMode: Mode of PROTOCOL
|
||||
#
|
||||
def SearchProtocols(SqlCommand, Table, SourceFileID, SourceFileFullPath, ItemMode, ProtocolMode):
|
||||
ItemName, ItemType, GuidName, GuidMacro, GuidValue = '', 'Protocol', '', '', ''
|
||||
BelongsToFunctionID, BelongsToFunction = -1, ''
|
||||
Db = EotGlobalData.gDb.TblReport
|
||||
RecordSet = Db.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
Parameter = ''
|
||||
BelongsToFile, StartLine, EndLine = Record[2], Record[3], Record[4]
|
||||
# Get BelongsToFunction
|
||||
BelongsToFunctionID, BelongsToFunction = SearchBelongsToFunction(BelongsToFile, StartLine, EndLine)
|
||||
|
||||
# Default is Not Found
|
||||
IsFound = False
|
||||
|
||||
if ProtocolMode == 0 or ProtocolMode == 1:
|
||||
Parameter = GetProtocolParameter(Record[0], ProtocolMode)
|
||||
if Parameter.startswith('g') or Parameter.endswith('Guid') or Parameter == 'ShellEnvProtocol' or Parameter == 'ShellInterfaceProtocol':
|
||||
GuidName = GetParameterName(Parameter)
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
IsFound = True
|
||||
|
||||
if ProtocolMode == 2:
|
||||
Protocols = GetSplitValueList(Record[0], TAB_COMMA_SPLIT)
|
||||
for Protocol in Protocols:
|
||||
if Protocol.startswith('&') and Protocol.endswith('Guid'):
|
||||
GuidName = GetParameterName(Protocol)
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
IsFound = True
|
||||
else:
|
||||
NewValue = FindKeyValue(EotGlobalData.gDb.TblFile, Table, Protocol)
|
||||
if Protocol != NewValue and NewValue.endswith('Guid'):
|
||||
GuidName = GetParameterName(NewValue)
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
IsFound = True
|
||||
|
||||
if not IsFound:
|
||||
if BelongsToFunction in EotGlobalData.gProducedProtocolLibrary or BelongsToFunction in EotGlobalData.gConsumedProtocolLibrary:
|
||||
EotGlobalData.gOP_UN_MATCHED_IN_LIBRARY_CALLING.write('%s, %s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter, BelongsToFunction))
|
||||
else:
|
||||
EotGlobalData.gOP_UN_MATCHED.write('%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter))
|
||||
|
||||
## SearchFunctionCalling() method
|
||||
#
|
||||
# Search all used PPI/PROTOCOL calling function by library
|
||||
# Store the result to database
|
||||
#
|
||||
# @param SqlCommand: SQL command statement
|
||||
# @param Table: Table id
|
||||
# @param SourceFileID: Source file id
|
||||
# @param SourceFileFullPath: Source file full path
|
||||
# @param ItemType: Type of the item, PPI or PROTOCOL
|
||||
# @param ItemMode: Mode of item
|
||||
#
|
||||
def SearchFunctionCalling(Table, SourceFileID, SourceFileFullPath, ItemType, ItemMode):
|
||||
LibraryList = sdict()
|
||||
Db = EotGlobalData.gDb.TblReport
|
||||
Parameters, ItemName, GuidName, GuidMacro, GuidValue, BelongsToFunction = [], '', '', '', '', ''
|
||||
if ItemType == 'Protocol' and ItemMode == 'Produced':
|
||||
LibraryList = EotGlobalData.gProducedProtocolLibrary
|
||||
elif ItemType == 'Protocol' and ItemMode == 'Consumed':
|
||||
LibraryList = EotGlobalData.gConsumedProtocolLibrary
|
||||
elif ItemType == 'Protocol' and ItemMode == 'Callback':
|
||||
LibraryList = EotGlobalData.gCallbackProtocolLibrary
|
||||
elif ItemType == 'Ppi' and ItemMode == 'Produced':
|
||||
LibraryList = EotGlobalData.gProducedPpiLibrary
|
||||
elif ItemType == 'Ppi' and ItemMode == 'Consumed':
|
||||
LibraryList = EotGlobalData.gConsumedPpiLibrary
|
||||
|
||||
for Library in LibraryList:
|
||||
Index = LibraryList[Library]
|
||||
SqlCommand = """select Value, StartLine from %s
|
||||
where Name like '%%%s%%' and Model = %s""" \
|
||||
% (Table, Library, MODEL_IDENTIFIER_FUNCTION_CALLING)
|
||||
RecordSet = Db.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
IsFound = False
|
||||
if Index == -1:
|
||||
ParameterList = GetSplitValueList(Record[0], TAB_COMMA_SPLIT)
|
||||
for Parameter in ParameterList:
|
||||
Parameters.append(GetParameterName(Parameter))
|
||||
else:
|
||||
Parameters = [GetProtocolParameter(Record[0], Index)]
|
||||
StartLine = Record[1]
|
||||
for Parameter in Parameters:
|
||||
if Parameter.startswith('g') or Parameter.endswith('Guid') or Parameter == 'ShellEnvProtocol' or Parameter == 'ShellInterfaceProtocol':
|
||||
GuidName = GetParameterName(Parameter)
|
||||
Db.Insert(-1, '', '', SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue, BelongsToFunction, 0)
|
||||
IsFound = True
|
||||
|
||||
if not IsFound:
|
||||
EotGlobalData.gOP_UN_MATCHED.write('%s, %s, %s, %s, %s, %s\n' % (ItemType, ItemMode, SourceFileID, SourceFileFullPath, StartLine, Parameter))
|
||||
|
||||
## FindProtocols() method
|
||||
#
|
||||
# Find defined protocols
|
||||
#
|
||||
# @param SqlCommand: SQL command statement
|
||||
# @param Table: Table id
|
||||
# @param SourceFileID: Source file id
|
||||
# @param SourceFileFullPath: Source file full path
|
||||
# @param ItemName: String of protocol definition
|
||||
# @param ItemType: Type of the item, PPI or PROTOCOL
|
||||
# @param ItemMode: Mode of item
|
||||
#
|
||||
#def FindProtocols(Db, SqlCommand, Table, SourceFileID, SourceFileFullPath, ItemName, ItemType, ItemMode, GuidName, GuidMacro, GuidValue):
|
||||
# BelongsToFunction = ''
|
||||
# RecordSet = Db.Exec(SqlCommand)
|
||||
# for Record in RecordSet:
|
||||
# IsFound = True
|
||||
# Parameter = GetProtocolParameter(Record[0])
|
||||
|
||||
## GetProtocolParameter() method
|
||||
#
|
||||
# Parse string of protocol and find parameters
|
||||
#
|
||||
# @param Parameter: Parameter to be parsed
|
||||
# @param Index: The index of the parameter
|
||||
#
|
||||
# @return: call common GetParameter
|
||||
#
|
||||
def GetProtocolParameter(Parameter, Index = 1):
|
||||
return GetParameter(Parameter, Index)
|
||||
|
||||
## GetPpiParameter() method
|
||||
#
|
||||
# Parse string of ppi and find parameters
|
||||
#
|
||||
# @param Parameter: Parameter to be parsed
|
||||
# @param Index: The index of the parameter
|
||||
#
|
||||
# @return: call common GetParameter
|
||||
#
|
||||
def GetPpiParameter(Parameter, Index = 1):
|
||||
return GetParameter(Parameter, Index)
|
||||
|
||||
## GetParameter() method
|
||||
#
|
||||
# Get a parameter by index
|
||||
#
|
||||
# @param Parameter: Parameter to be parsed
|
||||
# @param Index: The index of the parameter
|
||||
#
|
||||
# @return Parameter: The found parameter
|
||||
#
|
||||
def GetParameter(Parameter, Index = 1):
|
||||
ParameterList = GetSplitValueList(Parameter, TAB_COMMA_SPLIT)
|
||||
if len(ParameterList) > Index:
|
||||
Parameter = GetParameterName(ParameterList[Index])
|
||||
|
||||
return Parameter
|
||||
|
||||
return ''
|
||||
|
||||
## GetParameterName() method
|
||||
#
|
||||
# Get a parameter name
|
||||
#
|
||||
# @param Parameter: Parameter to be parsed
|
||||
#
|
||||
# @return: The name of parameter
|
||||
#
|
||||
def GetParameterName(Parameter):
|
||||
if type(Parameter) == type('') and Parameter.startswith('&'):
|
||||
return Parameter[1:].replace('{', '').replace('}', '').replace('\r', '').replace('\n', '').strip()
|
||||
else:
|
||||
return Parameter.strip()
|
||||
|
||||
## FindKeyValue() method
|
||||
#
|
||||
# Find key value of a variable
|
||||
#
|
||||
# @param Db: Database to be searched
|
||||
# @param Table: Table to be searched
|
||||
# @param Key: The keyword
|
||||
#
|
||||
# @return Value: The value of the the keyword
|
||||
#
|
||||
def FindKeyValue(Db, Table, Key):
|
||||
SqlCommand = """select Value from %s where Name = '%s' and (Model = %s or Model = %s)""" % (Table, Key, MODEL_IDENTIFIER_VARIABLE, MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION)
|
||||
RecordSet = Db.Exec(SqlCommand)
|
||||
Value = ''
|
||||
for Record in RecordSet:
|
||||
if Record[0] != 'NULL':
|
||||
Value = FindKeyValue(Db, Table, GetParameterName(Record[0]))
|
||||
|
||||
if Value != '':
|
||||
return Value
|
||||
else:
|
||||
return Key
|
||||
|
||||
## ParseMapFile() method
|
||||
#
|
||||
# Parse map files to get a dict of 'ModuleName' : {FunName : FunAddress}
|
||||
#
|
||||
# @param Files: A list of map files
|
||||
#
|
||||
# @return AllMaps: An object of all map files
|
||||
#
|
||||
def ParseMapFile(Files):
|
||||
AllMaps = {}
|
||||
CurrentModule = ''
|
||||
CurrentMaps = {}
|
||||
for File in Files:
|
||||
Content = open(File, 'r').readlines()
|
||||
for Line in Content:
|
||||
Line = CleanString(Line)
|
||||
# skip empty line
|
||||
if Line == '':
|
||||
continue
|
||||
|
||||
if Line.find('(') > -1 and Line.find(')') > -1:
|
||||
if CurrentModule != '' and CurrentMaps != {}:
|
||||
AllMaps[CurrentModule] = CurrentMaps
|
||||
CurrentModule = Line[:Line.find('(')]
|
||||
CurrentMaps = {}
|
||||
continue
|
||||
else:
|
||||
Name = ''
|
||||
Address = ''
|
||||
List = Line.split()
|
||||
Address = List[0]
|
||||
if List[1] == 'F' or List[1] == 'FS':
|
||||
Name = List[2]
|
||||
else:
|
||||
Name = List[1]
|
||||
CurrentMaps[Name] = Address
|
||||
continue
|
||||
|
||||
return AllMaps
|
||||
|
||||
## ConvertGuid
|
||||
#
|
||||
# Convert a GUID to a GUID with all upper letters
|
||||
#
|
||||
# @param guid: The GUID to be converted
|
||||
#
|
||||
# @param newGuid: The GUID with all upper letters.
|
||||
#
|
||||
def ConvertGuid(guid):
|
||||
numList = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
|
||||
newGuid = ''
|
||||
if guid.startswith('g'):
|
||||
guid = guid[1:]
|
||||
for i in guid:
|
||||
if i.upper() == i and i not in numList:
|
||||
newGuid = newGuid + ('_' + i)
|
||||
else:
|
||||
newGuid = newGuid + i.upper()
|
||||
if newGuid.startswith('_'):
|
||||
newGuid = newGuid[1:]
|
||||
if newGuid.endswith('_'):
|
||||
newGuid = newGuid[:-1]
|
||||
|
||||
return newGuid
|
||||
|
||||
## ConvertGuid2() method
|
||||
#
|
||||
# Convert a GUID to a GUID with new string instead of old string
|
||||
#
|
||||
# @param guid: The GUID to be converted
|
||||
# @param old: Old string to be replaced
|
||||
# @param new: New string to replace the old one
|
||||
#
|
||||
# @param newGuid: The GUID after replacement
|
||||
#
|
||||
def ConvertGuid2(guid, old, new):
|
||||
newGuid = ConvertGuid(guid)
|
||||
newGuid = newGuid.replace(old, new)
|
||||
|
||||
return newGuid
|
||||
|
||||
##
|
||||
#
|
||||
# This acts like the main() function for the script, unless it is 'import'ed into another
|
||||
# script.
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
pass
|
26
BaseTools/Source/Python/Eot/ParserWarning.py
Normal file
26
BaseTools/Source/Python/Eot/ParserWarning.py
Normal file
@@ -0,0 +1,26 @@
|
||||
## @file
|
||||
# Warning information of Eot
|
||||
#
|
||||
# Copyright (c) 2007 - 2010, Intel Corporation
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
class Warning (Exception):
|
||||
## The constructor
|
||||
#
|
||||
# @param self The object pointer
|
||||
# @param Str The message to record
|
||||
# @param File The FDF name
|
||||
# @param Line The Line number that error occurs
|
||||
#
|
||||
def __init__(self, Str, File = None, Line = None):
|
||||
self.message = Str
|
||||
self.FileName = File
|
||||
self.LineNumber = Line
|
||||
self.ToolName = 'EOT'
|
472
BaseTools/Source/Python/Eot/Report.py
Normal file
472
BaseTools/Source/Python/Eot/Report.py
Normal file
@@ -0,0 +1,472 @@
|
||||
## @file
|
||||
# This file is used to create report for Eot tool
|
||||
#
|
||||
# Copyright (c) 2008 - 2010, Intel Corporation
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import os
|
||||
import EotGlobalData
|
||||
|
||||
## Report() class
|
||||
#
|
||||
# This class defined Report
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
class Report(object):
|
||||
## The constructor
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param ReportName: name of the report
|
||||
# @param FvObj: FV object after parsing FV images
|
||||
#
|
||||
def __init__(self, ReportName = 'Report.html', FvObj = None, DispatchName=None):
|
||||
self.ReportName = ReportName
|
||||
self.Op = open(ReportName, 'w+')
|
||||
self.DispatchList = None
|
||||
if DispatchName:
|
||||
self.DispatchList = open(DispatchName, 'w+')
|
||||
self.FvObj = FvObj
|
||||
self.FfsIndex = 0
|
||||
self.PpiIndex = 0
|
||||
self.ProtocolIndex = 0
|
||||
if EotGlobalData.gMACRO['EFI_SOURCE'] == '':
|
||||
EotGlobalData.gMACRO['EFI_SOURCE'] = EotGlobalData.gMACRO['EDK_SOURCE']
|
||||
|
||||
## WriteLn() method
|
||||
#
|
||||
# Write a line in the report
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Line: The lint to be written into
|
||||
#
|
||||
def WriteLn(self, Line):
|
||||
self.Op.write('%s\n' % Line)
|
||||
|
||||
## GenerateReport() method
|
||||
#
|
||||
# A caller to generate report
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def GenerateReport(self):
|
||||
self.GenerateHeader()
|
||||
self.GenerateFv()
|
||||
self.GenerateTail()
|
||||
self.Op.close()
|
||||
self.GenerateUnDispatchedList()
|
||||
|
||||
## GenerateUnDispatchedList() method
|
||||
#
|
||||
# Create a list for not dispatched items
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def GenerateUnDispatchedList(self):
|
||||
FvObj = self.FvObj
|
||||
EotGlobalData.gOP_UN_DISPATCHED.write('%s\n' % FvObj.Name)
|
||||
for Item in FvObj.UnDispatchedFfsDict:
|
||||
EotGlobalData.gOP_UN_DISPATCHED.write('%s\n' % FvObj.UnDispatchedFfsDict[Item])
|
||||
|
||||
## GenerateFv() method
|
||||
#
|
||||
# Generate FV information
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def GenerateFv(self):
|
||||
FvObj = self.FvObj
|
||||
Content = """ <tr>
|
||||
<td width="20%%"><strong>Name</strong></td>
|
||||
<td width="60%%"><strong>Guid</strong></td>
|
||||
<td width="20%%"><strong>Size</strong></td>
|
||||
</tr>"""
|
||||
self.WriteLn(Content)
|
||||
|
||||
for Info in FvObj.BasicInfo:
|
||||
FvName = Info[0]
|
||||
FvGuid = Info[1]
|
||||
FvSize = Info[2]
|
||||
|
||||
Content = """ <tr>
|
||||
<td>%s</td>
|
||||
<td>%s</td>
|
||||
<td>%s</td>
|
||||
</tr>""" % (FvName, FvGuid, FvSize)
|
||||
self.WriteLn(Content)
|
||||
|
||||
Content = """ <td colspan="3"><table width="100%%" border="1">
|
||||
<tr>"""
|
||||
self.WriteLn(Content)
|
||||
|
||||
EotGlobalData.gOP_DISPATCH_ORDER.write('Dispatched:\n')
|
||||
for FfsId in FvObj.OrderedFfsDict:
|
||||
self.GenerateFfs(FvObj.OrderedFfsDict[FfsId])
|
||||
Content = """ </table></td>
|
||||
</tr>"""
|
||||
self.WriteLn(Content)
|
||||
|
||||
# For UnDispatched
|
||||
Content = """ <td colspan="3"><table width="100%%" border="1">
|
||||
<tr>
|
||||
<tr><strong>UnDispatched</strong></tr>"""
|
||||
self.WriteLn(Content)
|
||||
|
||||
EotGlobalData.gOP_DISPATCH_ORDER.write('\nUnDispatched:\n')
|
||||
for FfsId in FvObj.UnDispatchedFfsDict:
|
||||
self.GenerateFfs(FvObj.UnDispatchedFfsDict[FfsId])
|
||||
Content = """ </table></td>
|
||||
</tr>"""
|
||||
self.WriteLn(Content)
|
||||
|
||||
## GenerateDepex() method
|
||||
#
|
||||
# Generate Depex information
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param DepexString: A DEPEX string needed to be parsed
|
||||
#
|
||||
def GenerateDepex(self, DepexString):
|
||||
NonGuidList = ['AND', 'OR', 'NOT', 'BEFORE', 'AFTER', 'TRUE', 'FALSE']
|
||||
ItemList = DepexString.split(' ')
|
||||
DepexString = ''
|
||||
for Item in ItemList:
|
||||
if Item not in NonGuidList:
|
||||
SqlCommand = """select DISTINCT GuidName from Report where GuidValue like '%s' and ItemMode = 'Produced' group by GuidName""" % (Item)
|
||||
RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
if RecordSet != []:
|
||||
Item = RecordSet[0][0]
|
||||
DepexString = DepexString + Item + ' '
|
||||
Content = """ <tr>
|
||||
<td width="5%%"></td>
|
||||
<td width="95%%">%s</td>
|
||||
</tr>""" % (DepexString)
|
||||
self.WriteLn(Content)
|
||||
|
||||
## GeneratePpi() method
|
||||
#
|
||||
# Generate PPI information
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Name: CName of a GUID
|
||||
# @param Guid: Value of a GUID
|
||||
# @param Type: Type of a GUID
|
||||
#
|
||||
def GeneratePpi(self, Name, Guid, Type):
|
||||
self.GeneratePpiProtocol('Ppi', Name, Guid, Type, self.PpiIndex)
|
||||
|
||||
## GenerateProtocol() method
|
||||
#
|
||||
# Generate PROTOCOL information
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Name: CName of a GUID
|
||||
# @param Guid: Value of a GUID
|
||||
# @param Type: Type of a GUID
|
||||
#
|
||||
def GenerateProtocol(self, Name, Guid, Type):
|
||||
self.GeneratePpiProtocol('Protocol', Name, Guid, Type, self.ProtocolIndex)
|
||||
|
||||
## GeneratePpiProtocol() method
|
||||
#
|
||||
# Generate PPI/PROTOCOL information
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param Model: Model of a GUID, PPI or PROTOCOL
|
||||
# @param Name: Name of a GUID
|
||||
# @param Guid: Value of a GUID
|
||||
# @param Type: Type of a GUID
|
||||
# @param CName: CName(Index) of a GUID
|
||||
#
|
||||
def GeneratePpiProtocol(self, Model, Name, Guid, Type, CName):
|
||||
Content = """ <tr>
|
||||
<td width="5%%"></td>
|
||||
<td width="10%%">%s</td>
|
||||
<td width="85%%" colspan="3">%s</td>
|
||||
<!-- %s -->
|
||||
</tr>""" % (Model, Name, Guid)
|
||||
self.WriteLn(Content)
|
||||
if Type == 'Produced':
|
||||
SqlCommand = """select DISTINCT SourceFileFullPath, BelongsToFunction from Report where GuidName like '%s' and ItemMode = 'Callback'""" % Name
|
||||
RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
for Record in RecordSet:
|
||||
SqlCommand = """select FullPath from File
|
||||
where ID = (
|
||||
select DISTINCT BelongsToFile from Inf
|
||||
where Value1 like '%s')""" % Record[0]
|
||||
ModuleSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
Inf = ModuleSet[0][0].replace(EotGlobalData.gMACRO['WORKSPACE'], '.')
|
||||
Function = Record[1]
|
||||
Address = ''
|
||||
for Item in EotGlobalData.gMap:
|
||||
if Function in EotGlobalData.gMap[Item]:
|
||||
Address = EotGlobalData.gMap[Item][Function]
|
||||
break
|
||||
if '_' + Function in EotGlobalData.gMap[Item]:
|
||||
Address = EotGlobalData.gMap[Item]['_' + Function]
|
||||
break
|
||||
Content = """ <tr>
|
||||
<td width="5%%"></td>
|
||||
<td width="10%%">%s</td>
|
||||
<td width="40%%">%s</td>
|
||||
<td width="35%%">%s</td>
|
||||
<td width="10%%">%s</td>
|
||||
</tr>""" % ('Callback', Inf, Function, Address)
|
||||
self.WriteLn(Content)
|
||||
|
||||
## GenerateFfs() method
|
||||
#
|
||||
# Generate FFS information
|
||||
#
|
||||
# @param self: The object pointer
|
||||
# @param FfsObj: FFS object after FV image is parsed
|
||||
#
|
||||
def GenerateFfs(self, FfsObj):
|
||||
self.FfsIndex = self.FfsIndex + 1
|
||||
if FfsObj != None and FfsObj.Type in [0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0xA]:
|
||||
FfsGuid = FfsObj.Guid
|
||||
FfsOffset = FfsObj._OFF_
|
||||
FfsName = 'Unknown-Module'
|
||||
FfsPath = FfsGuid
|
||||
FfsType = FfsObj._TypeName[FfsObj.Type]
|
||||
|
||||
# Hard code for Binary INF
|
||||
if FfsGuid.upper() == '7BB28B99-61BB-11D5-9A5D-0090273FC14D':
|
||||
FfsName = 'Logo'
|
||||
|
||||
if FfsGuid.upper() == '7E374E25-8E01-4FEE-87F2-390C23C606CD':
|
||||
FfsName = 'AcpiTables'
|
||||
|
||||
if FfsGuid.upper() == '961578FE-B6B7-44C3-AF35-6BC705CD2B1F':
|
||||
FfsName = 'Fat'
|
||||
|
||||
# Find FFS Path and Name
|
||||
SqlCommand = """select Value2 from Inf
|
||||
where BelongsToFile = (select BelongsToFile from Inf where Value1 = 'FILE_GUID' and lower(Value2) = lower('%s') and Model = %s)
|
||||
and Model = %s and Value1='BASE_NAME'""" % (FfsGuid, 5001, 5001)
|
||||
RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
if RecordSet != []:
|
||||
FfsName = RecordSet[0][0]
|
||||
|
||||
SqlCommand = """select FullPath from File
|
||||
where ID = (select BelongsToFile from Inf where Value1 = 'FILE_GUID' and lower(Value2) = lower('%s') and Model = %s)
|
||||
and Model = %s""" % (FfsGuid, 5001, 1011)
|
||||
RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
if RecordSet != []:
|
||||
FfsPath = RecordSet[0][0]
|
||||
|
||||
Content = """ <tr>
|
||||
<tr class='styleFfs' id='FfsHeader%s'>
|
||||
<td width="55%%"><span onclick="Display('FfsHeader%s', 'Ffs%s')" onMouseOver="funOnMouseOver()" onMouseOut="funOnMouseOut()">%s</span></td>
|
||||
<td width="15%%">%s</td>
|
||||
<!--<td width="20%%">%s</td>-->
|
||||
<!--<td width="20%%">%s</td>-->
|
||||
<td width="10%%">%s</td>
|
||||
</tr>
|
||||
<tr id='Ffs%s' style='display:none;'>
|
||||
<td colspan="4"><table width="100%%" border="1">""" % (self.FfsIndex, self.FfsIndex, self.FfsIndex, FfsPath, FfsName, FfsGuid, FfsOffset, FfsType, self.FfsIndex)
|
||||
|
||||
if self.DispatchList:
|
||||
if FfsObj.Type in [0x04, 0x06]:
|
||||
self.DispatchList.write("%s %s %s %s\n" % (FfsGuid, "P", FfsName, FfsPath))
|
||||
if FfsObj.Type in [0x05, 0x07, 0x08, 0x0A]:
|
||||
self.DispatchList.write("%s %s %s %s\n" % (FfsGuid, "D", FfsName, FfsPath))
|
||||
|
||||
self.WriteLn(Content)
|
||||
|
||||
EotGlobalData.gOP_DISPATCH_ORDER.write('%s\n' %FfsName)
|
||||
|
||||
if FfsObj.Depex != '':
|
||||
Content = """ <tr>
|
||||
<td><span id='DepexHeader%s' class="styleDepex" onclick="Display('DepexHeader%s', 'Depex%s')" onMouseOver="funOnMouseOver()" onMouseOut="funOnMouseOut()">  DEPEX expression</span></td>
|
||||
</tr>
|
||||
<tr id='Depex%s' style='display:none;'>
|
||||
<td><table width="100%%" border="1">""" % (self.FfsIndex, self.FfsIndex, self.FfsIndex, self.FfsIndex)
|
||||
self.WriteLn(Content)
|
||||
self.GenerateDepex(FfsObj.Depex)
|
||||
Content = """ </table></td>
|
||||
</tr>"""
|
||||
self.WriteLn(Content)
|
||||
# End of DEPEX
|
||||
|
||||
# Find Consumed Ppi/Protocol
|
||||
SqlCommand = """select ModuleName, ItemType, GuidName, GuidValue, GuidMacro from Report
|
||||
where SourceFileFullPath in
|
||||
(select Value1 from Inf where BelongsToFile =
|
||||
(select BelongsToFile from Inf
|
||||
where Value1 = 'FILE_GUID' and Value2 like '%s' and Model = %s)
|
||||
and Model = %s)
|
||||
and ItemMode = 'Consumed' group by GuidName order by ItemType""" \
|
||||
% (FfsGuid, 5001, 3007)
|
||||
|
||||
RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
if RecordSet != []:
|
||||
Count = len(RecordSet)
|
||||
Content = """ <tr>
|
||||
<td><span id='ConsumedHeader%s' class="styleConsumed" onclick="Display('ConsumedHeader%s', 'Consumed%s')" onMouseOver="funOnMouseOver()" onMouseOut="funOnMouseOut()">  Consumed Ppis/Protocols List (%s)</span></td>
|
||||
</tr>
|
||||
<tr id='Consumed%s' style='display:none;'>
|
||||
<td><table width="100%%" border="1">""" % (self.FfsIndex, self.FfsIndex, self.FfsIndex, Count, self.FfsIndex)
|
||||
self.WriteLn(Content)
|
||||
self.ProtocolIndex = 0
|
||||
for Record in RecordSet:
|
||||
self.ProtocolIndex = self.ProtocolIndex + 1
|
||||
Name = Record[2]
|
||||
CName = Record[4]
|
||||
Guid = Record[3]
|
||||
Type = Record[1]
|
||||
self.GeneratePpiProtocol(Type, Name, Guid, 'Consumed', CName)
|
||||
|
||||
Content = """ </table></td>
|
||||
</tr>"""
|
||||
self.WriteLn(Content)
|
||||
#End of Consumed Ppi/Portocol
|
||||
|
||||
# Find Produced Ppi/Protocol
|
||||
SqlCommand = """select ModuleName, ItemType, GuidName, GuidValue, GuidMacro from Report
|
||||
where SourceFileFullPath in
|
||||
(select Value1 from Inf where BelongsToFile =
|
||||
(select BelongsToFile from Inf
|
||||
where Value1 = 'FILE_GUID' and Value2 like '%s' and Model = %s)
|
||||
and Model = %s)
|
||||
and ItemMode = 'Produced' group by GuidName order by ItemType""" \
|
||||
% (FfsGuid, 5001, 3007)
|
||||
|
||||
RecordSet = EotGlobalData.gDb.TblReport.Exec(SqlCommand)
|
||||
if RecordSet != []:
|
||||
Count = len(RecordSet)
|
||||
Content = """ <tr>
|
||||
<td><span id='ProducedHeader%s' class="styleProduced" onclick="Display('ProducedHeader%s', 'Produced%s')" onMouseOver="funOnMouseOver()" onMouseOut="funOnMouseOut()">  Produced Ppis/Protocols List (%s)</span></td>
|
||||
</tr>
|
||||
<tr id='Produced%s' style='display:none;'>
|
||||
<td><table width="100%%" border="1">""" % (self.FfsIndex, self.FfsIndex, self.FfsIndex, Count, self.FfsIndex)
|
||||
self.WriteLn(Content)
|
||||
self.PpiIndex = 0
|
||||
for Record in RecordSet:
|
||||
self.PpiIndex = self.PpiIndex + 1
|
||||
Name = Record[2]
|
||||
CName = Record[4]
|
||||
Guid = Record[3]
|
||||
Type = Record[1]
|
||||
self.GeneratePpiProtocol(Type, Name, Guid, 'Produced', CName)
|
||||
|
||||
Content = """ </table></td>
|
||||
</tr>"""
|
||||
self.WriteLn(Content)
|
||||
RecordSet = None
|
||||
# End of Produced Ppi/Protocol
|
||||
|
||||
Content = """ </table></td>
|
||||
</tr>"""
|
||||
self.WriteLn(Content)
|
||||
|
||||
## GenerateTail() method
|
||||
#
|
||||
# Generate end tags of HTML report
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def GenerateTail(self):
|
||||
Tail = """</table>
|
||||
</body>
|
||||
</html>"""
|
||||
self.WriteLn(Tail)
|
||||
|
||||
## GenerateHeader() method
|
||||
#
|
||||
# Generate start tags of HTML report
|
||||
#
|
||||
# @param self: The object pointer
|
||||
#
|
||||
def GenerateHeader(self):
|
||||
Header = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<title>Execution Order Tool Report</title>
|
||||
<meta http-equiv="Content-Type" content="text/html">
|
||||
<style type="text/css">
|
||||
<!--
|
||||
.styleFfs {
|
||||
color: #006600;
|
||||
font-weight: bold;
|
||||
}
|
||||
.styleDepex {
|
||||
color: #FF0066;
|
||||
font-weight: bold;
|
||||
}
|
||||
.styleProduced {
|
||||
color: #0000FF;
|
||||
font-weight: bold;
|
||||
}
|
||||
.styleConsumed {
|
||||
color: #FF00FF;
|
||||
font-weight: bold;
|
||||
}
|
||||
-->
|
||||
</style>
|
||||
<Script type="text/javascript">
|
||||
function Display(ParentID, SubID)
|
||||
{
|
||||
SubItem = document.getElementById(SubID);
|
||||
ParentItem = document.getElementById(ParentID);
|
||||
if (SubItem.style.display == 'none')
|
||||
{
|
||||
SubItem.style.display = ''
|
||||
ParentItem.style.fontWeight = 'normal'
|
||||
}
|
||||
else
|
||||
{
|
||||
SubItem.style.display = 'none'
|
||||
ParentItem.style.fontWeight = 'bold'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function funOnMouseOver()
|
||||
{
|
||||
document.body.style.cursor = "hand";
|
||||
}
|
||||
|
||||
function funOnMouseOut()
|
||||
{
|
||||
document.body.style.cursor = "";
|
||||
}
|
||||
|
||||
</Script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<table width="100%%" border="1">"""
|
||||
self.WriteLn(Header)
|
||||
|
||||
##
|
||||
#
|
||||
# This acts like the main() function for the script, unless it is 'import'ed into another
|
||||
# script.
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
# Initialize log system
|
||||
FilePath = 'FVRECOVERYFLOPPY.fv'
|
||||
if FilePath.lower().endswith(".fv"):
|
||||
fd = open(FilePath, 'rb')
|
||||
buf = array('B')
|
||||
try:
|
||||
buf.fromfile(fd, os.path.getsize(FilePath))
|
||||
except EOFError:
|
||||
pass
|
||||
|
||||
fv = FirmwareVolume("FVRECOVERY", buf, 0)
|
||||
|
||||
report = Report('Report.html', fv)
|
||||
report.GenerateReport()
|
15
BaseTools/Source/Python/Eot/__init__.py
Normal file
15
BaseTools/Source/Python/Eot/__init__.py
Normal file
@@ -0,0 +1,15 @@
|
||||
## @file
|
||||
# Python 'Eot' package initialization file.
|
||||
#
|
||||
# This file is required to make Python interpreter treat the directory
|
||||
# as containing package.
|
||||
#
|
||||
# Copyright (c) 2010, Intel Corporation<BR>
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
394
BaseTools/Source/Python/Eot/c.py
Normal file
394
BaseTools/Source/Python/Eot/c.py
Normal file
@@ -0,0 +1,394 @@
|
||||
## @file
|
||||
# preprocess source file
|
||||
#
|
||||
# Copyright (c) 2007 - 2010, Intel Corporation
|
||||
#
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions of the BSD License
|
||||
# which accompanies this distribution. The full text of the license may be found at
|
||||
# http://opensource.org/licenses/bsd-license.php
|
||||
#
|
||||
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import CodeFragmentCollector
|
||||
import FileProfile
|
||||
from CommonDataClass import DataClass
|
||||
from Common import EdkLogger
|
||||
from EotToolError import *
|
||||
import EotGlobalData
|
||||
|
||||
# Global Dicts
|
||||
IncludeFileListDict = {}
|
||||
IncludePathListDict = {}
|
||||
ComplexTypeDict = {}
|
||||
SUDict = {}
|
||||
|
||||
## GetIgnoredDirListPattern() method
|
||||
#
|
||||
# Get the pattern of ignored direction list
|
||||
#
|
||||
# @return p: the pattern of ignored direction list
|
||||
#
|
||||
def GetIgnoredDirListPattern():
|
||||
p = re.compile(r'.*[\\/](?:BUILD|INTELRESTRICTEDTOOLS|INTELRESTRICTEDPKG|PCCTS)[\\/].*')
|
||||
return p
|
||||
|
||||
## GetFuncDeclPattern() method
|
||||
#
|
||||
# Get the pattern of function declaration
|
||||
#
|
||||
# @return p: the pattern of function declaration
|
||||
#
|
||||
def GetFuncDeclPattern():
|
||||
p = re.compile(r'(EFIAPI|EFI_BOOT_SERVICE|EFI_RUNTIME_SERVICE)?\s*[_\w]+\s*\(.*\).*', re.DOTALL)
|
||||
return p
|
||||
|
||||
## GetArrayPattern() method
|
||||
#
|
||||
# Get the pattern of array
|
||||
#
|
||||
# @return p: the pattern of array
|
||||
#
|
||||
def GetArrayPattern():
|
||||
p = re.compile(r'[_\w]*\s*[\[.*\]]+')
|
||||
return p
|
||||
|
||||
## GetTypedefFuncPointerPattern() method
|
||||
#
|
||||
# Get the pattern of function pointer
|
||||
#
|
||||
# @return p: the pattern of function pointer
|
||||
#
|
||||
def GetTypedefFuncPointerPattern():
|
||||
p = re.compile('[_\w\s]*\([\w\s]*\*+\s*[_\w]+\s*\)\s*\(.*\)', re.DOTALL)
|
||||
return p
|
||||
|
||||
## GetDB() method
|
||||
#
|
||||
# Get global database instance
|
||||
#
|
||||
# @return EotGlobalData.gDb: the global database instance
|
||||
#
|
||||
def GetDB():
|
||||
return EotGlobalData.gDb
|
||||
|
||||
## PrintErrorMsg() method
|
||||
#
|
||||
# print error message
|
||||
#
|
||||
# @param ErrorType: Type of error
|
||||
# @param Msg: Error message
|
||||
# @param TableName: table name of error found
|
||||
# @param ItemId: id of item
|
||||
#
|
||||
def PrintErrorMsg(ErrorType, Msg, TableName, ItemId):
|
||||
Msg = Msg.replace('\n', '').replace('\r', '')
|
||||
MsgPartList = Msg.split()
|
||||
Msg = ''
|
||||
for Part in MsgPartList:
|
||||
Msg += Part
|
||||
Msg += ' '
|
||||
GetDB().TblReport.Insert(ErrorType, OtherMsg = Msg, BelongsToTable = TableName, BelongsToItem = ItemId)
|
||||
|
||||
## GetIdType() method
|
||||
#
|
||||
# Find type of input string
|
||||
#
|
||||
# @param Str: String to be parsed
|
||||
#
|
||||
# @return Type: The type of the string
|
||||
#
|
||||
def GetIdType(Str):
|
||||
Type = DataClass.MODEL_UNKNOWN
|
||||
Str = Str.replace('#', '# ')
|
||||
List = Str.split()
|
||||
if List[1] == 'include':
|
||||
Type = DataClass.MODEL_IDENTIFIER_INCLUDE
|
||||
elif List[1] == 'define':
|
||||
Type = DataClass.MODEL_IDENTIFIER_MACRO_DEFINE
|
||||
elif List[1] == 'ifdef':
|
||||
Type = DataClass.MODEL_IDENTIFIER_MACRO_IFDEF
|
||||
elif List[1] == 'ifndef':
|
||||
Type = DataClass.MODEL_IDENTIFIER_MACRO_IFNDEF
|
||||
elif List[1] == 'endif':
|
||||
Type = DataClass.MODEL_IDENTIFIER_MACRO_ENDIF
|
||||
elif List[1] == 'pragma':
|
||||
Type = DataClass.MODEL_IDENTIFIER_MACRO_PROGMA
|
||||
else:
|
||||
Type = DataClass.MODEL_UNKNOWN
|
||||
return Type
|
||||
|
||||
## GetIdentifierList() method
|
||||
#
|
||||
# Get id of all files
|
||||
#
|
||||
# @return IdList: The list of all id of files
|
||||
#
|
||||
def GetIdentifierList():
|
||||
IdList = []
|
||||
|
||||
for pp in FileProfile.PPDirectiveList:
|
||||
Type = GetIdType(pp.Content)
|
||||
IdPP = DataClass.IdentifierClass(-1, '', '', '', pp.Content, Type, -1, -1, pp.StartPos[0],pp.StartPos[1],pp.EndPos[0],pp.EndPos[1])
|
||||
IdList.append(IdPP)
|
||||
|
||||
for ae in FileProfile.AssignmentExpressionList:
|
||||
IdAE = DataClass.IdentifierClass(-1, ae.Operator, '', ae.Name, ae.Value, DataClass.MODEL_IDENTIFIER_ASSIGNMENT_EXPRESSION, -1, -1, ae.StartPos[0],ae.StartPos[1],ae.EndPos[0],ae.EndPos[1])
|
||||
IdList.append(IdAE)
|
||||
|
||||
FuncDeclPattern = GetFuncDeclPattern()
|
||||
ArrayPattern = GetArrayPattern()
|
||||
for var in FileProfile.VariableDeclarationList:
|
||||
DeclText = var.Declarator.strip()
|
||||
while DeclText.startswith('*'):
|
||||
var.Modifier += '*'
|
||||
DeclText = DeclText.lstrip('*').strip()
|
||||
var.Declarator = DeclText
|
||||
if FuncDeclPattern.match(var.Declarator):
|
||||
DeclSplitList = var.Declarator.split('(')
|
||||
FuncName = DeclSplitList[0]
|
||||
FuncNamePartList = FuncName.split()
|
||||
if len(FuncNamePartList) > 1:
|
||||
FuncName = FuncNamePartList[-1]
|
||||
Index = 0
|
||||
while Index < len(FuncNamePartList) - 1:
|
||||
var.Modifier += ' ' + FuncNamePartList[Index]
|
||||
var.Declarator = var.Declarator.lstrip().lstrip(FuncNamePartList[Index])
|
||||
Index += 1
|
||||
IdVar = DataClass.IdentifierClass(-1, var.Modifier, '', var.Declarator, '', DataClass.MODEL_IDENTIFIER_FUNCTION_DECLARATION, -1, -1, var.StartPos[0],var.StartPos[1],var.EndPos[0],var.EndPos[1])
|
||||
IdList.append(IdVar)
|
||||
continue
|
||||
|
||||
if var.Declarator.find('{') == -1:
|
||||
for decl in var.Declarator.split(','):
|
||||
DeclList = decl.split('=')
|
||||
Name = DeclList[0].strip()
|
||||
if ArrayPattern.match(Name):
|
||||
LSBPos = var.Declarator.find('[')
|
||||
var.Modifier += ' ' + Name[LSBPos:]
|
||||
Name = Name[0:LSBPos]
|
||||
|
||||
IdVar = DataClass.IdentifierClass(-1, var.Modifier, '', Name, (len(DeclList) > 1 and [DeclList[1]]or [''])[0], DataClass.MODEL_IDENTIFIER_VARIABLE, -1, -1, var.StartPos[0],var.StartPos[1],var.EndPos[0],var.EndPos[1])
|
||||
IdList.append(IdVar)
|
||||
else:
|
||||
DeclList = var.Declarator.split('=')
|
||||
Name = DeclList[0].strip()
|
||||
if ArrayPattern.match(Name):
|
||||
LSBPos = var.Declarator.find('[')
|
||||
var.Modifier += ' ' + Name[LSBPos:]
|
||||
Name = Name[0:LSBPos]
|
||||
IdVar = DataClass.IdentifierClass(-1, var.Modifier, '', Name, (len(DeclList) > 1 and [DeclList[1]]or [''])[0], DataClass.MODEL_IDENTIFIER_VARIABLE, -1, -1, var.StartPos[0],var.StartPos[1],var.EndPos[0],var.EndPos[1])
|
||||
IdList.append(IdVar)
|
||||
|
||||
for enum in FileProfile.EnumerationDefinitionList:
|
||||
LBPos = enum.Content.find('{')
|
||||
RBPos = enum.Content.find('}')
|
||||
Name = enum.Content[4:LBPos].strip()
|
||||
Value = enum.Content[LBPos+1:RBPos]
|
||||
IdEnum = DataClass.IdentifierClass(-1, '', '', Name, Value, DataClass.MODEL_IDENTIFIER_ENUMERATE, -1, -1, enum.StartPos[0],enum.StartPos[1],enum.EndPos[0],enum.EndPos[1])
|
||||
IdList.append(IdEnum)
|
||||
|
||||
for su in FileProfile.StructUnionDefinitionList:
|
||||
Type = DataClass.MODEL_IDENTIFIER_STRUCTURE
|
||||
SkipLen = 6
|
||||
if su.Content.startswith('union'):
|
||||
Type = DataClass.MODEL_IDENTIFIER_UNION
|
||||
SkipLen = 5
|
||||
LBPos = su.Content.find('{')
|
||||
RBPos = su.Content.find('}')
|
||||
if LBPos == -1 or RBPos == -1:
|
||||
Name = su.Content[SkipLen:].strip()
|
||||
Value = ''
|
||||
else:
|
||||
Name = su.Content[SkipLen:LBPos].strip()
|
||||
Value = su.Content[LBPos+1:RBPos]
|
||||
IdPE = DataClass.IdentifierClass(-1, '', '', Name, Value, Type, -1, -1, su.StartPos[0],su.StartPos[1],su.EndPos[0],su.EndPos[1])
|
||||
IdList.append(IdPE)
|
||||
|
||||
TdFuncPointerPattern = GetTypedefFuncPointerPattern()
|
||||
for td in FileProfile.TypedefDefinitionList:
|
||||
Modifier = ''
|
||||
Name = td.ToType
|
||||
Value = td.FromType
|
||||
if TdFuncPointerPattern.match(td.ToType):
|
||||
Modifier = td.FromType
|
||||
LBPos = td.ToType.find('(')
|
||||
TmpStr = td.ToType[LBPos+1:].strip()
|
||||
StarPos = TmpStr.find('*')
|
||||
if StarPos != -1:
|
||||
Modifier += ' ' + TmpStr[0:StarPos]
|
||||
while TmpStr[StarPos] == '*':
|
||||
Modifier += ' ' + '*'
|
||||
StarPos += 1
|
||||
TmpStr = TmpStr[StarPos:].strip()
|
||||
RBPos = TmpStr.find(')')
|
||||
Name = TmpStr[0:RBPos]
|
||||
Value = 'FP' + TmpStr[RBPos + 1:]
|
||||
|
||||
IdTd = DataClass.IdentifierClass(-1, Modifier, '', Name, Value, DataClass.MODEL_IDENTIFIER_TYPEDEF, -1, -1, td.StartPos[0],td.StartPos[1],td.EndPos[0],td.EndPos[1])
|
||||
IdList.append(IdTd)
|
||||
|
||||
for funcCall in FileProfile.FunctionCallingList:
|
||||
IdFC = DataClass.IdentifierClass(-1, '', '', funcCall.FuncName, funcCall.ParamList, DataClass.MODEL_IDENTIFIER_FUNCTION_CALLING, -1, -1, funcCall.StartPos[0],funcCall.StartPos[1],funcCall.EndPos[0],funcCall.EndPos[1])
|
||||
IdList.append(IdFC)
|
||||
return IdList
|
||||
|
||||
## GetParamList() method
|
||||
#
|
||||
# Get a list of parameters
|
||||
#
|
||||
# @param FuncDeclarator: Function declarator
|
||||
# @param FuncNameLine: Line number of function name
|
||||
# @param FuncNameOffset: Offset of function name
|
||||
#
|
||||
# @return ParamIdList: A list of parameters
|
||||
#
|
||||
def GetParamList(FuncDeclarator, FuncNameLine = 0, FuncNameOffset = 0):
|
||||
ParamIdList = []
|
||||
DeclSplitList = FuncDeclarator.split('(')
|
||||
if len(DeclSplitList) < 2:
|
||||
return ParamIdList
|
||||
FuncName = DeclSplitList[0]
|
||||
ParamStr = DeclSplitList[1].rstrip(')')
|
||||
LineSkipped = 0
|
||||
OffsetSkipped = 0
|
||||
Start = 0
|
||||
while FuncName.find('\n', Start) != -1:
|
||||
LineSkipped += 1
|
||||
OffsetSkipped = 0
|
||||
Start += FuncName.find('\n', Start)
|
||||
Start += 1
|
||||
OffsetSkipped += len(FuncName[Start:])
|
||||
OffsetSkipped += 1 #skip '('
|
||||
ParamBeginLine = FuncNameLine + LineSkipped
|
||||
ParamBeginOffset = OffsetSkipped
|
||||
for p in ParamStr.split(','):
|
||||
ListP = p.split()
|
||||
if len(ListP) == 0:
|
||||
continue
|
||||
ParamName = ListP[-1]
|
||||
DeclText = ParamName.strip()
|
||||
RightSpacePos = p.rfind(ParamName)
|
||||
ParamModifier = p[0:RightSpacePos]
|
||||
if ParamName == 'OPTIONAL':
|
||||
if ParamModifier == '':
|
||||
ParamModifier += ' ' + 'OPTIONAL'
|
||||
DeclText = ''
|
||||
else:
|
||||
ParamName = ListP[-2]
|
||||
DeclText = ParamName.strip()
|
||||
RightSpacePos = p.rfind(ParamName)
|
||||
ParamModifier = p[0:RightSpacePos]
|
||||
ParamModifier += 'OPTIONAL'
|
||||
while DeclText.startswith('*'):
|
||||
ParamModifier += ' ' + '*'
|
||||
DeclText = DeclText.lstrip('*').strip()
|
||||
ParamName = DeclText
|
||||
|
||||
Start = 0
|
||||
while p.find('\n', Start) != -1:
|
||||
LineSkipped += 1
|
||||
OffsetSkipped = 0
|
||||
Start += p.find('\n', Start)
|
||||
Start += 1
|
||||
OffsetSkipped += len(p[Start:])
|
||||
|
||||
ParamEndLine = ParamBeginLine + LineSkipped
|
||||
ParamEndOffset = OffsetSkipped
|
||||
IdParam = DataClass.IdentifierClass(-1, ParamModifier, '', ParamName, '', DataClass.MODEL_IDENTIFIER_PARAMETER, -1, -1, ParamBeginLine, ParamBeginOffset, ParamEndLine, ParamEndOffset)
|
||||
ParamIdList.append(IdParam)
|
||||
ParamBeginLine = ParamEndLine
|
||||
ParamBeginOffset = OffsetSkipped + 1 #skip ','
|
||||
|
||||
return ParamIdList
|
||||
|
||||
## GetFunctionList()
|
||||
#
|
||||
# Get a list of functions
|
||||
#
|
||||
# @return FuncObjList: A list of function objects
|
||||
#
|
||||
def GetFunctionList():
|
||||
FuncObjList = []
|
||||
for FuncDef in FileProfile.FunctionDefinitionList:
|
||||
ParamIdList = []
|
||||
DeclText = FuncDef.Declarator.strip()
|
||||
while DeclText.startswith('*'):
|
||||
FuncDef.Modifier += '*'
|
||||
DeclText = DeclText.lstrip('*').strip()
|
||||
|
||||
FuncDef.Declarator = FuncDef.Declarator.lstrip('*')
|
||||
DeclSplitList = FuncDef.Declarator.split('(')
|
||||
if len(DeclSplitList) < 2:
|
||||
continue
|
||||
|
||||
FuncName = DeclSplitList[0]
|
||||
FuncNamePartList = FuncName.split()
|
||||
if len(FuncNamePartList) > 1:
|
||||
FuncName = FuncNamePartList[-1]
|
||||
Index = 0
|
||||
while Index < len(FuncNamePartList) - 1:
|
||||
FuncDef.Modifier += ' ' + FuncNamePartList[Index]
|
||||
Index += 1
|
||||
|
||||
FuncObj = DataClass.FunctionClass(-1, FuncDef.Declarator, FuncDef.Modifier, FuncName.strip(), '', FuncDef.StartPos[0],FuncDef.StartPos[1],FuncDef.EndPos[0],FuncDef.EndPos[1], FuncDef.LeftBracePos[0], FuncDef.LeftBracePos[1], -1, ParamIdList, [])
|
||||
FuncObjList.append(FuncObj)
|
||||
|
||||
return FuncObjList
|
||||
|
||||
## CreateCCodeDB() method
|
||||
#
|
||||
# Create database for all c code
|
||||
#
|
||||
# @param FileNameList: A list of all c code file names
|
||||
#
|
||||
def CreateCCodeDB(FileNameList):
|
||||
FileObjList = []
|
||||
ParseErrorFileList = []
|
||||
|
||||
for FullName in FileNameList:
|
||||
if os.path.splitext(FullName)[1] in ('.h', '.c'):
|
||||
EdkLogger.info("Parsing " + FullName)
|
||||
model = FullName.endswith('c') and DataClass.MODEL_FILE_C or DataClass.MODEL_FILE_H
|
||||
collector = CodeFragmentCollector.CodeFragmentCollector(FullName)
|
||||
try:
|
||||
collector.ParseFile()
|
||||
except UnicodeError:
|
||||
ParseErrorFileList.append(FullName)
|
||||
BaseName = os.path.basename(FullName)
|
||||
DirName = os.path.dirname(FullName)
|
||||
Ext = os.path.splitext(BaseName)[1].lstrip('.')
|
||||
ModifiedTime = os.path.getmtime(FullName)
|
||||
FileObj = DataClass.FileClass(-1, BaseName, Ext, DirName, FullName, model, ModifiedTime, GetFunctionList(), GetIdentifierList(), [])
|
||||
FileObjList.append(FileObj)
|
||||
collector.CleanFileProfileBuffer()
|
||||
|
||||
if len(ParseErrorFileList) > 0:
|
||||
EdkLogger.info("Found unrecoverable error during parsing:\n\t%s\n" % "\n\t".join(ParseErrorFileList))
|
||||
|
||||
Db = EotGlobalData.gDb
|
||||
for file in FileObjList:
|
||||
Db.InsertOneFile(file)
|
||||
|
||||
Db.UpdateIdentifierBelongsToFunction()
|
||||
|
||||
##
|
||||
#
|
||||
# This acts like the main() function for the script, unless it is 'import'ed into another
|
||||
# script.
|
||||
#
|
||||
if __name__ == '__main__':
|
||||
|
||||
EdkLogger.Initialize()
|
||||
EdkLogger.SetLevel(EdkLogger.QUIET)
|
||||
CollectSourceCodeDataIntoDB(sys.argv[1])
|
||||
|
||||
print 'Done!'
|
Reference in New Issue
Block a user