BaseTools/Ecc/EOT: Add Python 3 support on ECC and EOT tools.

1. Add Python 3 support on ECC and EOT tools
2. Add C grammar file of ANTLR4 and fix some bugs

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hess Chen <hesheng.chen@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
Hess Chen 2018-10-09 12:44:35 +08:00 committed by Yonghong Zhu
parent 472eb3b896
commit 22c4de1ac8
20 changed files with 14963 additions and 47753 deletions

View File

@ -988,7 +988,7 @@ class sdict(IterableUserDict):
## append support
def append(self, sdict):
for key in sdict:
for key in sdict.keys():
if key not in self._key_list:
self._key_list.append(key)
IterableUserDict.__setitem__(self, key, sdict[key])

View File

@ -0,0 +1,636 @@
/* @file
This file is used to be the grammar file of ECC tool
Copyright (c) 2009 - 2018, Intel Corporation. All rights reserved.<BR>
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.
*/
grammar C;
options {
language=Python;
}
@header {
## @file
# The file defines the parser for C source files.
#
# THIS FILE IS AUTO-GENENERATED. PLEASE DON NOT MODIFY THIS FILE.
# This file is generated by running:
# java org.antlr.Tool C.g
#
# Copyright (c) 2009 - 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 Ecc.CodeFragment as CodeFragment
import Ecc.FileProfile as FileProfile
}
@members {
def printTokenInfo(self, line, offset, tokenText):
print(str(line)+ ',' + str(offset) + ':' + str(tokenText))
def StorePredicateExpression(self, StartLine, StartOffset, EndLine, EndOffset, Text):
PredExp = CodeFragment.PredicateExpression(Text, (StartLine, StartOffset), (EndLine, EndOffset))
FileProfile.PredicateExpressionList.append(PredExp)
def StoreEnumerationDefinition(self, StartLine, StartOffset, EndLine, EndOffset, Text):
EnumDef = CodeFragment.EnumerationDefinition(Text, (StartLine, StartOffset), (EndLine, EndOffset))
FileProfile.EnumerationDefinitionList.append(EnumDef)
def StoreStructUnionDefinition(self, StartLine, StartOffset, EndLine, EndOffset, Text):
SUDef = CodeFragment.StructUnionDefinition(Text, (StartLine, StartOffset), (EndLine, EndOffset))
FileProfile.StructUnionDefinitionList.append(SUDef)
def StoreTypedefDefinition(self, StartLine, StartOffset, EndLine, EndOffset, FromText, ToText):
Tdef = CodeFragment.TypedefDefinition(FromText, ToText, (StartLine, StartOffset), (EndLine, EndOffset))
FileProfile.TypedefDefinitionList.append(Tdef)
def StoreFunctionDefinition(self, StartLine, StartOffset, EndLine, EndOffset, ModifierText, DeclText, LeftBraceLine, LeftBraceOffset, DeclLine, DeclOffset):
FuncDef = CodeFragment.FunctionDefinition(ModifierText, DeclText, (StartLine, StartOffset), (EndLine, EndOffset), (LeftBraceLine, LeftBraceOffset), (DeclLine, DeclOffset))
FileProfile.FunctionDefinitionList.append(FuncDef)
def StoreVariableDeclaration(self, StartLine, StartOffset, EndLine, EndOffset, ModifierText, DeclText):
VarDecl = CodeFragment.VariableDeclaration(ModifierText, DeclText, (StartLine, StartOffset), (EndLine, EndOffset))
FileProfile.VariableDeclarationList.append(VarDecl)
def StoreFunctionCalling(self, StartLine, StartOffset, EndLine, EndOffset, FuncName, ParamList):
FuncCall = CodeFragment.FunctionCalling(FuncName, ParamList, (StartLine, StartOffset), (EndLine, EndOffset))
FileProfile.FunctionCallingList.append(FuncCall)
}
translation_unit
: external_declaration*
;
external_declaration
: ( declaration_specifiers? declarator declaration* '{' )
| function_definition
| declaration
| macro_statement (';')?
;
function_definition
locals [String ModifierText = '', String DeclText = '', int LBLine = 0, int LBOffset = 0, int DeclLine = 0, int DeclOffset = 0]
@init {
ModifierText = '';
DeclText = '';
LBLine = 0;
LBOffset = 0;
DeclLine = 0;
DeclOffset = 0;
}
@after{
self.StoreFunctionDefinition(localctx.start.line, localctx.start.column, localctx.stop.line, localctx.stop.column, ModifierText, DeclText, LBLine, LBOffset, DeclLine, DeclOffset)
}
: d=declaration_specifiers? declarator
( declaration+ a=compound_statement // K&R style
| b=compound_statement // ANSI style
) {
if localctx.d != None:
ModifierText = $declaration_specifiers.text
else:
ModifierText = ''
DeclText = $declarator.text
DeclLine = $declarator.start.line
DeclOffset = $declarator.start.column
if localctx.a != None:
LBLine = $a.start.line
LBOffset = $a.start.column
else:
LBLine = $b.start.line
LBOffset = $b.start.column
}
;
declaration_specifiers
: ( storage_class_specifier
| type_specifier
| type_qualifier
)+
;
declaration
: a='typedef' b=declaration_specifiers? c=init_declarator_list d=';'
{
if localctx.b is not None:
self.StoreTypedefDefinition(localctx.a.line, localctx.a.column, $d.line, localctx.d.column, $b.text, $c.text)
else:
self.StoreTypedefDefinition(localctx.a.line, localctx.a.column, $d.line, localctx.d.column, '', $c.text)
}
| s=declaration_specifiers t=init_declarator_list? e=';'
{
if localctx.t is not None:
self.StoreVariableDeclaration($s.start.line, $s.start.column, $t.start.line, $t.start.column, $s.text, $t.text)
}
;
init_declarator_list
: init_declarator (',' init_declarator)*
;
init_declarator
: declarator ('=' initializer)?
;
storage_class_specifier
: 'extern'
| 'static'
| 'auto'
| 'register'
| 'STATIC'
;
type_specifier
: 'void'
| 'char'
| 'short'
| 'int'
| 'long'
| 'float'
| 'double'
| 'signed'
| 'unsigned'
| s=struct_or_union_specifier
{
if localctx.s.stop is not None:
self.StoreStructUnionDefinition($s.start.line, $s.start.column, $s.stop.line, $s.stop.column, $s.text)
}
| e=enum_specifier
{
if localctx.e.stop is not None:
self.StoreEnumerationDefinition($e.start.line, $e.start.column, $e.stop.line, $e.stop.column, $e.text)
}
| (IDENTIFIER type_qualifier* declarator)
| type_id
;
type_id
: IDENTIFIER
//{self.printTokenInfo($a.line, $a.pos, $a.text)}
;
struct_or_union_specifier
: struct_or_union IDENTIFIER? '{' struct_declaration_list '}'
| struct_or_union IDENTIFIER
;
struct_or_union
: 'struct'
| 'union'
;
struct_declaration_list
: struct_declaration+
;
struct_declaration
: specifier_qualifier_list struct_declarator_list ';'
;
specifier_qualifier_list
: ( type_qualifier | type_specifier )+
;
struct_declarator_list
: struct_declarator (',' struct_declarator)*
;
struct_declarator
: declarator (':' constant_expression)?
| ':' constant_expression
;
enum_specifier
: 'enum' '{' enumerator_list ','? '}'
| 'enum' IDENTIFIER '{' enumerator_list ','? '}'
| 'enum' IDENTIFIER
;
enumerator_list
: enumerator (',' enumerator)*
;
enumerator
: IDENTIFIER ('=' constant_expression)?
;
type_qualifier
: 'const'
| 'volatile'
| 'IN'
| 'OUT'
| 'OPTIONAL'
| 'CONST'
| 'UNALIGNED'
| 'VOLATILE'
| 'GLOBAL_REMOVE_IF_UNREFERENCED'
| 'EFIAPI'
| 'EFI_BOOTSERVICE'
| 'EFI_RUNTIMESERVICE'
| 'PACKED'
;
declarator
: pointer? ('EFIAPI')? ('EFI_BOOTSERVICE')? ('EFI_RUNTIMESERVICE')? direct_declarator
// | ('EFIAPI')? ('EFI_BOOTSERVICE')? ('EFI_RUNTIMESERVICE')? pointer? direct_declarator
| pointer
;
direct_declarator
: IDENTIFIER declarator_suffix*
| '(' ('EFIAPI')? declarator ')' declarator_suffix+
;
declarator_suffix
: '[' constant_expression ']'
| '[' ']'
| '(' parameter_type_list ')'
| '(' identifier_list ')'
| '(' ')'
;
pointer
: '*' type_qualifier+ pointer?
| '*' pointer
| '*'
;
parameter_type_list
: parameter_list (',' ('OPTIONAL')? '...')?
;
parameter_list
: parameter_declaration (',' ('OPTIONAL')? parameter_declaration)*
;
parameter_declaration
: declaration_specifiers (declarator|abstract_declarator)* ('OPTIONAL')?
//accomerdate user-defined type only, no declarator follow.
| pointer* IDENTIFIER
;
identifier_list
: IDENTIFIER
(',' IDENTIFIER)*
;
type_name
: specifier_qualifier_list abstract_declarator?
| type_id
;
abstract_declarator
: pointer direct_abstract_declarator?
| direct_abstract_declarator
;
direct_abstract_declarator
: ( '(' abstract_declarator ')' | abstract_declarator_suffix ) abstract_declarator_suffix*
;
abstract_declarator_suffix
: '[' ']'
| '[' constant_expression ']'
| '(' ')'
| '(' parameter_type_list ')'
;
initializer
: assignment_expression
| '{' initializer_list ','? '}'
;
initializer_list
: initializer (',' initializer )*
;
// E x p r e s s i o n s
argument_expression_list
: assignment_expression ('OPTIONAL')? (',' assignment_expression ('OPTIONAL')?)*
;
additive_expression
: (multiplicative_expression) ('+' multiplicative_expression | '-' multiplicative_expression)*
;
multiplicative_expression
: (cast_expression) ('*' cast_expression | '/' cast_expression | '%' cast_expression)*
;
cast_expression
: '(' type_name ')' cast_expression
| unary_expression
;
unary_expression
: postfix_expression
| '++' unary_expression
| '--' unary_expression
| unary_operator cast_expression
| 'sizeof' unary_expression
| 'sizeof' '(' type_name ')'
;
postfix_expression
locals [FuncCallText='']
@init
{
self.FuncCallText=''
}
: p=primary_expression {self.FuncCallText += $p.text}
( '[' expression ']'
| '(' a=')'{self.StoreFunctionCalling($p.start.line, $p.start.column, $a.line, localctx.a.column, self.FuncCallText, '')}
| '(' c=argument_expression_list b=')' {self.StoreFunctionCalling($p.start.line, $p.start.column, $b.line, localctx.b.column, self.FuncCallText, $c.text)}
| '(' macro_parameter_list ')'
| '.' x=IDENTIFIER {self.FuncCallText += '.' + $x.text}
| '*' y=IDENTIFIER {self.FuncCallText = $y.text}
| '->' z=IDENTIFIER {self.FuncCallText += '->' + $z.text}
| '++'
| '--'
)*
;
macro_parameter_list
: parameter_declaration (',' parameter_declaration)*
;
unary_operator
: '&'
| '*'
| '+'
| '-'
| '~'
| '!'
;
primary_expression
: IDENTIFIER
| constant
| '(' expression ')'
;
constant
: HEX_LITERAL
| OCTAL_LITERAL
| DECIMAL_LITERAL
| CHARACTER_LITERAL
| (IDENTIFIER* STRING_LITERAL+)+ IDENTIFIER*
| FLOATING_POINT_LITERAL
;
/////
expression
: assignment_expression (',' assignment_expression)*
;
constant_expression
: conditional_expression
;
assignment_expression
: lvalue assignment_operator assignment_expression
| conditional_expression
;
lvalue
: unary_expression
;
assignment_operator
: '='
| '*='
| '/='
| '%='
| '+='
| '-='
| '<<='
| '>>='
| '&='
| '^='
| '|='
;
conditional_expression
: e=logical_or_expression ('?' expression ':' conditional_expression {self.StorePredicateExpression($e.start.line, $e.start.column, $e.stop.line, $e.stop.column, $e.text)})?
;
logical_or_expression
: logical_and_expression ('||' logical_and_expression)*
;
logical_and_expression
: inclusive_or_expression ('&&' inclusive_or_expression)*
;
inclusive_or_expression
: exclusive_or_expression ('|' exclusive_or_expression)*
;
exclusive_or_expression
: and_expression ('^' and_expression)*
;
and_expression
: equality_expression ('&' equality_expression)*
;
equality_expression
: relational_expression (('=='|'!=') relational_expression )*
;
relational_expression
: shift_expression (('<'|'>'|'<='|'>=') shift_expression)*
;
shift_expression
: additive_expression (('<<'|'>>') additive_expression)*
;
// S t a t e m e n t s
statement
: labeled_statement
| compound_statement
| expression_statement
| selection_statement
| iteration_statement
| jump_statement
| macro_statement
| asm2_statement
| asm1_statement
| asm_statement
| declaration
;
asm2_statement
: '__asm__'? IDENTIFIER '(' (~(';'))* ')' ';'
;
asm1_statement
: '_asm' '{' (~('}'))* '}'
;
asm_statement
: '__asm' '{' (~('}'))* '}'
;
macro_statement
: IDENTIFIER '(' declaration* statement_list? expression? ')'
;
labeled_statement
: IDENTIFIER ':' statement
| 'case' constant_expression ':' statement
| 'default' ':' statement
;
compound_statement
: '{' declaration* statement_list? '}'
;
statement_list
: statement+
;
expression_statement
: ';'
| expression ';'
;
selection_statement
: 'if' '(' e=expression ')' {self.StorePredicateExpression($e.start.line, $e.start.column, $e.stop.line, $e.stop.column, $e.text)} statement (:'else' statement)?
| 'switch' '(' expression ')' statement
;
iteration_statement
: 'while' '(' e=expression ')' statement {self.StorePredicateExpression($e.start.line, $e.start.column, $e.stop.line, $e.stop.column, $e.text)}
| 'do' statement 'while' '(' e=expression ')' ';' {self.StorePredicateExpression($e.start.line, $e.start.column, $e.stop.line, $e.stop.column, $e.text)}
//| 'for' '(' expression_statement e=expression_statement expression? ')' statement {self.StorePredicateExpression($e.start.line, $e.start.column, $e.stop.line, $e.stop.column, $e.text)}
;
jump_statement
: 'goto' IDENTIFIER ';'
| 'continue' ';'
| 'break' ';'
| 'return' ';'
| 'return' expression ';'
;
IDENTIFIER
: LETTER (LETTER|'0'..'9')*
;
fragment
LETTER
: '$'
| 'A'..'Z'
| 'a'..'z'
| '_'
;
CHARACTER_LITERAL
: ('L')? '\'' ( EscapeSequence | ~('\''|'\\') ) '\''
;
STRING_LITERAL
: ('L')? '"' ( EscapeSequence | ~('\\'|'"') )* '"'
;
HEX_LITERAL : '0' ('x'|'X') HexDigit+ IntegerTypeSuffix? ;
DECIMAL_LITERAL : ('0' | '1'..'9' '0'..'9'*) IntegerTypeSuffix? ;
OCTAL_LITERAL : '0' ('0'..'7')+ IntegerTypeSuffix? ;
fragment
HexDigit : ('0'..'9'|'a'..'f'|'A'..'F') ;
fragment
IntegerTypeSuffix
: ('u'|'U')
| ('l'|'L')
| ('u'|'U') ('l'|'L')
| ('u'|'U') ('l'|'L') ('l'|'L')
;
FLOATING_POINT_LITERAL
: ('0'..'9')+ '.' ('0'..'9')* Exponent? FloatTypeSuffix?
| '.' ('0'..'9')+ Exponent? FloatTypeSuffix?
| ('0'..'9')+ Exponent FloatTypeSuffix?
| ('0'..'9')+ Exponent? FloatTypeSuffix
;
fragment
Exponent : ('e'|'E') ('+'|'-')? ('0'..'9')+ ;
fragment
FloatTypeSuffix : ('f'|'F'|'d'|'D') ;
fragment
EscapeSequence
: '\\' ('b'|'t'|'n'|'f'|'r'|'\''|'\\')
| OctalEscape
;
fragment
OctalEscape
: '\\' ('0'..'3') ('0'..'7') ('0'..'7')
| '\\' ('0'..'7') ('0'..'7')
| '\\' ('0'..'7')
;
fragment
UnicodeEscape
: '\\' 'u' HexDigit HexDigit HexDigit HexDigit
;
WS : (' '|'\r'|'\t'|'\u000C'|'\n')
-> channel(HIDDEN)
;
// ingore '\' of line concatenation
BS : ('\\')
-> channel(HIDDEN)
;
UnicodeVocabulary
: '\u0003'..'\uFFFE'
;
COMMENT
: '/*' .*? '*/'
-> channel(HIDDEN)
;
LINE_COMMENT
: '//' ~('\n'|'\r')* '\r'? '\n'
-> channel(HIDDEN)
;
// ignore #line info for now
LINE_COMMAND
: '#' ~('\n'|'\r')* '\r'? '\n'
-> channel(HIDDEN)
;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,672 @@
# Generated from C.g4 by ANTLR 4.7.1
from antlr4 import *
if __name__ is not None and "." in __name__:
from .CParser import CParser
else:
from CParser import CParser
## @file
# The file defines the parser for C source files.
#
# THIS FILE IS AUTO-GENENERATED. PLEASE DON NOT MODIFY THIS FILE.
# This file is generated by running:
# java org.antlr.Tool C.g
#
# Copyright (c) 2009 - 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 Ecc.CodeFragment as CodeFragment
import Ecc.FileProfile as FileProfile
# This class defines a complete listener for a parse tree produced by CParser.
class CListener(ParseTreeListener):
# Enter a parse tree produced by CParser#translation_unit.
def enterTranslation_unit(self, ctx:CParser.Translation_unitContext):
pass
# Exit a parse tree produced by CParser#translation_unit.
def exitTranslation_unit(self, ctx:CParser.Translation_unitContext):
pass
# Enter a parse tree produced by CParser#external_declaration.
def enterExternal_declaration(self, ctx:CParser.External_declarationContext):
pass
# Exit a parse tree produced by CParser#external_declaration.
def exitExternal_declaration(self, ctx:CParser.External_declarationContext):
pass
# Enter a parse tree produced by CParser#function_definition.
def enterFunction_definition(self, ctx:CParser.Function_definitionContext):
pass
# Exit a parse tree produced by CParser#function_definition.
def exitFunction_definition(self, ctx:CParser.Function_definitionContext):
pass
# Enter a parse tree produced by CParser#declaration_specifiers.
def enterDeclaration_specifiers(self, ctx:CParser.Declaration_specifiersContext):
pass
# Exit a parse tree produced by CParser#declaration_specifiers.
def exitDeclaration_specifiers(self, ctx:CParser.Declaration_specifiersContext):
pass
# Enter a parse tree produced by CParser#declaration.
def enterDeclaration(self, ctx:CParser.DeclarationContext):
pass
# Exit a parse tree produced by CParser#declaration.
def exitDeclaration(self, ctx:CParser.DeclarationContext):
pass
# Enter a parse tree produced by CParser#init_declarator_list.
def enterInit_declarator_list(self, ctx:CParser.Init_declarator_listContext):
pass
# Exit a parse tree produced by CParser#init_declarator_list.
def exitInit_declarator_list(self, ctx:CParser.Init_declarator_listContext):
pass
# Enter a parse tree produced by CParser#init_declarator.
def enterInit_declarator(self, ctx:CParser.Init_declaratorContext):
pass
# Exit a parse tree produced by CParser#init_declarator.
def exitInit_declarator(self, ctx:CParser.Init_declaratorContext):
pass
# Enter a parse tree produced by CParser#storage_class_specifier.
def enterStorage_class_specifier(self, ctx:CParser.Storage_class_specifierContext):
pass
# Exit a parse tree produced by CParser#storage_class_specifier.
def exitStorage_class_specifier(self, ctx:CParser.Storage_class_specifierContext):
pass
# Enter a parse tree produced by CParser#type_specifier.
def enterType_specifier(self, ctx:CParser.Type_specifierContext):
pass
# Exit a parse tree produced by CParser#type_specifier.
def exitType_specifier(self, ctx:CParser.Type_specifierContext):
pass
# Enter a parse tree produced by CParser#type_id.
def enterType_id(self, ctx:CParser.Type_idContext):
pass
# Exit a parse tree produced by CParser#type_id.
def exitType_id(self, ctx:CParser.Type_idContext):
pass
# Enter a parse tree produced by CParser#struct_or_union_specifier.
def enterStruct_or_union_specifier(self, ctx:CParser.Struct_or_union_specifierContext):
pass
# Exit a parse tree produced by CParser#struct_or_union_specifier.
def exitStruct_or_union_specifier(self, ctx:CParser.Struct_or_union_specifierContext):
pass
# Enter a parse tree produced by CParser#struct_or_union.
def enterStruct_or_union(self, ctx:CParser.Struct_or_unionContext):
pass
# Exit a parse tree produced by CParser#struct_or_union.
def exitStruct_or_union(self, ctx:CParser.Struct_or_unionContext):
pass
# Enter a parse tree produced by CParser#struct_declaration_list.
def enterStruct_declaration_list(self, ctx:CParser.Struct_declaration_listContext):
pass
# Exit a parse tree produced by CParser#struct_declaration_list.
def exitStruct_declaration_list(self, ctx:CParser.Struct_declaration_listContext):
pass
# Enter a parse tree produced by CParser#struct_declaration.
def enterStruct_declaration(self, ctx:CParser.Struct_declarationContext):
pass
# Exit a parse tree produced by CParser#struct_declaration.
def exitStruct_declaration(self, ctx:CParser.Struct_declarationContext):
pass
# Enter a parse tree produced by CParser#specifier_qualifier_list.
def enterSpecifier_qualifier_list(self, ctx:CParser.Specifier_qualifier_listContext):
pass
# Exit a parse tree produced by CParser#specifier_qualifier_list.
def exitSpecifier_qualifier_list(self, ctx:CParser.Specifier_qualifier_listContext):
pass
# Enter a parse tree produced by CParser#struct_declarator_list.
def enterStruct_declarator_list(self, ctx:CParser.Struct_declarator_listContext):
pass
# Exit a parse tree produced by CParser#struct_declarator_list.
def exitStruct_declarator_list(self, ctx:CParser.Struct_declarator_listContext):
pass
# Enter a parse tree produced by CParser#struct_declarator.
def enterStruct_declarator(self, ctx:CParser.Struct_declaratorContext):
pass
# Exit a parse tree produced by CParser#struct_declarator.
def exitStruct_declarator(self, ctx:CParser.Struct_declaratorContext):
pass
# Enter a parse tree produced by CParser#enum_specifier.
def enterEnum_specifier(self, ctx:CParser.Enum_specifierContext):
pass
# Exit a parse tree produced by CParser#enum_specifier.
def exitEnum_specifier(self, ctx:CParser.Enum_specifierContext):
pass
# Enter a parse tree produced by CParser#enumerator_list.
def enterEnumerator_list(self, ctx:CParser.Enumerator_listContext):
pass
# Exit a parse tree produced by CParser#enumerator_list.
def exitEnumerator_list(self, ctx:CParser.Enumerator_listContext):
pass
# Enter a parse tree produced by CParser#enumerator.
def enterEnumerator(self, ctx:CParser.EnumeratorContext):
pass
# Exit a parse tree produced by CParser#enumerator.
def exitEnumerator(self, ctx:CParser.EnumeratorContext):
pass
# Enter a parse tree produced by CParser#type_qualifier.
def enterType_qualifier(self, ctx:CParser.Type_qualifierContext):
pass
# Exit a parse tree produced by CParser#type_qualifier.
def exitType_qualifier(self, ctx:CParser.Type_qualifierContext):
pass
# Enter a parse tree produced by CParser#declarator.
def enterDeclarator(self, ctx:CParser.DeclaratorContext):
pass
# Exit a parse tree produced by CParser#declarator.
def exitDeclarator(self, ctx:CParser.DeclaratorContext):
pass
# Enter a parse tree produced by CParser#direct_declarator.
def enterDirect_declarator(self, ctx:CParser.Direct_declaratorContext):
pass
# Exit a parse tree produced by CParser#direct_declarator.
def exitDirect_declarator(self, ctx:CParser.Direct_declaratorContext):
pass
# Enter a parse tree produced by CParser#declarator_suffix.
def enterDeclarator_suffix(self, ctx:CParser.Declarator_suffixContext):
pass
# Exit a parse tree produced by CParser#declarator_suffix.
def exitDeclarator_suffix(self, ctx:CParser.Declarator_suffixContext):
pass
# Enter a parse tree produced by CParser#pointer.
def enterPointer(self, ctx:CParser.PointerContext):
pass
# Exit a parse tree produced by CParser#pointer.
def exitPointer(self, ctx:CParser.PointerContext):
pass
# Enter a parse tree produced by CParser#parameter_type_list.
def enterParameter_type_list(self, ctx:CParser.Parameter_type_listContext):
pass
# Exit a parse tree produced by CParser#parameter_type_list.
def exitParameter_type_list(self, ctx:CParser.Parameter_type_listContext):
pass
# Enter a parse tree produced by CParser#parameter_list.
def enterParameter_list(self, ctx:CParser.Parameter_listContext):
pass
# Exit a parse tree produced by CParser#parameter_list.
def exitParameter_list(self, ctx:CParser.Parameter_listContext):
pass
# Enter a parse tree produced by CParser#parameter_declaration.
def enterParameter_declaration(self, ctx:CParser.Parameter_declarationContext):
pass
# Exit a parse tree produced by CParser#parameter_declaration.
def exitParameter_declaration(self, ctx:CParser.Parameter_declarationContext):
pass
# Enter a parse tree produced by CParser#identifier_list.
def enterIdentifier_list(self, ctx:CParser.Identifier_listContext):
pass
# Exit a parse tree produced by CParser#identifier_list.
def exitIdentifier_list(self, ctx:CParser.Identifier_listContext):
pass
# Enter a parse tree produced by CParser#type_name.
def enterType_name(self, ctx:CParser.Type_nameContext):
pass
# Exit a parse tree produced by CParser#type_name.
def exitType_name(self, ctx:CParser.Type_nameContext):
pass
# Enter a parse tree produced by CParser#abstract_declarator.
def enterAbstract_declarator(self, ctx:CParser.Abstract_declaratorContext):
pass
# Exit a parse tree produced by CParser#abstract_declarator.
def exitAbstract_declarator(self, ctx:CParser.Abstract_declaratorContext):
pass
# Enter a parse tree produced by CParser#direct_abstract_declarator.
def enterDirect_abstract_declarator(self, ctx:CParser.Direct_abstract_declaratorContext):
pass
# Exit a parse tree produced by CParser#direct_abstract_declarator.
def exitDirect_abstract_declarator(self, ctx:CParser.Direct_abstract_declaratorContext):
pass
# Enter a parse tree produced by CParser#abstract_declarator_suffix.
def enterAbstract_declarator_suffix(self, ctx:CParser.Abstract_declarator_suffixContext):
pass
# Exit a parse tree produced by CParser#abstract_declarator_suffix.
def exitAbstract_declarator_suffix(self, ctx:CParser.Abstract_declarator_suffixContext):
pass
# Enter a parse tree produced by CParser#initializer.
def enterInitializer(self, ctx:CParser.InitializerContext):
pass
# Exit a parse tree produced by CParser#initializer.
def exitInitializer(self, ctx:CParser.InitializerContext):
pass
# Enter a parse tree produced by CParser#initializer_list.
def enterInitializer_list(self, ctx:CParser.Initializer_listContext):
pass
# Exit a parse tree produced by CParser#initializer_list.
def exitInitializer_list(self, ctx:CParser.Initializer_listContext):
pass
# Enter a parse tree produced by CParser#argument_expression_list.
def enterArgument_expression_list(self, ctx:CParser.Argument_expression_listContext):
pass
# Exit a parse tree produced by CParser#argument_expression_list.
def exitArgument_expression_list(self, ctx:CParser.Argument_expression_listContext):
pass
# Enter a parse tree produced by CParser#additive_expression.
def enterAdditive_expression(self, ctx:CParser.Additive_expressionContext):
pass
# Exit a parse tree produced by CParser#additive_expression.
def exitAdditive_expression(self, ctx:CParser.Additive_expressionContext):
pass
# Enter a parse tree produced by CParser#multiplicative_expression.
def enterMultiplicative_expression(self, ctx:CParser.Multiplicative_expressionContext):
pass
# Exit a parse tree produced by CParser#multiplicative_expression.
def exitMultiplicative_expression(self, ctx:CParser.Multiplicative_expressionContext):
pass
# Enter a parse tree produced by CParser#cast_expression.
def enterCast_expression(self, ctx:CParser.Cast_expressionContext):
pass
# Exit a parse tree produced by CParser#cast_expression.
def exitCast_expression(self, ctx:CParser.Cast_expressionContext):
pass
# Enter a parse tree produced by CParser#unary_expression.
def enterUnary_expression(self, ctx:CParser.Unary_expressionContext):
pass
# Exit a parse tree produced by CParser#unary_expression.
def exitUnary_expression(self, ctx:CParser.Unary_expressionContext):
pass
# Enter a parse tree produced by CParser#postfix_expression.
def enterPostfix_expression(self, ctx:CParser.Postfix_expressionContext):
pass
# Exit a parse tree produced by CParser#postfix_expression.
def exitPostfix_expression(self, ctx:CParser.Postfix_expressionContext):
pass
# Enter a parse tree produced by CParser#macro_parameter_list.
def enterMacro_parameter_list(self, ctx:CParser.Macro_parameter_listContext):
pass
# Exit a parse tree produced by CParser#macro_parameter_list.
def exitMacro_parameter_list(self, ctx:CParser.Macro_parameter_listContext):
pass
# Enter a parse tree produced by CParser#unary_operator.
def enterUnary_operator(self, ctx:CParser.Unary_operatorContext):
pass
# Exit a parse tree produced by CParser#unary_operator.
def exitUnary_operator(self, ctx:CParser.Unary_operatorContext):
pass
# Enter a parse tree produced by CParser#primary_expression.
def enterPrimary_expression(self, ctx:CParser.Primary_expressionContext):
pass
# Exit a parse tree produced by CParser#primary_expression.
def exitPrimary_expression(self, ctx:CParser.Primary_expressionContext):
pass
# Enter a parse tree produced by CParser#constant.
def enterConstant(self, ctx:CParser.ConstantContext):
pass
# Exit a parse tree produced by CParser#constant.
def exitConstant(self, ctx:CParser.ConstantContext):
pass
# Enter a parse tree produced by CParser#expression.
def enterExpression(self, ctx:CParser.ExpressionContext):
pass
# Exit a parse tree produced by CParser#expression.
def exitExpression(self, ctx:CParser.ExpressionContext):
pass
# Enter a parse tree produced by CParser#constant_expression.
def enterConstant_expression(self, ctx:CParser.Constant_expressionContext):
pass
# Exit a parse tree produced by CParser#constant_expression.
def exitConstant_expression(self, ctx:CParser.Constant_expressionContext):
pass
# Enter a parse tree produced by CParser#assignment_expression.
def enterAssignment_expression(self, ctx:CParser.Assignment_expressionContext):
pass
# Exit a parse tree produced by CParser#assignment_expression.
def exitAssignment_expression(self, ctx:CParser.Assignment_expressionContext):
pass
# Enter a parse tree produced by CParser#lvalue.
def enterLvalue(self, ctx:CParser.LvalueContext):
pass
# Exit a parse tree produced by CParser#lvalue.
def exitLvalue(self, ctx:CParser.LvalueContext):
pass
# Enter a parse tree produced by CParser#assignment_operator.
def enterAssignment_operator(self, ctx:CParser.Assignment_operatorContext):
pass
# Exit a parse tree produced by CParser#assignment_operator.
def exitAssignment_operator(self, ctx:CParser.Assignment_operatorContext):
pass
# Enter a parse tree produced by CParser#conditional_expression.
def enterConditional_expression(self, ctx:CParser.Conditional_expressionContext):
pass
# Exit a parse tree produced by CParser#conditional_expression.
def exitConditional_expression(self, ctx:CParser.Conditional_expressionContext):
pass
# Enter a parse tree produced by CParser#logical_or_expression.
def enterLogical_or_expression(self, ctx:CParser.Logical_or_expressionContext):
pass
# Exit a parse tree produced by CParser#logical_or_expression.
def exitLogical_or_expression(self, ctx:CParser.Logical_or_expressionContext):
pass
# Enter a parse tree produced by CParser#logical_and_expression.
def enterLogical_and_expression(self, ctx:CParser.Logical_and_expressionContext):
pass
# Exit a parse tree produced by CParser#logical_and_expression.
def exitLogical_and_expression(self, ctx:CParser.Logical_and_expressionContext):
pass
# Enter a parse tree produced by CParser#inclusive_or_expression.
def enterInclusive_or_expression(self, ctx:CParser.Inclusive_or_expressionContext):
pass
# Exit a parse tree produced by CParser#inclusive_or_expression.
def exitInclusive_or_expression(self, ctx:CParser.Inclusive_or_expressionContext):
pass
# Enter a parse tree produced by CParser#exclusive_or_expression.
def enterExclusive_or_expression(self, ctx:CParser.Exclusive_or_expressionContext):
pass
# Exit a parse tree produced by CParser#exclusive_or_expression.
def exitExclusive_or_expression(self, ctx:CParser.Exclusive_or_expressionContext):
pass
# Enter a parse tree produced by CParser#and_expression.
def enterAnd_expression(self, ctx:CParser.And_expressionContext):
pass
# Exit a parse tree produced by CParser#and_expression.
def exitAnd_expression(self, ctx:CParser.And_expressionContext):
pass
# Enter a parse tree produced by CParser#equality_expression.
def enterEquality_expression(self, ctx:CParser.Equality_expressionContext):
pass
# Exit a parse tree produced by CParser#equality_expression.
def exitEquality_expression(self, ctx:CParser.Equality_expressionContext):
pass
# Enter a parse tree produced by CParser#relational_expression.
def enterRelational_expression(self, ctx:CParser.Relational_expressionContext):
pass
# Exit a parse tree produced by CParser#relational_expression.
def exitRelational_expression(self, ctx:CParser.Relational_expressionContext):
pass
# Enter a parse tree produced by CParser#shift_expression.
def enterShift_expression(self, ctx:CParser.Shift_expressionContext):
pass
# Exit a parse tree produced by CParser#shift_expression.
def exitShift_expression(self, ctx:CParser.Shift_expressionContext):
pass
# Enter a parse tree produced by CParser#statement.
def enterStatement(self, ctx:CParser.StatementContext):
pass
# Exit a parse tree produced by CParser#statement.
def exitStatement(self, ctx:CParser.StatementContext):
pass
# Enter a parse tree produced by CParser#asm2_statement.
def enterAsm2_statement(self, ctx:CParser.Asm2_statementContext):
pass
# Exit a parse tree produced by CParser#asm2_statement.
def exitAsm2_statement(self, ctx:CParser.Asm2_statementContext):
pass
# Enter a parse tree produced by CParser#asm1_statement.
def enterAsm1_statement(self, ctx:CParser.Asm1_statementContext):
pass
# Exit a parse tree produced by CParser#asm1_statement.
def exitAsm1_statement(self, ctx:CParser.Asm1_statementContext):
pass
# Enter a parse tree produced by CParser#asm_statement.
def enterAsm_statement(self, ctx:CParser.Asm_statementContext):
pass
# Exit a parse tree produced by CParser#asm_statement.
def exitAsm_statement(self, ctx:CParser.Asm_statementContext):
pass
# Enter a parse tree produced by CParser#macro_statement.
def enterMacro_statement(self, ctx:CParser.Macro_statementContext):
pass
# Exit a parse tree produced by CParser#macro_statement.
def exitMacro_statement(self, ctx:CParser.Macro_statementContext):
pass
# Enter a parse tree produced by CParser#labeled_statement.
def enterLabeled_statement(self, ctx:CParser.Labeled_statementContext):
pass
# Exit a parse tree produced by CParser#labeled_statement.
def exitLabeled_statement(self, ctx:CParser.Labeled_statementContext):
pass
# Enter a parse tree produced by CParser#compound_statement.
def enterCompound_statement(self, ctx:CParser.Compound_statementContext):
pass
# Exit a parse tree produced by CParser#compound_statement.
def exitCompound_statement(self, ctx:CParser.Compound_statementContext):
pass
# Enter a parse tree produced by CParser#statement_list.
def enterStatement_list(self, ctx:CParser.Statement_listContext):
pass
# Exit a parse tree produced by CParser#statement_list.
def exitStatement_list(self, ctx:CParser.Statement_listContext):
pass
# Enter a parse tree produced by CParser#expression_statement.
def enterExpression_statement(self, ctx:CParser.Expression_statementContext):
pass
# Exit a parse tree produced by CParser#expression_statement.
def exitExpression_statement(self, ctx:CParser.Expression_statementContext):
pass
# Enter a parse tree produced by CParser#selection_statement.
def enterSelection_statement(self, ctx:CParser.Selection_statementContext):
pass
# Exit a parse tree produced by CParser#selection_statement.
def exitSelection_statement(self, ctx:CParser.Selection_statementContext):
pass
# Enter a parse tree produced by CParser#iteration_statement.
def enterIteration_statement(self, ctx:CParser.Iteration_statementContext):
pass
# Exit a parse tree produced by CParser#iteration_statement.
def exitIteration_statement(self, ctx:CParser.Iteration_statementContext):
pass
# Enter a parse tree produced by CParser#jump_statement.
def enterJump_statement(self, ctx:CParser.Jump_statementContext):
pass
# Exit a parse tree produced by CParser#jump_statement.
def exitJump_statement(self, ctx:CParser.Jump_statementContext):
pass

