From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 973E121AE30D0 for ; Tue, 6 Jun 2017 00:15:09 -0700 (PDT) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2017 00:16:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,305,1493708400"; d="scan'208";a="1157047361" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga001.fm.intel.com with ESMTP; 06 Jun 2017 00:16:05 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 6 Jun 2017 00:16:04 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.151]) by SHSMSX101.ccr.corp.intel.com ([169.254.1.197]) with mapi id 14.03.0319.002; Tue, 6 Jun 2017 15:16:03 +0800 From: "Ni, Ruiyu" To: "Bi, Dandan" , "edk2-devel@lists.01.org" CC: "Dong, Eric" , "Gao, Liming" Thread-Topic: [RFC v3 1/2] BaseTool/VfrCompile: Support Union type in VFR Thread-Index: AQHS3nDvpRACglBLY06Aqji66vxyuKIXbILA Date: Tue, 6 Jun 2017 07:16:02 +0000 Deferred-Delivery: Tue, 6 Jun 2017 07:16:00 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B988BF9@SHSMSX104.ccr.corp.intel.com> References: <1496717906-372916-1-git-send-email-dandan.bi@intel.com> <1496717906-372916-2-git-send-email-dandan.bi@intel.com> In-Reply-To: <1496717906-372916-2-git-send-email-dandan.bi@intel.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [RFC v3 1/2] BaseTool/VfrCompile: Support Union type in VFR X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jun 2017 07:15:09 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: Bi, Dandan > Sent: Tuesday, June 6, 2017 10:58 AM > To: edk2-devel@lists.01.org > Cc: Dong, Eric ; Gao, Liming ;= Ni, > Ruiyu > Subject: [RFC v3 1/2] BaseTool/VfrCompile: Support Union type in VFR >=20 > V3: Avoid adding new member in current stucture to indicate indicate whet= her > current date type is Union or not. We can directly paas the data type inf= o to sub- > statement/function during parsing phase. >=20 > Cc: Eric Dong > Cc: Liming Gao > Cc: Ruiyu Ni > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Dandan Bi > --- > BaseTools/Source/C/VfrCompile/VfrSyntax.g | 81 +++++++++++++++----= ----- > - > BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 17 +++++- > BaseTools/Source/C/VfrCompile/VfrUtilityLib.h | 4 +- > 3 files changed, 65 insertions(+), 37 deletions(-) >=20 > diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g > b/BaseTools/Source/C/VfrCompile/VfrSyntax.g > index 406dbc5..1dc9477 100644 > --- a/BaseTools/Source/C/VfrCompile/VfrSyntax.g > +++ b/BaseTools/Source/C/VfrCompile/VfrSyntax.g > @@ -155,10 +155,11 @@ VfrParserStart ( > #token Label("label") "label" > #token Timeout("timeout") "timeout" > #token Inventory("inventory") "inventory" > #token NonNvDataMap("_NON_NV_DATA_MAP") "_NON_NV_DATA_MAP" > #token Struct("struct") "struct" > +#token Union("union") "union" > #token Boolean("BOOLEAN") "BOOLEAN" > #token Uint64("UINT64") "UINT64" > #token Uint32("UINT32") "UINT32" > #token Uint16("UINT16") "UINT16" > #token Char16("CHAR16") "CHAR16" > @@ -270,10 +271,11 @@ vfrProgram > [UINT8 Return] : > mConstantOnlyInExpression =3D FALSE; > >> > ( > vfrPragmaPackDefinition > | vfrDataStructDefinition > + | vfrDataUnionDefinition > )* > vfrFormSetDefinition > << $Return =3D mParserStatus; >> > ; >=20 > @@ -318,140 +320,155 @@ vfrPragmaPackDefinition : > | pragmaPackNumber > } > "\)" > ; >=20 > + vfrDataUnionDefinition : > + { TypeDef } Union << > gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >> > + { NonNvDataMap } > + { > + N1:StringIdentifier << > _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >> > + } > + OpenBrace > + vfrDataStructFields[TRUE] > + CloseBrace > + { > + N2:StringIdentifier << > _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >> > + } > + ";" << gCVfrVarDataTypeD= B.DeclareDataTypeEnd > ();>> > + ; > + > vfrDataStructDefinition : > { TypeDef } Struct << > gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >> > { NonNvDataMap } > { > N1:StringIdentifier << > _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >> > } > OpenBrace > - vfrDataStructFields > + vfrDataStructFields[FALSE] > CloseBrace > { > N2:StringIdentifier << > _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >> > } > ";" << gCVfrVarDataTypeD= B.DeclareDataTypeEnd (); >> > ; >=20 > -vfrDataStructFields : > +vfrDataStructFields [BOOLEAN FieldInUnion]: > ( > - dataStructField64 | > - dataStructField32 | > - dataStructField16 | > - dataStructField8 | > - dataStructFieldBool | > - dataStructFieldString | > - dataStructFieldDate | > - dataStructFieldTime | > - dataStructFieldRef | > - dataStructFieldUser > + dataStructField64 [FieldInUnion] | > + dataStructField32 [FieldInUnion] | > + dataStructField16 [FieldInUnion] | > + dataStructField8 [FieldInUnion] | > + dataStructFieldBool [FieldInUnion] | > + dataStructFieldString [FieldInUnion]| > + dataStructFieldDate [FieldInUnion] | > + dataStructFieldTime [FieldInUnion] | > + dataStructFieldRef [FieldInUnion] | > + dataStructFieldUser [FieldInUnion] > )* > ; >=20 > -dataStructField64 : > +dataStructField64 [BOOLEAN FieldInUnion] : > << UINT32 ArrayNum =3D 0; >> > D:"UINT64" > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructField32 : > +dataStructField32 [BOOLEAN FieldInUnion]: > << UINT32 ArrayNum =3D 0; >> > D:"UINT32" > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructField16 : > +dataStructField16 [BOOLEAN FieldInUnion]: > << > UINT32 ArrayNum =3D 0; > >> > ("UINT16" | "CHAR16") > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), (CHAR8 *) > "UINT16", ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), (CHAR8 *) > "UINT16", ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructField8 : > +dataStructField8 [BOOLEAN FieldInUnion]: > << UINT32 ArrayNum =3D 0; >> > D:"UINT8" > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructFieldBool : > +dataStructFieldBool [BOOLEAN FieldInUnion]: > << UINT32 ArrayNum =3D 0; >> > D:"BOOLEAN" > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructFieldString : > +dataStructFieldString [BOOLEAN FieldInUnion]: > << UINT32 ArrayNum =3D 0; >> > D:"EFI_STRING_ID" > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructFieldDate : > +dataStructFieldDate [BOOLEAN FieldInUnion]: > << UINT32 ArrayNum =3D 0; >> > D:"EFI_HII_DATE" > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructFieldTime : > +dataStructFieldTime [BOOLEAN FieldInUnion]: > << UINT32 ArrayNum =3D 0; >> > D:"EFI_HII_TIME" > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructFieldRef : > +dataStructFieldRef [BOOLEAN FieldInUnion]: > << UINT32 ArrayNum =3D 0; >> > D:"EFI_HII_REF" > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum), N); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), D->getText(), > ArrayNum, FieldInUnion), N); >> > ; >=20 > -dataStructFieldUser : > +dataStructFieldUser [BOOLEAN FieldInUnion]: > << UINT32 ArrayNum =3D 0; >> > T:StringIdentifier > N:StringIdentifier > { > OpenBracket I:Number CloseBracket << ArrayNum =3D _STO= U32(I- > >getText(), I->getLine()); >> > } > - ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), T->getText(), > ArrayNum), T); >> > + ";" << > _PCATCH(gCVfrVarDataTypeDB.DataTypeAddField (N->getText(), T->getText(), > ArrayNum, FieldInUnion), T); >> > ; >=20 >=20 > //*************************************************************** > ************** > // > // the syntax of GUID definition > diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp > b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp > index 2f97975..37b58e2 100644 > --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp > +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp > @@ -1,10 +1,10 @@ > /** @file >=20 > Vfr common library functions. >=20 > -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
> +Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the BS= D > License > which accompanies this distribution. The full text of the license may b= e found > at > http://opensource.org/licenses/bsd-license.php >=20 > @@ -1011,19 +1011,22 @@ CVfrVarDataTypeDB::SetNewTypeName ( >=20 > EFI_VFR_RETURN_CODE > CVfrVarDataTypeDB::DataTypeAddField ( > IN CHAR8 *FieldName, > IN CHAR8 *TypeName, > - IN UINT32 ArrayNum > + IN UINT32 ArrayNum, > + IN BOOLEAN FieldInUnion > ) > { > SVfrDataField *pNewField =3D NULL; > SVfrDataType *pFieldType =3D NULL; > SVfrDataField *pTmp; > UINT32 Align; > + UINT32 MaxDataTypeSize; >=20 > CHECK_ERROR_RETURN (GetDataType (TypeName, &pFieldType), > VFR_RETURN_SUCCESS); > + MaxDataTypeSize =3D mNewDataType->mTotalSize; >=20 > if (strlen (FieldName) >=3D MAX_NAME_LEN) { > return VFR_RETURN_INVALID_PARAMETER; > } >=20 > @@ -1055,11 +1058,19 @@ CVfrVarDataTypeDB::DataTypeAddField ( > pTmp->mNext =3D pNewField; > pNewField->mNext =3D NULL; > } >=20 > mNewDataType->mAlign =3D MIN (mPackAlign, MAX (pFieldType->mAlign, > mNewDataType->mAlign)); > - mNewDataType->mTotalSize =3D pNewField->mOffset + (pNewField- > >mFieldType->mTotalSize) * ((ArrayNum =3D=3D 0) ? 1 : ArrayNum); > + > + if (FieldInUnion) { > + if (MaxDataTypeSize < pNewField->mFieldType->mTotalSize) { > + mNewDataType->mTotalSize =3D pNewField->mFieldType->mTotalSize; > + } > + pNewField->mOffset =3D 0; > + } else { > + mNewDataType->mTotalSize =3D pNewField->mOffset + > + (pNewField->mFieldType->mTotalSize) * ((ArrayNum =3D=3D 0) ? 1 : > + ArrayNum); } >=20 > return VFR_RETURN_SUCCESS; > } >=20 > VOID > diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h > b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h > index 59509c3..0c67d73 100644 > --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h > +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h > @@ -1,10 +1,10 @@ > /** @file >=20 > Vfr common library functions. >=20 > -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
> +Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
> This program and the accompanying materials > are licensed and made available under the terms and conditions of the BS= D > License > which accompanies this distribution. The full text of the license may b= e found > at > http://opensource.org/licenses/bsd-license.php >=20 > @@ -203,11 +203,11 @@ public: > CVfrVarDataTypeDB (VOID); > ~CVfrVarDataTypeDB (VOID); >=20 > VOID DeclareDataTypeBegin (VOID); > EFI_VFR_RETURN_CODE SetNewTypeName (IN CHAR8 *); > - EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN > UINT32); > + EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN > + UINT32, IN BOOLEAN); > VOID DeclareDataTypeEnd (VOID); >=20 > EFI_VFR_RETURN_CODE GetDataType (IN CHAR8 *, OUT SVfrDataType **); > EFI_VFR_RETURN_CODE GetDataTypeSize (IN CHAR8 *, OUT UINT32 *); > EFI_VFR_RETURN_CODE GetDataTypeSize (IN UINT8, OUT UINT32 *); > -- > 1.9.5.msysgit.1