From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 30F5621945DCB for ; Sun, 4 Jun 2017 23:48:18 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Jun 2017 23:49:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,299,1493708400"; d="scan'208";a="95603134" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga002.jf.intel.com with ESMTP; 04 Jun 2017 23:49:22 -0700 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 4 Jun 2017 23:49:22 -0700 Received: from shsmsx101.ccr.corp.intel.com (10.239.4.153) by FMSMSX112.amr.corp.intel.com (10.18.116.6) with Microsoft SMTP Server (TLS) id 14.3.319.2; Sun, 4 Jun 2017 23:49:21 -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; Mon, 5 Jun 2017 14:49:19 +0800 From: "Ni, Ruiyu" To: "Bi, Dandan" , "edk2-devel@lists.01.org" CC: "Dong, Eric" , "Gao, Liming" Thread-Topic: [RFC v2 1/2] BaseTool/VfrCompile: Support Union type in VFR Thread-Index: AQHS3bSQOxh7AbXFakGDZLfVILwugaIV09fA Date: Mon, 5 Jun 2017 06:49:19 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B987242@SHSMSX104.ccr.corp.intel.com> References: <1496637040-369220-1-git-send-email-dandan.bi@intel.com> <1496637040-369220-2-git-send-email-dandan.bi@intel.com> In-Reply-To: <1496637040-369220-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 v2 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: Mon, 05 Jun 2017 06:48:18 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Dandan, Is it possible to avoid adding IsUnion member variable? I remember .G syntax supports passing value to sub-statement. In this case, can you use: vfrDataStructFields [IsUnion]? Thanks/Ray > -----Original Message----- > From: Bi, Dandan > Sent: Monday, June 5, 2017 12:31 PM > To: edk2-devel@lists.01.org > Cc: Dong, Eric ; Gao, Liming ;= Ni, > Ruiyu > Subject: [RFC v2 1/2] BaseTool/VfrCompile: Support Union type in VFR >=20 > V2: Update VfrCompiler to use member variable instead of global varable t= o > indicate whether current date type is Union. >=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 | 19 ++++++++++++++++++- > BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 16 ++++++++++++++-- > BaseTools/Source/C/VfrCompile/VfrUtilityLib.h | 3 ++- > 3 files changed, 34 insertions(+), 4 deletions(-) >=20 > diff --git a/BaseTools/Source/C/VfrCompile/VfrSyntax.g > b/BaseTools/Source/C/VfrCompile/VfrSyntax.g > index 406dbc5..9e1212a 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,12 +320,27 @@ vfrPragmaPackDefinition : > | pragmaPackNumber > } > "\)" > ; >=20 > + vfrDataUnionDefinition : > + { TypeDef } Union << > gCVfrVarDataTypeDB.DeclareDataTypeBegin (TRUE); >> > + { NonNvDataMap } > + { > + N1:StringIdentifier << > _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >> > + } > + OpenBrace > + vfrDataStructFields > + CloseBrace > + { > + N2:StringIdentifier << > _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N2->getText()), N2); >> > + } > + ";" << gCVfrVarDataTypeD= B.DeclareDataTypeEnd > ();>> > + ; > + > vfrDataStructDefinition : > - { TypeDef } Struct << > gCVfrVarDataTypeDB.DeclareDataTypeBegin (); >> > + { TypeDef } Struct << > gCVfrVarDataTypeDB.DeclareDataTypeBegin (FALSE); >> > { NonNvDataMap } > { > N1:StringIdentifier << > _PCATCH(gCVfrVarDataTypeDB.SetNewTypeName (N1->getText()), N1); >> > } > OpenBrace > diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp > b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp > index 2f97975..186b9c9 100644 > --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp > +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp > @@ -776,10 +776,11 @@ CVfrVarDataTypeDB::InternalTypesListInit ( > if (New !=3D NULL) { > strcpy (New->mTypeName, gInternalTypesTable[Index].mTypeName); > New->mType =3D gInternalTypesTable[Index].mType; > New->mAlign =3D gInternalTypesTable[Index].mAlign; > New->mTotalSize =3D gInternalTypesTable[Index].mSize; > + New->mIsUnionType =3D FALSE; > if (strcmp (gInternalTypesTable[Index].mTypeName, "EFI_HII_DATE") = =3D=3D 0) { > SVfrDataField *pYearField =3D new SVfrDataField; > SVfrDataField *pMonthField =3D new SVfrDataField; > SVfrDataField *pDayField =3D new SVfrDataField; >=20 > @@ -964,11 +965,11 @@ CVfrVarDataTypeDB::Pack ( > return VFR_RETURN_SUCCESS; > } >=20 > VOID > CVfrVarDataTypeDB::DeclareDataTypeBegin ( > - VOID > + BOOLEAN IsUnionType > ) > { > SVfrDataType *pNewType =3D NULL; >=20 > pNewType =3D new SVfrDataType; > @@ -976,10 +977,11 @@ CVfrVarDataTypeDB::DeclareDataTypeBegin ( > pNewType->mType =3D EFI_IFR_TYPE_OTHER; > pNewType->mAlign =3D DEFAULT_ALIGN; > pNewType->mTotalSize =3D 0; > pNewType->mMembers =3D NULL; > pNewType->mNext =3D NULL; > + pNewType->mIsUnionType =3D IsUnionType; >=20 > mNewDataType =3D pNewType; > } >=20 > EFI_VFR_RETURN_CODE > @@ -1018,12 +1020,14 @@ CVfrVarDataTypeDB::DataTypeAddField ( { > 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 +1059,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 (mNewDataType->mIsUnionType) { > + 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..13b75e4 100644 > --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h > +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.h > @@ -124,10 +124,11 @@ struct SVfrDataType { > UINT8 mType; > UINT32 mAlign; > UINT32 mTotalSize; > SVfrDataField *mMembers; > SVfrDataType *mNext; > + BOOLEAN mIsUnionType; > }; >=20 > #define VFR_PACK_ASSIGN 0x01 > #define VFR_PACK_SHOW 0x02 > #define VFR_PACK_PUSH 0x04 > @@ -201,11 +202,11 @@ private: >=20 > public: > CVfrVarDataTypeDB (VOID); > ~CVfrVarDataTypeDB (VOID); >=20 > - VOID DeclareDataTypeBegin (VOID); > + VOID DeclareDataTypeBegin (BOOLEAN); > EFI_VFR_RETURN_CODE SetNewTypeName (IN CHAR8 *); > EFI_VFR_RETURN_CODE DataTypeAddField (IN CHAR8 *, IN CHAR8 *, IN > UINT32); > VOID DeclareDataTypeEnd (VOID); >=20 > EFI_VFR_RETURN_CODE GetDataType (IN CHAR8 *, OUT SVfrDataType **); > -- > 1.9.5.msysgit.1