File diff suppressed because it is too large Load Diff

View File

@ -223,7 +223,7 @@ class Check(object):
IndexOfLine = 0
for Line in op:
IndexOfLine += 1
if not Line.endswith('\r\n'):
if not bytes.decode(Line).endswith('\r\n'):
OtherMsg = "File %s has invalid line ending at line %s" % (Record[1], IndexOfLine)
EccGlobalData.gDb.TblReport.Insert(ERROR_GENERAL_CHECK_INVALID_LINE_ENDING, OtherMsg=OtherMsg, BelongsToTable='File', BelongsToItem=Record[0])
@ -235,7 +235,7 @@ class Check(object):
RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)
for Record in RecordSet:
if Record[2].upper() not in EccGlobalData.gConfig.BinaryExtList:
op = open(Record[1], 'rb').readlines()
op = open(Record[1], 'r').readlines()
IndexOfLine = 0
for Line in op:
IndexOfLine += 1

View File

@ -22,7 +22,7 @@ import re
import Common.LongFilePathOs as os
import sys
import antlr3
import antlr4
from Ecc.CLexer import CLexer
from Ecc.CParser import CParser
@ -499,13 +499,14 @@ class CodeFragmentCollector:
def ParseFile(self):
self.PreprocessFile()
# restore from ListOfList to ListOfString
# print(self.Profile.FileLinesList)
self.Profile.FileLinesList = ["".join(list) for list in self.Profile.FileLinesList]
FileStringContents = ''
for fileLine in self.Profile.FileLinesList:
FileStringContents += fileLine
cStream = antlr3.StringStream(FileStringContents)
cStream = antlr4.InputStream(FileStringContents)
lexer = CLexer(cStream)
tStream = antlr3.CommonTokenStream(lexer)
tStream = antlr4.CommonTokenStream(lexer)
parser = CParser(tStream)
parser.translation_unit()
@ -516,9 +517,9 @@ class CodeFragmentCollector:
FileStringContents = ''
for fileLine in self.Profile.FileLinesList:
FileStringContents += fileLine
cStream = antlr3.StringStream(FileStringContents)
cStream = antlr4.InputStream(FileStringContents)
lexer = CLexer(cStream)
tStream = antlr3.CommonTokenStream(lexer)
tStream = antlr4.CommonTokenStream(lexer)
parser = CParser(tStream)
parser.translation_unit()

View File

@ -205,7 +205,7 @@ class Ecc(object):
Op = open(EccGlobalData.gConfig.MetaDataFileCheckPathOfGenerateFileList, 'w+')
#SkipDirs = Read from config file
SkipDirs = EccGlobalData.gConfig.SkipDirList
SkipDirString = string.join(SkipDirs, '|')
SkipDirString = '|'.join(SkipDirs)
# p = re.compile(r'.*[\\/](?:%s)[\\/]?.*' % SkipDirString)
p = re.compile(r'.*[\\/](?:%s^\S)[\\/]?.*' % SkipDirString)
for scanFolder in ScanFolders:

View File

@ -47,7 +47,7 @@ class FileProfile :
self.FileLinesList = []
self.FileLinesListFromFile = []
try:
fsock = open(FileName, "rb", 0)
fsock = open(FileName, "r")
try:
self.FileLinesListFromFile = fsock.readlines()
finally:

View File

@ -113,7 +113,7 @@ def ParseHeaderCommentSection(CommentList, FileName = None):
#
Last = 0
HeaderCommentStage = HEADER_COMMENT_NOT_STARTED
for Index in xrange(len(CommentList)-1, 0, -1):
for Index in range(len(CommentList) - 1, 0, -1):
Line = CommentList[Index][0]
if _IsCopyrightLine(Line):
Last = Index

View File

@ -35,7 +35,7 @@ IgnoredKeywordList = ['EFI_ERROR']
def GetIgnoredDirListPattern():
skipList = list(EccGlobalData.gConfig.SkipDirList) + ['.svn']
DirString = string.join(skipList, '|')
DirString = '|'.join(skipList)
p = re.compile(r'.*[\\/](?:%s)[\\/]?.*' % DirString)
return p
@ -963,7 +963,7 @@ def StripComments(Str):
ListFromStr[Index] = ' '
Index += 1
# check for // comment
elif ListFromStr[Index] == '/' and ListFromStr[Index + 1] == '/' and ListFromStr[Index + 2] != '\n':
elif ListFromStr[Index] == '/' and ListFromStr[Index + 1] == '/':
InComment = True
DoubleSlashComment = True
@ -1297,7 +1297,7 @@ def CheckFuncLayoutReturnType(FullFileName):
Result0 = Result[0]
if Result0.upper().startswith('STATIC'):
Result0 = Result0[6:].strip()
Index = Result0.find(ReturnType)
Index = Result0.find(TypeStart)
if Index != 0 or Result[3] != 0:
PrintErrorMsg(ERROR_C_FUNCTION_LAYOUT_CHECK_RETURN_TYPE, '[%s] Return Type should appear at the start of line' % FuncName, 'Function', Result[1])

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,672 @@
# Generated from C.g4 by ANTLR 4.7.1
from antlr4 import *
if __name__ is not None and "." in __name__:
from .CParser import CParser
else:
from CParser import CParser
## @file
# The file defines the parser for C source files.
#
# THIS FILE IS AUTO-GENENERATED. PLEASE DON NOT MODIFY THIS FILE.
# This file is generated by running:
# java org.antlr.Tool C.g
#
# Copyright (c) 2009 - 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 Ecc.CodeFragment as CodeFragment
import Ecc.FileProfile as FileProfile
# This class defines a complete listener for a parse tree produced by CParser.
class CListener(ParseTreeListener):
# Enter a parse tree produced by CParser#translation_unit.
def enterTranslation_unit(self, ctx:CParser.Translation_unitContext):
pass
# Exit a parse tree produced by CParser#translation_unit.
def exitTranslation_unit(self, ctx:CParser.Translation_unitContext):
pass
# Enter a parse tree produced by CParser#external_declaration.
def enterExternal_declaration(self, ctx:CParser.External_declarationContext):
pass
# Exit a parse tree produced by CParser#external_declaration.
def exitExternal_declaration(self, ctx:CParser.External_declarationContext):
pass
# Enter a parse tree produced by CParser#function_definition.
def enterFunction_definition(self, ctx:CParser.Function_definitionContext):
pass
# Exit a parse tree produced by CParser#function_definition.
def exitFunction_definition(self, ctx:CParser.Function_definitionContext):
pass
# Enter a parse tree produced by CParser#declaration_specifiers.
def enterDeclaration_specifiers(self, ctx:CParser.Declaration_specifiersContext):
pass
# Exit a parse tree produced by CParser#declaration_specifiers.
def exitDeclaration_specifiers(self, ctx:CParser.Declaration_specifiersContext):
pass
# Enter a parse tree produced by CParser#declaration.
def enterDeclaration(self, ctx:CParser.DeclarationContext):
pass
# Exit a parse tree produced by CParser#declaration.
def exitDeclaration(self, ctx:CParser.DeclarationContext):
pass
# Enter a parse tree produced by CParser#init_declarator_list.
def enterInit_declarator_list(self, ctx:CParser.Init_declarator_listContext):
pass
# Exit a parse tree produced by CParser#init_declarator_list.
def exitInit_declarator_list(self, ctx:CParser.Init_declarator_listContext):
pass
# Enter a parse tree produced by CParser#init_declarator.
def enterInit_declarator(self, ctx:CParser.Init_declaratorContext):
pass
# Exit a parse tree produced by CParser#init_declarator.
def exitInit_declarator(self, ctx:CParser.Init_declaratorContext):
pass
# Enter a parse tree produced by CParser#storage_class_specifier.
def enterStorage_class_specifier(self, ctx:CParser.Storage_class_specifierContext):
pass
# Exit a parse tree produced by CParser#storage_class_specifier.
def exitStorage_class_specifier(self, ctx:CParser.Storage_class_specifierContext):
pass
# Enter a parse tree produced by CParser#type_specifier.
def enterType_specifier(self, ctx:CParser.Type_specifierContext):
pass
# Exit a parse tree produced by CParser#type_specifier.
def exitType_specifier(self, ctx:CParser.Type_specifierContext):
pass
# Enter a parse tree produced by CParser#type_id.
def enterType_id(self, ctx:CParser.Type_idContext):
pass
# Exit a parse tree produced by CParser#type_id.
def exitType_id(self, ctx:CParser.Type_idContext):
pass
# Enter a parse tree produced by CParser#struct_or_union_specifier.
def enterStruct_or_union_specifier(self, ctx:CParser.Struct_or_union_specifierContext):
pass
# Exit a parse tree produced by CParser#struct_or_union_specifier.
def exitStruct_or_union_specifier(self, ctx:CParser.Struct_or_union_specifierContext):
pass
# Enter a parse tree produced by CParser#struct_or_union.
def enterStruct_or_union(self, ctx:CParser.Struct_or_unionContext):
pass
# Exit a parse tree produced by CParser#struct_or_union.
def exitStruct_or_union(self, ctx:CParser.Struct_or_unionContext):
pass
# Enter a parse tree produced by CParser#struct_declaration_list.
def enterStruct_declaration_list(self, ctx:CParser.Struct_declaration_listContext):
pass
# Exit a parse tree produced by CParser#struct_declaration_list.
def exitStruct_declaration_list(self, ctx:CParser.Struct_declaration_listContext):
pass
# Enter a parse tree produced by CParser#struct_declaration.
def enterStruct_declaration(self, ctx:CParser.Struct_declarationContext):
pass
# Exit a parse tree produced by CParser#struct_declaration.
def exitStruct_declaration(self, ctx:CParser.Struct_declarationContext):
pass
# Enter a parse tree produced by CParser#specifier_qualifier_list.
def enterSpecifier_qualifier_list(self, ctx:CParser.Specifier_qualifier_listContext):
pass
# Exit a parse tree produced by CParser#specifier_qualifier_list.
def exitSpecifier_qualifier_list(self, ctx:CParser.Specifier_qualifier_listContext):
pass
# Enter a parse tree produced by CParser#struct_declarator_list.
def enterStruct_declarator_list(self, ctx:CParser.Struct_declarator_listContext):
pass
# Exit a parse tree produced by CParser#struct_declarator_list.
def exitStruct_declarator_list(self, ctx:CParser.Struct_declarator_listContext):
pass
# Enter a parse tree produced by CParser#struct_declarator.
def enterStruct_declarator(self, ctx:CParser.Struct_declaratorContext):
pass
# Exit a parse tree produced by CParser#struct_declarator.
def exitStruct_declarator(self, ctx:CParser.Struct_declaratorContext):
pass
# Enter a parse tree produced by CParser#enum_specifier.
def enterEnum_specifier(self, ctx:CParser.Enum_specifierContext):
pass
# Exit a parse tree produced by CParser#enum_specifier.
def exitEnum_specifier(self, ctx:CParser.Enum_specifierContext):
pass
# Enter a parse tree produced by CParser#enumerator_list.
def enterEnumerator_list(self, ctx:CParser.Enumerator_listContext):
pass
# Exit a parse tree produced by CParser#enumerator_list.
def exitEnumerator_list(self, ctx:CParser.Enumerator_listContext):
pass
# Enter a parse tree produced by CParser#enumerator.
def enterEnumerator(self, ctx:CParser.EnumeratorContext):
pass
# Exit a parse tree produced by CParser#enumerator.
def exitEnumerator(self, ctx:CParser.EnumeratorContext):
pass
# Enter a parse tree produced by CParser#type_qualifier.
def enterType_qualifier(self, ctx:CParser.Type_qualifierContext):
pass
# Exit a parse tree produced by CParser#type_qualifier.
def exitType_qualifier(self, ctx:CParser.Type_qualifierContext):
pass
# Enter a parse tree produced by CParser#declarator.
def enterDeclarator(self, ctx:CParser.DeclaratorContext):
pass
# Exit a parse tree produced by CParser#declarator.
def exitDeclarator(self, ctx:CParser.DeclaratorContext):
pass
# Enter a parse tree produced by CParser#direct_declarator.
def enterDirect_declarator(self, ctx:CParser.Direct_declaratorContext):
pass
# Exit a parse tree produced by CParser#direct_declarator.
def exitDirect_declarator(self, ctx:CParser.Direct_declaratorContext):
pass
# Enter a parse tree produced by CParser#declarator_suffix.
def enterDeclarator_suffix(self, ctx:CParser.Declarator_suffixContext):
pass
# Exit a parse tree produced by CParser#declarator_suffix.
def exitDeclarator_suffix(self, ctx:CParser.Declarator_suffixContext):
pass
# Enter a parse tree produced by CParser#pointer.
def enterPointer(self, ctx:CParser.PointerContext):
pass
# Exit a parse tree produced by CParser#pointer.
def exitPointer(self, ctx:CParser.PointerContext):
pass
# Enter a parse tree produced by CParser#parameter_type_list.
def enterParameter_type_list(self, ctx:CParser.Parameter_type_listContext):
pass
# Exit a parse tree produced by CParser#parameter_type_list.
def exitParameter_type_list(self, ctx:CParser.Parameter_type_listContext):
pass
# Enter a parse tree produced by CParser#parameter_list.
def enterParameter_list(self, ctx:CParser.Parameter_listContext):
pass
# Exit a parse tree produced by CParser#parameter_list.
def exitParameter_list(self, ctx:CParser.Parameter_listContext):
pass
# Enter a parse tree produced by CParser#parameter_declaration.
def enterParameter_declaration(self, ctx:CParser.Parameter_declarationContext):
pass
# Exit a parse tree produced by CParser#parameter_declaration.
def exitParameter_declaration(self, ctx:CParser.Parameter_declarationContext):
pass
# Enter a parse tree produced by CParser#identifier_list.
def enterIdentifier_list(self, ctx:CParser.Identifier_listContext):
pass
# Exit a parse tree produced by CParser#identifier_list.
def exitIdentifier_list(self, ctx:CParser.Identifier_listContext):
pass
# Enter a parse tree produced by CParser#type_name.
def enterType_name(self, ctx:CParser.Type_nameContext):
pass
# Exit a parse tree produced by CParser#type_name.
def exitType_name(self, ctx:CParser.Type_nameContext):
pass
# Enter a parse tree produced by CParser#abstract_declarator.
def enterAbstract_declarator(self, ctx:CParser.Abstract_declaratorContext):
pass
# Exit a parse tree produced by CParser#abstract_declarator.
def exitAbstract_declarator(self, ctx:CParser.Abstract_declaratorContext):
pass
# Enter a parse tree produced by CParser#direct_abstract_declarator.
def enterDirect_abstract_declarator(self, ctx:CParser.Direct_abstract_declaratorContext):
pass
# Exit a parse tree produced by CParser#direct_abstract_declarator.
def exitDirect_abstract_declarator(self, ctx:CParser.Direct_abstract_declaratorContext):
pass
# Enter a parse tree produced by CParser#abstract_declarator_suffix.
def enterAbstract_declarator_suffix(self, ctx:CParser.Abstract_declarator_suffixContext):
pass
# Exit a parse tree produced by CParser#abstract_declarator_suffix.
def exitAbstract_declarator_suffix(self, ctx:CParser.Abstract_declarator_suffixContext):
pass
# Enter a parse tree produced by CParser#initializer.
def enterInitializer(self, ctx:CParser.InitializerContext):
pass
# Exit a parse tree produced by CParser#initializer.
def exitInitializer(self, ctx:CParser.InitializerContext):
pass
# Enter a parse tree produced by CParser#initializer_list.
def enterInitializer_list(self, ctx:CParser.Initializer_listContext):
pass
# Exit a parse tree produced by CParser#initializer_list.
def exitInitializer_list(self, ctx:CParser.Initializer_listContext):
pass
# Enter a parse tree produced by CParser#argument_expression_list.
def enterArgument_expression_list(self, ctx:CParser.Argument_expression_listContext):
pass
# Exit a parse tree produced by CParser#argument_expression_list.
def exitArgument_expression_list(self, ctx:CParser.Argument_expression_listContext):
pass
# Enter a parse tree produced by CParser#additive_expression.
def enterAdditive_expression(self, ctx:CParser.Additive_expressionContext):
pass
# Exit a parse tree produced by CParser#additive_expression.
def exitAdditive_expression(self, ctx:CParser.Additive_expressionContext):
pass
# Enter a parse tree produced by CParser#multiplicative_expression.
def enterMultiplicative_expression(self, ctx:CParser.Multiplicative_expressionContext):
pass
# Exit a parse tree produced by CParser#multiplicative_expression.
def exitMultiplicative_expression(self, ctx:CParser.Multiplicative_expressionContext):
pass
# Enter a parse tree produced by CParser#cast_expression.
def enterCast_expression(self, ctx:CParser.Cast_expressionContext):
pass
# Exit a parse tree produced by CParser#cast_expression.
def exitCast_expression(self, ctx:CParser.Cast_expressionContext):
pass
# Enter a parse tree produced by CParser#unary_expression.
def enterUnary_expression(self, ctx:CParser.Unary_expressionContext):
pass
# Exit a parse tree produced by CParser#unary_expression.
def exitUnary_expression(self, ctx:CParser.Unary_expressionContext):
pass
# Enter a parse tree produced by CParser#postfix_expression.
def enterPostfix_expression(self, ctx:CParser.Postfix_expressionContext):
pass
# Exit a parse tree produced by CParser#postfix_expression.
def exitPostfix_expression(self, ctx:CParser.Postfix_expressionContext):
pass
# Enter a parse tree produced by CParser#macro_parameter_list.
def enterMacro_parameter_list(self, ctx:CParser.Macro_parameter_listContext):
pass
# Exit a parse tree produced by CParser#macro_parameter_list.
def exitMacro_parameter_list(self, ctx:CParser.Macro_parameter_listContext):
pass
# Enter a parse tree produced by CParser#unary_operator.
def enterUnary_operator(self, ctx:CParser.Unary_operatorContext):
pass
# Exit a parse tree produced by CParser#unary_operator.
def exitUnary_operator(self, ctx:CParser.Unary_operatorContext):
pass
# Enter a parse tree produced by CParser#primary_expression.
def enterPrimary_expression(self, ctx:CParser.Primary_expressionContext):
pass
# Exit a parse tree produced by CParser#primary_expression.
def exitPrimary_expression(self, ctx:CParser.Primary_expressionContext):
pass
# Enter a parse tree produced by CParser#constant.
def enterConstant(self, ctx:CParser.ConstantContext):
pass
# Exit a parse tree produced by CParser#constant.
def exitConstant(self, ctx:CParser.ConstantContext):
pass
# Enter a parse tree produced by CParser#expression.
def enterExpression(self, ctx:CParser.ExpressionContext):
pass
# Exit a parse tree produced by CParser#expression.
def exitExpression(self, ctx:CParser.ExpressionContext):
pass
# Enter a parse tree produced by CParser#constant_expression.
def enterConstant_expression(self, ctx:CParser.Constant_expressionContext):
pass
# Exit a parse tree produced by CParser#constant_expression.
def exitConstant_expression(self, ctx:CParser.Constant_expressionContext):
pass
# Enter a parse tree produced by CParser#assignment_expression.
def enterAssignment_expression(self, ctx:CParser.Assignment_expressionContext):
pass
# Exit a parse tree produced by CParser#assignment_expression.
def exitAssignment_expression(self, ctx:CParser.Assignment_expressionContext):
pass
# Enter a parse tree produced by CParser#lvalue.
def enterLvalue(self, ctx:CParser.LvalueContext):
pass
# Exit a parse tree produced by CParser#lvalue.
def exitLvalue(self, ctx:CParser.LvalueContext):
pass
# Enter a parse tree produced by CParser#assignment_operator.
def enterAssignment_operator(self, ctx:CParser.Assignment_operatorContext):
pass
# Exit a parse tree produced by CParser#assignment_operator.
def exitAssignment_operator(self, ctx:CParser.Assignment_operatorContext):
pass
# Enter a parse tree produced by CParser#conditional_expression.
def enterConditional_expression(self, ctx:CParser.Conditional_expressionContext):
pass
# Exit a parse tree produced by CParser#conditional_expression.
def exitConditional_expression(self, ctx:CParser.Conditional_expressionContext):
pass
# Enter a parse tree produced by CParser#logical_or_expression.
def enterLogical_or_expression(self, ctx:CParser.Logical_or_expressionContext):
pass
# Exit a parse tree produced by CParser#logical_or_expression.
def exitLogical_or_expression(self, ctx:CParser.Logical_or_expressionContext):
pass
# Enter a parse tree produced by CParser#logical_and_expression.
def enterLogical_and_expression(self, ctx:CParser.Logical_and_expressionContext):
pass
# Exit a parse tree produced by CParser#logical_and_expression.
def exitLogical_and_expression(self, ctx:CParser.Logical_and_expressionContext):
pass
# Enter a parse tree produced by CParser#inclusive_or_expression.
def enterInclusive_or_expression(self, ctx:CParser.Inclusive_or_expressionContext):
pass
# Exit a parse tree produced by CParser#inclusive_or_expression.
def exitInclusive_or_expression(self, ctx:CParser.Inclusive_or_expressionContext):
pass
# Enter a parse tree produced by CParser#exclusive_or_expression.
def enterExclusive_or_expression(self, ctx:CParser.Exclusive_or_expressionContext):
pass
# Exit a parse tree produced by CParser#exclusive_or_expression.
def exitExclusive_or_expression(self, ctx:CParser.Exclusive_or_expressionContext):
pass
# Enter a parse tree produced by CParser#and_expression.
def enterAnd_expression(self, ctx:CParser.And_expressionContext):
pass
# Exit a parse tree produced by CParser#and_expression.
def exitAnd_expression(self, ctx:CParser.And_expressionContext):
pass
# Enter a parse tree produced by CParser#equality_expression.
def enterEquality_expression(self, ctx:CParser.Equality_expressionContext):
pass
# Exit a parse tree produced by CParser#equality_expression.
def exitEquality_expression(self, ctx:CParser.Equality_expressionContext):
pass
# Enter a parse tree produced by CParser#relational_expression.
def enterRelational_expression(self, ctx:CParser.Relational_expressionContext):
pass
# Exit a parse tree produced by CParser#relational_expression.
def exitRelational_expression(self, ctx:CParser.Relational_expressionContext):
pass
# Enter a parse tree produced by CParser#shift_expression.
def enterShift_expression(self, ctx:CParser.Shift_expressionContext):
pass
# Exit a parse tree produced by CParser#shift_expression.
def exitShift_expression(self, ctx:CParser.Shift_expressionContext):
pass
# Enter a parse tree produced by CParser#statement.
def enterStatement(self, ctx:CParser.StatementContext):
pass
# Exit a parse tree produced by CParser#statement.
def exitStatement(self, ctx:CParser.StatementContext):
pass
# Enter a parse tree produced by CParser#asm2_statement.
def enterAsm2_statement(self, ctx:CParser.Asm2_statementContext):
pass
# Exit a parse tree produced by CParser#asm2_statement.
def exitAsm2_statement(self, ctx:CParser.Asm2_statementContext):
pass
# Enter a parse tree produced by CParser#asm1_statement.
def enterAsm1_statement(self, ctx:CParser.Asm1_statementContext):
pass
# Exit a parse tree produced by CParser#asm1_statement.
def exitAsm1_statement(self, ctx:CParser.Asm1_statementContext):
pass
# Enter a parse tree produced by CParser#asm_statement.
def enterAsm_statement(self, ctx:CParser.Asm_statementContext):
pass
# Exit a parse tree produced by CParser#asm_statement.
def exitAsm_statement(self, ctx:CParser.Asm_statementContext):
pass
# Enter a parse tree produced by CParser#macro_statement.
def enterMacro_statement(self, ctx:CParser.Macro_statementContext):
pass
# Exit a parse tree produced by CParser#macro_statement.
def exitMacro_statement(self, ctx:CParser.Macro_statementContext):
pass
# Enter a parse tree produced by CParser#labeled_statement.
def enterLabeled_statement(self, ctx:CParser.Labeled_statementContext):
pass
# Exit a parse tree produced by CParser#labeled_statement.
def exitLabeled_statement(self, ctx:CParser.Labeled_statementContext):
pass
# Enter a parse tree produced by CParser#compound_statement.
def enterCompound_statement(self, ctx:CParser.Compound_statementContext):
pass
# Exit a parse tree produced by CParser#compound_statement.
def exitCompound_statement(self, ctx:CParser.Compound_statementContext):
pass
# Enter a parse tree produced by CParser#statement_list.
def enterStatement_list(self, ctx:CParser.Statement_listContext):
pass
# Exit a parse tree produced by CParser#statement_list.
def exitStatement_list(self, ctx:CParser.Statement_listContext):
pass
# Enter a parse tree produced by CParser#expression_statement.
def enterExpression_statement(self, ctx:CParser.Expression_statementContext):
pass
# Exit a parse tree produced by CParser#expression_statement.
def exitExpression_statement(self, ctx:CParser.Expression_statementContext):
pass
# Enter a parse tree produced by CParser#selection_statement.
def enterSelection_statement(self, ctx:CParser.Selection_statementContext):
pass
# Exit a parse tree produced by CParser#selection_statement.
def exitSelection_statement(self, ctx:CParser.Selection_statementContext):
pass
# Enter a parse tree produced by CParser#iteration_statement.
def enterIteration_statement(self, ctx:CParser.Iteration_statementContext):
pass
# Exit a parse tree produced by CParser#iteration_statement.
def exitIteration_statement(self, ctx:CParser.Iteration_statementContext):
pass
# Enter a parse tree produced by CParser#jump_statement.
def enterJump_statement(self, ctx:CParser.Jump_statementContext):
pass
# Exit a parse tree produced by CParser#jump_statement.
def exitJump_statement(self, ctx:CParser.Jump_statementContext):
pass

File diff suppressed because it is too large Load Diff

View File

@ -21,7 +21,7 @@ import re
import Common.LongFilePathOs as os
import sys
import antlr3
import antlr4
from .CLexer import CLexer
from .CParser import CParser

View File

@ -17,18 +17,20 @@
from __future__ import absolute_import
import Common.LongFilePathOs as os, time, glob
import Common.EdkLogger as EdkLogger
from . import EotGlobalData
from Eot import EotGlobalData
from optparse import OptionParser
from Common.StringUtils import NormPath
from Common import BuildToolError
from Common.Misc import GuidStructureStringToGuidString, sdict
from .InfParserLite import *
from . import c
from . import Database
from Eot.Parser import *
from Eot.InfParserLite import EdkInfParser
from Common.StringUtils import GetSplitValueList
from Eot import c
from Eot import Database
from array import array
from .Report import Report
from Eot.Report import Report
from Common.BuildVersion import gBUILD_VERSION
from .Parser import ConvertGuid
from Eot.Parser import ConvertGuid
from Common.LongFilePathSupport import OpenLongFilePath as open
import struct
import uuid
@ -58,14 +60,14 @@ class Image(array):
self._SubImages = sdict() # {offset: Image()}
array.__init__(self, 'B')
array.__init__(self)
def __repr__(self):
return self._ID_
def __len__(self):
Len = array.__len__(self)
for Offset in self._SubImages:
for Offset in self._SubImages.keys():
Len += len(self._SubImages[Offset])
return Len
@ -154,19 +156,11 @@ class CompressedImage(Image):
def _GetSections(self):
try:
from . import EfiCompressor
TmpData = EfiCompressor.FrameworkDecompress(
self[self._HEADER_SIZE_:],
len(self) - self._HEADER_SIZE_
)
TmpData = DeCompress('Efi', self[self._HEADER_SIZE_:])
DecData = array('B')
DecData.fromstring(TmpData)
except:
from . import EfiCompressor
TmpData = EfiCompressor.UefiDecompress(
self[self._HEADER_SIZE_:],
len(self) - self._HEADER_SIZE_
)
TmpData = DeCompress('Framework', self[self._HEADER_SIZE_:])
DecData = array('B')
DecData.fromstring(TmpData)
@ -297,7 +291,7 @@ class Depex(Image):
Expression = property(_GetExpression)
## FirmwareVolume() class
# # FirmwareVolume() class
#
# A class for Firmware Volume
#
@ -308,12 +302,12 @@ class FirmwareVolume(Image):
_FfsGuid = "8C8CE578-8A3D-4F1C-9935-896185C32DD3"
_GUID_ = struct.Struct("16x 1I2H8B")
_LENGTH_ = struct.Struct("16x 16x 1Q")
_SIG_ = struct.Struct("16x 16x 8x 1I")
_ATTR_ = struct.Struct("16x 16x 8x 4x 1I")
_HLEN_ = struct.Struct("16x 16x 8x 4x 4x 1H")
_CHECKSUM_ = struct.Struct("16x 16x 8x 4x 4x 2x 1H")
_GUID_ = struct.Struct("16x 1I2H8B")
_LENGTH_ = struct.Struct("16x 16x 1Q")
_SIG_ = struct.Struct("16x 16x 8x 1I")
_ATTR_ = struct.Struct("16x 16x 8x 4x 1I")
_HLEN_ = struct.Struct("16x 16x 8x 4x 4x 1H")
_CHECKSUM_ = struct.Struct("16x 16x 8x 4x 4x 2x 1H")
def __init__(self, Name=''):
Image.__init__(self)
@ -387,7 +381,7 @@ class FirmwareVolume(Image):
DepexString = DepexList[0].strip()
return (CouldBeLoaded, DepexString, FileDepex)
def Dispatch(self, Db = None):
def Dispatch(self, Db=None):
if Db is None:
return False
self.UnDispatchedFfsDict = copy.copy(self.FfsDict)
@ -397,7 +391,7 @@ class FirmwareVolume(Image):
FfsDxeCoreGuid = None
FfsPeiPrioriGuid = None
FfsDxePrioriGuid = None
for FfsID in self.UnDispatchedFfsDict:
for FfsID in self.UnDispatchedFfsDict.keys():
Ffs = self.UnDispatchedFfsDict[FfsID]
if Ffs.Type == 0x03:
FfsSecCoreGuid = FfsID
@ -439,6 +433,7 @@ class FirmwareVolume(Image):
if GuidString in self.UnDispatchedFfsDict:
self.OrderedFfsDict[GuidString] = self.UnDispatchedFfsDict.pop(GuidString)
self.LoadPpi(Db, GuidString)
self.DisPatchPei(Db)
# Parse DXE then
@ -460,6 +455,7 @@ class FirmwareVolume(Image):
if GuidString in self.UnDispatchedFfsDict:
self.OrderedFfsDict[GuidString] = self.UnDispatchedFfsDict.pop(GuidString)
self.LoadProtocol(Db, GuidString)
self.DisPatchDxe(Db)
def LoadProtocol(self, Db, ModuleGuid):
@ -501,7 +497,7 @@ class FirmwareVolume(Image):
def DisPatchDxe(self, Db):
IsInstalled = False
ScheduleList = sdict()
for FfsID in self.UnDispatchedFfsDict:
for FfsID in self.UnDispatchedFfsDict.keys():
CouldBeLoaded = False
DepexString = ''
FileDepex = None
@ -548,7 +544,7 @@ class FirmwareVolume(Image):
else:
self.UnDispatchedFfsDict[FfsID].Depex = DepexString
for FfsID in ScheduleList:
for FfsID in ScheduleList.keys():
NewFfs = ScheduleList.pop(FfsID)
FfsName = 'UnKnown'
self.OrderedFfsDict[FfsID] = NewFfs
@ -560,12 +556,13 @@ class FirmwareVolume(Image):
RecordSet = Db.TblReport.Exec(SqlCommand)
if RecordSet != []:
FfsName = RecordSet[0][0]
if IsInstalled:
self.DisPatchDxe(Db)
def DisPatchPei(self, Db):
IsInstalled = False
for FfsID in self.UnDispatchedFfsDict:
for FfsID in self.UnDispatchedFfsDict.keys():
CouldBeLoaded = True
DepexString = ''
FileDepex = None
@ -576,7 +573,6 @@ class FirmwareVolume(Image):
if Section.Type == 0x1B:
CouldBeLoaded, DepexString, FileDepex = self.ParseDepex(Section._SubImages[4], 'Ppi')
break
if Section.Type == 0x01:
CompressSections = Section._SubImages[4]
for CompressSection in CompressSections.Sections:
@ -603,11 +599,12 @@ class FirmwareVolume(Image):
if IsInstalled:
self.DisPatchPei(Db)
def __str__(self):
global gIndention
gIndention += 4
FvInfo = '\n' + ' ' * gIndention
FvInfo += "[FV:%s] file_system=%s size=%x checksum=%s\n" % (self.Name, self.FileSystemGuid, self.Size, self.Checksum)
FvInfo += "[FV:%s] file_system=%s size=%x checksum=%s\n" % (self.Name, self.FileSystemGuid, self.Size, self.Checksum)
FfsInfo = "\n".join([str(self.FfsDict[FfsId]) for FfsId in self.FfsDict])
gIndention -= 4
return FvInfo + FfsInfo
@ -615,7 +612,7 @@ class FirmwareVolume(Image):
def _Unpack(self):
Size = self._LENGTH_.unpack_from(self._BUF_, self._OFF_)[0]
self.empty()
self.extend(self._BUF_[self._OFF_:self._OFF_+Size])
self.extend(self._BUF_[self._OFF_:self._OFF_ + Size])
# traverse the FFS
EndOfFv = Size
@ -743,10 +740,9 @@ class GuidDefinedImage(Image):
SectionList.append(Sec)
elif Guid == self.TIANO_COMPRESS_GUID:
try:
from . import EfiCompressor
# skip the header
Offset = self.DataOffset - 4
TmpData = EfiCompressor.FrameworkDecompress(self[Offset:], len(self)-Offset)
TmpData = DeCompress('Framework', self[self.Offset:])
DecData = array('B')
DecData.fromstring(TmpData)
Offset = 0
@ -764,10 +760,10 @@ class GuidDefinedImage(Image):
pass
elif Guid == self.LZMA_COMPRESS_GUID:
try:
from . import LzmaCompressor
# skip the header
Offset = self.DataOffset - 4
TmpData = LzmaCompressor.LzmaDecompress(self[Offset:], len(self)-Offset)
TmpData = DeCompress('Lzma', self[self.Offset:])
DecData = array('B')
DecData.fromstring(TmpData)
Offset = 0
@ -848,7 +844,7 @@ class Section(Image):
SectionInfo += "[SECTION:%s] offset=%x size=%x" % (self._TypeName[self.Type], self._OFF_, self.Size)
else:
SectionInfo += "[SECTION:%x<unknown>] offset=%x size=%x " % (self.Type, self._OFF_, self.Size)
for Offset in self._SubImages:
for Offset in self._SubImages.keys():
SectionInfo += ", " + str(self._SubImages[Offset])
gIndention -= 4
return SectionInfo
@ -982,7 +978,7 @@ class Ffs(Image):
FfsInfo = Indention
FfsInfo += "[FFS:%s] offset=%x size=%x guid=%s free_space=%x alignment=%s\n" % \
(Ffs._TypeName[self.Type], self._OFF_, self.Size, self.Guid, self.FreeSpace, self.Alignment)
SectionInfo = '\n'.join([str(self.Sections[Offset]) for Offset in self.Sections])
SectionInfo = '\n'.join([str(self.Sections[Offset]) for Offset in self.Sections.keys()])
gIndention -= 4
return FfsInfo + SectionInfo + "\n"
@ -1087,379 +1083,6 @@ class Ffs(Image):
Alignment = property(_GetAlignment)
State = property(_GetState, _SetState)
## FirmwareVolume() class
#
# A class for Firmware Volume
#
class FirmwareVolume(Image):
# Read FvLength, Attributes, HeaderLength, Checksum
_HEADER_ = struct.Struct("16x 1I2H8B 1Q 4x 1I 1H 1H")
_HEADER_SIZE_ = _HEADER_.size
_FfsGuid = "8C8CE578-8A3D-4F1C-9935-896185C32DD3"
_GUID_ = struct.Struct("16x 1I2H8B")
_LENGTH_ = struct.Struct("16x 16x 1Q")
_SIG_ = struct.Struct("16x 16x 8x 1I")
_ATTR_ = struct.Struct("16x 16x 8x 4x 1I")
_HLEN_ = struct.Struct("16x 16x 8x 4x 4x 1H")
_CHECKSUM_ = struct.Struct("16x 16x 8x 4x 4x 2x 1H")
def __init__(self, Name=''):
Image.__init__(self)
self.Name = Name
self.FfsDict = sdict()
self.OrderedFfsDict = sdict()
self.UnDispatchedFfsDict = sdict()
self.ProtocolList = sdict()
def CheckArchProtocol(self):
for Item in EotGlobalData.gArchProtocolGuids:
if Item.lower() not in EotGlobalData.gProtocolList:
return False
return True
def ParseDepex(self, Depex, Type):
List = None
if Type == 'Ppi':
List = EotGlobalData.gPpiList
if Type == 'Protocol':
List = EotGlobalData.gProtocolList
DepexStack = []
DepexList = []
DepexString = ''
FileDepex = None
CouldBeLoaded = True
for Index in range(0, len(Depex.Expression)):
Item = Depex.Expression[Index]
if Item == 0x00:
Index = Index + 1
Guid = gGuidStringFormat % Depex.Expression[Index]
if Guid in self.OrderedFfsDict and Depex.Expression[Index + 1] == 0x08:
return (True, 'BEFORE %s' % Guid, [Guid, 'BEFORE'])
elif Item == 0x01:
Index = Index + 1
Guid = gGuidStringFormat % Depex.Expression[Index]
if Guid in self.OrderedFfsDict and Depex.Expression[Index + 1] == 0x08:
return (True, 'AFTER %s' % Guid, [Guid, 'AFTER'])
elif Item == 0x02:
Index = Index + 1
Guid = gGuidStringFormat % Depex.Expression[Index]
if Guid.lower() in List:
DepexStack.append(True)
DepexList.append(Guid)
else:
DepexStack.append(False)
DepexList.append(Guid)
continue
elif Item == 0x03 or Item == 0x04:
DepexStack.append(eval(str(DepexStack.pop()) + ' ' + Depex._OPCODE_STRING_[Item].lower() + ' ' + str(DepexStack.pop())))
DepexList.append(str(DepexList.pop()) + ' ' + Depex._OPCODE_STRING_[Item].upper() + ' ' + str(DepexList.pop()))
elif Item == 0x05:
DepexStack.append(eval(Depex._OPCODE_STRING_[Item].lower() + ' ' + str(DepexStack.pop())))
DepexList.append(Depex._OPCODE_STRING_[Item].lower() + ' ' + str(DepexList.pop()))
elif Item == 0x06:
DepexStack.append(True)
DepexList.append('TRUE')
DepexString = DepexString + 'TRUE' + ' '
elif Item == 0x07:
DepexStack.append(False)
DepexList.append('False')
DepexString = DepexString + 'FALSE' + ' '
elif Item == 0x08:
if Index != len(Depex.Expression) - 1:
CouldBeLoaded = False
else:
CouldBeLoaded = DepexStack.pop()
else:
CouldBeLoaded = False
if DepexList != []:
DepexString = DepexList[0].strip()
return (CouldBeLoaded, DepexString, FileDepex)
def Dispatch(self, Db = None):
if Db is None:
return False
self.UnDispatchedFfsDict = copy.copy(self.FfsDict)
# Find PeiCore, DexCore, PeiPriori, DxePriori first
FfsSecCoreGuid = None
FfsPeiCoreGuid = None
FfsDxeCoreGuid = None
FfsPeiPrioriGuid = None
FfsDxePrioriGuid = None
for FfsID in self.UnDispatchedFfsDict:
Ffs = self.UnDispatchedFfsDict[FfsID]
if Ffs.Type == 0x03:
FfsSecCoreGuid = FfsID
continue
if Ffs.Type == 0x04:
FfsPeiCoreGuid = FfsID
continue
if Ffs.Type == 0x05:
FfsDxeCoreGuid = FfsID
continue
if Ffs.Guid.lower() == gPeiAprioriFileNameGuid:
FfsPeiPrioriGuid = FfsID
continue
if Ffs.Guid.lower() == gAprioriGuid:
FfsDxePrioriGuid = FfsID
continue
# Parse SEC_CORE first
if FfsSecCoreGuid is not None:
self.OrderedFfsDict[FfsSecCoreGuid] = self.UnDispatchedFfsDict.pop(FfsSecCoreGuid)
self.LoadPpi(Db, FfsSecCoreGuid)
# Parse PEI first
if FfsPeiCoreGuid is not None:
self.OrderedFfsDict[FfsPeiCoreGuid] = self.UnDispatchedFfsDict.pop(FfsPeiCoreGuid)
self.LoadPpi(Db, FfsPeiCoreGuid)
if FfsPeiPrioriGuid is not None:
# Load PEIM described in priori file
FfsPeiPriori = self.UnDispatchedFfsDict.pop(FfsPeiPrioriGuid)
if len(FfsPeiPriori.Sections) == 1:
Section = FfsPeiPriori.Sections.popitem()[1]
if Section.Type == 0x19:
GuidStruct = struct.Struct('1I2H8B')
Start = 4
while len(Section) > Start:
Guid = GuidStruct.unpack_from(Section[Start : Start + 16])
GuidString = gGuidStringFormat % Guid
Start = Start + 16
if GuidString in self.UnDispatchedFfsDict:
self.OrderedFfsDict[GuidString] = self.UnDispatchedFfsDict.pop(GuidString)
self.LoadPpi(Db, GuidString)
self.DisPatchPei(Db)
# Parse DXE then
if FfsDxeCoreGuid is not None:
self.OrderedFfsDict[FfsDxeCoreGuid] = self.UnDispatchedFfsDict.pop(FfsDxeCoreGuid)
self.LoadProtocol(Db, FfsDxeCoreGuid)
if FfsDxePrioriGuid is not None:
# Load PEIM described in priori file
FfsDxePriori = self.UnDispatchedFfsDict.pop(FfsDxePrioriGuid)
if len(FfsDxePriori.Sections) == 1:
Section = FfsDxePriori.Sections.popitem()[1]
if Section.Type == 0x19:
GuidStruct = struct.Struct('1I2H8B')
Start = 4
while len(Section) > Start:
Guid = GuidStruct.unpack_from(Section[Start : Start + 16])
GuidString = gGuidStringFormat % Guid
Start = Start + 16
if GuidString in self.UnDispatchedFfsDict:
self.OrderedFfsDict[GuidString] = self.UnDispatchedFfsDict.pop(GuidString)
self.LoadProtocol(Db, GuidString)
self.DisPatchDxe(Db)
def LoadProtocol(self, Db, ModuleGuid):
SqlCommand = """select GuidValue 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 ItemType = 'Protocol' and ItemMode = 'Produced'""" \
% (ModuleGuid, 5001, 3007)
RecordSet = Db.TblReport.Exec(SqlCommand)
for Record in RecordSet:
SqlCommand = """select Value2 from Inf where BelongsToFile =
(select DISTINCT BelongsToFile from Inf
where Value1 =
(select SourceFileFullPath from Report
where GuidValue like '%s' and ItemMode = 'Callback'))
and Value1 = 'FILE_GUID'""" % Record[0]
CallBackSet = Db.TblReport.Exec(SqlCommand)
if CallBackSet != []:
EotGlobalData.gProtocolList[Record[0].lower()] = ModuleGuid
else:
EotGlobalData.gProtocolList[Record[0].lower()] = ModuleGuid
def LoadPpi(self, Db, ModuleGuid):
SqlCommand = """select GuidValue 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 ItemType = 'Ppi' and ItemMode = 'Produced'""" \
% (ModuleGuid, 5001, 3007)
RecordSet = Db.TblReport.Exec(SqlCommand)
for Record in RecordSet:
EotGlobalData.gPpiList[Record[0].lower()] = ModuleGuid
def DisPatchDxe(self, Db):
IsInstalled = False
ScheduleList = sdict()
for FfsID in self.UnDispatchedFfsDict:
CouldBeLoaded = False
DepexString = ''
FileDepex = None
Ffs = self.UnDispatchedFfsDict[FfsID]
if Ffs.Type == 0x07:
# Get Depex
IsFoundDepex = False
for Section in Ffs.Sections.values():
# Find Depex
if Section.Type == 0x13:
IsFoundDepex = True
CouldBeLoaded, DepexString, FileDepex = self.ParseDepex(Section._SubImages[4], 'Protocol')
break
if Section.Type == 0x01:
CompressSections = Section._SubImages[4]
for CompressSection in CompressSections.Sections:
if CompressSection.Type == 0x13:
IsFoundDepex = True
CouldBeLoaded, DepexString, FileDepex = self.ParseDepex(CompressSection._SubImages[4], 'Protocol')
break
if CompressSection.Type == 0x02:
NewSections = CompressSection._SubImages[4]
for NewSection in NewSections.Sections:
if NewSection.Type == 0x13:
IsFoundDepex = True
CouldBeLoaded, DepexString, FileDepex = self.ParseDepex(NewSection._SubImages[4], 'Protocol')
break
# Not find Depex
if not IsFoundDepex:
CouldBeLoaded = self.CheckArchProtocol()
DepexString = ''
FileDepex = None
# Append New Ffs
if CouldBeLoaded:
IsInstalled = True
NewFfs = self.UnDispatchedFfsDict.pop(FfsID)
NewFfs.Depex = DepexString
if FileDepex is not None:
ScheduleList.insert(FileDepex[1], FfsID, NewFfs, FileDepex[0])
else:
ScheduleList[FfsID] = NewFfs
else:
self.UnDispatchedFfsDict[FfsID].Depex = DepexString
for FfsID in ScheduleList:
NewFfs = ScheduleList.pop(FfsID)
FfsName = 'UnKnown'
self.OrderedFfsDict[FfsID] = NewFfs
self.LoadProtocol(Db, FfsID)
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'""" % (FfsID, 5001, 5001)
RecordSet = Db.TblReport.Exec(SqlCommand)
if RecordSet != []:
FfsName = RecordSet[0][0]
if IsInstalled:
self.DisPatchDxe(Db)
def DisPatchPei(self, Db):
IsInstalled = False
for FfsID in self.UnDispatchedFfsDict:
CouldBeLoaded = True
DepexString = ''
FileDepex = None
Ffs = self.UnDispatchedFfsDict[FfsID]
if Ffs.Type == 0x06 or Ffs.Type == 0x08:
# Get Depex
for Section in Ffs.Sections.values():
if Section.Type == 0x1B:
CouldBeLoaded, DepexString, FileDepex = self.ParseDepex(Section._SubImages[4], 'Ppi')
break
if Section.Type == 0x01:
CompressSections = Section._SubImages[4]
for CompressSection in CompressSections.Sections:
if CompressSection.Type == 0x1B:
CouldBeLoaded, DepexString, FileDepex = self.ParseDepex(CompressSection._SubImages[4], 'Ppi')
break
if CompressSection.Type == 0x02:
NewSections = CompressSection._SubImages[4]
for NewSection in NewSections.Sections:
if NewSection.Type == 0x1B:
CouldBeLoaded, DepexString, FileDepex = self.ParseDepex(NewSection._SubImages[4], 'Ppi')
break
# Append New Ffs
if CouldBeLoaded:
IsInstalled = True
NewFfs = self.UnDispatchedFfsDict.pop(FfsID)
NewFfs.Depex = DepexString
self.OrderedFfsDict[FfsID] = NewFfs
self.LoadPpi(Db, FfsID)
else:
self.UnDispatchedFfsDict[FfsID].Depex = DepexString
if IsInstalled:
self.DisPatchPei(Db)
def __str__(self):
global gIndention
gIndention += 4
FvInfo = '\n' + ' ' * gIndention
FvInfo += "[FV:%s] file_system=%s size=%x checksum=%s\n" % (self.Name, self.FileSystemGuid, self.Size, self.Checksum)
FfsInfo = "\n".join([str(self.FfsDict[FfsId]) for FfsId in self.FfsDict])
gIndention -= 4
return FvInfo + FfsInfo
def _Unpack(self):
Size = self._LENGTH_.unpack_from(self._BUF_, self._OFF_)[0]
self.empty()
self.extend(self._BUF_[self._OFF_:self._OFF_+Size])
# traverse the FFS
EndOfFv = Size
FfsStartAddress = self.HeaderSize
LastFfsObj = None
while FfsStartAddress < EndOfFv:
FfsObj = Ffs()
FfsObj.frombuffer(self, FfsStartAddress)
FfsId = repr(FfsObj)
if ((self.Attributes & 0x00000800) != 0 and len(FfsObj) == 0xFFFFFF) \
or ((self.Attributes & 0x00000800) == 0 and len(FfsObj) == 0):
if LastFfsObj is not None:
LastFfsObj.FreeSpace = EndOfFv - LastFfsObj._OFF_ - len(LastFfsObj)
else:
if FfsId in self.FfsDict:
EdkLogger.error("FV", 0, "Duplicate GUID in FFS",
ExtraData="\t%s @ %s\n\t%s @ %s" \
% (FfsObj.Guid, FfsObj.Offset,
self.FfsDict[FfsId].Guid, self.FfsDict[FfsId].Offset))
self.FfsDict[FfsId] = FfsObj
if LastFfsObj is not None:
LastFfsObj.FreeSpace = FfsStartAddress - LastFfsObj._OFF_ - len(LastFfsObj)
FfsStartAddress += len(FfsObj)
#
# align to next 8-byte aligned address: A = (A + 8 - 1) & (~(8 - 1))
# The next FFS must be at the latest next 8-byte aligned address
#
FfsStartAddress = (FfsStartAddress + 7) & (~7)
LastFfsObj = FfsObj
def _GetAttributes(self):
return self.GetField(self._ATTR_, 0)[0]
def _GetSize(self):
return self.GetField(self._LENGTH_, 0)[0]
def _GetChecksum(self):
return self.GetField(self._CHECKSUM_, 0)[0]
def _GetHeaderLength(self):
return self.GetField(self._HLEN_, 0)[0]
def _GetFileSystemGuid(self):
return gGuidStringFormat % self.GetField(self._GUID_, 0)
Attributes = property(_GetAttributes)
Size = property(_GetSize)
Checksum = property(_GetChecksum)
HeaderSize = property(_GetHeaderLength)
FileSystemGuid = property(_GetFileSystemGuid)
## MultipleFv() class
#
@ -1470,8 +1093,10 @@ class MultipleFv(FirmwareVolume):
FirmwareVolume.__init__(self)
self.BasicInfo = []
for FvPath in FvList:
Fd = None
FvName = os.path.splitext(os.path.split(FvPath)[1])[0]
Fd = open(FvPath, 'rb')
if FvPath.strip():
Fd = open(FvPath, 'rb')
Buf = array('B')
try:
Buf.fromfile(Fd, os.path.getsize(FvPath))
@ -1632,8 +1257,9 @@ class Eot(object):
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
if Line.strip():
(GuidName, GuidValue) = Line.split()
EotGlobalData.gGuidDict[GuidName] = GuidValue
## ConvertLogFile() method
#
@ -1694,7 +1320,7 @@ class Eot(object):
mCurrentSourceFileList = []
if SourceFileList:
sfl = open(SourceFileList, 'rb')
sfl = open(SourceFileList, 'r')
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':
@ -1970,6 +1596,8 @@ class Eot(object):
def BuildMetaDataFileDatabase(self, Inf_Files):
EdkLogger.quiet("Building database for meta data files ...")
for InfFile in Inf_Files:
if not InfFile:
continue
EdkLogger.quiet("Parsing %s ..." % str(InfFile))
EdkInfParser(InfFile, EotGlobalData.gDb, Inf_Files[InfFile], '')
@ -2083,7 +1711,10 @@ if __name__ == '__main__':
EdkLogger.quiet(time.strftime("%H:%M:%S, %b.%d %Y ", time.localtime()) + "[00:00]" + "\n")
StartTime = time.clock()
Eot = Eot()
Eot = Eot(CommandLineOption=False,
SourceFileList=r'C:\TestEot\Source.txt',
GuidList=r'C:\TestEot\Guid.txt',
FvFileList=r'C:\TestEot\FVRECOVERY.Fv')
FinishTime = time.clock()
BuildDuration = time.strftime("%M:%S", time.gmtime(int(round(FinishTime - StartTime))))

View File

@ -22,8 +22,8 @@ from Common.DataType import *
from CommonDataClass.DataClass import *
from Common.Identification import *
from Common.StringUtils import *
from .Parser import *
from . import Database
from Eot.Parser import *
from Eot import Database
## EdkInfParser() class
#
@ -153,21 +153,3 @@ class EdkInfParser(object):
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()

View File

@ -2,7 +2,7 @@
# This file is used to define common parsing related functions used in parsing
# Inf/Dsc/Makefile process
#
# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
# 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
@ -25,6 +25,32 @@ from . import EotGlobalData
from Common.StringUtils import GetSplitList
from Common.LongFilePathSupport import OpenLongFilePath as open
import subprocess
## DeCompress
#
# Call external decompress tool to decompress the fv section
#
def DeCompress(Method, Input):
# Write the input to a temp file
open('_Temp.bin', 'wb').write(Input)
cmd = ''
if Method == 'Lzma':
cmd = r'LzmaCompress -o _New.bin -d _Temp.bin'
if Method == 'Efi':
cmd = r'TianoCompress -d --uefi -o _New.bin _Temp.bin'
if Method == 'Framework':
cmd = r'TianoCompress -d -o _New.bin _Temp.bin'
# Call tool to create the decompressed output file
Process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
Process.communicate()[0]
# Return the beffer of New.bin
if os.path.exists('New.bin'):
return open('New.bin', 'rb').read()
## PreProcess() method
#
# Pre process a file

View File

@ -77,7 +77,7 @@ class Report(object):
def GenerateUnDispatchedList(self):
FvObj = self.FvObj
EotGlobalData.gOP_UN_DISPATCHED.write('%s\n' % FvObj.Name)
for Item in FvObj.UnDispatchedFfsDict:
for Item in FvObj.UnDispatchedFfsDict.keys():
EotGlobalData.gOP_UN_DISPATCHED.write('%s\n' % FvObj.UnDispatchedFfsDict[Item])
## GenerateFv() method
@ -112,7 +112,7 @@ class Report(object):
self.WriteLn(Content)
EotGlobalData.gOP_DISPATCH_ORDER.write('Dispatched:\n')
for FfsId in FvObj.OrderedFfsDict:
for FfsId in FvObj.OrderedFfsDict.keys():
self.GenerateFfs(FvObj.OrderedFfsDict[FfsId])
Content = """ </table></td>
</tr>"""
@ -125,7 +125,7 @@ class Report(object):
self.WriteLn(Content)
EotGlobalData.gOP_DISPATCH_ORDER.write('\nUnDispatched:\n')
for FfsId in FvObj.UnDispatchedFfsDict:
for FfsId in FvObj.UnDispatchedFfsDict.keys():
self.GenerateFfs(FvObj.UnDispatchedFfsDict[FfsId])
Content = """ </table></td>
</tr>"""

View File

@ -1626,7 +1626,7 @@ class PredictionReport(object):
TempFile.close()
try:
from Eot.Eot import Eot
from Eot.EotMain import Eot
#
# Invoke EOT tool and echo its runtime performance