summaryrefslogtreecommitdiff
path: root/src/ilasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/ilasm')
-rw-r--r--src/ilasm/.gitmirrorall1
-rw-r--r--src/ilasm/CMakeLists.txt85
-rw-r--r--src/ilasm/MscorpeSxS.cpp23
-rw-r--r--src/ilasm/MscorpeSxS.h20
-rw-r--r--src/ilasm/Native.rc8
-rw-r--r--src/ilasm/asmenum.h41
-rw-r--r--src/ilasm/asmman.cpp1283
-rw-r--r--src/ilasm/asmman.hpp305
-rw-r--r--src/ilasm/asmparse.h326
-rw-r--r--src/ilasm/asmparse.y2053
-rw-r--r--src/ilasm/asmtemplates.h845
-rw-r--r--src/ilasm/assem.cpp1654
-rw-r--r--src/ilasm/assembler.cpp2462
-rw-r--r--src/ilasm/assembler.h1203
-rw-r--r--src/ilasm/binstr.h77
-rw-r--r--src/ilasm/class.hpp118
-rw-r--r--src/ilasm/extractGrammar.pl60
-rw-r--r--src/ilasm/grammar_after.cpp1722
-rw-r--r--src/ilasm/grammar_before.cpp150
-rw-r--r--src/ilasm/ilasm.nativeproj88
-rw-r--r--src/ilasm/ilasmpch.cpp5
-rw-r--r--src/ilasm/ilasmpch.h27
-rw-r--r--src/ilasm/main.cpp966
-rw-r--r--src/ilasm/method.cpp157
-rw-r--r--src/ilasm/method.hpp380
-rw-r--r--src/ilasm/nvpair.h46
-rw-r--r--src/ilasm/prebuilt/asmparse.c4907
-rw-r--r--src/ilasm/typar.hpp166
-rw-r--r--src/ilasm/writer.cpp1814
-rw-r--r--src/ilasm/writer_enc.cpp661
30 files changed, 21653 insertions, 0 deletions
diff --git a/src/ilasm/.gitmirrorall b/src/ilasm/.gitmirrorall
new file mode 100644
index 0000000000..9ee5c57b99
--- /dev/null
+++ b/src/ilasm/.gitmirrorall
@@ -0,0 +1 @@
+This folder will be mirrored by the Git-TFS Mirror recursively. \ No newline at end of file
diff --git a/src/ilasm/CMakeLists.txt b/src/ilasm/CMakeLists.txt
new file mode 100644
index 0000000000..34ec7997c4
--- /dev/null
+++ b/src/ilasm/CMakeLists.txt
@@ -0,0 +1,85 @@
+project(ilasm)
+
+add_definitions(-DUNICODE)
+add_definitions(-D_UNICODE)
+add_definitions(-D_FEATURE_NO_HOST)
+add_definitions(-D__ILASM__)
+
+add_definitions(-DFEATURE_CORECLR)
+
+include_directories(.)
+include_directories(../ildasm/unixcoreclrloader)
+
+if(CLR_CMAKE_PLATFORM_UNIX)
+ add_compile_options(-fPIE)
+endif(CLR_CMAKE_PLATFORM_UNIX)
+
+set(ILASM_SOURCES
+ assem.cpp
+ writer.cpp
+ writer_enc.cpp
+ method.cpp
+ asmman.cpp
+ main.cpp
+ assembler.cpp
+ prebuilt/asmparse.c
+)
+if(WIN32)
+ set(ILASM_RESOURCES Native.rc)
+ add_definitions(-DFX_VER_INTERNALNAME_STR=ilasm.exe)
+endif(WIN32)
+
+set_source_files_properties( prebuilt/asmparse.c PROPERTIES LANGUAGE CXX )
+
+if(CLR_CMAKE_PLATFORM_UNIX)
+ add_compile_options(-x c++)
+ # Need generate a right form of asmparse.c to avoid the following options.
+ # Clang also produces a bad-codegen on this prebuilt file with optimization.
+ # https://github.com/dotnet/coreclr/issues/2305
+ add_compile_options(-Wno-delete-non-virtual-dtor)
+ add_compile_options(-Wno-deprecated-register)
+ add_compile_options(-Wno-array-bounds)
+ add_compile_options(-Wno-unused-label)
+ set_source_files_properties( prebuilt/asmparse.c PROPERTIES COMPILE_FLAGS -O0 )
+endif(CLR_CMAKE_PLATFORM_UNIX)
+
+_add_executable(ilasm
+ ${ILASM_SOURCES}
+ ${ILASM_RESOURCES}
+)
+
+set(ILASM_LINK_LIBRARIES
+ utilcodestaticnohost
+ mscorpe
+ mdhotdata_full
+ corguids
+)
+
+if(CLR_CMAKE_PLATFORM_UNIX)
+ target_link_libraries(ilasm
+ ${ILASM_LINK_LIBRARIES}
+ ceefgen
+ unixcoreclrloader
+ utilcodestaticnohost
+ mscorrc_debug
+ coreclrpal
+ palrt
+ )
+
+ # FreeBSD and NetBSD implement dlopen(3) in libc
+ if(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD AND NOT CMAKE_SYSTEM_NAME STREQUAL NetBSD)
+ target_link_libraries(ilasm
+ dl
+ )
+ endif(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD AND NOT CMAKE_SYSTEM_NAME STREQUAL NetBSD)
+else()
+ target_link_libraries(ilasm
+ ${ILASM_LINK_LIBRARIES}
+ coreclr
+ ole32
+ oleaut32
+ shell32
+ )
+endif(CLR_CMAKE_PLATFORM_UNIX)
+
+install_clr(ilasm) \ No newline at end of file
diff --git a/src/ilasm/MscorpeSxS.cpp b/src/ilasm/MscorpeSxS.cpp
new file mode 100644
index 0000000000..b3b94f466b
--- /dev/null
+++ b/src/ilasm/MscorpeSxS.cpp
@@ -0,0 +1,23 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// File: MscorpeSxS.cpp
+//
+
+//
+// This file defines a wrapper for SxS version of mscorpe.dll (dynamically loaded via shim).
+//
+#include "ilasmpch.h"
+
+#include "MscorpeSxS.h"
+
+#include <LegacyActivationShim.h>
+
+// Loads mscorpe.dll (uses shim)
+HRESULT
+LoadMscorpeDll(HMODULE * phModule)
+{
+ // Load SxS version of mscorpe.dll (i.e. mscorpehost.dll) and initialize it
+ return LegacyActivationShim::LoadLibraryShim(L"mscorpe.dll", NULL, NULL, phModule);
+}
diff --git a/src/ilasm/MscorpeSxS.h b/src/ilasm/MscorpeSxS.h
new file mode 100644
index 0000000000..8cee9c49cd
--- /dev/null
+++ b/src/ilasm/MscorpeSxS.h
@@ -0,0 +1,20 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// File: MscorpeSxS.h
+//
+
+//
+// This file defines a wrapper for SxS version of mscorpe.dll (dynamically loaded via shim).
+//
+
+#pragma once
+
+#include <MscorpeSxSWrapper.h>
+
+// Loads mscorpe.dll (uses shim)
+HRESULT LoadMscorpeDll(HMODULE * phModule);
+
+// Wrapper for mscorpe.dll calls
+typedef MscorpeSxSWrapper<LoadMscorpeDll> MscorpeSxS;
diff --git a/src/ilasm/Native.rc b/src/ilasm/Native.rc
new file mode 100644
index 0000000000..2164680d3c
--- /dev/null
+++ b/src/ilasm/Native.rc
@@ -0,0 +1,8 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#define FX_VER_FILEDESCRIPTION_STR "Microsoft .NET Framework IL assembler\0"
+
+#include <fxver.h>
+#include <fxver.rc>
diff --git a/src/ilasm/asmenum.h b/src/ilasm/asmenum.h
new file mode 100644
index 0000000000..e16ee23dd0
--- /dev/null
+++ b/src/ilasm/asmenum.h
@@ -0,0 +1,41 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+#ifndef __asmenum_h__
+#define __asmenum_h__
+
+#include "openum.h"
+
+typedef struct
+{
+ const char * pszName;
+ OPCODE op;
+
+ BYTE Type; // Inline0 etc.
+
+ BYTE Len; // std mapping
+ BYTE Std1;
+ BYTE Std2;
+} opcodeinfo_t;
+
+#ifdef DECLARE_DATA
+opcodeinfo_t OpcodeInfo[] =
+{
+#define OPALIAS(c,s,real) { s, real, 0, 0, 0, 0 },
+#define OPDEF(c,s,pop,push,args,type,l,s1,s2,ctrl) { s, c, args,l,s1,s2 },
+#include "opcode.def"
+#undef OPDEF
+#undef OPALIAS
+};
+
+unsigned OpcodeInfoLen = sizeof(OpcodeInfo) / sizeof(opcodeinfo_t);
+#else
+extern opcodeinfo_t OpcodeInfo[];
+extern unsigned OpcodeInfoLen;
+#endif
+
+
+
+#endif /* __openum_h__ */
+
+
diff --git a/src/ilasm/asmman.cpp b/src/ilasm/asmman.cpp
new file mode 100644
index 0000000000..dba481faf2
--- /dev/null
+++ b/src/ilasm/asmman.cpp
@@ -0,0 +1,1283 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// asmman.cpp - manifest info handling (implementation of class AsmMan, see asmman.hpp)
+//
+
+//
+#include "ilasmpch.h"
+
+#include "assembler.h"
+#include "strongname.h"
+#ifndef FEATURE_CORECLR
+#include "LegacyActivationShim.h"
+#endif
+#include <limits.h>
+#include <fusion.h>
+
+extern WCHAR* pwzInputFiles[];
+
+BinStr* BinStrToUnicode(BinStr* pSource, bool Swap)
+{
+ if(pSource)
+ {
+ pSource->appendInt8(0);
+ BinStr* tmp = new BinStr();
+ char* pb = (char*)(pSource->ptr());
+ int l=pSource->length(), L = sizeof(WCHAR)*l;
+ if(tmp)
+ {
+ WCHAR* wz = (WCHAR*)(tmp->getBuff(L));
+ if(wz)
+ {
+ memset(wz,0,L);
+ WszMultiByteToWideChar(g_uCodePage,0,pb,-1,wz,l);
+ tmp->remove(L-(DWORD)wcslen(wz)*sizeof(WCHAR));
+#if BIGENDIAN
+ if (Swap)
+ SwapStringLength(wz, (DWORD)wcslen(wz));
+#endif
+ delete pSource;
+ }
+ else
+ {
+ delete tmp;
+ tmp = NULL;
+ fprintf(stderr,"\nOut of memory!\n");
+ }
+ }
+ else
+ fprintf(stderr,"\nOut of memory!\n");
+ return tmp;
+ }
+ return NULL;
+}
+
+AsmManFile* AsmMan::GetFileByName(__in __nullterminated char* szFileName)
+{
+ AsmManFile* ret = NULL;
+ if(szFileName)
+ {
+ //AsmManFile X;
+ //X.szName = szFileName;
+ //ret = m_FileLst.FIND(&X);
+ //X.szName = NULL;
+ for(int i=0; (ret = m_FileLst.PEEK(i))&&strcmp(ret->szName,szFileName); i++);
+ }
+ return ret;
+}
+
+mdToken AsmMan::GetFileTokByName(__in __nullterminated char* szFileName)
+{
+ AsmManFile* tmp = GetFileByName(szFileName);
+ return(tmp ? tmp->tkTok : mdFileNil);
+}
+
+AsmManComType* AsmMan::GetComTypeByName(__in_opt __nullterminated char* szComTypeName,
+ __in_opt __nullterminated char* szComEnclosingTypeName)
+{
+ AsmManComType* ret = NULL;
+ if(szComTypeName)
+ {
+ //AsmManComType X;
+ //X.szName = szComTypeName;
+ //ret = m_ComTypeLst.FIND(&X);
+ //X.szName = NULL;
+ for(int i=0; (ret = m_ComTypeLst.PEEK(i)) != NULL; i++)
+ {
+ if (strcmp(ret->szName, szComTypeName) == 0)
+ {
+ if (ret->szComTypeName == NULL && szComEnclosingTypeName == NULL)
+ {
+ break;
+ }
+
+ if (ret->szComTypeName != NULL && szComEnclosingTypeName != NULL)
+ {
+ if (strcmp(ret->szComTypeName, szComEnclosingTypeName) == 0)
+ {
+ break;
+ }
+ }
+ }
+ }
+ }
+ return ret;
+}
+
+mdToken AsmMan::GetComTypeTokByName(
+ __in_opt __nullterminated char* szComTypeName,
+ __in_opt __nullterminated char* szComEnclosingTypeName)
+{
+ AsmManComType* tmp = GetComTypeByName(szComTypeName, szComEnclosingTypeName);
+ return(tmp ? tmp->tkTok : mdExportedTypeNil);
+}
+
+AsmManAssembly* AsmMan::GetAsmRefByName(__in __nullterminated const char* szAsmRefName)
+{
+ AsmManAssembly* ret = NULL;
+ if(szAsmRefName)
+ {
+ //AsmManAssembly X;
+ //X.szAlias = szAsmRefName;
+ //ret = m_AsmRefLst.FIND(&X);
+ //X.szAlias = NULL;
+ DWORD L = (DWORD)strlen(szAsmRefName);
+ for(int i=0; (ret = m_AsmRefLst.PEEK(i))&&
+ ((ret->dwAlias != L)||strcmp(ret->szAlias,szAsmRefName)); i++);
+ }
+ return ret;
+}
+mdToken AsmMan::GetAsmRefTokByName(__in __nullterminated const char* szAsmRefName)
+{
+ AsmManAssembly* tmp = GetAsmRefByName(szAsmRefName);
+ return(tmp ? tmp->tkTok : mdAssemblyRefNil);
+}
+//==============================================================================================================
+void AsmMan::SetModuleName(__inout_opt __nullterminated char* szName)
+{
+ if(m_szScopeName == NULL) // ignore all duplicate declarations
+ {
+ if(szName && *szName)
+ {
+ ULONG L = (ULONG)strlen(szName);
+ if(L >= MAX_SCOPE_LENGTH)
+ {
+ ((Assembler*)m_pAssembler)->report->warn("Module name too long (%d chars, max.allowed: %d chars), truncated\n",L,MAX_SCOPE_LENGTH-1);
+ szName[MAX_SCOPE_LENGTH-1] = 0;
+ }
+ m_szScopeName = szName;
+ strcpy_s(((Assembler*)m_pAssembler)->m_szScopeName, MAX_SCOPE_LENGTH, szName);
+ }
+ }
+}
+//==============================================================================================================
+// Borrowed from VM\assembly.cpp
+#ifndef FEATURE_CORECLR
+HRESULT GetHash(__in LPWSTR moduleName,
+ ALG_ID iHashAlg,
+ BYTE** pbCurrentValue, // should be NULL
+ DWORD *cbCurrentValue)
+{
+ HRESULT hr = E_FAIL;
+ HCRYPTPROV hProv = 0;
+ HCRYPTHASH hHash = 0;
+ DWORD dwCount = sizeof(DWORD);
+ PBYTE pbBuffer = NULL;
+ DWORD dwBufferLen;
+ HANDLE hFile = INVALID_HANDLE_VALUE;
+ HANDLE hMapFile = NULL;
+
+ hFile = WszCreateFile(moduleName, GENERIC_READ, FILE_SHARE_READ,
+ 0, OPEN_EXISTING, 0, 0);
+ if (hFile == INVALID_HANDLE_VALUE) return E_FAIL;
+
+ dwBufferLen = SafeGetFileSize(hFile,NULL);
+ if (dwBufferLen == 0xffffffff)
+ {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ goto exit;
+ }
+ hMapFile = WszCreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
+ if (hMapFile == NULL) goto exit;
+
+ pbBuffer = (PBYTE) MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
+ if (pbBuffer == NULL) goto exit;
+
+ // No need to late bind this stuff, all these crypto API entry points happen
+ // to live in ADVAPI32.
+
+ if ((!WszCryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) ||
+ (!CryptCreateHash(hProv, iHashAlg, 0, 0, &hHash)) ||
+ (!CryptHashData(hHash, pbBuffer, dwBufferLen, 0)) ||
+ (!CryptGetHashParam(hHash, HP_HASHSIZE, (BYTE *) cbCurrentValue,
+ &dwCount, 0))) {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ goto exit;
+ }
+
+ *pbCurrentValue = new BYTE[*cbCurrentValue];
+ if (!(*pbCurrentValue)) {
+ hr = E_OUTOFMEMORY;
+ goto exit;
+ }
+
+ if(!CryptGetHashParam(hHash, HP_HASHVAL, *pbCurrentValue, cbCurrentValue, 0)) {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ delete[] *pbCurrentValue;
+ *pbCurrentValue = 0;
+ goto exit;
+ }
+
+ hr = S_OK;
+
+ exit:
+ if (pbBuffer) UnmapViewOfFile(pbBuffer);
+ if (hMapFile) CloseHandle(hMapFile);
+ CloseHandle(hFile);
+ if (hHash)
+ CryptDestroyHash(hHash);
+ if (hProv)
+ CryptReleaseContext(hProv, 0);
+
+ return hr;
+}
+#endif // !FEATURE_CORECLR
+//==============================================================================================================
+
+void AsmMan::AddFile(__in __nullterminated char* szName, DWORD dwAttr, BinStr* pHashBlob)
+{
+ AsmManFile* tmp = GetFileByName(szName);
+ Assembler* pAsm = (Assembler*)m_pAssembler;
+ if(tmp==NULL)
+ {
+ tmp = new AsmManFile;
+ if(tmp==NULL)
+ {
+ pAsm->report->error("\nOut of memory!\n");
+ return;
+ }
+ memset(tmp,0,sizeof(AsmManFile));
+ if((dwAttr & 0x80000000)!=0) pAsm->m_fEntryPointPresent = TRUE;
+ tmp->szName = szName;
+ tmp->dwAttr = dwAttr;
+ tmp->pHash = pHashBlob;
+ tmp->m_fNew = TRUE;
+ m_FileLst.PUSH(tmp);
+ tmp->tkTok = TokenFromRid(m_FileLst.COUNT(),mdtFile);
+ }
+ pAsm->m_tkCurrentCVOwner = 0;
+ if(tmp) pAsm->m_pCustomDescrList = &(tmp->m_CustomDescrList);
+}
+//==============================================================================================================
+
+void AsmMan::EmitFiles()
+{
+ AsmManFile* tmp;
+ Assembler* pAsm = (Assembler*)m_pAssembler;
+ int i;
+ HRESULT hr = S_OK;
+ mdToken tk;
+ for(i = 0; (tmp=m_FileLst.PEEK(i)) != NULL; i++)
+ {
+ BOOL fEntry = ((tmp->dwAttr & 0x80000000)!=0);
+
+ wzUniBuf[0] = 0;
+
+ BYTE* pHash=NULL;
+ DWORD cbHash= 0;
+
+ if(!tmp->m_fNew) continue;
+ tmp->m_fNew = FALSE;
+
+ WszMultiByteToWideChar(g_uCodePage,0,tmp->szName,-1,wzUniBuf,dwUniBuf);
+ if(tmp->pHash==NULL) // if hash not explicitly specified
+ {
+ if(m_pAssembly // and assembly is defined
+ && m_pAssembly->ulHashAlgorithm) // and hash algorithm is defined...
+ { // then try to compute it
+#ifndef FEATURE_CORECLR
+ if(SUCCEEDED(GetHash(wzUniBuf,(ALG_ID)(m_pAssembly->ulHashAlgorithm),&pHash,&cbHash)))
+ {
+ tmp->pHash = new BinStr(pHash,cbHash);
+ }
+ else
+#endif // !FEATURE_CORECLR
+ {
+ pHash = NULL;
+ cbHash = 0;
+ }
+ }
+ }
+ else
+ {
+ pHash = tmp->pHash->ptr();
+ cbHash = tmp->pHash->length();
+ }
+
+ hr = m_pAsmEmitter->DefineFile(wzUniBuf,
+ (const void*)pHash,
+ cbHash,
+ tmp->dwAttr & 0x7FFFFFFF,
+ (mdFile*)&tk);
+ _ASSERTE(tk == tmp->tkTok);
+ if(FAILED(hr)) report->error("Failed to define file '%s': 0x%08X\n",tmp->szName,hr);
+ else
+ {
+ if(fEntry)
+ {
+ if (FAILED(pAsm->m_pCeeFileGen->SetEntryPoint(pAsm->m_pCeeFile, tmp->tkTok)))
+ {
+ pAsm->report->error("Failed to set external entry point for file '%s'\n",tmp->szName);
+ }
+ }
+ pAsm->EmitCustomAttributes(tmp->tkTok, &(tmp->m_CustomDescrList));
+ }
+ } //end for(i = 0; tmp=m_FileLst.PEEK(i); i++)
+}
+
+void AsmMan::StartAssembly(__in __nullterminated char* szName, __in_opt __nullterminated char* szAlias, DWORD dwAttr, BOOL isRef)
+{
+ if(!isRef && (0==strcmp(szName, "mscorlib"))) ((Assembler*)m_pAssembler)->m_fIsMscorlib = TRUE;
+ if(!isRef && (m_pAssembly != NULL))
+ {
+ if(strcmp(szName, m_pAssembly->szName))
+ report->error("Multiple assembly declarations\n");
+ // if name is the same, just ignore it
+ m_pCurAsmRef = NULL;
+ }
+ else
+ {
+ if((m_pCurAsmRef = new AsmManAssembly))
+ {
+ memset(m_pCurAsmRef,0,sizeof(AsmManAssembly));
+ m_pCurAsmRef->usVerMajor = (USHORT)0xFFFF;
+ m_pCurAsmRef->usVerMinor = (USHORT)0xFFFF;
+ m_pCurAsmRef->usBuild = (USHORT)0xFFFF;
+ m_pCurAsmRef->usRevision = (USHORT)0xFFFF;
+ m_pCurAsmRef->szName = szName;
+ m_pCurAsmRef->szAlias = szAlias ? szAlias : szName;
+ m_pCurAsmRef->dwAlias = (DWORD)strlen(m_pCurAsmRef->szAlias);
+ m_pCurAsmRef->dwAttr = dwAttr;
+ m_pCurAsmRef->isRef = isRef;
+ m_pCurAsmRef->isAutodetect = FALSE;
+ m_pCurAsmRef->m_fNew = TRUE;
+ if(!isRef) m_pAssembly = m_pCurAsmRef;
+ }
+ else
+ report->error("Failed to allocate AsmManAssembly structure\n");
+ }
+ ((Assembler*)m_pAssembler)->m_tkCurrentCVOwner = 0;
+ ((Assembler*)m_pAssembler)->m_CustomDescrListStack.PUSH(((Assembler*)m_pAssembler)->m_pCustomDescrList);
+ ((Assembler*)m_pAssembler)->m_pCustomDescrList = m_pCurAsmRef ? &(m_pCurAsmRef->m_CustomDescrList) : NULL;
+
+}
+// copied from asmparse.y
+static void corEmitInt(BinStr* buff, unsigned data)
+{
+ unsigned cnt = CorSigCompressData(data, buff->getBuff(5));
+ buff->remove(5 - cnt);
+}
+
+void AsmMan::EmitDebuggableAttribute(mdToken tkOwner)
+{
+ mdToken tkCA;
+ Assembler* pAsm = (Assembler*)m_pAssembler;
+ mdToken tkTypeSpec, tkMscorlib, tkParamType;
+ BinStr *pbsSig = new BinStr();
+ BinStr* bsBytes = new BinStr();;
+ char* szName;
+ tkMscorlib = pAsm->m_fIsMscorlib ? 1 : pAsm->GetBaseAsmRef();
+ tkTypeSpec = pAsm->ResolveClassRef(tkMscorlib,"System.Diagnostics.DebuggableAttribute",NULL);
+
+ EmitAssemblyRefs(); // just in case we gained 'mscorlib' AsmRef in GetAsmRef above
+
+ BOOL fOldStyle = FALSE;
+ if(tkMscorlib == 1)
+ fOldStyle = (m_pAssembly->usVerMajor == 1);
+ else
+ {
+ AsmManAssembly *pAssembly = GetAsmRefByName("mscorlib");
+ _ASSERTE(pAssembly != NULL);
+ PREFIX_ASSUME(pAssembly != NULL);
+ fOldStyle = (pAssembly->usVerMajor == 1);
+ }
+
+ bsBytes->appendInt8(1);
+ bsBytes->appendInt8(0);
+ if(fOldStyle)
+ {
+ pbsSig->appendInt8(IMAGE_CEE_CS_CALLCONV_HASTHIS);
+ corEmitInt(pbsSig,2);
+ pbsSig->appendInt8(ELEMENT_TYPE_VOID);
+ pbsSig->appendInt8(ELEMENT_TYPE_BOOLEAN);
+ pbsSig->appendInt8(ELEMENT_TYPE_BOOLEAN);
+
+ //New to old: 0x101->(true,true),0x03->(true,false),0x103->(true,true)+warning
+ bsBytes->appendInt8(1);
+ bsBytes->appendInt8((pAsm->m_dwIncludeDebugInfo==0x03 ? 0 : 1));
+ if(pAsm->m_dwIncludeDebugInfo == 0x103)
+ {
+ report->warn("\nOption /DEBUG=IMPL is invalid for legacy DebuggableAttribute, /DEBUG used.\n" );
+ }
+ }
+ else
+ {
+ BinStr bsSigArg;
+ char buffer[80];
+ sprintf_s(buffer,80,
+ "%s%c%s",
+ "System.Diagnostics.DebuggableAttribute",
+ NESTING_SEP,
+ "DebuggingModes"
+ );
+
+ tkParamType = pAsm->ResolveClassRef(tkMscorlib,buffer, NULL);
+
+ bsSigArg.appendInt8(ELEMENT_TYPE_VALUETYPE);
+
+ unsigned cnt = CorSigCompressToken(tkParamType, bsSigArg.getBuff(5));
+ bsSigArg.remove(5 - cnt);
+
+ pbsSig->appendInt8(IMAGE_CEE_CS_CALLCONV_HASTHIS);
+ corEmitInt(pbsSig,1);
+ pbsSig->appendInt8(ELEMENT_TYPE_VOID);
+ pbsSig->append(&bsSigArg);
+
+ bsBytes->appendInt32(pAsm->m_dwIncludeDebugInfo);
+ }
+ bsBytes->appendInt8(0);
+ bsBytes->appendInt8(0);
+
+ szName = new char[16];
+ strcpy_s(szName,16,".ctor");
+ tkCA = pAsm->MakeMemberRef(tkTypeSpec,szName,pbsSig);
+ pAsm->DefineCV(new CustomDescr(tkOwner,tkCA,bsBytes));
+}
+
+void AsmMan::EndAssembly()
+{
+ if(m_pCurAsmRef)
+ {
+ if(m_pCurAsmRef->isRef)
+ { // list the assembly ref
+ if(GetAsmRefByName(m_pCurAsmRef->szAlias))
+ {
+ //report->warn("Multiple declarations of Assembly Ref '%s', ignored except the 1st one\n",m_pCurAsmRef->szName);
+ delete m_pCurAsmRef;
+ m_pCurAsmRef = NULL;
+ return;
+ }
+#ifndef FEATURE_CORECLR
+ if(m_pCurAsmRef->isAutodetect)
+ {
+ IAssemblyName* pIAsmName;
+ HRESULT hr;
+ // Convert name to Unicode
+ WszMultiByteToWideChar(g_uCodePage,0,m_pCurAsmRef->szName,-1,wzUniBuf,dwUniBuf);
+ hr = CreateAssemblyNameObject(&pIAsmName,wzUniBuf,CANOF_PARSE_DISPLAY_NAME,NULL);
+ if(SUCCEEDED(hr))
+ {
+ // set enumeration criteria: what is known about AsmRef (besides name)
+ if(m_pCurAsmRef->usVerMajor != (USHORT)0xFFFF)
+ pIAsmName->SetProperty(ASM_NAME_MAJOR_VERSION,&(m_pCurAsmRef->usVerMajor),2);
+ if(m_pCurAsmRef->usVerMinor != (USHORT)0xFFFF)
+ pIAsmName->SetProperty(ASM_NAME_MINOR_VERSION,&(m_pCurAsmRef->usVerMinor),2);
+ if(m_pCurAsmRef->usBuild != (USHORT)0xFFFF)
+ pIAsmName->SetProperty(ASM_NAME_BUILD_NUMBER,&(m_pCurAsmRef->usBuild),2);
+ if(m_pCurAsmRef->usRevision != (USHORT)0xFFFF)
+ pIAsmName->SetProperty(ASM_NAME_REVISION_NUMBER,&(m_pCurAsmRef->usRevision),2);
+ if(m_pCurAsmRef->pPublicKeyToken)
+ pIAsmName->SetProperty(ASM_NAME_PUBLIC_KEY_TOKEN,
+ m_pCurAsmRef->pPublicKeyToken->ptr(),
+ m_pCurAsmRef->pPublicKeyToken->length());
+ if(m_pCurAsmRef->pLocale)
+ pIAsmName->SetProperty(ASM_NAME_CULTURE,
+ m_pCurAsmRef->pLocale->ptr(),
+ m_pCurAsmRef->pLocale->length());
+
+ // enumerate assemblies
+ IAssemblyEnum* pIAsmEnum = NULL;
+ hr = CreateAssemblyEnum(&pIAsmEnum, NULL, pIAsmName, ASM_CACHE_GAC, NULL);
+ if(SUCCEEDED(hr))
+ {
+ IAssemblyName* pIAsmNameFound;
+ IAssemblyName* pIAsmNameLatestVer = NULL;
+ ULONGLONG ullVer=0, ullVerLatest=0;
+ DWORD dwVerHi, dwVerLo;
+
+ // find the latest and greatest, if any
+ for(;;)
+ {
+ pIAsmNameFound = NULL;
+ hr = pIAsmEnum->GetNextAssembly(NULL,&pIAsmNameFound,0);
+ if(SUCCEEDED(hr) && pIAsmNameFound)
+ {
+
+ pIAsmNameFound->GetVersion(&dwVerHi,&dwVerLo);
+ ullVer = (ULONGLONG)dwVerHi;
+ ullVer <<= sizeof(DWORD);
+ ullVer |= dwVerLo;
+ if(ullVer > ullVerLatest)
+ {
+ if(pIAsmNameLatestVer)
+ pIAsmNameLatestVer->Release();
+ ullVerLatest = ullVer;
+ pIAsmNameLatestVer = pIAsmNameFound;
+ }
+ else
+ pIAsmNameFound->Release();
+ }
+ else break;
+ }
+ // if found, fill the gaps
+ if(pIAsmNameLatestVer)
+ {
+ DWORD cbSize=0;
+ USHORT usDummy=0;
+
+ if(m_pCurAsmRef->pPublicKeyToken == NULL)
+ {
+ cbSize = 1024;
+ pIAsmNameLatestVer->GetProperty(ASM_NAME_PUBLIC_KEY_TOKEN,
+ wzUniBuf, &cbSize);
+ if(cbSize)
+ {
+ if((m_pCurAsmRef->pPublicKeyToken = new BinStr()))
+ memcpy(m_pCurAsmRef->pPublicKeyToken->getBuff(cbSize),
+ wzUniBuf, cbSize);
+ }
+ }
+
+ if(m_pCurAsmRef->usVerMajor == (USHORT)0xFFFF)
+ {
+ cbSize = (DWORD)sizeof(WORD);
+ pIAsmNameLatestVer->GetProperty(ASM_NAME_MAJOR_VERSION,
+ &usDummy, &cbSize);
+ m_pCurAsmRef->usVerMajor = usDummy;
+ }
+ if(m_pCurAsmRef->usVerMinor == (USHORT)0xFFFF)
+ {
+ cbSize = (DWORD)sizeof(WORD);
+ pIAsmNameLatestVer->GetProperty(ASM_NAME_MINOR_VERSION,
+ &usDummy, &cbSize);
+ m_pCurAsmRef->usVerMinor = usDummy;
+ }
+ if(m_pCurAsmRef->usBuild == (USHORT)0xFFFF)
+ {
+ cbSize = (DWORD)sizeof(WORD);
+ pIAsmNameLatestVer->GetProperty(ASM_NAME_BUILD_NUMBER,
+ &usDummy, &cbSize);
+ m_pCurAsmRef->usBuild = usDummy;
+ }
+ if(m_pCurAsmRef->usRevision == (USHORT)0xFFFF)
+ {
+ cbSize = (DWORD)sizeof(WORD);
+ pIAsmNameLatestVer->GetProperty(ASM_NAME_REVISION_NUMBER,
+ &usDummy, &cbSize);
+ m_pCurAsmRef->usRevision = usDummy;
+ }
+
+ if(m_pCurAsmRef->pLocale == NULL)
+ {
+ cbSize = 1024;
+ pIAsmNameLatestVer->GetProperty(ASM_NAME_CULTURE,
+ wzUniBuf, &cbSize);
+
+ if(cbSize > (DWORD)sizeof(WCHAR))
+ {
+ if((m_pCurAsmRef->pLocale = new BinStr()))
+ memcpy(m_pCurAsmRef->pLocale->getBuff(cbSize),
+ wzUniBuf, cbSize);
+ }
+ }
+ pIAsmNameLatestVer->Release();
+ }
+ else
+ report->warn("Failed to autodetect assembly '%s'\n",m_pCurAsmRef->szName);
+ // if no assembly found, leave it as is, it might be not a GAC assembly
+
+ pIAsmEnum->Release();
+ }
+ else
+ report->error("Failed to enum assemblies %S, hr=0x%08X\n",wzUniBuf,hr);
+ pIAsmName->Release();
+ }
+ else
+ report->error("Failed to create assembly name object for %S, hr=0x%08X\n",wzUniBuf,hr);
+ } // end if isAutodetect
+#endif // !FEATURE_CORECLR
+ m_AsmRefLst.PUSH(m_pCurAsmRef);
+ m_pCurAsmRef->tkTok = TokenFromRid(m_AsmRefLst.COUNT(),mdtAssemblyRef);
+ }
+ else
+ {
+ HRESULT hr = S_OK;
+ m_pCurAsmRef->tkTok = TokenFromRid(1,mdtAssembly);
+
+ // Determine the strong name public key. This may have been set
+ // via a directive in the source or from the command line (which
+ // overrides the directive). From the command line we may have
+ // been provided with a file or the name of a CAPI key
+ // container. Either may contain a public key or a full key
+ // pair.
+ if (((Assembler*)m_pAssembler)->m_wzKeySourceName)
+ {
+ // Key file versus container is determined by the first
+ // character of the source ('@' for container).
+ if (*(((Assembler*)m_pAssembler)->m_wzKeySourceName) == L'@')
+ {
+#ifdef FEATURE_CORECLR
+ report->error("Error: ilasm on CoreCLR does not support getting public key from container.\n");
+ m_pCurAsmRef = NULL;
+ return;
+#else
+ // Extract public key from container (works whether
+ // container has just a public key or an entire key
+ // pair).
+ m_sStrongName.m_wzKeyContainer = &((Assembler*)m_pAssembler)->m_wzKeySourceName[1];
+ if (FAILED(hr = LegacyActivationShim::StrongNameGetPublicKey_HRESULT(
+ m_sStrongName.m_wzKeyContainer,
+ NULL,
+ 0,
+ &m_sStrongName.m_pbPublicKey,
+ &m_sStrongName.m_cbPublicKey)))
+ {
+ report->error("Failed to extract public key from '%S': 0x%08X\n",m_sStrongName.m_wzKeyContainer,hr);
+ m_pCurAsmRef = NULL;
+ return;
+ }
+ m_sStrongName.m_fFullSign = TRUE;
+ m_sStrongName.m_dwPublicKeyAllocated = AsmManStrongName::AllocatedBySNApi;
+#endif // FEATURE_CORECLR
+ }
+ else
+ {
+ // Read public key or key pair from file.
+ HANDLE hFile = WszCreateFile(((Assembler*)m_pAssembler)->m_wzKeySourceName,
+ GENERIC_READ,
+ FILE_SHARE_READ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN,
+ NULL);
+ if(hFile == INVALID_HANDLE_VALUE)
+ {
+ hr = GetLastError();
+ report->error("Failed to open key file '%S': 0x%08X\n",((Assembler*)m_pAssembler)->m_wzKeySourceName,hr);
+ m_pCurAsmRef = NULL;
+ return;
+ }
+
+ // Determine file size and allocate an appropriate buffer.
+ m_sStrongName.m_cbPublicKey = SafeGetFileSize(hFile, NULL);
+ if (m_sStrongName.m_cbPublicKey == 0xffffffff) {
+ report->error("File size too large\n");
+ m_pCurAsmRef = NULL;
+ CloseHandle(hFile);
+ return;
+ }
+
+ m_sStrongName.m_pbPublicKey = new BYTE[m_sStrongName.m_cbPublicKey];
+ if (m_sStrongName.m_pbPublicKey == NULL) {
+ report->error("Failed to allocate key buffer\n");
+ m_pCurAsmRef = NULL;
+ CloseHandle(hFile);
+ return;
+ }
+ m_sStrongName.m_dwPublicKeyAllocated = AsmManStrongName::AllocatedByNew;
+
+ // Read the file into the buffer.
+ DWORD dwBytesRead;
+ if (!ReadFile(hFile, m_sStrongName.m_pbPublicKey, m_sStrongName.m_cbPublicKey, &dwBytesRead, NULL)) {
+ hr = GetLastError();
+ report->error("Failed to read key file '%S': 0x%08X\n",((Assembler*)m_pAssembler)->m_wzKeySourceName,hr);
+ m_pCurAsmRef = NULL;
+ CloseHandle(hFile);
+ return;
+ }
+
+ CloseHandle(hFile);
+
+ // Guess whether we're full or delay signing based on
+ // whether the blob passed to us looks like a public
+ // key. (I.e. we may just have copied a full key pair
+ // into the public key buffer).
+ if (m_sStrongName.m_cbPublicKey >= sizeof(PublicKeyBlob) &&
+ (offsetof(PublicKeyBlob, PublicKey) +
+ ((PublicKeyBlob*)m_sStrongName.m_pbPublicKey)->cbPublicKey) == m_sStrongName.m_cbPublicKey)
+ m_sStrongName.m_fFullSign = FALSE;
+ else
+ m_sStrongName.m_fFullSign = TRUE;
+
+ // If we really have a key pair, we'll move it into a
+ // key container so the signing code gets the key pair
+ // from a consistent place.
+ if (m_sStrongName.m_fFullSign)
+ {
+#ifdef FEATURE_CORECLR
+ report->error("Error: ilasm on CoreCLR does not support full sign.\n");
+ m_pCurAsmRef = NULL;
+ return;
+#else
+ m_sStrongName.m_pbPrivateKey = m_sStrongName.m_pbPublicKey;
+ m_sStrongName.m_cbPrivateKey = m_sStrongName.m_cbPublicKey;
+
+ m_sStrongName.m_pbPublicKey = NULL;
+ m_sStrongName.m_cbPublicKey = NULL;
+ m_sStrongName.m_dwPublicKeyAllocated = AsmManStrongName::NotAllocated;
+
+ // Retrieve the public key portion as a byte blob.
+ if (FAILED(hr = LegacyActivationShim::StrongNameGetPublicKey_HRESULT(
+ NULL,
+ m_sStrongName.m_pbPrivateKey,
+ m_sStrongName.m_cbPrivateKey,
+ &m_sStrongName.m_pbPublicKey,
+ &m_sStrongName.m_cbPublicKey)))
+ {
+ report->error("Failed to extract public key: 0x%08X\n",hr);
+ m_pCurAsmRef = NULL;
+ return;
+ }
+
+ m_sStrongName.m_dwPublicKeyAllocated = AsmManStrongName::AllocatedBySNApi;
+#endif // FEATURE_CORECLR
+ }
+ }
+ }
+ else
+ {
+ if (m_pAssembly->pPublicKey)
+ {
+ m_sStrongName.m_pbPublicKey = m_pAssembly->pPublicKey->ptr();
+ m_sStrongName.m_cbPublicKey = m_pAssembly->pPublicKey->length();
+ }
+ else
+ {
+ m_sStrongName.m_pbPublicKey = NULL;
+ m_sStrongName.m_cbPublicKey = 0;
+ }
+
+ m_sStrongName.m_wzKeyContainer = NULL;
+ m_sStrongName.m_fFullSign = FALSE;
+ m_sStrongName.m_dwPublicKeyAllocated = AsmManStrongName::NotAllocated;
+ }
+ }
+ m_pCurAsmRef = NULL;
+ }
+ ((Assembler*)m_pAssembler)->m_pCustomDescrList = ((Assembler*)m_pAssembler)->m_CustomDescrListStack.POP();
+}
+
+void FillAssemblyMetadata(AsmManAssembly *pAsm, ASSEMBLYMETADATA *pmd)
+{
+ pmd->usMajorVersion = pAsm->usVerMajor;
+ pmd->usMinorVersion = pAsm->usVerMinor;
+ pmd->usBuildNumber = pAsm->usBuild;
+ pmd->usRevisionNumber = pAsm->usRevision;
+ if(pmd->usMajorVersion == 0xFFFF) pmd->usMajorVersion = 0;
+ if(pmd->usMinorVersion == 0xFFFF) pmd->usMinorVersion = 0;
+ if(pmd->usBuildNumber == 0xFFFF) pmd->usBuildNumber = 0;
+ if(pmd->usRevisionNumber == 0xFFFF) pmd->usRevisionNumber = 0;
+
+ if(pAsm->pLocale != NULL)
+ {
+ pmd->szLocale = (LPWSTR)(pAsm->pLocale->ptr());
+ pmd->cbLocale = pAsm->pLocale->length()/((ULONG)sizeof(WCHAR));
+ }
+ else
+ {
+ pmd->szLocale = NULL;
+ pmd->cbLocale = 0;
+ }
+
+ pmd->rProcessor = NULL;
+ pmd->rOS = NULL;
+ pmd->ulProcessor = 0;
+ pmd->ulOS = 0;
+}
+
+void AsmMan::EmitAssemblyRefs()
+{
+ int i;
+ HRESULT hr = S_OK;
+ ASSEMBLYMETADATA md;
+ mdToken tk;
+
+ for(i=0; (m_pCurAsmRef=m_AsmRefLst.PEEK(i)) != NULL; i++)
+ {
+ if(!m_pCurAsmRef->m_fNew) continue;
+ m_pCurAsmRef->m_fNew = FALSE;
+
+ wzUniBuf[0] = 0;
+ FillAssemblyMetadata(m_pCurAsmRef,&md);
+
+ // See if we've got a full public key or the tokenized version (or neither).
+ BYTE *pbPublicKeyOrToken = NULL;
+ DWORD cbPublicKeyOrToken = 0;
+ DWORD dwFlags = m_pCurAsmRef->dwAttr;
+ if (m_pCurAsmRef->pPublicKeyToken)
+ {
+ pbPublicKeyOrToken = m_pCurAsmRef->pPublicKeyToken->ptr();
+ cbPublicKeyOrToken = m_pCurAsmRef->pPublicKeyToken->length();
+
+ }
+ else if (m_pCurAsmRef->pPublicKey)
+ {
+ pbPublicKeyOrToken = m_pCurAsmRef->pPublicKey->ptr();
+ cbPublicKeyOrToken = m_pCurAsmRef->pPublicKey->length();
+ dwFlags |= afPublicKey;
+ }
+ // Convert name to Unicode
+ WszMultiByteToWideChar(g_uCodePage,0,m_pCurAsmRef->szName,-1,wzUniBuf,dwUniBuf);
+ hr = m_pAsmEmitter->DefineAssemblyRef( // S_OK or error.
+ pbPublicKeyOrToken, // [IN] Public key or token of the assembly.
+ cbPublicKeyOrToken, // [IN] Count of bytes in the key or token.
+ (LPCWSTR)wzUniBuf, // [IN] Name of the assembly being referenced.
+ (const ASSEMBLYMETADATA*)&md, // [IN] Assembly MetaData.
+ (m_pCurAsmRef->pHashBlob ? (const void*)(m_pCurAsmRef->pHashBlob->ptr()) : NULL), // [IN] Hash Blob.
+ (m_pCurAsmRef->pHashBlob ? m_pCurAsmRef->pHashBlob->length() : 0), // [IN] Count of bytes in the Hash Blob.
+ dwFlags, // [IN] Flags.
+ (mdAssemblyRef*)&tk); // [OUT] Returned AssemblyRef token.
+ if(m_pCurAsmRef->tkTok != tk)
+ {
+ report->error("AsmRef'%S' tok %8.8X -> %8.8X\n",wzUniBuf,m_pCurAsmRef->tkTok,tk);
+ }
+ if(FAILED(hr)) report->error("Failed to define assembly ref '%s': 0x%08X\n",m_pCurAsmRef->szName,hr);
+ else
+ {
+ ((Assembler*)m_pAssembler)->EmitCustomAttributes(m_pCurAsmRef->tkTok, &(m_pCurAsmRef->m_CustomDescrList));
+ }
+ } // end for(i=0; m_pCurAsmRef=m_AsmRefLst.PEEK(i); i++)
+}
+
+void AsmMan::EmitAssembly()
+{
+ HRESULT hr = S_OK;
+ ASSEMBLYMETADATA md;
+
+ wzUniBuf[0] = 0;
+ if(m_pAssembly == NULL) return;
+ if(!m_pAssembly->m_fNew) return;
+ m_pAssembly->m_fNew = FALSE;
+
+ FillAssemblyMetadata(m_pAssembly, &md);
+
+ // Convert name to Unicode
+ WszMultiByteToWideChar(g_uCodePage,0,m_pAssembly->szName,-1,wzUniBuf,dwUniBuf);
+
+ hr = m_pAsmEmitter->DefineAssembly( // S_OK or error.
+ (const void*)(m_sStrongName.m_pbPublicKey), // [IN] Public key of the assembly.
+ m_sStrongName.m_cbPublicKey, // [IN] Count of bytes in the public key.
+ m_pAssembly->ulHashAlgorithm, // [IN] Hash algorithm used to hash the files.
+ (LPCWSTR)wzUniBuf, // [IN] Name of the assembly.
+ (const ASSEMBLYMETADATA*)&md, // [IN] Assembly MetaData.
+ m_pAssembly->dwAttr, // [IN] Flags.
+ (mdAssembly*)&(m_pAssembly->tkTok)); // [OUT] Returned Assembly token.
+
+ if(FAILED(hr)) report->error("Failed to define assembly '%s': 0x%08X\n",m_pAssembly->szName,hr);
+ else
+ {
+ Assembler* pAsm = ((Assembler*)m_pAssembler);
+ pAsm->EmitSecurityInfo(m_pAssembly->tkTok,
+ m_pAssembly->m_pPermissions,
+ m_pAssembly->m_pPermissionSets);
+ if(pAsm->m_dwIncludeDebugInfo)
+ {
+ EmitDebuggableAttribute(m_pAssembly->tkTok);
+ }
+ pAsm->EmitCustomAttributes(m_pAssembly->tkTok, &(m_pAssembly->m_CustomDescrList));
+ }
+}
+
+void AsmMan::SetAssemblyPublicKey(BinStr* pPublicKey)
+{
+ if(m_pCurAsmRef)
+ {
+ m_pCurAsmRef->pPublicKey = pPublicKey;
+ }
+}
+
+void AsmMan::SetAssemblyPublicKeyToken(BinStr* pPublicKeyToken)
+{
+ if(m_pCurAsmRef)
+ {
+ m_pCurAsmRef->pPublicKeyToken = pPublicKeyToken;
+ }
+}
+
+void AsmMan::SetAssemblyHashAlg(ULONG ulAlgID)
+{
+ if(m_pCurAsmRef)
+ {
+ m_pCurAsmRef->ulHashAlgorithm = ulAlgID;
+ }
+}
+
+void AsmMan::SetAssemblyVer(USHORT usMajor, USHORT usMinor, USHORT usBuild, USHORT usRevision)
+{
+ if(m_pCurAsmRef)
+ {
+ m_pCurAsmRef->usVerMajor = usMajor;
+ m_pCurAsmRef->usVerMinor = usMinor;
+ m_pCurAsmRef->usBuild = usBuild;
+ m_pCurAsmRef->usRevision = usRevision;
+ }
+}
+
+void AsmMan::SetAssemblyLocale(BinStr* pLocale, BOOL bConvertToUnicode)
+{
+ if(m_pCurAsmRef)
+ {
+ m_pCurAsmRef->pLocale = bConvertToUnicode ? ::BinStrToUnicode(pLocale) : pLocale;
+ }
+}
+
+void AsmMan::SetAssemblyHashBlob(BinStr* pHashBlob)
+{
+ if(m_pCurAsmRef)
+ {
+ m_pCurAsmRef->pHashBlob = pHashBlob;
+ }
+}
+
+void AsmMan::SetAssemblyAutodetect()
+{
+ if(m_pCurAsmRef)
+ {
+ m_pCurAsmRef->isAutodetect = TRUE;
+ }
+}
+
+void AsmMan::StartComType(__in __nullterminated char* szName, DWORD dwAttr)
+{
+ if((m_pCurComType = new AsmManComType))
+ {
+ memset(m_pCurComType,0,sizeof(AsmManComType));
+ m_pCurComType->szName = szName;
+ m_pCurComType->dwAttr = dwAttr;
+ m_pCurComType->m_fNew = TRUE;
+ ((Assembler*)m_pAssembler)->m_tkCurrentCVOwner = 0;
+ ((Assembler*)m_pAssembler)->m_CustomDescrListStack.PUSH(((Assembler*)m_pAssembler)->m_pCustomDescrList);
+ ((Assembler*)m_pAssembler)->m_pCustomDescrList = &(m_pCurComType->m_CustomDescrList);
+ }
+ else
+ report->error("Failed to allocate AsmManComType structure\n");
+}
+
+void AsmMan::EndComType()
+{
+ if(m_pCurComType)
+ {
+ if(m_pAssembler)
+ {
+ Class* pClass =((Assembler*)m_pAssembler)->m_pCurClass;
+ if(pClass)
+ {
+ m_pCurComType->tkClass = pClass->m_cl;
+ if(pClass->m_pEncloser)
+ {
+ mdTypeDef tkEncloser = pClass->m_pEncloser->m_cl;
+ AsmManComType* pCT;
+ for(unsigned i=0; (pCT=m_ComTypeLst.PEEK(i)); i++)
+ {
+ if(pCT->tkClass == tkEncloser)
+ {
+ m_pCurComType->szComTypeName = pCT->szName;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (IsTdNested(m_pCurComType->dwAttr) && GetComTypeByName(m_pCurComType->szName, m_pCurComType->szComTypeName) != NULL)
+ {
+ report->error("Invalid TypeDefID of exported type\n");
+ delete m_pCurComType;
+ }
+ else
+ {
+ m_ComTypeLst.PUSH(m_pCurComType);
+ }
+
+ m_pCurComType = NULL;
+ ((Assembler*)m_pAssembler)->m_tkCurrentCVOwner = 0;
+ ((Assembler*)m_pAssembler)->m_pCustomDescrList = ((Assembler*)m_pAssembler)->m_CustomDescrListStack.POP();
+ }
+}
+
+void AsmMan::SetComTypeFile(__in __nullterminated char* szFileName)
+{
+ if(m_pCurComType)
+ {
+ m_pCurComType->szFileName = szFileName;
+ }
+}
+
+void AsmMan::SetComTypeAsmRef(__in __nullterminated char* szAsmRefName)
+{
+ if(m_pCurComType)
+ {
+ m_pCurComType->szAsmRefName = szAsmRefName;
+ }
+}
+
+void AsmMan::SetComTypeComType(__in __nullterminated char* szComTypeName)
+{
+ if(m_pCurComType)
+ {
+ m_pCurComType->szComTypeName = szComTypeName;
+ }
+}
+BOOL AsmMan::SetComTypeImplementationTok(mdToken tk)
+{
+ if(m_pCurComType)
+ {
+ switch(TypeFromToken(tk))
+ {
+ case mdtAssemblyRef:
+ case mdtExportedType:
+ case mdtFile:
+ m_pCurComType->tkImpl = tk;
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+BOOL AsmMan::SetComTypeClassTok(mdToken tkClass)
+{
+ if((m_pCurComType)&&(TypeFromToken(tkClass)==mdtTypeDef))
+ {
+ m_pCurComType->tkClass = tkClass;
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void AsmMan::StartManifestRes(__in __nullterminated char* szName, __in __nullterminated char* szAlias, DWORD dwAttr)
+{
+ if((m_pCurManRes = new AsmManRes))
+ {
+ m_pCurManRes->szName = szName;
+ m_pCurManRes->szAlias = szAlias;
+ m_pCurManRes->dwAttr = dwAttr;
+ m_pCurManRes->m_fNew = TRUE;
+ ((Assembler*)m_pAssembler)->m_tkCurrentCVOwner = 0;
+ ((Assembler*)m_pAssembler)->m_CustomDescrListStack.PUSH(((Assembler*)m_pAssembler)->m_pCustomDescrList);
+ ((Assembler*)m_pAssembler)->m_pCustomDescrList = &(m_pCurManRes->m_CustomDescrList);
+ }
+ else
+ report->error("Failed to allocate AsmManRes structure\n");
+}
+
+void AsmMan::EndManifestRes()
+{
+ if(m_pCurManRes)
+ {
+ m_ManResLst.PUSH(m_pCurManRes);
+ m_pCurManRes = NULL;
+ ((Assembler*)m_pAssembler)->m_tkCurrentCVOwner = 0;
+ ((Assembler*)m_pAssembler)->m_pCustomDescrList = ((Assembler*)m_pAssembler)->m_CustomDescrListStack.POP();
+ }
+}
+
+
+void AsmMan::SetManifestResFile(__in __nullterminated char* szFileName, ULONG ulOffset)
+{
+ if(m_pCurManRes)
+ {
+ m_pCurManRes->szFileName = szFileName;
+ m_pCurManRes->ulOffset = ulOffset;
+ }
+}
+
+void AsmMan::SetManifestResAsmRef(__in __nullterminated char* szAsmRefName)
+{
+ if(m_pCurManRes)
+ {
+ m_pCurManRes->szAsmRefName = szAsmRefName;
+ }
+}
+
+HRESULT AsmMan::EmitManifest()
+{
+ //AsmManAssembly* pAsmRef;
+ AsmManComType* pComType;
+ AsmManRes* pManRes;
+ HRESULT hr = S_OK;
+
+ wzUniBuf[0] = 0;
+
+ if(m_pAsmEmitter==NULL)
+ hr=m_pEmitter->QueryInterface(IID_IMetaDataAssemblyEmit, (void**) &m_pAsmEmitter);
+
+ if(SUCCEEDED(hr))
+ {
+ EmitFiles();
+ EmitAssembly();
+
+ if((((Assembler*)m_pAssembler)->m_dwIncludeDebugInfo != 0) && (m_pAssembly == NULL)
+ && !(((Assembler*)m_pAssembler)->m_fENCMode))
+ {
+ mdToken tkOwner, tkMscorlib;
+ tkMscorlib = ((Assembler*)m_pAssembler)->GetAsmRef("mscorlib");
+ tkOwner = ((Assembler*)m_pAssembler)->ResolveClassRef(tkMscorlib,
+ "System.Runtime.CompilerServices.AssemblyAttributesGoHere",
+ NULL);
+ EmitDebuggableAttribute(tkOwner);
+ }
+
+ // Emit all com types
+ unsigned i;
+ for(i = 0; (pComType = m_ComTypeLst.PEEK(i)); i++)
+ {
+ if(!pComType->m_fNew) continue;
+ pComType->m_fNew = FALSE;
+
+ WszMultiByteToWideChar(g_uCodePage,0,pComType->szName,-1,wzUniBuf,dwUniBuf);
+ mdToken tkImplementation = mdTokenNil;
+ if(pComType->tkImpl) tkImplementation = pComType->tkImpl;
+ else if(pComType->szFileName)
+ {
+ tkImplementation = GetFileTokByName(pComType->szFileName);
+ if(tkImplementation==mdFileNil)
+ {
+ report->error("Undefined File '%s' in ExportedType '%s'\n",pComType->szFileName,pComType->szName);
+ if(!((Assembler*)m_pAssembler)->OnErrGo) continue;
+ }
+ }
+ else if(pComType->szAsmRefName)
+ {
+ tkImplementation = GetAsmRefTokByName(pComType->szAsmRefName);
+ if(RidFromToken(tkImplementation)==0)
+ {
+ report->error("Undefined AssemblyRef '%s' in ExportedType '%s'\n",pComType->szAsmRefName,pComType->szName);
+ if(!((Assembler*)m_pAssembler)->OnErrGo) continue;
+ }
+ }
+ else if(pComType->szComTypeName)
+ {
+ char* szLastName = strrchr(pComType->szComTypeName, NESTING_SEP);
+
+ if(szLastName)
+ {
+ *szLastName = 0;
+ szLastName ++;
+ tkImplementation = GetComTypeTokByName(szLastName, pComType->szComTypeName);
+ *(szLastName-1) = NESTING_SEP; // not really necessary
+ }
+
+ else
+ {
+ tkImplementation = GetComTypeTokByName(pComType->szComTypeName);
+ }
+
+ if(tkImplementation==mdExportedTypeNil)
+ {
+ report->error("Undefined ExportedType '%s' in ExportedType '%s'\n",pComType->szComTypeName,pComType->szName);
+ if(!((Assembler*)m_pAssembler)->OnErrGo) continue;
+ }
+ }
+ else
+ {
+ report->warn("Undefined implementation in ExportedType '%s' -- ExportType not emitted\n",pComType->szName);
+ if(!((Assembler*)m_pAssembler)->OnErrGo) continue;
+ }
+ hr = m_pAsmEmitter->DefineExportedType( // S_OK or error.
+ (LPCWSTR)wzUniBuf, // [IN] Name of the Com Type.
+ tkImplementation, // [IN] mdFile or mdAssemblyRef that provides the ComType.
+ (mdTypeDef)pComType->tkClass, // [IN] TypeDef token within the file.
+ pComType->dwAttr, // [IN] Flags.
+ (mdExportedType*)&(pComType->tkTok)); // [OUT] Returned ComType token.
+ if(FAILED(hr)) report->error("Failed to define ExportedType '%s': 0x%08X\n",pComType->szName,hr);
+ else
+ {
+ ((Assembler*)m_pAssembler)->EmitCustomAttributes(pComType->tkTok, &(pComType->m_CustomDescrList));
+ }
+ }
+
+ // Emit all manifest resources
+ m_dwMResSizeTotal = 0;
+ m_dwMResNum = 0;
+ for(i = 0; (pManRes = m_ManResLst.PEEK(i)); i++)
+ {
+ BOOL fOK = TRUE;
+ mdToken tkImplementation = mdFileNil;
+
+ if(!pManRes->m_fNew) continue;
+ pManRes->m_fNew = FALSE;
+
+ WszMultiByteToWideChar(g_uCodePage,0,pManRes->szAlias,-1,wzUniBuf,dwUniBuf);
+ if(pManRes->szAsmRefName)
+ {
+ tkImplementation = GetAsmRefTokByName(pManRes->szAsmRefName);
+ if(RidFromToken(tkImplementation)==0)
+ {
+ report->error("Undefined AssemblyRef '%s' in MResource '%s'\n",pManRes->szAsmRefName,pManRes->szName);
+ fOK = FALSE;
+ }
+ }
+ else if(pManRes->szFileName)
+ {
+ tkImplementation = GetFileTokByName(pManRes->szFileName);
+ if(RidFromToken(tkImplementation)==0)
+ {
+ report->error("Undefined File '%s' in MResource '%s'\n",pManRes->szFileName,pManRes->szName);
+ fOK = FALSE;
+ }
+ }
+ else // embedded mgd.resource, go after the file
+ {
+ HANDLE hFile = INVALID_HANDLE_VALUE;
+ int j;
+ WCHAR wzFileName[2048];
+ WCHAR* pwz;
+
+ pManRes->ulOffset = m_dwMResSizeTotal;
+ for(j=0; (hFile == INVALID_HANDLE_VALUE)&&(pwzInputFiles[j] != NULL); j++)
+ {
+ wcscpy_s(wzFileName,2048,pwzInputFiles[j]);
+ pwz = wcsrchr(wzFileName,'\\');
+ if(pwz == NULL) pwz = wcsrchr(wzFileName,':');
+ if(pwz == NULL) pwz = &wzFileName[0];
+ else pwz++;
+ wcscpy_s(pwz,2048-(pwz-wzFileName),wzUniBuf);
+ hFile = WszCreateFile(wzFileName, GENERIC_READ, FILE_SHARE_READ,
+ 0, OPEN_EXISTING, 0, 0);
+ }
+ if (hFile == INVALID_HANDLE_VALUE)
+ {
+ report->error("Failed to open managed resource file '%s'\n",pManRes->szAlias);
+ fOK = FALSE;
+ }
+ else
+ {
+ if (m_dwMResNum >= MAX_MANIFEST_RESOURCES)
+ {
+ report->error("Too many resources (implementation limit: %d); skipping file '%s'\n",MAX_MANIFEST_RESOURCES,pManRes->szAlias);
+ fOK = FALSE;
+ }
+ else
+ {
+ m_dwMResSize[m_dwMResNum] = SafeGetFileSize(hFile,NULL);
+ if(m_dwMResSize[m_dwMResNum] == 0xFFFFFFFF)
+ {
+ report->error("Failed to get size of managed resource file '%s'\n",pManRes->szAlias);
+ fOK = FALSE;
+ }
+ else
+ {
+ m_dwMResSizeTotal += m_dwMResSize[m_dwMResNum]+sizeof(DWORD);
+ m_wzMResName[m_dwMResNum] = new WCHAR[wcslen(wzFileName)+1];
+ wcscpy_s(m_wzMResName[m_dwMResNum],wcslen(wzFileName)+1,wzFileName);
+ m_fMResNew[m_dwMResNum] = TRUE;
+ m_dwMResNum++;
+ }
+ CloseHandle(hFile);
+ }
+ }
+ }
+ if(fOK || ((Assembler*)m_pAssembler)->OnErrGo)
+ {
+ WszMultiByteToWideChar(g_uCodePage,0,pManRes->szName,-1,wzUniBuf,dwUniBuf);
+ hr = m_pAsmEmitter->DefineManifestResource( // S_OK or error.
+ (LPCWSTR)wzUniBuf, // [IN] Name of the resource.
+ tkImplementation, // [IN] mdFile or mdAssemblyRef that provides the resource.
+ pManRes->ulOffset, // [IN] Offset to the beginning of the resource within the file.
+ pManRes->dwAttr, // [IN] Flags.
+ (mdManifestResource*)&(pManRes->tkTok)); // [OUT] Returned ManifestResource token.
+ if(FAILED(hr))
+ report->error("Failed to define manifest resource '%s': 0x%08X\n",pManRes->szName,hr);
+ }
+ }
+
+
+ m_pAsmEmitter->Release();
+ m_pAsmEmitter = NULL;
+ }
+ else
+ report->error("Failed to obtain IMetaDataAssemblyEmit interface: 0x%08X\n",hr);
+ return hr;
+}
+
diff --git a/src/ilasm/asmman.hpp b/src/ilasm/asmman.hpp
new file mode 100644
index 0000000000..35d8fdc0bc
--- /dev/null
+++ b/src/ilasm/asmman.hpp
@@ -0,0 +1,305 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// asmman.hpp - header file for manifest-related ILASM functions
+//
+
+#ifndef ASMMAN_HPP
+#define ASMMAN_HPP
+
+#include "strongname.h"
+#ifndef FEATURE_CORECLR
+#include "LegacyActivationShim.h"
+#endif
+#include "specstrings.h"
+
+struct AsmManFile
+{
+ char* szName;
+ mdToken tkTok;
+ DWORD dwAttr;
+ BinStr* pHash;
+ BOOL m_fNew;
+ CustomDescrList m_CustomDescrList;
+ AsmManFile()
+ {
+ szName = NULL;
+ pHash = NULL;
+ m_fNew = TRUE;
+ }
+ ~AsmManFile()
+ {
+ if(szName) delete szName;
+ if(pHash) delete pHash;
+ }
+ int ComparedTo(AsmManFile* pX){ return strcmp(szName,pX->szName); }
+};
+//typedef SORTEDARRAY<AsmManFile> AsmManFileList;
+typedef FIFO<AsmManFile> AsmManFileList;
+
+struct AsmManAssembly
+{
+ BOOL isRef;
+ BOOL isAutodetect;
+ char* szName;
+ char* szAlias;
+ DWORD dwAlias;
+ mdToken tkTok;
+ DWORD dwAttr;
+ BinStr* pPublicKey;
+ BinStr* pPublicKeyToken;
+ ULONG ulHashAlgorithm;
+ BinStr* pHashBlob;
+ BinStr* pLocale;
+ BOOL m_fNew;
+ // Security attributes
+ PermissionDecl* m_pPermissions;
+ PermissionSetDecl* m_pPermissionSets;
+ CustomDescrList m_CustomDescrList;
+ USHORT usVerMajor;
+ USHORT usVerMinor;
+ USHORT usBuild;
+ USHORT usRevision;
+ AsmManAssembly()
+ {
+ /*
+ usVerMajor = usVerMinor = usBuild = usRevision = 0xFFFF;
+ szName = szAlias = NULL;
+ dwAlias = dwAttr = 0;
+ tkTok = 0;
+ pPublicKey = pPublicKeyToken =pHashBlob = pLocale = NULL;
+ ulHashAlgorithm = 0;
+ m_fNew = TRUE;
+ isAutodetect = isRef = FALSE;
+ */
+ }
+ ~AsmManAssembly()
+ {
+ if(szAlias && (szAlias != szName)) delete [] szAlias;
+ if(szName) delete [] szName;
+ if(pPublicKey) delete pPublicKey;
+ if(pPublicKeyToken) delete pPublicKeyToken;
+ if(pHashBlob) delete pHashBlob;
+ if(pLocale) delete pLocale;
+ }
+ int ComparedTo(AsmManAssembly* pX){ return strcmp(szAlias,pX->szAlias); }
+};
+//typedef SORTEDARRAY<AsmManAssembly> AsmManAssemblyList;
+typedef FIFO<AsmManAssembly> AsmManAssemblyList;
+
+struct AsmManComType
+{
+ char* szName;
+ mdToken tkTok;
+ mdToken tkImpl;
+ DWORD dwAttr;
+ char* szFileName;
+ char* szAsmRefName;
+ char* szComTypeName;
+ mdToken tkClass;
+ BOOL m_fNew;
+ CustomDescrList m_CustomDescrList;
+ AsmManComType()
+ {
+ szName = szFileName = szAsmRefName = szComTypeName = NULL;
+ m_fNew = TRUE;
+ tkImpl = 0;
+ };
+ ~AsmManComType()
+ {
+ if(szName) delete szName;
+ if(szFileName) delete szFileName;
+ };
+ int ComparedTo(AsmManComType* pX){ return strcmp(szName,pX->szName); };
+};
+//typedef SORTEDARRAY<AsmManComType> AsmManComTypeList;
+typedef FIFO<AsmManComType> AsmManComTypeList;
+
+
+struct AsmManRes
+{
+ char* szName;
+ char* szAlias;
+ mdToken tkTok;
+ DWORD dwAttr;
+ char* szFileName;
+ ULONG ulOffset;
+ BOOL m_fNew;
+ CustomDescrList m_CustomDescrList;
+ char* szAsmRefName;
+ AsmManRes() { szName = szAlias = szAsmRefName = szFileName = NULL; ulOffset = 0; tkTok = 0; dwAttr = 0; m_fNew = TRUE; };
+ ~AsmManRes()
+ {
+ if(szAlias && (szAlias != szName)) delete szAlias;
+ if(szName) delete szName;
+ if(szFileName) delete szFileName;
+ if(szAsmRefName) delete szAsmRefName;
+ }
+};
+typedef FIFO<AsmManRes> AsmManResList;
+
+struct AsmManModRef
+{
+ char* szName;
+ mdToken tkTok;
+ BOOL m_fNew;
+ AsmManModRef() {szName = NULL; tkTok = 0; m_fNew = TRUE; };
+ ~AsmManModRef() { if(szName) delete szName; };
+};
+typedef FIFO<AsmManModRef> AsmManModRefList;
+
+struct AsmManStrongName
+{
+ enum AllocationState
+ {
+ NotAllocated = 0,
+ AllocatedBySNApi,
+ AllocatedByNew
+ };
+
+ BYTE *m_pbSignatureKey;
+ DWORD m_cbSignatureKey;
+ BYTE *m_pbPublicKey;
+ DWORD m_cbPublicKey;
+ BYTE *m_pbPrivateKey;
+ DWORD m_cbPrivateKey;
+ WCHAR *m_wzKeyContainer;
+ BOOL m_fFullSign;
+
+ // Where has the memory pointed to by m_pbPublicKey been taken from:
+ AllocationState m_dwPublicKeyAllocated;
+
+ AsmManStrongName() { ZeroMemory(this, sizeof(*this)); }
+ ~AsmManStrongName()
+ {
+#ifndef FEATURE_CORECLR
+ if (m_dwPublicKeyAllocated == AllocatedBySNApi)
+ {
+ LegacyActivationShim::StrongNameFreeBuffer(m_pbPublicKey);
+ }
+ else
+#endif
+ if (m_dwPublicKeyAllocated == AllocatedByNew)
+ delete [] m_pbPublicKey;
+
+ if (m_pbPrivateKey)
+ delete [] m_pbPrivateKey;
+
+ if (m_pbSignatureKey)
+ delete [] m_pbSignatureKey;
+ }
+};
+
+class ErrorReporter;
+
+class AsmMan
+{
+ AsmManFileList m_FileLst;
+ AsmManComTypeList m_ComTypeLst;
+ AsmManResList m_ManResLst;
+ AsmManModRefList m_ModRefLst;
+
+ AsmManComType* m_pCurComType;
+ AsmManRes* m_pCurManRes;
+ ErrorReporter* report;
+ void* m_pAssembler;
+
+ AsmManFile* GetFileByName(__in __nullterminated char* szFileName);
+ AsmManAssembly* GetAsmRefByName(__in __nullterminated const char* szAsmRefName);
+ AsmManComType* GetComTypeByName(__in_opt __nullterminated char* szComTypeName,
+ __in_opt __nullterminated char* szComEnclosingTypeName = NULL);
+ mdToken GetComTypeTokByName(__in_opt __nullterminated char* szComTypeName,
+ __in_opt __nullterminated char* szComEnclosingTypeName = NULL);
+
+ IMetaDataEmit* m_pEmitter;
+
+public:
+ IMetaDataAssemblyEmit* m_pAsmEmitter;
+ AsmManAssemblyList m_AsmRefLst;
+ AsmManAssembly* m_pAssembly;
+ AsmManAssembly* m_pCurAsmRef;
+ char* m_szScopeName;
+ BinStr* m_pGUID;
+ AsmManStrongName m_sStrongName;
+ // Embedded manifest resources paraphernalia:
+ WCHAR* m_wzMResName[MAX_MANIFEST_RESOURCES];
+ DWORD m_dwMResSize[MAX_MANIFEST_RESOURCES];
+ BOOL m_fMResNew[MAX_MANIFEST_RESOURCES];
+ DWORD m_dwMResNum;
+ DWORD m_dwMResSizeTotal;
+ AsmMan() { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; m_pAsmEmitter = NULL;
+ memset(m_wzMResName,0,sizeof(m_wzMResName));
+ memset(m_dwMResSize,0,sizeof(m_dwMResSize));
+ m_dwMResNum = m_dwMResSizeTotal = 0; };
+ AsmMan(void* pAsm) { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; m_pAssembler = pAsm; m_pAsmEmitter = NULL;
+ memset(m_wzMResName,0,sizeof(m_wzMResName));
+ memset(m_dwMResSize,0,sizeof(m_dwMResSize));
+ m_dwMResNum = m_dwMResSizeTotal = 0; };
+ AsmMan(ErrorReporter* rpt) { m_pAssembly = NULL; m_szScopeName = NULL; m_pGUID = NULL; report = rpt; m_pAsmEmitter = NULL;
+ memset(m_wzMResName,0,sizeof(m_wzMResName));
+ memset(m_dwMResSize,0,sizeof(m_dwMResSize));
+ m_dwMResNum = m_dwMResSizeTotal = 0; };
+ ~AsmMan()
+ {
+ if(m_pAssembly) delete m_pAssembly;
+ if(m_szScopeName) delete m_szScopeName;
+ if(m_pGUID) delete m_pGUID;
+ };
+ void SetErrorReporter(ErrorReporter* rpt) { report = rpt; };
+ HRESULT EmitManifest(void);
+
+ void SetEmitter( IMetaDataEmit* pEmitter) { m_pEmitter = pEmitter; };
+
+ void SetModuleName(__inout_opt __nullterminated char* szName);
+
+ void AddFile(__in __nullterminated char* szName, DWORD dwAttr, BinStr* pHashBlob);
+ void EmitFiles();
+ void EmitDebuggableAttribute(mdToken tkOwner);
+
+ void StartAssembly(__in __nullterminated char* szName, __in_opt __nullterminated char* szAlias, DWORD dwAttr, BOOL isRef);
+ void EndAssembly();
+ void EmitAssemblyRefs();
+ void EmitAssembly();
+ void SetAssemblyPublicKey(BinStr* pPublicKey);
+ void SetAssemblyPublicKeyToken(BinStr* pPublicKeyToken);
+ void SetAssemblyHashAlg(ULONG ulAlgID);
+ void SetAssemblyVer(USHORT usMajor, USHORT usMinor, USHORT usBuild, USHORT usRevision);
+ void SetAssemblyLocale(BinStr* pLocale, BOOL bConvertToUnicode);
+ void SetAssemblyHashBlob(BinStr* pHashBlob);
+ void SetAssemblyAutodetect();
+
+ void StartComType(__in __nullterminated char* szName, DWORD dwAttr);
+ void EndComType();
+ void SetComTypeFile(__in __nullterminated char* szFileName);
+ void SetComTypeAsmRef(__in __nullterminated char* szAsmRefName);
+ void SetComTypeComType(__in __nullterminated char* szComTypeName);
+ BOOL SetComTypeImplementationTok(mdToken tk);
+ BOOL SetComTypeClassTok(mdToken tkClass);
+
+ void StartManifestRes(__in __nullterminated char* szName, __in __nullterminated char* szAlias, DWORD dwAttr);
+ void EndManifestRes();
+ void SetManifestResFile(__in __nullterminated char* szFileName, ULONG ulOffset);
+ void SetManifestResAsmRef(__in __nullterminated char* szAsmRefName);
+
+ mdToken GetFileTokByName(__in __nullterminated char* szFileName);
+ mdToken GetAsmRefTokByName(__in __nullterminated const char* szAsmRefName);
+ mdToken GetAsmTokByName(__in __nullterminated const char* szAsmName)
+ { return (m_pAssembly && (strcmp(m_pAssembly->szName,szAsmName)==0)) ? m_pAssembly->tkTok : 0; };
+
+ mdToken GetModuleRefTokByName(__in __nullterminated char* szName)
+ {
+ if(szName && *szName)
+ {
+ AsmManModRef* pMR;
+ for(unsigned i=0; (pMR=m_ModRefLst.PEEK(i)); i++)
+ {
+ if(!strcmp(szName, pMR->szName)) return pMR->tkTok;
+ }
+ }
+ return 0;
+ };
+
+};
+
+#endif
diff --git a/src/ilasm/asmparse.h b/src/ilasm/asmparse.h
new file mode 100644
index 0000000000..3c18f35a75
--- /dev/null
+++ b/src/ilasm/asmparse.h
@@ -0,0 +1,326 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+/**************************************************************************/
+/* asmParse is basically a wrapper around a YACC grammer COM+ assembly */
+
+#ifndef asmparse_h
+#define asmparse_h
+
+#include <stdio.h> // for FILE
+
+#include "assembler.h" // for ErrorReporter Labels
+//class Assembler;
+//class BinStr;
+
+
+/**************************************************************************/
+/* an abstraction of a stream of input characters */
+class ReadStream {
+public:
+
+ virtual unsigned getAll(__out char** ppch) = 0;
+
+ // read at most 'buffLen' bytes into 'buff', Return the
+ // number of characters read. On EOF return 0
+ virtual unsigned read(__out_ecount(buffLen) char* buff, unsigned buffLen) = 0;
+
+ // Return the name of the stream, (for error reporting).
+ //virtual const char* name() = 0;
+ // Return the Unicode name of the stream
+ virtual const WCHAR* namew() = 0;
+ //return ptr to buffer containing specified source line
+ virtual char* getLine(int lineNum) = 0;
+};
+
+/**************************************************************************/
+class BinStrStream : public ReadStream {
+public:
+ BinStrStream(BinStr* pbs)
+ {
+ m_pStart = (char*)(pbs->ptr());
+ m_pCurr = m_pStart;
+ m_pEnd = m_pStart + pbs->length();
+ m_pBS = pbs;
+ };
+ ~BinStrStream()
+ {
+ //if(m_pBS)
+ // delete m_pBS;
+ };
+ unsigned getAll(__out char **ppbuff)
+ {
+ *ppbuff = m_pStart;
+ return m_pBS->length();
+ };
+ unsigned read(__out_ecount(buffLen) char* buff, unsigned buffLen)
+ {
+ _ASSERTE(m_pStart != NULL);
+ unsigned Remainder = (unsigned)(m_pEnd - m_pCurr);
+ unsigned Len = buffLen;
+ if(Len > Remainder) Len = Remainder;
+ memcpy(buff,m_pCurr,Len);
+ m_pCurr += Len;
+ if(Len < buffLen)
+ {
+ memset(buff+Len,0,buffLen-Len);
+ }
+ return Len;
+ }
+
+ const WCHAR* namew()
+ {
+ return W("local_define");
+ }
+
+ BOOL IsValid()
+ {
+ return(m_pStart != NULL);
+ }
+
+ char* getLine(int lineNum)
+ {
+ return NULL; // this function is not used
+ }
+
+private:
+ char* m_pStart;
+ char* m_pEnd;
+ char* m_pCurr;
+ BinStr* m_pBS;
+
+
+};
+/**************************************************************************/
+class MappedFileStream : public ReadStream {
+public:
+ MappedFileStream(__in __nullterminated WCHAR* wFileName)
+ {
+ fileNameW = wFileName;
+ m_hFile = INVALID_HANDLE_VALUE;
+ m_hMapFile = NULL;
+ m_pStart = open(wFileName);
+ m_pCurr = m_pStart;
+ m_pEnd = m_pStart + m_FileSize;
+ //memset(fileNameANSI,0,MAX_FILENAME_LENGTH*4);
+ //WszWideCharToMultiByte(CP_ACP,0,wFileName,-1,fileNameANSI,MAX_FILENAME_LENGTH*4,NULL,NULL);
+ }
+ ~MappedFileStream()
+ {
+ if (m_hFile != INVALID_HANDLE_VALUE)
+ {
+ if (m_pStart)
+ UnmapViewOfFile((void*)m_pStart);
+ if (m_hMapFile)
+ CloseHandle(m_hMapFile);
+ CloseHandle(m_hFile);
+
+ m_pStart = NULL;
+ m_hMapFile = NULL;
+ m_hFile = INVALID_HANDLE_VALUE;
+ m_FileSize = 0;
+ delete [] fileNameW;
+ fileNameW = NULL;
+ }
+ }
+ unsigned getAll(__out char** pbuff)
+ {
+ *pbuff = m_pStart;
+ return m_FileSize;
+ }
+ unsigned read(__out_ecount(buffLen) char* buff, unsigned buffLen)
+ {
+ _ASSERTE(m_pStart != NULL);
+ unsigned Remainder = (unsigned)(m_pEnd - m_pCurr);
+ unsigned Len = buffLen;
+ if(Len > Remainder) Len = Remainder;
+ memcpy(buff,m_pCurr,Len);
+ m_pCurr += Len;
+ if(Len < buffLen)
+ {
+ memset(buff+Len,0,buffLen-Len);
+ }
+ return Len;
+ }
+
+ //const char* name()
+ //{
+ // return(&fileNameANSI[0]);
+ //}
+
+ const WCHAR* namew()
+ {
+ return fileNameW;
+ }
+
+ void set_namew(const WCHAR* namew)
+ {
+ fileNameW = namew;
+ }
+
+ BOOL IsValid()
+ {
+ return(m_pStart != NULL);
+ }
+
+ char* getLine(int lineNum)
+ {
+ return NULL; // this function is not used
+ }
+
+private:
+ char* map_file()
+ {
+ DWORD dwFileSizeLow;
+
+ dwFileSizeLow = GetFileSize( m_hFile, NULL);
+ if (dwFileSizeLow == INVALID_FILE_SIZE)
+ return NULL;
+ m_FileSize = dwFileSizeLow;
+
+ // No difference between A and W in this case: last param (LPCTSTR) is NULL
+ m_hMapFile = WszCreateFileMapping(m_hFile, NULL, PAGE_READONLY, 0, 0, NULL);
+ if (m_hMapFile == NULL)
+ return NULL;
+
+ return (char*)(HMODULE) MapViewOfFile(m_hMapFile, FILE_MAP_READ, 0, 0, 0);
+ }
+ char* open(const WCHAR* moduleName)
+ {
+ _ASSERTE(moduleName);
+ if (!moduleName)
+ return NULL;
+
+ m_hFile = WszCreateFile(moduleName, GENERIC_READ, FILE_SHARE_READ,
+ 0, OPEN_EXISTING, 0, 0);
+ return (m_hFile == INVALID_HANDLE_VALUE) ? NULL : map_file();
+ }
+
+ const WCHAR* fileNameW; // FileName (for error reporting)
+ //char fileNameANSI[MAX_FILENAME_LENGTH*4];
+ HANDLE m_hFile; // File we are reading from
+ DWORD m_FileSize;
+ HANDLE m_hMapFile;
+ char* m_pStart;
+ char* m_pEnd;
+ char* m_pCurr;
+
+};
+
+typedef LIFO<ARG_NAME_LIST> ARG_NAME_LIST_STACK;
+
+// functional pointers used in parsing
+/*--------------------------------------------------------------------------*/
+typedef char*(*PFN_NEXTCHAR)(char*);
+
+char* nextcharA(__in __nullterminated char* pos);
+char* nextcharU(__in __nullterminated char* pos);
+char* nextcharW(__in __nullterminated char* pos);
+
+/*--------------------------------------------------------------------------*/
+typedef unsigned(*PFN_SYM)(char*);
+
+unsigned SymAU(__in __nullterminated char* curPos);
+unsigned SymW(__in __nullterminated char* curPos);
+/*--------------------------------------------------------------------------*/
+typedef char*(*PFN_NEWSTRFROMTOKEN)(char*,size_t);
+
+char* NewStrFromTokenAU(__in_ecount(tokLen) char* curTok, size_t tokLen);
+char* NewStrFromTokenW(__in_ecount(tokLen) char* curTok, size_t tokLen);
+/*--------------------------------------------------------------------------*/
+typedef char*(*PFN_NEWSTATICSTRFROMTOKEN)(char*,size_t,char*,size_t);
+
+char* NewStaticStrFromTokenAU(__in_ecount(tokLen) char* curTok, size_t tokLen, __out_ecount(bufSize) char* staticBuf, size_t bufSize);
+char* NewStaticStrFromTokenW(__in_ecount(tokLen) char* curTok, size_t tokLen, __out_ecount(bufSize) char* staticBuf, size_t bufSize);
+/*--------------------------------------------------------------------------*/
+typedef unsigned(*PFN_GETDOUBLE)(char*,unsigned,double**);
+
+unsigned GetDoubleAU(__in __nullterminated char* begNum, unsigned L, double** ppRes);
+unsigned GetDoubleW(__in __nullterminated char* begNum, unsigned L, double** ppRes);
+/*--------------------------------------------------------------------------*/
+struct PARSING_ENVIRONMENT
+{
+ char* curTok; // The token we are in the process of processing (for error reporting)
+ char* curPos; // current place in input buffer
+ char* endPos; // points just past the end of valid data in the buffer
+
+ ReadStream* in; // how we fill up our buffer
+
+ PFN_NEXTCHAR pfn_nextchar;
+ PFN_SYM pfn_Sym;
+ PFN_NEWSTRFROMTOKEN pfn_NewStrFromToken;
+ PFN_NEWSTATICSTRFROMTOKEN pfn_NewStaticStrFromToken;
+ PFN_GETDOUBLE pfn_GetDouble;
+
+ bool bExternSource;
+ bool bExternSourceAutoincrement;
+ unsigned nExtLine;
+ unsigned nExtCol;
+ unsigned nExtLineEnd;
+ unsigned nExtColEnd;
+ unsigned curLine; // Line number (for error reporting)
+
+ unsigned uCodePage;
+
+ char szFileName[MAX_FILENAME_LENGTH*3+1];
+
+};
+typedef LIFO<PARSING_ENVIRONMENT> PARSING_ENVIRONMENT_STACK;
+
+/**************************************************************************/
+/* AsmParse does all the parsing. It also builds up simple data structures,
+ (like signatures), but does not do the any 'heavy lifting' like define
+ methods or classes. Instead it calls to the Assembler object to do that */
+
+class AsmParse : public ErrorReporter
+{
+public:
+ AsmParse(ReadStream* stream, Assembler *aAssem);
+ ~AsmParse();
+ void CreateEnvironment(ReadStream* stream);
+ void ParseFile(ReadStream* stream);
+ // The parser knows how to put line numbers on things and report the error
+ virtual void error(const char* fmt, ...);
+ virtual void warn(const char* fmt, ...);
+ virtual void msg(const char* fmt, ...);
+ char *getLine(int lineNum) { return penv->in->getLine(lineNum); };
+ unsigned getAll(__out char** pbuff) { return penv->in->getAll(pbuff); };
+ bool Success() {return success; };
+ void SetIncludePath(__in WCHAR* wz) { wzIncludePath = wz; };
+
+ ARG_NAME_LIST_STACK m_ANSFirst;
+ ARG_NAME_LIST_STACK m_ANSLast;
+ PARSING_ENVIRONMENT *penv;
+ PARSING_ENVIRONMENT_STACK PEStack;
+
+private:
+ BinStr* MakeSig(unsigned callConv, BinStr* retType, BinStr* args, int ntyargs = 0);
+ BinStr* MakeTypeClass(CorElementType kind, mdToken tk);
+ BinStr* MakeTypeArray(CorElementType kind, BinStr* elemType, BinStr* bounds);
+
+ char* fillBuff(__in_opt __nullterminated char* curPos); // refill the input buffer
+ DWORD IsItUnicode(CONST LPVOID pBuff, int cb, LPINT lpi);
+ HANDLE hstdout;
+ HANDLE hstderr;
+
+private:
+ friend void yyerror(__in __nullterminated const char* str);
+ friend int parse_literal(unsigned curSym, __inout __nullterminated char* &curPos, BOOL translate_escapes);
+ friend int yyparse();
+ friend int yylex();
+ friend Instr* SetupInstr(unsigned short opcode);
+ friend int findKeyword(const char* name, size_t nameLen, unsigned short* opcode);
+ friend TypeDefDescr* findTypedef(__in_ecount(nameLen) char* name, size_t nameLen);
+ friend char* skipBlanks(__in __nullterminated char*,unsigned*);
+ friend char* nextBlank(__in __nullterminated char*);
+ friend int ProcessEOF();
+ friend unsigned __int8* skipType(unsigned __int8* ptr, BOOL fFixupType);
+ friend void FixupConstraints();
+
+ Assembler* assem; // This does most of the semantic processing
+ bool success; // overall success of the compilation
+ WCHAR* wzIncludePath;
+};
+
+#endif
+
diff --git a/src/ilasm/asmparse.y b/src/ilasm/asmparse.y
new file mode 100644
index 0000000000..051df92199
--- /dev/null
+++ b/src/ilasm/asmparse.y
@@ -0,0 +1,2053 @@
+%{
+
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//
+// File asmparse.y
+//
+#include "ilasmpch.h"
+
+#include "grammar_before.cpp"
+
+%}
+
+%union {
+ CorRegTypeAttr classAttr;
+ CorMethodAttr methAttr;
+ CorFieldAttr fieldAttr;
+ CorMethodImpl implAttr;
+ CorEventAttr eventAttr;
+ CorPropertyAttr propAttr;
+ CorPinvokeMap pinvAttr;
+ CorDeclSecurity secAct;
+ CorFileFlags fileAttr;
+ CorAssemblyFlags asmAttr;
+ CorAssemblyFlags asmRefAttr;
+ CorTypeAttr exptAttr;
+ CorManifestResourceFlags manresAttr;
+ double* float64;
+ __int64* int64;
+ __int32 int32;
+ char* string;
+ BinStr* binstr;
+ Labels* labels;
+ Instr* instr; // instruction opcode
+ NVPair* pair;
+ pTyParList typarlist;
+ mdToken token;
+ TypeDefDescr* tdd;
+ CustomDescr* cad;
+ unsigned short opcode;
+};
+
+ /* These are returned by the LEXER and have values */
+%token ERROR_ BAD_COMMENT_ BAD_LITERAL_ /* bad strings, */
+%token <string> ID /* testing343 */
+%token <string> DOTTEDNAME /* System.Object */
+%token <binstr> QSTRING /* "Hello World\n" */
+%token <string> SQSTRING /* 'Hello World\n' */
+%token <int32> INT32 /* 3425 0x34FA 0352 */
+%token <int64> INT64 /* 342534523534534 0x34FA434644554 */
+%token <float64> FLOAT64 /* -334234 24E-34 */
+%token <int32> HEXBYTE /* 05 1A FA */
+%token <tdd> TYPEDEF_T
+%token <tdd> TYPEDEF_M
+%token <tdd> TYPEDEF_F
+%token <tdd> TYPEDEF_TS
+%token <tdd> TYPEDEF_MR
+%token <tdd> TYPEDEF_CA
+
+
+ /* multi-character punctuation */
+%token DCOLON /* :: */
+%token ELIPSIS /* ... */
+
+ /* Keywords Note the undersores are to avoid collisions as these are common names */
+%token VOID_ BOOL_ CHAR_ UNSIGNED_ INT_ INT8_ INT16_ INT32_ INT64_ FLOAT_ FLOAT32_ FLOAT64_ BYTEARRAY_
+%token UINT_ UINT8_ UINT16_ UINT32_ UINT64_ FLAGS_ CALLCONV_ MDTOKEN_
+%token OBJECT_ STRING_ NULLREF_
+ /* misc keywords */
+%token DEFAULT_ CDECL_ VARARG_ STDCALL_ THISCALL_ FASTCALL_ CLASS_
+%token TYPEDREF_ UNMANAGED_ FINALLY_ HANDLER_ CATCH_ FILTER_ FAULT_
+%token EXTENDS_ IMPLEMENTS_ TO_ AT_ TLS_ TRUE_ FALSE_ _INTERFACEIMPL
+
+ /* class, method, field attributes */
+
+%token VALUE_ VALUETYPE_ NATIVE_ INSTANCE_ SPECIALNAME_ FORWARDER_
+%token STATIC_ PUBLIC_ PRIVATE_ FAMILY_ FINAL_ SYNCHRONIZED_ INTERFACE_ SEALED_ NESTED_
+%token ABSTRACT_ AUTO_ SEQUENTIAL_ EXPLICIT_ ANSI_ UNICODE_ AUTOCHAR_ IMPORT_ ENUM_
+%token VIRTUAL_ NOINLINING_ AGGRESSIVEINLINING_ NOOPTIMIZATION_ UNMANAGEDEXP_ BEFOREFIELDINIT_
+%token STRICT_ RETARGETABLE_ WINDOWSRUNTIME_ NOPLATFORM_
+%token METHOD_ FIELD_ PINNED_ MODREQ_ MODOPT_ SERIALIZABLE_ PROPERTY_ TYPE_
+%token ASSEMBLY_ FAMANDASSEM_ FAMORASSEM_ PRIVATESCOPE_ HIDEBYSIG_ NEWSLOT_ RTSPECIALNAME_ PINVOKEIMPL_
+%token _CTOR _CCTOR LITERAL_ NOTSERIALIZED_ INITONLY_ REQSECOBJ_
+ /* method implementation attributes: NATIVE_ and UNMANAGED_ listed above */
+%token CIL_ OPTIL_ MANAGED_ FORWARDREF_ PRESERVESIG_ RUNTIME_ INTERNALCALL_
+ /* PInvoke-specific keywords */
+%token _IMPORT NOMANGLE_ LASTERR_ WINAPI_ AS_ BESTFIT_ ON_ OFF_ CHARMAPERROR_
+
+ /* intruction tokens (actually instruction groupings) */
+%token <opcode> INSTR_NONE INSTR_VAR INSTR_I INSTR_I8 INSTR_R INSTR_BRTARGET INSTR_METHOD INSTR_FIELD
+%token <opcode> INSTR_TYPE INSTR_STRING INSTR_SIG INSTR_TOK
+%token <opcode> INSTR_SWITCH
+
+ /* assember directives */
+%token _CLASS _NAMESPACE _METHOD _FIELD _DATA _THIS _BASE _NESTER
+%token _EMITBYTE _TRY _MAXSTACK _LOCALS _ENTRYPOINT _ZEROINIT
+%token _EVENT _ADDON _REMOVEON _FIRE _OTHER
+%token _PROPERTY _SET _GET DEFAULT_
+%token _PERMISSION _PERMISSIONSET
+
+ /* security actions */
+%token REQUEST_ DEMAND_ ASSERT_ DENY_ PERMITONLY_ LINKCHECK_ INHERITCHECK_
+%token REQMIN_ REQOPT_ REQREFUSE_ PREJITGRANT_ PREJITDENY_ NONCASDEMAND_
+%token NONCASLINKDEMAND_ NONCASINHERITANCE_
+
+ /* extern debug info specifier (to be used by precompilers only) */
+%token _LINE P_LINE _LANGUAGE
+ /* custom value specifier */
+%token _CUSTOM
+ /* local vars zeroinit specifier */
+%token INIT_
+ /* class layout */
+%token _SIZE _PACK
+%token _VTABLE _VTFIXUP FROMUNMANAGED_ CALLMOSTDERIVED_ _VTENTRY RETAINAPPDOMAIN_
+ /* manifest */
+%token _FILE NOMETADATA_ _HASH _ASSEMBLY _PUBLICKEY _PUBLICKEYTOKEN ALGORITHM_ _VER _LOCALE EXTERN_
+%token _MRESOURCE
+%token _MODULE _EXPORT
+%token LEGACY_ LIBRARY_ X86_ IA64_ AMD64_ ARM_
+ /* field marshaling */
+%token MARSHAL_ CUSTOM_ SYSSTRING_ FIXED_ VARIANT_ CURRENCY_ SYSCHAR_ DECIMAL_ DATE_ BSTR_ TBSTR_ LPSTR_
+%token LPWSTR_ LPTSTR_ OBJECTREF_ IUNKNOWN_ IDISPATCH_ STRUCT_ SAFEARRAY_ BYVALSTR_ LPVOID_ ANY_ ARRAY_ LPSTRUCT_
+%token IIDPARAM_
+ /* parameter attributes */
+%token IN_ OUT_ OPT_ PARAM_
+ /* method implementations */
+%token _OVERRIDE WITH_
+ /* variant type specifics */
+%token NULL_ ERROR_ HRESULT_ CARRAY_ USERDEFINED_ RECORD_ FILETIME_ BLOB_ STREAM_ STORAGE_
+%token STREAMED_OBJECT_ STORED_OBJECT_ BLOB_OBJECT_ CF_ CLSID_ VECTOR_
+ /* header flags */
+%token _SUBSYSTEM _CORFLAGS ALIGNMENT_ _IMAGEBASE _STACKRESERVE
+
+ /* syntactic sugar */
+%token _TYPEDEF _TEMPLATE _TYPELIST _MSCORLIB
+
+ /* compilation control directives */
+%token P_DEFINE P_UNDEF P_IFDEF P_IFNDEF P_ELSE P_ENDIF P_INCLUDE
+
+ /* nonTerminals */
+%type <string> dottedName id methodName atOpt slashedName
+%type <labels> labels
+%type <int32> callConv callKind int32 customHead customHeadWithOwner vtfixupAttr paramAttr ddItemCount variantType repeatOpt truefalse typarAttrib typarAttribs
+%type <int32> iidParamIndex genArity genArityNotEmpty
+%type <float64> float64
+%type <int64> int64
+%type <binstr> sigArgs0 sigArgs1 sigArg type bound bounds1 bytes hexbytes nativeType marshalBlob initOpt compQstring caValue
+%type <binstr> marshalClause
+%type <binstr> fieldInit serInit fieldSerInit
+%type <binstr> f32seq f64seq i8seq i16seq i32seq i64seq boolSeq sqstringSeq classSeq objSeq
+%type <binstr> simpleType
+%type <binstr> tyArgs0 tyArgs1 tyArgs2 typeList typeListNotEmpty tyBound
+%type <binstr> customBlobDescr serializType customBlobArgs customBlobNVPairs
+%type <binstr> secAttrBlob secAttrSetBlob
+%type <int32> fieldOrProp intOrWildcard
+%type <typarlist> typarsRest typars typarsClause
+%type <token> className typeSpec ownerType customType memberRef methodRef mdtoken
+%type <classAttr> classAttr
+%type <methAttr> methAttr
+%type <fieldAttr> fieldAttr
+%type <implAttr> implAttr
+%type <eventAttr> eventAttr
+%type <propAttr> propAttr
+%type <pinvAttr> pinvAttr
+%type <pair> nameValPairs nameValPair
+%type <secAct> secAction
+%type <secAct> psetHead
+%type <fileAttr> fileAttr
+%type <fileAttr> fileEntry
+%type <asmAttr> asmAttr
+%type <exptAttr> exptAttr
+%type <manresAttr> manresAttr
+%type <cad> customDescr customDescrWithOwner
+%type <instr> instr_none instr_var instr_i instr_i8 instr_r instr_brtarget instr_method instr_field
+%type <instr> instr_type instr_string instr_sig instr_tok instr_switch
+%type <instr> instr_r_head
+
+%start decls
+
+/**************************************************************************/
+%%
+
+decls : /* EMPTY */
+ | decls decl
+ ;
+/* Module-level declarations */
+decl : classHead '{' classDecls '}' { PASM->EndClass(); }
+ | nameSpaceHead '{' decls '}' { PASM->EndNameSpace(); }
+ | methodHead methodDecls '}' { if(PASM->m_pCurMethod->m_ulLines[1] ==0)
+ { PASM->m_pCurMethod->m_ulLines[1] = PASM->m_ulCurLine;
+ PASM->m_pCurMethod->m_ulColumns[1]=PASM->m_ulCurColumn;}
+ PASM->EndMethod(); }
+ | fieldDecl
+ | dataDecl
+ | vtableDecl
+ | vtfixupDecl
+ | extSourceSpec
+ | fileDecl
+ | assemblyHead '{' assemblyDecls '}' { PASMM->EndAssembly(); }
+ | assemblyRefHead '{' assemblyRefDecls '}' { PASMM->EndAssembly(); }
+ | exptypeHead '{' exptypeDecls '}' { PASMM->EndComType(); }
+ | manifestResHead '{' manifestResDecls '}' { PASMM->EndManifestRes(); }
+ | moduleHead
+ | secDecl
+ | customAttrDecl
+ | _SUBSYSTEM int32 {
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:22011) // Suppress PREFast warning about integer overflow/underflow
+#endif
+ PASM->m_dwSubsystem = $2;
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+ }
+ | _CORFLAGS int32 { PASM->m_dwComImageFlags = $2; }
+ | _FILE ALIGNMENT_ int32 { PASM->m_dwFileAlignment = $3;
+ if(($3 & ($3 - 1))||($3 < 0x200)||($3 > 0x10000))
+ PASM->report->error("Invalid file alignment, must be power of 2 from 0x200 to 0x10000\n");}
+ | _IMAGEBASE int64 { PASM->m_stBaseAddress = (ULONGLONG)(*($2)); delete $2;
+ if(PASM->m_stBaseAddress & 0xFFFF)
+ PASM->report->error("Invalid image base, must be 0x10000-aligned\n");}
+ | _STACKRESERVE int64 { PASM->m_stSizeOfStackReserve = (size_t)(*($2)); delete $2; }
+ | languageDecl
+ | typedefDecl
+ | compControl
+ | _TYPELIST '{' classNameSeq '}'
+ | _MSCORLIB { PASM->m_fIsMscorlib = TRUE; }
+ ;
+
+classNameSeq : /* EMPTY */
+ | className classNameSeq
+ ;
+
+compQstring : QSTRING { $$ = $1; }
+ | compQstring '+' QSTRING { $$ = $1; $$->append($3); delete $3; }
+ ;
+
+languageDecl : _LANGUAGE SQSTRING { LPCSTRToGuid($2,&(PASM->m_guidLang)); }
+ | _LANGUAGE SQSTRING ',' SQSTRING { LPCSTRToGuid($2,&(PASM->m_guidLang));
+ LPCSTRToGuid($4,&(PASM->m_guidLangVendor));}
+ | _LANGUAGE SQSTRING ',' SQSTRING ',' SQSTRING { LPCSTRToGuid($2,&(PASM->m_guidLang));
+ LPCSTRToGuid($4,&(PASM->m_guidLangVendor));
+ LPCSTRToGuid($4,&(PASM->m_guidDoc));}
+ ;
+/* Basic tokens */
+id : ID { $$ = $1; }
+ | SQSTRING { $$ = $1; }
+ ;
+
+dottedName : id { $$ = $1; }
+ | DOTTEDNAME { $$ = $1; }
+ | dottedName '.' dottedName { $$ = newStringWDel($1, '.', $3); }
+ ;
+
+int32 : INT32 { $$ = $1; }
+ ;
+
+int64 : INT64 { $$ = $1; }
+ | INT32 { $$ = neg ? new __int64($1) : new __int64((unsigned)$1); }
+ ;
+
+float64 : FLOAT64 { $$ = $1; }
+ | FLOAT32_ '(' int32 ')' { float f; *((__int32*) (&f)) = $3; $$ = new double(f); }
+ | FLOAT64_ '(' int64 ')' { $$ = (double*) $3; }
+ ;
+
+/* Aliasing of types, type specs, methods, fields and custom attributes */
+typedefDecl : _TYPEDEF type AS_ dottedName { PASM->AddTypeDef($2,$4); }
+ | _TYPEDEF className AS_ dottedName { PASM->AddTypeDef($2,$4); }
+ | _TYPEDEF memberRef AS_ dottedName { PASM->AddTypeDef($2,$4); }
+ | _TYPEDEF customDescr AS_ dottedName { $2->tkOwner = 0; PASM->AddTypeDef($2,$4); }
+ | _TYPEDEF customDescrWithOwner AS_ dottedName { PASM->AddTypeDef($2,$4); }
+ ;
+
+/* Compilation control directives are processed within yylex(),
+ displayed here just for grammar completeness */
+compControl : P_DEFINE dottedName { DefineVar($2, NULL); }
+ | P_DEFINE dottedName compQstring { DefineVar($2, $3); }
+ | P_UNDEF dottedName { UndefVar($2); }
+ | P_IFDEF dottedName { SkipToken = !IsVarDefined($2);
+ IfEndif++;
+ }
+ | P_IFNDEF dottedName { SkipToken = IsVarDefined($2);
+ IfEndif++;
+ }
+ | P_ELSE { if(IfEndif == 1) SkipToken = !SkipToken;}
+ | P_ENDIF { if(IfEndif == 0)
+ PASM->report->error("Unmatched #endif\n");
+ else IfEndif--;
+ }
+ | P_INCLUDE QSTRING { _ASSERTE(!"yylex should have dealt with this"); }
+ | ';' { }
+ ;
+
+/* Custom attribute declarations */
+customDescr : _CUSTOM customType { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, NULL); }
+ | _CUSTOM customType '=' compQstring { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, $4); }
+ | _CUSTOM customType '=' '{' customBlobDescr '}' { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $2, $5); }
+ | customHead bytes ')' { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $1, $2); }
+ ;
+
+customDescrWithOwner : _CUSTOM '(' ownerType ')' customType { $$ = new CustomDescr($3, $5, NULL); }
+ | _CUSTOM '(' ownerType ')' customType '=' compQstring { $$ = new CustomDescr($3, $5, $7); }
+ | _CUSTOM '(' ownerType ')' customType '=' '{' customBlobDescr '}'
+ { $$ = new CustomDescr($3, $5, $8); }
+ | customHeadWithOwner bytes ')' { $$ = new CustomDescr(PASM->m_tkCurrentCVOwner, $1, $2); }
+ ;
+
+customHead : _CUSTOM customType '=' '(' { $$ = $2; bParsingByteArray = TRUE; }
+ ;
+
+customHeadWithOwner : _CUSTOM '(' ownerType ')' customType '=' '('
+ { PASM->m_pCustomDescrList = NULL;
+ PASM->m_tkCurrentCVOwner = $3;
+ $$ = $5; bParsingByteArray = TRUE; }
+ ;
+
+customType : methodRef { $$ = $1; }
+ ;
+
+ownerType : typeSpec { $$ = $1; }
+ | memberRef { $$ = $1; }
+ ;
+
+/* Verbal description of custom attribute initialization blob */
+customBlobDescr : customBlobArgs customBlobNVPairs { $$ = $1;
+ $$->appendInt16(nCustomBlobNVPairs);
+ $$->append($2);
+ nCustomBlobNVPairs = 0; }
+ ;
+
+customBlobArgs : /* EMPTY */ { $$ = new BinStr(); $$->appendInt16(VAL16(0x0001)); }
+ | customBlobArgs serInit { $$ = $1;
+ $$->appendFrom($2, (*($2->ptr()) == ELEMENT_TYPE_SZARRAY) ? 2 : 1); }
+ | customBlobArgs compControl { $$ = $1; }
+ ;
+
+customBlobNVPairs : /* EMPTY */ { $$ = new BinStr(); }
+ | customBlobNVPairs fieldOrProp serializType dottedName '=' serInit
+ { $$ = $1; $$->appendInt8($2);
+ $$->append($3);
+ AppendStringWithLength($$,$4);
+ $$->appendFrom($6, (*($6->ptr()) == ELEMENT_TYPE_SZARRAY) ? 2 : 1);
+ nCustomBlobNVPairs++; }
+ | customBlobNVPairs compControl { $$ = $1; }
+ ;
+
+fieldOrProp : FIELD_ { $$ = SERIALIZATION_TYPE_FIELD; }
+ | PROPERTY_ { $$ = SERIALIZATION_TYPE_PROPERTY; }
+ ;
+
+customAttrDecl : customDescr { if($1->tkOwner && !$1->tkInterfacePair)
+ PASM->DefineCV($1);
+ else if(PASM->m_pCustomDescrList)
+ PASM->m_pCustomDescrList->PUSH($1); }
+ | customDescrWithOwner { PASM->DefineCV($1); }
+ | TYPEDEF_CA { CustomDescr* pNew = new CustomDescr($1->m_pCA);
+ if(pNew->tkOwner == 0) pNew->tkOwner = PASM->m_tkCurrentCVOwner;
+ if(pNew->tkOwner)
+ PASM->DefineCV(pNew);
+ else if(PASM->m_pCustomDescrList)
+ PASM->m_pCustomDescrList->PUSH(pNew); }
+ ;
+
+serializType : simpleType { $$ = $1; }
+ | TYPE_ { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE); }
+ | OBJECT_ { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TAGGED_OBJECT); }
+ | ENUM_ CLASS_ SQSTRING { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_ENUM);
+ AppendStringWithLength($$,$3); }
+ | ENUM_ className { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_ENUM);
+ AppendStringWithLength($$,PASM->ReflectionNotation($2)); }
+ | serializType '[' ']' { $$ = $1; $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ ;
+
+
+/* Module declaration */
+moduleHead : _MODULE { PASMM->SetModuleName(NULL); PASM->m_tkCurrentCVOwner=1; }
+ | _MODULE dottedName { PASMM->SetModuleName($2); PASM->m_tkCurrentCVOwner=1; }
+ | _MODULE EXTERN_ dottedName { BinStr* pbs = new BinStr();
+ unsigned L = (unsigned)strlen($3);
+ memcpy((char*)(pbs->getBuff(L)),$3,L);
+ PASM->EmitImport(pbs); delete pbs;}
+ ;
+
+/* VTable Fixup table declaration */
+vtfixupDecl : _VTFIXUP '[' int32 ']' vtfixupAttr AT_ id { /*PASM->SetDataSection(); PASM->EmitDataLabel($7);*/
+ PASM->m_VTFList.PUSH(new VTFEntry((USHORT)$3, (USHORT)$5, $7)); }
+ ;
+
+vtfixupAttr : /* EMPTY */ { $$ = 0; }
+ | vtfixupAttr INT32_ { $$ = $1 | COR_VTABLE_32BIT; }
+ | vtfixupAttr INT64_ { $$ = $1 | COR_VTABLE_64BIT; }
+ | vtfixupAttr FROMUNMANAGED_ { $$ = $1 | COR_VTABLE_FROM_UNMANAGED; }
+ | vtfixupAttr CALLMOSTDERIVED_ { $$ = $1 | COR_VTABLE_CALL_MOST_DERIVED; }
+ | vtfixupAttr RETAINAPPDOMAIN_ { $$ = $1 | COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN; }
+ ;
+
+vtableDecl : vtableHead bytes ')' /* deprecated */ { PASM->m_pVTable = $2; }
+ ;
+
+vtableHead : _VTABLE '=' '(' /* deprecated */ { bParsingByteArray = TRUE; }
+ ;
+
+/* Namespace and class declaration */
+nameSpaceHead : _NAMESPACE dottedName { PASM->StartNameSpace($2); }
+ ;
+
+_class : _CLASS { newclass = TRUE; }
+ ;
+
+classHeadBegin : _class classAttr dottedName typarsClause { if($4) FixupConstraints();
+ PASM->StartClass($3, $2, $4);
+ TyParFixupList.RESET(false);
+ newclass = FALSE;
+ }
+ ;
+classHead : classHeadBegin extendsClause implClause { PASM->AddClass(); }
+ ;
+
+classAttr : /* EMPTY */ { $$ = (CorRegTypeAttr) 0; }
+ | classAttr PUBLIC_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdPublic); }
+ | classAttr PRIVATE_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNotPublic); }
+ | classAttr VALUE_ { $$ = (CorRegTypeAttr) ($1 | 0x80000000 | tdSealed); }
+ | classAttr ENUM_ { $$ = (CorRegTypeAttr) ($1 | 0x40000000); }
+ | classAttr INTERFACE_ { $$ = (CorRegTypeAttr) ($1 | tdInterface | tdAbstract); }
+ | classAttr SEALED_ { $$ = (CorRegTypeAttr) ($1 | tdSealed); }
+ | classAttr ABSTRACT_ { $$ = (CorRegTypeAttr) ($1 | tdAbstract); }
+ | classAttr AUTO_ { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdAutoLayout); }
+ | classAttr SEQUENTIAL_ { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdSequentialLayout); }
+ | classAttr EXPLICIT_ { $$ = (CorRegTypeAttr) (($1 & ~tdLayoutMask) | tdExplicitLayout); }
+ | classAttr ANSI_ { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdAnsiClass); }
+ | classAttr UNICODE_ { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdUnicodeClass); }
+ | classAttr AUTOCHAR_ { $$ = (CorRegTypeAttr) (($1 & ~tdStringFormatMask) | tdAutoClass); }
+ | classAttr IMPORT_ { $$ = (CorRegTypeAttr) ($1 | tdImport); }
+ | classAttr SERIALIZABLE_ { $$ = (CorRegTypeAttr) ($1 | tdSerializable); }
+ | classAttr WINDOWSRUNTIME_ { $$ = (CorRegTypeAttr) ($1 | tdWindowsRuntime); }
+ | classAttr NESTED_ PUBLIC_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedPublic); }
+ | classAttr NESTED_ PRIVATE_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedPrivate); }
+ | classAttr NESTED_ FAMILY_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamily); }
+ | classAttr NESTED_ ASSEMBLY_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedAssembly); }
+ | classAttr NESTED_ FAMANDASSEM_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamANDAssem); }
+ | classAttr NESTED_ FAMORASSEM_ { $$ = (CorRegTypeAttr) (($1 & ~tdVisibilityMask) | tdNestedFamORAssem); }
+ | classAttr BEFOREFIELDINIT_ { $$ = (CorRegTypeAttr) ($1 | tdBeforeFieldInit); }
+ | classAttr SPECIALNAME_ { $$ = (CorRegTypeAttr) ($1 | tdSpecialName); }
+ | classAttr RTSPECIALNAME_ { $$ = (CorRegTypeAttr) ($1); }
+ | classAttr FLAGS_ '(' int32 ')' { $$ = (CorRegTypeAttr) ($4); }
+ ;
+
+extendsClause : /* EMPTY */
+ | EXTENDS_ typeSpec { PASM->m_crExtends = $2; }
+ ;
+
+implClause : /* EMPTY */
+ | IMPLEMENTS_ implList
+ ;
+
+classDecls : /* EMPTY */
+ | classDecls classDecl
+ ;
+
+implList : implList ',' typeSpec { PASM->AddToImplList($3); }
+ | typeSpec { PASM->AddToImplList($1); }
+ ;
+
+/* Generic type parameters declaration */
+typeList : /* EMPTY */ { $$ = new BinStr(); }
+ | typeListNotEmpty { $$ = $1; }
+ ;
+
+typeListNotEmpty : typeSpec { $$ = new BinStr(); $$->appendInt32($1); }
+ | typeListNotEmpty ',' typeSpec { $$ = $1; $$->appendInt32($3); }
+ ;
+
+typarsClause : /* EMPTY */ { $$ = NULL; PASM->m_TyParList = NULL;}
+ | '<' typars '>' { $$ = $2; PASM->m_TyParList = $2;}
+ ;
+
+typarAttrib : '+' { $$ = gpCovariant; }
+ | '-' { $$ = gpContravariant; }
+ | CLASS_ { $$ = gpReferenceTypeConstraint; }
+ | VALUETYPE_ { $$ = gpNotNullableValueTypeConstraint; }
+ | _CTOR { $$ = gpDefaultConstructorConstraint; }
+ ;
+
+typarAttribs : /* EMPTY */ { $$ = 0; }
+ | typarAttrib typarAttribs { $$ = $1 | $2; }
+ ;
+
+typars : typarAttribs tyBound dottedName typarsRest {$$ = new TyParList($1, $2, $3, $4);}
+ | typarAttribs dottedName typarsRest {$$ = new TyParList($1, NULL, $2, $3);}
+ ;
+
+typarsRest : /* EMPTY */ { $$ = NULL; }
+ | ',' typars { $$ = $2; }
+ ;
+
+tyBound : '(' typeList ')' { $$ = $2; }
+ ;
+
+genArity : /* EMPTY */ { $$= 0; }
+ | genArityNotEmpty { $$ = $1; }
+ ;
+
+genArityNotEmpty : '<' '[' int32 ']' '>' { $$ = $3; }
+ ;
+
+/* Class body declarations */
+classDecl : methodHead methodDecls '}' { if(PASM->m_pCurMethod->m_ulLines[1] ==0)
+ { PASM->m_pCurMethod->m_ulLines[1] = PASM->m_ulCurLine;
+ PASM->m_pCurMethod->m_ulColumns[1]=PASM->m_ulCurColumn;}
+ PASM->EndMethod(); }
+ | classHead '{' classDecls '}' { PASM->EndClass(); }
+ | eventHead '{' eventDecls '}' { PASM->EndEvent(); }
+ | propHead '{' propDecls '}' { PASM->EndProp(); }
+ | fieldDecl
+ | dataDecl
+ | secDecl
+ | extSourceSpec
+ | customAttrDecl
+ | _SIZE int32 { PASM->m_pCurClass->m_ulSize = $2; }
+ | _PACK int32 { PASM->m_pCurClass->m_ulPack = $2; }
+ | exportHead '{' exptypeDecls '}' { PASMM->EndComType(); }
+ | _OVERRIDE typeSpec DCOLON methodName WITH_ callConv type typeSpec DCOLON methodName '(' sigArgs0 ')'
+ { BinStr *sig1 = parser->MakeSig($6, $7, $12);
+ BinStr *sig2 = new BinStr(); sig2->append(sig1);
+ PASM->AddMethodImpl($2,$4,sig1,$8,$10,sig2);
+ PASM->ResetArgNameList();
+ }
+ | _OVERRIDE METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')' WITH_ METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')'
+ { PASM->AddMethodImpl($5,$7,
+ ($8==0 ? parser->MakeSig($3,$4,$10) :
+ parser->MakeSig($3| IMAGE_CEE_CS_CALLCONV_GENERIC,$4,$10,$8)),
+ $16,$18,
+ ($19==0 ? parser->MakeSig($14,$15,$21) :
+ parser->MakeSig($14| IMAGE_CEE_CS_CALLCONV_GENERIC,$15,$21,$19)));
+ PASM->ResetArgNameList();
+ }
+ | languageDecl
+ | compControl
+ | PARAM_ TYPE_ '[' int32 ']' { if(($4 > 0) && ($4 <= (int)PASM->m_pCurClass->m_NumTyPars))
+ PASM->m_pCustomDescrList = PASM->m_pCurClass->m_TyPars[$4-1].CAList();
+ else
+ PASM->report->error("Type parameter index out of range\n");
+ }
+ | PARAM_ TYPE_ dottedName { int n = PASM->m_pCurClass->FindTyPar($3);
+ if(n >= 0)
+ PASM->m_pCustomDescrList = PASM->m_pCurClass->m_TyPars[n].CAList();
+ else
+ PASM->report->error("Type parameter '%s' undefined\n",$3);
+ }
+ | _INTERFACEIMPL TYPE_ typeSpec customDescr { $4->tkInterfacePair = $3;
+ if(PASM->m_pCustomDescrList)
+ PASM->m_pCustomDescrList->PUSH($4);
+ }
+ ;
+
+/* Field declaration */
+fieldDecl : _FIELD repeatOpt fieldAttr type dottedName atOpt initOpt
+ { $4->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ PASM->AddField($5, $4, $3, $6, $7, $2); }
+ ;
+
+fieldAttr : /* EMPTY */ { $$ = (CorFieldAttr) 0; }
+ | fieldAttr STATIC_ { $$ = (CorFieldAttr) ($1 | fdStatic); }
+ | fieldAttr PUBLIC_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPublic); }
+ | fieldAttr PRIVATE_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPrivate); }
+ | fieldAttr FAMILY_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamily); }
+ | fieldAttr INITONLY_ { $$ = (CorFieldAttr) ($1 | fdInitOnly); }
+ | fieldAttr RTSPECIALNAME_ { $$ = $1; } /*{ $$ = (CorFieldAttr) ($1 | fdRTSpecialName); }*/
+ | fieldAttr SPECIALNAME_ { $$ = (CorFieldAttr) ($1 | fdSpecialName); }
+ /* <STRIP>commented out because PInvoke for fields is not supported by EE
+ | fieldAttr PINVOKEIMPL_ '(' compQstring AS_ compQstring pinvAttr ')'
+ { $$ = (CorFieldAttr) ($1 | fdPinvokeImpl);
+ PASM->SetPinvoke($4,0,$6,$7); }
+ | fieldAttr PINVOKEIMPL_ '(' compQstring pinvAttr ')'
+ { $$ = (CorFieldAttr) ($1 | fdPinvokeImpl);
+ PASM->SetPinvoke($4,0,NULL,$5); }
+ | fieldAttr PINVOKEIMPL_ '(' pinvAttr ')'
+ { PASM->SetPinvoke(new BinStr(),0,NULL,$4);
+ $$ = (CorFieldAttr) ($1 | fdPinvokeImpl); }
+ </STRIP>*/
+ | fieldAttr MARSHAL_ '(' marshalBlob ')'
+ { PASM->m_pMarshal = $4; }
+ | fieldAttr ASSEMBLY_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdAssembly); }
+ | fieldAttr FAMANDASSEM_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamANDAssem); }
+ | fieldAttr FAMORASSEM_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdFamORAssem); }
+ | fieldAttr PRIVATESCOPE_ { $$ = (CorFieldAttr) (($1 & ~mdMemberAccessMask) | fdPrivateScope); }
+ | fieldAttr LITERAL_ { $$ = (CorFieldAttr) ($1 | fdLiteral); }
+ | fieldAttr NOTSERIALIZED_ { $$ = (CorFieldAttr) ($1 | fdNotSerialized); }
+ | fieldAttr FLAGS_ '(' int32 ')' { $$ = (CorFieldAttr) ($4); }
+ ;
+
+atOpt : /* EMPTY */ { $$ = 0; }
+ | AT_ id { $$ = $2; }
+ ;
+
+initOpt : /* EMPTY */ { $$ = NULL; }
+ | '=' fieldInit { $$ = $2; }
+ ;
+
+repeatOpt : /* EMPTY */ { $$ = 0xFFFFFFFF; }
+ | '[' int32 ']' { $$ = $2; }
+ ;
+
+/* Method referencing */
+methodRef : callConv type typeSpec DCOLON methodName tyArgs0 '(' sigArgs0 ')'
+ { PASM->ResetArgNameList();
+ if ($6 == NULL)
+ {
+ if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ $$ = PASM->MakeMemberRef($3, $5, parser->MakeSig($1|iCallConv, $2, $8));
+ }
+ else
+ {
+ mdToken mr;
+ if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ mr = PASM->MakeMemberRef($3, $5,
+ parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $8, corCountArgs($6)));
+ $$ = PASM->MakeMethodSpec(mr,
+ parser->MakeSig(IMAGE_CEE_CS_CALLCONV_INSTANTIATION, 0, $6));
+ }
+ }
+ | callConv type typeSpec DCOLON methodName genArityNotEmpty '(' sigArgs0 ')'
+ { PASM->ResetArgNameList();
+ if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ $$ = PASM->MakeMemberRef($3, $5,
+ parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $8, $6));
+ }
+ | callConv type methodName tyArgs0 '(' sigArgs0 ')'
+ { PASM->ResetArgNameList();
+ if ($4 == NULL)
+ {
+ if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ $$ = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1|iCallConv, $2, $6));
+ }
+ else
+ {
+ mdToken mr;
+ if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ mr = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $6, corCountArgs($4)));
+ $$ = PASM->MakeMethodSpec(mr,
+ parser->MakeSig(IMAGE_CEE_CS_CALLCONV_INSTANTIATION, 0, $4));
+ }
+ }
+ | callConv type methodName genArityNotEmpty '(' sigArgs0 ')'
+ { PASM->ResetArgNameList();
+ if((iCallConv)&&(($1 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ $$ = PASM->MakeMemberRef(mdTokenNil, $3, parser->MakeSig($1 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, $2, $6, $4));
+ }
+ | mdtoken { $$ = $1; }
+ | TYPEDEF_M { $$ = $1->m_tkTypeSpec; }
+ | TYPEDEF_MR { $$ = $1->m_tkTypeSpec; }
+ ;
+
+callConv : INSTANCE_ callConv { $$ = ($2 | IMAGE_CEE_CS_CALLCONV_HASTHIS); }
+ | EXPLICIT_ callConv { $$ = ($2 | IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS); }
+ | callKind { $$ = $1; }
+ | CALLCONV_ '(' int32 ')' { $$ = $3; }
+ ;
+
+callKind : /* EMPTY */ { $$ = IMAGE_CEE_CS_CALLCONV_DEFAULT; }
+ | DEFAULT_ { $$ = IMAGE_CEE_CS_CALLCONV_DEFAULT; }
+ | VARARG_ { $$ = IMAGE_CEE_CS_CALLCONV_VARARG; }
+ | UNMANAGED_ CDECL_ { $$ = IMAGE_CEE_CS_CALLCONV_C; }
+ | UNMANAGED_ STDCALL_ { $$ = IMAGE_CEE_CS_CALLCONV_STDCALL; }
+ | UNMANAGED_ THISCALL_ { $$ = IMAGE_CEE_CS_CALLCONV_THISCALL; }
+ | UNMANAGED_ FASTCALL_ { $$ = IMAGE_CEE_CS_CALLCONV_FASTCALL; }
+ ;
+
+mdtoken : MDTOKEN_ '(' int32 ')' { $$ = $3; }
+ ;
+
+memberRef : methodSpec methodRef { $$ = $2;
+ PASM->delArgNameList(PASM->m_firstArgName);
+ PASM->m_firstArgName = parser->m_ANSFirst.POP();
+ PASM->m_lastArgName = parser->m_ANSLast.POP();
+ PASM->SetMemberRefFixup($2,iOpcodeLen); }
+ | FIELD_ type typeSpec DCOLON dottedName
+ { $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ $$ = PASM->MakeMemberRef($3, $5, $2);
+ PASM->SetMemberRefFixup($$,iOpcodeLen); }
+ | FIELD_ type dottedName
+ { $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ $$ = PASM->MakeMemberRef(NULL, $3, $2);
+ PASM->SetMemberRefFixup($$,iOpcodeLen); }
+ | FIELD_ TYPEDEF_F { $$ = $2->m_tkTypeSpec;
+ PASM->SetMemberRefFixup($$,iOpcodeLen); }
+ | FIELD_ TYPEDEF_MR { $$ = $2->m_tkTypeSpec;
+ PASM->SetMemberRefFixup($$,iOpcodeLen); }
+ | mdtoken { $$ = $1;
+ PASM->SetMemberRefFixup($$,iOpcodeLen); }
+ ;
+
+/* Event declaration */
+eventHead : _EVENT eventAttr typeSpec dottedName { PASM->ResetEvent($4, $3, $2); }
+ | _EVENT eventAttr dottedName { PASM->ResetEvent($3, mdTypeRefNil, $2); }
+ ;
+
+
+eventAttr : /* EMPTY */ { $$ = (CorEventAttr) 0; }
+ | eventAttr RTSPECIALNAME_ { $$ = $1; }/*{ $$ = (CorEventAttr) ($1 | evRTSpecialName); }*/
+ | eventAttr SPECIALNAME_ { $$ = (CorEventAttr) ($1 | evSpecialName); }
+ ;
+
+eventDecls : /* EMPTY */
+ | eventDecls eventDecl
+ ;
+
+eventDecl : _ADDON methodRef { PASM->SetEventMethod(0, $2); }
+ | _REMOVEON methodRef { PASM->SetEventMethod(1, $2); }
+ | _FIRE methodRef { PASM->SetEventMethod(2, $2); }
+ | _OTHER methodRef { PASM->SetEventMethod(3, $2); }
+ | extSourceSpec
+ | customAttrDecl
+ | languageDecl
+ | compControl
+ ;
+
+/* Property declaration */
+propHead : _PROPERTY propAttr callConv type dottedName '(' sigArgs0 ')' initOpt
+ { PASM->ResetProp($5,
+ parser->MakeSig((IMAGE_CEE_CS_CALLCONV_PROPERTY |
+ ($3 & IMAGE_CEE_CS_CALLCONV_HASTHIS)),$4,$7), $2, $9);}
+ ;
+
+propAttr : /* EMPTY */ { $$ = (CorPropertyAttr) 0; }
+ | propAttr RTSPECIALNAME_ { $$ = $1; }/*{ $$ = (CorPropertyAttr) ($1 | prRTSpecialName); }*/
+ | propAttr SPECIALNAME_ { $$ = (CorPropertyAttr) ($1 | prSpecialName); }
+ ;
+
+propDecls : /* EMPTY */
+ | propDecls propDecl
+ ;
+
+
+propDecl : _SET methodRef { PASM->SetPropMethod(0, $2); }
+ | _GET methodRef { PASM->SetPropMethod(1, $2); }
+ | _OTHER methodRef { PASM->SetPropMethod(2, $2); }
+ | customAttrDecl
+ | extSourceSpec
+ | languageDecl
+ | compControl
+ ;
+
+/* Method declaration */
+methodHeadPart1 : _METHOD { PASM->ResetForNextMethod();
+ uMethodBeginLine = PASM->m_ulCurLine;
+ uMethodBeginColumn=PASM->m_ulCurColumn;
+ }
+ ;
+
+marshalClause : /* EMPTY */ { $$ = NULL; }
+ | MARSHAL_ '(' marshalBlob ')' { $$ = $3; }
+ ;
+
+marshalBlob : nativeType { $$ = $1; }
+ | marshalBlobHead hexbytes '}' { $$ = $2; }
+ ;
+
+marshalBlobHead : '{' { bParsingByteArray = TRUE; }
+ ;
+
+methodHead : methodHeadPart1 methAttr callConv paramAttr type marshalClause methodName typarsClause'(' sigArgs0 ')' implAttr '{'
+ { BinStr* sig;
+ if ($8 == NULL) sig = parser->MakeSig($3, $5, $10);
+ else {
+ FixupTyPars($5);
+ sig = parser->MakeSig($3 | IMAGE_CEE_CS_CALLCONV_GENERIC, $5, $10, $8->Count());
+ FixupConstraints();
+ }
+ PASM->StartMethod($7, sig, $2, $6, $4, $8);
+ TyParFixupList.RESET(false);
+ PASM->SetImplAttr((USHORT)$12);
+ PASM->m_pCurMethod->m_ulLines[0] = uMethodBeginLine;
+ PASM->m_pCurMethod->m_ulColumns[0]=uMethodBeginColumn;
+ }
+ ;
+
+methAttr : /* EMPTY */ { $$ = (CorMethodAttr) 0; }
+ | methAttr STATIC_ { $$ = (CorMethodAttr) ($1 | mdStatic); }
+ | methAttr PUBLIC_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPublic); }
+ | methAttr PRIVATE_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPrivate); }
+ | methAttr FAMILY_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamily); }
+ | methAttr FINAL_ { $$ = (CorMethodAttr) ($1 | mdFinal); }
+ | methAttr SPECIALNAME_ { $$ = (CorMethodAttr) ($1 | mdSpecialName); }
+ | methAttr VIRTUAL_ { $$ = (CorMethodAttr) ($1 | mdVirtual); }
+ | methAttr STRICT_ { $$ = (CorMethodAttr) ($1 | mdCheckAccessOnOverride); }
+ | methAttr ABSTRACT_ { $$ = (CorMethodAttr) ($1 | mdAbstract); }
+ | methAttr ASSEMBLY_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdAssem); }
+ | methAttr FAMANDASSEM_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamANDAssem); }
+ | methAttr FAMORASSEM_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdFamORAssem); }
+ | methAttr PRIVATESCOPE_ { $$ = (CorMethodAttr) (($1 & ~mdMemberAccessMask) | mdPrivateScope); }
+ | methAttr HIDEBYSIG_ { $$ = (CorMethodAttr) ($1 | mdHideBySig); }
+ | methAttr NEWSLOT_ { $$ = (CorMethodAttr) ($1 | mdNewSlot); }
+ | methAttr RTSPECIALNAME_ { $$ = $1; }/*{ $$ = (CorMethodAttr) ($1 | mdRTSpecialName); }*/
+ | methAttr UNMANAGEDEXP_ { $$ = (CorMethodAttr) ($1 | mdUnmanagedExport); }
+ | methAttr REQSECOBJ_ { $$ = (CorMethodAttr) ($1 | mdRequireSecObject); }
+ | methAttr FLAGS_ '(' int32 ')' { $$ = (CorMethodAttr) ($4); }
+ | methAttr PINVOKEIMPL_ '(' compQstring AS_ compQstring pinvAttr ')'
+ { PASM->SetPinvoke($4,0,$6,$7);
+ $$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
+ | methAttr PINVOKEIMPL_ '(' compQstring pinvAttr ')'
+ { PASM->SetPinvoke($4,0,NULL,$5);
+ $$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
+ | methAttr PINVOKEIMPL_ '(' pinvAttr ')'
+ { PASM->SetPinvoke(new BinStr(),0,NULL,$4);
+ $$ = (CorMethodAttr) ($1 | mdPinvokeImpl); }
+ ;
+
+pinvAttr : /* EMPTY */ { $$ = (CorPinvokeMap) 0; }
+ | pinvAttr NOMANGLE_ { $$ = (CorPinvokeMap) ($1 | pmNoMangle); }
+ | pinvAttr ANSI_ { $$ = (CorPinvokeMap) ($1 | pmCharSetAnsi); }
+ | pinvAttr UNICODE_ { $$ = (CorPinvokeMap) ($1 | pmCharSetUnicode); }
+ | pinvAttr AUTOCHAR_ { $$ = (CorPinvokeMap) ($1 | pmCharSetAuto); }
+ | pinvAttr LASTERR_ { $$ = (CorPinvokeMap) ($1 | pmSupportsLastError); }
+ | pinvAttr WINAPI_ { $$ = (CorPinvokeMap) ($1 | pmCallConvWinapi); }
+ | pinvAttr CDECL_ { $$ = (CorPinvokeMap) ($1 | pmCallConvCdecl); }
+ | pinvAttr STDCALL_ { $$ = (CorPinvokeMap) ($1 | pmCallConvStdcall); }
+ | pinvAttr THISCALL_ { $$ = (CorPinvokeMap) ($1 | pmCallConvThiscall); }
+ | pinvAttr FASTCALL_ { $$ = (CorPinvokeMap) ($1 | pmCallConvFastcall); }
+ | pinvAttr BESTFIT_ ':' ON_ { $$ = (CorPinvokeMap) ($1 | pmBestFitEnabled); }
+ | pinvAttr BESTFIT_ ':' OFF_ { $$ = (CorPinvokeMap) ($1 | pmBestFitDisabled); }
+ | pinvAttr CHARMAPERROR_ ':' ON_ { $$ = (CorPinvokeMap) ($1 | pmThrowOnUnmappableCharEnabled); }
+ | pinvAttr CHARMAPERROR_ ':' OFF_ { $$ = (CorPinvokeMap) ($1 | pmThrowOnUnmappableCharDisabled); }
+ | pinvAttr FLAGS_ '(' int32 ')' { $$ = (CorPinvokeMap) ($4); }
+ ;
+
+methodName : _CTOR { $$ = newString(COR_CTOR_METHOD_NAME); }
+ | _CCTOR { $$ = newString(COR_CCTOR_METHOD_NAME); }
+ | dottedName { $$ = $1; }
+ ;
+
+paramAttr : /* EMPTY */ { $$ = 0; }
+ | paramAttr '[' IN_ ']' { $$ = $1 | pdIn; }
+ | paramAttr '[' OUT_ ']' { $$ = $1 | pdOut; }
+ | paramAttr '[' OPT_ ']' { $$ = $1 | pdOptional; }
+ | paramAttr '[' int32 ']' { $$ = $3 + 1; }
+ ;
+
+implAttr : /* EMPTY */ { $$ = (CorMethodImpl) (miIL | miManaged); }
+ | implAttr NATIVE_ { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miNative); }
+ | implAttr CIL_ { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miIL); }
+ | implAttr OPTIL_ { $$ = (CorMethodImpl) (($1 & 0xFFF4) | miOPTIL); }
+ | implAttr MANAGED_ { $$ = (CorMethodImpl) (($1 & 0xFFFB) | miManaged); }
+ | implAttr UNMANAGED_ { $$ = (CorMethodImpl) (($1 & 0xFFFB) | miUnmanaged); }
+ | implAttr FORWARDREF_ { $$ = (CorMethodImpl) ($1 | miForwardRef); }
+ | implAttr PRESERVESIG_ { $$ = (CorMethodImpl) ($1 | miPreserveSig); }
+ | implAttr RUNTIME_ { $$ = (CorMethodImpl) ($1 | miRuntime); }
+ | implAttr INTERNALCALL_ { $$ = (CorMethodImpl) ($1 | miInternalCall); }
+ | implAttr SYNCHRONIZED_ { $$ = (CorMethodImpl) ($1 | miSynchronized); }
+ | implAttr NOINLINING_ { $$ = (CorMethodImpl) ($1 | miNoInlining); }
+ | implAttr AGGRESSIVEINLINING_ { $$ = (CorMethodImpl) ($1 | miAggressiveInlining); }
+ | implAttr NOOPTIMIZATION_ { $$ = (CorMethodImpl) ($1 | miNoOptimization); }
+ | implAttr FLAGS_ '(' int32 ')' { $$ = (CorMethodImpl) ($4); }
+ ;
+
+localsHead : _LOCALS { PASM->delArgNameList(PASM->m_firstArgName); PASM->m_firstArgName = NULL;PASM->m_lastArgName = NULL;
+ }
+ ;
+
+methodDecls : /* EMPTY */
+ | methodDecls methodDecl
+ ;
+
+methodDecl : _EMITBYTE int32 { PASM->EmitByte($2); }
+ | sehBlock { delete PASM->m_SEHD; PASM->m_SEHD = PASM->m_SEHDstack.POP(); }
+ | _MAXSTACK int32 { PASM->EmitMaxStack($2); }
+ | localsHead '(' sigArgs0 ')' { PASM->EmitLocals(parser->MakeSig(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG, 0, $3));
+ }
+ | localsHead INIT_ '(' sigArgs0 ')' { PASM->EmitZeroInit();
+ PASM->EmitLocals(parser->MakeSig(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG, 0, $4));
+ }
+ | _ENTRYPOINT { PASM->EmitEntryPoint(); }
+ | _ZEROINIT { PASM->EmitZeroInit(); }
+ | dataDecl
+ | instr
+ | id ':' { PASM->AddLabel(PASM->m_CurPC,$1); /*PASM->EmitLabel($1);*/ }
+ | secDecl
+ | extSourceSpec
+ | languageDecl
+ | customAttrDecl
+ | compControl
+ | _EXPORT '[' int32 ']' { if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
+ {
+ PASM->m_pCurMethod->m_dwExportOrdinal = $3;
+ PASM->m_pCurMethod->m_szExportAlias = NULL;
+ if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
+ if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = $3 + 0x8000;
+ }
+ else
+ PASM->report->warn("Duplicate .export directive, ignored\n");
+ }
+ | _EXPORT '[' int32 ']' AS_ id { if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
+ {
+ PASM->m_pCurMethod->m_dwExportOrdinal = $3;
+ PASM->m_pCurMethod->m_szExportAlias = $6;
+ if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
+ if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = $3 + 0x8000;
+ }
+ else
+ PASM->report->warn("Duplicate .export directive, ignored\n");
+ }
+ | _VTENTRY int32 ':' int32 { PASM->m_pCurMethod->m_wVTEntry = (WORD)$2;
+ PASM->m_pCurMethod->m_wVTSlot = (WORD)$4; }
+ | _OVERRIDE typeSpec DCOLON methodName
+ { PASM->AddMethodImpl($2,$4,NULL,NULL,NULL,NULL); }
+
+ | _OVERRIDE METHOD_ callConv type typeSpec DCOLON methodName genArity '(' sigArgs0 ')'
+ { PASM->AddMethodImpl($5,$7,
+ ($8==0 ? parser->MakeSig($3,$4,$10) :
+ parser->MakeSig($3| IMAGE_CEE_CS_CALLCONV_GENERIC,$4,$10,$8))
+ ,NULL,NULL,NULL);
+ PASM->ResetArgNameList();
+ }
+ | scopeBlock
+ | PARAM_ TYPE_ '[' int32 ']' { if(($4 > 0) && ($4 <= (int)PASM->m_pCurMethod->m_NumTyPars))
+ PASM->m_pCustomDescrList = PASM->m_pCurMethod->m_TyPars[$4-1].CAList();
+ else
+ PASM->report->error("Type parameter index out of range\n");
+ }
+ | PARAM_ TYPE_ dottedName { int n = PASM->m_pCurMethod->FindTyPar($3);
+ if(n >= 0)
+ PASM->m_pCustomDescrList = PASM->m_pCurMethod->m_TyPars[n].CAList();
+ else
+ PASM->report->error("Type parameter '%s' undefined\n",$3);
+ }
+ | PARAM_ '[' int32 ']' initOpt
+ { if( $3 ) {
+ ARG_NAME_LIST* pAN=PASM->findArg(PASM->m_pCurMethod->m_firstArgName, $3 - 1);
+ if(pAN)
+ {
+ PASM->m_pCustomDescrList = &(pAN->CustDList);
+ pAN->pValue = $5;
+ }
+ else
+ {
+ PASM->m_pCustomDescrList = NULL;
+ if($5) delete $5;
+ }
+ } else {
+ PASM->m_pCustomDescrList = &(PASM->m_pCurMethod->m_RetCustDList);
+ PASM->m_pCurMethod->m_pRetValue = $5;
+ }
+ PASM->m_tkCurrentCVOwner = 0;
+ }
+ ;
+
+scopeBlock : scopeOpen methodDecls '}' { PASM->m_pCurMethod->CloseScope(); }
+ ;
+
+scopeOpen : '{' { PASM->m_pCurMethod->OpenScope(); }
+ ;
+
+/* Structured exception handling directives */
+sehBlock : tryBlock sehClauses
+ ;
+
+sehClauses : sehClause sehClauses
+ | sehClause
+ ;
+
+tryBlock : tryHead scopeBlock { PASM->m_SEHD->tryTo = PASM->m_CurPC; }
+ | tryHead id TO_ id { PASM->SetTryLabels($2, $4); }
+ | tryHead int32 TO_ int32 { if(PASM->m_SEHD) {PASM->m_SEHD->tryFrom = $2;
+ PASM->m_SEHD->tryTo = $4;} }
+ ;
+
+tryHead : _TRY { PASM->NewSEHDescriptor();
+ PASM->m_SEHD->tryFrom = PASM->m_CurPC; }
+ ;
+
+
+sehClause : catchClause handlerBlock { PASM->EmitTry(); }
+ | filterClause handlerBlock { PASM->EmitTry(); }
+ | finallyClause handlerBlock { PASM->EmitTry(); }
+ | faultClause handlerBlock { PASM->EmitTry(); }
+ ;
+
+
+filterClause : filterHead scopeBlock { PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
+ | filterHead id { PASM->SetFilterLabel($2);
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
+ | filterHead int32 { PASM->m_SEHD->sehFilter = $2;
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
+ ;
+
+filterHead : FILTER_ { PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FILTER;
+ PASM->m_SEHD->sehFilter = PASM->m_CurPC; }
+ ;
+
+catchClause : CATCH_ typeSpec { PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_NONE;
+ PASM->SetCatchClass($2);
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
+ ;
+
+finallyClause : FINALLY_ { PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FINALLY;
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
+ ;
+
+faultClause : FAULT_ { PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FAULT;
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; }
+ ;
+
+handlerBlock : scopeBlock { PASM->m_SEHD->sehHandlerTo = PASM->m_CurPC; }
+ | HANDLER_ id TO_ id { PASM->SetHandlerLabels($2, $4); }
+ | HANDLER_ int32 TO_ int32 { PASM->m_SEHD->sehHandler = $2;
+ PASM->m_SEHD->sehHandlerTo = $4; }
+ ;
+
+/* Data declaration */
+dataDecl : ddHead ddBody
+ ;
+
+ddHead : _DATA tls id '=' { PASM->EmitDataLabel($3); }
+ | _DATA tls
+ ;
+
+tls : /* EMPTY */ { PASM->SetDataSection(); }
+ | TLS_ { PASM->SetTLSSection(); }
+ | CIL_ { PASM->SetILSection(); }
+ ;
+
+ddBody : '{' ddItemList '}'
+ | ddItem
+ ;
+
+ddItemList : ddItem ',' ddItemList
+ | ddItem
+ ;
+
+ddItemCount : /* EMPTY */ { $$ = 1; }
+ | '[' int32 ']' { $$ = $2;
+ if($2 <= 0) { PASM->report->error("Illegal item count: %d\n",$2);
+ if(!PASM->OnErrGo) $$ = 1; }}
+ ;
+
+ddItem : CHAR_ '*' '(' compQstring ')' { PASM->EmitDataString($4); }
+ | '&' '(' id ')' { PASM->EmitDD($3); }
+ | bytearrayhead bytes ')' { PASM->EmitData($2->ptr(),$2->length()); }
+ | FLOAT32_ '(' float64 ')' ddItemCount
+ { float f = (float) (*$3); float* p = new (nothrow) float[$5];
+ if(p != NULL) {
+ for(int i=0; i < $5; i++) p[i] = f;
+ PASM->EmitData(p, sizeof(float)*$5); delete $3; delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(float)*$5); }
+ | FLOAT64_ '(' float64 ')' ddItemCount
+ { double* p = new (nothrow) double[$5];
+ if(p != NULL) {
+ for(int i=0; i<$5; i++) p[i] = *($3);
+ PASM->EmitData(p, sizeof(double)*$5); delete $3; delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(double)*$5); }
+ | INT64_ '(' int64 ')' ddItemCount
+ { __int64* p = new (nothrow) __int64[$5];
+ if(p != NULL) {
+ for(int i=0; i<$5; i++) p[i] = *($3);
+ PASM->EmitData(p, sizeof(__int64)*$5); delete $3; delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(__int64)*$5); }
+ | INT32_ '(' int32 ')' ddItemCount
+ { __int32* p = new (nothrow) __int32[$5];
+ if(p != NULL) {
+ for(int i=0; i<$5; i++) p[i] = $3;
+ PASM->EmitData(p, sizeof(__int32)*$5); delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(__int32)*$5); }
+ | INT16_ '(' int32 ')' ddItemCount
+ { __int16 i = (__int16) $3; FAIL_UNLESS(i == $3, ("Value %d too big\n", $3));
+ __int16* p = new (nothrow) __int16[$5];
+ if(p != NULL) {
+ for(int j=0; j<$5; j++) p[j] = i;
+ PASM->EmitData(p, sizeof(__int16)*$5); delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(__int16)*$5); }
+ | INT8_ '(' int32 ')' ddItemCount
+ { __int8 i = (__int8) $3; FAIL_UNLESS(i == $3, ("Value %d too big\n", $3));
+ __int8* p = new (nothrow) __int8[$5];
+ if(p != NULL) {
+ for(int j=0; j<$5; j++) p[j] = i;
+ PASM->EmitData(p, sizeof(__int8)*$5); delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(__int8)*$5); }
+ | FLOAT32_ ddItemCount { PASM->EmitData(NULL, sizeof(float)*$2); }
+ | FLOAT64_ ddItemCount { PASM->EmitData(NULL, sizeof(double)*$2); }
+ | INT64_ ddItemCount { PASM->EmitData(NULL, sizeof(__int64)*$2); }
+ | INT32_ ddItemCount { PASM->EmitData(NULL, sizeof(__int32)*$2); }
+ | INT16_ ddItemCount { PASM->EmitData(NULL, sizeof(__int16)*$2); }
+ | INT8_ ddItemCount { PASM->EmitData(NULL, sizeof(__int8)*$2); }
+ ;
+
+/* Default values declaration for fields, parameters and verbal form of CA blob description */
+fieldSerInit : FLOAT32_ '(' float64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R4);
+ float f = (float)(*$3);
+ $$->appendInt32(*((__int32*)&f)); delete $3; }
+ | FLOAT64_ '(' float64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R8);
+ $$->appendInt64((__int64 *)$3); delete $3; }
+ | FLOAT32_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R4);
+ $$->appendInt32($3); }
+ | FLOAT64_ '(' int64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R8);
+ $$->appendInt64((__int64 *)$3); delete $3; }
+ | INT64_ '(' int64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I8);
+ $$->appendInt64((__int64 *)$3); delete $3; }
+ | INT32_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I4);
+ $$->appendInt32($3); }
+ | INT16_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I2);
+ $$->appendInt16($3); }
+ | INT8_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I1);
+ $$->appendInt8($3); }
+ | UNSIGNED_ INT64_ '(' int64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8);
+ $$->appendInt64((__int64 *)$4); delete $4; }
+ | UNSIGNED_ INT32_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4);
+ $$->appendInt32($4); }
+ | UNSIGNED_ INT16_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2);
+ $$->appendInt16($4); }
+ | UNSIGNED_ INT8_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1);
+ $$->appendInt8($4); }
+ | UINT64_ '(' int64 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8);
+ $$->appendInt64((__int64 *)$3); delete $3; }
+ | UINT32_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4);
+ $$->appendInt32($3); }
+ | UINT16_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2);
+ $$->appendInt16($3); }
+ | UINT8_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1);
+ $$->appendInt8($3); }
+ | CHAR_ '(' int32 ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_CHAR);
+ $$->appendInt16($3); }
+ | BOOL_ '(' truefalse ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_BOOLEAN);
+ $$->appendInt8($3);}
+ | bytearrayhead bytes ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING);
+ $$->append($2); delete $2;}
+ ;
+
+bytearrayhead : BYTEARRAY_ '(' { bParsingByteArray = TRUE; }
+ ;
+
+bytes : /* EMPTY */ { $$ = new BinStr(); }
+ | hexbytes { $$ = $1; }
+ ;
+
+hexbytes : HEXBYTE { __int8 i = (__int8) $1; $$ = new BinStr(); $$->appendInt8(i); }
+ | hexbytes HEXBYTE { __int8 i = (__int8) $2; $$ = $1; $$->appendInt8(i); }
+ ;
+
+/* Field/parameter initialization */
+fieldInit : fieldSerInit { $$ = $1; }
+ | compQstring { $$ = BinStrToUnicode($1,true); $$->insertInt8(ELEMENT_TYPE_STRING);}
+ | NULLREF_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_CLASS);
+ $$->appendInt32(0); }
+ ;
+
+/* Values for verbal form of CA blob description */
+serInit : fieldSerInit { $$ = $1; }
+ | STRING_ '(' NULLREF_ ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING); $$->appendInt8(0xFF); }
+ | STRING_ '(' SQSTRING ')' { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING);
+ AppendStringWithLength($$,$3); delete [] $3;}
+ | TYPE_ '(' CLASS_ SQSTRING ')' { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE);
+ AppendStringWithLength($$,$4); delete [] $4;}
+ | TYPE_ '(' className ')' { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE);
+ AppendStringWithLength($$,PASM->ReflectionNotation($3));}
+ | TYPE_ '(' NULLREF_ ')' { $$ = new BinStr(); $$->appendInt8(SERIALIZATION_TYPE_TYPE); $$->appendInt8(0xFF); }
+ | OBJECT_ '(' serInit ')' { $$ = $3; $$->insertInt8(SERIALIZATION_TYPE_TAGGED_OBJECT);}
+ | FLOAT32_ '[' int32 ']' '(' f32seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_R4);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | FLOAT64_ '[' int32 ']' '(' f64seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_R8);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | INT64_ '[' int32 ']' '(' i64seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_I8);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | INT32_ '[' int32 ']' '(' i32seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_I4);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | INT16_ '[' int32 ']' '(' i16seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_I2);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | INT8_ '[' int32 ']' '(' i8seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_I1);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | UINT64_ '[' int32 ']' '(' i64seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_U8);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | UINT32_ '[' int32 ']' '(' i32seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_U4);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | UINT16_ '[' int32 ']' '(' i16seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_U2);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | UINT8_ '[' int32 ']' '(' i8seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_U1);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | UNSIGNED_ INT64_ '[' int32 ']' '(' i64seq ')'
+ { $$ = $7; $$->insertInt32($4);
+ $$->insertInt8(ELEMENT_TYPE_U8);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | UNSIGNED_ INT32_ '[' int32 ']' '(' i32seq ')'
+ { $$ = $7; $$->insertInt32($4);
+ $$->insertInt8(ELEMENT_TYPE_U4);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | UNSIGNED_ INT16_ '[' int32 ']' '(' i16seq ')'
+ { $$ = $7; $$->insertInt32($4);
+ $$->insertInt8(ELEMENT_TYPE_U2);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | UNSIGNED_ INT8_ '[' int32 ']' '(' i8seq ')'
+ { $$ = $7; $$->insertInt32($4);
+ $$->insertInt8(ELEMENT_TYPE_U1);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | CHAR_ '[' int32 ']' '(' i16seq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_CHAR);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | BOOL_ '[' int32 ']' '(' boolSeq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_BOOLEAN);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | STRING_ '[' int32 ']' '(' sqstringSeq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(ELEMENT_TYPE_STRING);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | TYPE_ '[' int32 ']' '(' classSeq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(SERIALIZATION_TYPE_TYPE);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | OBJECT_ '[' int32 ']' '(' objSeq ')'
+ { $$ = $6; $$->insertInt32($3);
+ $$->insertInt8(SERIALIZATION_TYPE_TAGGED_OBJECT);
+ $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ ;
+
+
+f32seq : /* EMPTY */ { $$ = new BinStr(); }
+ | f32seq float64 { $$ = $1;
+ float f = (float) (*$2); $$->appendInt32(*((__int32*)&f)); delete $2; }
+ | f32seq int32 { $$ = $1;
+ $$->appendInt32($2); }
+ ;
+
+f64seq : /* EMPTY */ { $$ = new BinStr(); }
+ | f64seq float64 { $$ = $1;
+ $$->appendInt64((__int64 *)$2); delete $2; }
+ | f64seq int64 { $$ = $1;
+ $$->appendInt64((__int64 *)$2); delete $2; }
+ ;
+
+i64seq : /* EMPTY */ { $$ = new BinStr(); }
+ | i64seq int64 { $$ = $1;
+ $$->appendInt64((__int64 *)$2); delete $2; }
+ ;
+
+i32seq : /* EMPTY */ { $$ = new BinStr(); }
+ | i32seq int32 { $$ = $1; $$->appendInt32($2);}
+ ;
+
+i16seq : /* EMPTY */ { $$ = new BinStr(); }
+ | i16seq int32 { $$ = $1; $$->appendInt16($2);}
+ ;
+
+i8seq : /* EMPTY */ { $$ = new BinStr(); }
+ | i8seq int32 { $$ = $1; $$->appendInt8($2); }
+ ;
+
+boolSeq : /* EMPTY */ { $$ = new BinStr(); }
+ | boolSeq truefalse { $$ = $1;
+ $$->appendInt8($2);}
+ ;
+
+sqstringSeq : /* EMPTY */ { $$ = new BinStr(); }
+ | sqstringSeq NULLREF_ { $$ = $1; $$->appendInt8(0xFF); }
+ | sqstringSeq SQSTRING { $$ = $1;
+ AppendStringWithLength($$,$2); delete [] $2;}
+ ;
+
+classSeq : /* EMPTY */ { $$ = new BinStr(); }
+ | classSeq NULLREF_ { $$ = $1; $$->appendInt8(0xFF); }
+ | classSeq CLASS_ SQSTRING { $$ = $1;
+ AppendStringWithLength($$,$3); delete [] $3;}
+ | classSeq className { $$ = $1;
+ AppendStringWithLength($$,PASM->ReflectionNotation($2));}
+ ;
+
+objSeq : /* EMPTY */ { $$ = new BinStr(); }
+ | objSeq serInit { $$ = $1; $$->append($2); delete $2; }
+ ;
+
+/* IL instructions and associated definitions */
+methodSpec : METHOD_ { parser->m_ANSFirst.PUSH(PASM->m_firstArgName);
+ parser->m_ANSLast.PUSH(PASM->m_lastArgName);
+ PASM->m_firstArgName = NULL;
+ PASM->m_lastArgName = NULL; }
+ ;
+
+instr_none : INSTR_NONE { $$ = SetupInstr($1); }
+ ;
+
+instr_var : INSTR_VAR { $$ = SetupInstr($1); }
+ ;
+
+instr_i : INSTR_I { $$ = SetupInstr($1); }
+ ;
+
+instr_i8 : INSTR_I8 { $$ = SetupInstr($1); }
+ ;
+
+instr_r : INSTR_R { $$ = SetupInstr($1); }
+ ;
+
+instr_brtarget : INSTR_BRTARGET { $$ = SetupInstr($1); }
+ ;
+
+instr_method : INSTR_METHOD { $$ = SetupInstr($1);
+ if((!PASM->OnErrGo)&&
+ (($1 == CEE_NEWOBJ)||
+ ($1 == CEE_CALLVIRT)))
+ iCallConv = IMAGE_CEE_CS_CALLCONV_HASTHIS;
+ }
+ ;
+
+instr_field : INSTR_FIELD { $$ = SetupInstr($1); }
+ ;
+
+instr_type : INSTR_TYPE { $$ = SetupInstr($1); }
+ ;
+
+instr_string : INSTR_STRING { $$ = SetupInstr($1); }
+ ;
+
+instr_sig : INSTR_SIG { $$ = SetupInstr($1); }
+ ;
+
+instr_tok : INSTR_TOK { $$ = SetupInstr($1); iOpcodeLen = PASM->OpcodeLen($$); }
+ ;
+
+instr_switch : INSTR_SWITCH { $$ = SetupInstr($1); }
+ ;
+
+instr_r_head : instr_r '(' { $$ = $1; bParsingByteArray = TRUE; }
+ ;
+
+
+instr : instr_none { PASM->EmitOpcode($1); }
+ | instr_var int32 { PASM->EmitInstrVar($1, $2); }
+ | instr_var id { PASM->EmitInstrVarByName($1, $2); }
+ | instr_i int32 { PASM->EmitInstrI($1, $2); }
+ | instr_i8 int64 { PASM->EmitInstrI8($1, $2); }
+ | instr_r float64 { PASM->EmitInstrR($1, $2); delete ($2);}
+ | instr_r int64 { double f = (double) (*$2); PASM->EmitInstrR($1, &f); }
+ | instr_r_head bytes ')' { unsigned L = $2->length();
+ FAIL_UNLESS(L >= sizeof(float), ("%d hexbytes, must be at least %d\n",
+ L,sizeof(float)));
+ if(L < sizeof(float)) {YYERROR; }
+ else {
+ double f = (L >= sizeof(double)) ? *((double *)($2->ptr()))
+ : (double)(*(float *)($2->ptr()));
+ PASM->EmitInstrR($1,&f); }
+ delete $2; }
+ | instr_brtarget int32 { PASM->EmitInstrBrOffset($1, $2); }
+ | instr_brtarget id { PASM->EmitInstrBrTarget($1, $2); }
+ | instr_method methodRef
+ { PASM->SetMemberRefFixup($2,PASM->OpcodeLen($1));
+ PASM->EmitInstrI($1,$2);
+ PASM->m_tkCurrentCVOwner = $2;
+ PASM->m_pCustomDescrList = NULL;
+ iCallConv = 0;
+ }
+ | instr_field type typeSpec DCOLON dottedName
+ { $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ mdToken mr = PASM->MakeMemberRef($3, $5, $2);
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
+ PASM->EmitInstrI($1,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ }
+ | instr_field type dottedName
+ { $2->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ mdToken mr = PASM->MakeMemberRef(mdTokenNil, $3, $2);
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
+ PASM->EmitInstrI($1,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ }
+ | instr_field mdtoken { mdToken mr = $2;
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
+ PASM->EmitInstrI($1,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ }
+ | instr_field TYPEDEF_F { mdToken mr = $2->m_tkTypeSpec;
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
+ PASM->EmitInstrI($1,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ }
+ | instr_field TYPEDEF_MR { mdToken mr = $2->m_tkTypeSpec;
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen($1));
+ PASM->EmitInstrI($1,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ }
+ | instr_type typeSpec { PASM->EmitInstrI($1, $2);
+ PASM->m_tkCurrentCVOwner = $2;
+ PASM->m_pCustomDescrList = NULL;
+ }
+ | instr_string compQstring { PASM->EmitInstrStringLiteral($1, $2,TRUE); }
+ | instr_string ANSI_ '(' compQstring ')'
+ { PASM->EmitInstrStringLiteral($1, $4,FALSE); }
+ | instr_string bytearrayhead bytes ')'
+ { PASM->EmitInstrStringLiteral($1, $3,FALSE,TRUE); }
+ | instr_sig callConv type '(' sigArgs0 ')'
+ { PASM->EmitInstrSig($1, parser->MakeSig($2, $3, $5));
+ PASM->ResetArgNameList();
+ }
+ | instr_tok ownerType /* ownerType ::= memberRef | typeSpec */
+ { PASM->EmitInstrI($1,$2);
+ PASM->m_tkCurrentCVOwner = $2;
+ PASM->m_pCustomDescrList = NULL;
+ iOpcodeLen = 0;
+ }
+ | instr_switch '(' labels ')' { PASM->EmitInstrSwitch($1, $3); }
+ ;
+
+labels : /* empty */ { $$ = 0; }
+ | id ',' labels { $$ = new Labels($1, $3, TRUE); }
+ | int32 ',' labels { $$ = new Labels((char *)(UINT_PTR)$1, $3, FALSE); }
+ | id { $$ = new Labels($1, NULL, TRUE); }
+ | int32 { $$ = new Labels((char *)(UINT_PTR)$1, NULL, FALSE); }
+ ;
+
+/* Signatures */
+tyArgs0 : /* EMPTY */ { $$ = NULL; }
+ | '<' tyArgs1 '>' { $$ = $2; }
+ ;
+
+tyArgs1 : /* EMPTY */ { $$ = NULL; }
+ | tyArgs2 { $$ = $1; }
+ ;
+
+tyArgs2 : type { $$ = $1; }
+ | tyArgs2 ',' type { $$ = $1; $$->append($3); delete $3; }
+ ;
+
+
+sigArgs0 : /* EMPTY */ { $$ = new BinStr(); }
+ | sigArgs1 { $$ = $1;}
+ ;
+
+sigArgs1 : sigArg { $$ = $1; }
+ | sigArgs1 ',' sigArg { $$ = $1; $$->append($3); delete $3; }
+ ;
+
+sigArg : ELIPSIS { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_SENTINEL); }
+ | paramAttr type marshalClause { $$ = new BinStr(); $$->append($2); PASM->addArgName(NULL, $2, $3, $1); }
+ | paramAttr type marshalClause id { $$ = new BinStr(); $$->append($2); PASM->addArgName($4, $2, $3, $1);}
+ ;
+
+/* Class referencing */
+className : '[' dottedName ']' slashedName { $$ = PASM->ResolveClassRef(PASM->GetAsmRef($2), $4, NULL); delete[] $2;}
+ | '[' mdtoken ']' slashedName { $$ = PASM->ResolveClassRef($2, $4, NULL); }
+ | '[' '*' ']' slashedName { $$ = PASM->ResolveClassRef(mdTokenNil, $4, NULL); }
+ | '[' _MODULE dottedName ']' slashedName { $$ = PASM->ResolveClassRef(PASM->GetModRef($3),$5, NULL); delete[] $3;}
+ | slashedName { $$ = PASM->ResolveClassRef(1,$1,NULL); }
+ | mdtoken { $$ = $1; }
+ | TYPEDEF_T { $$ = $1->m_tkTypeSpec; }
+ | _THIS { if(PASM->m_pCurClass != NULL) $$ = PASM->m_pCurClass->m_cl;
+ else { $$ = 0; PASM->report->error(".this outside class scope\n"); }
+ }
+ | _BASE { if(PASM->m_pCurClass != NULL) {
+ $$ = PASM->m_pCurClass->m_crExtends;
+ if(RidFromToken($$) == 0)
+ PASM->report->error(".base undefined\n");
+ } else { $$ = 0; PASM->report->error(".base outside class scope\n"); }
+ }
+ | _NESTER { if(PASM->m_pCurClass != NULL) {
+ if(PASM->m_pCurClass->m_pEncloser != NULL) $$ = PASM->m_pCurClass->m_pEncloser->m_cl;
+ else { $$ = 0; PASM->report->error(".nester undefined\n"); }
+ } else { $$ = 0; PASM->report->error(".nester outside class scope\n"); }
+ }
+ ;
+
+slashedName : dottedName { $$ = $1; }
+ | slashedName '/' dottedName { $$ = newStringWDel($1, NESTING_SEP, $3); }
+ ;
+
+typeSpec : className { $$ = $1;}
+ | '[' dottedName ']' { $$ = PASM->GetAsmRef($2); delete[] $2;}
+ | '[' _MODULE dottedName ']' { $$ = PASM->GetModRef($3); delete[] $3;}
+ | type { $$ = PASM->ResolveTypeSpec($1); }
+ ;
+
+/* Native types for marshaling signatures */
+nativeType : /* EMPTY */ { $$ = new BinStr(); }
+ | CUSTOM_ '(' compQstring ',' compQstring ',' compQstring ',' compQstring ')'
+ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_CUSTOMMARSHALER);
+ corEmitInt($$,$3->length()); $$->append($3);
+ corEmitInt($$,$5->length()); $$->append($5);
+ corEmitInt($$,$7->length()); $$->append($7);
+ corEmitInt($$,$9->length()); $$->append($9);
+ PASM->report->warn("Deprecated 4-string form of custom marshaler, first two strings ignored\n");}
+ | CUSTOM_ '(' compQstring ',' compQstring ')'
+ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_CUSTOMMARSHALER);
+ corEmitInt($$,0);
+ corEmitInt($$,0);
+ corEmitInt($$,$3->length()); $$->append($3);
+ corEmitInt($$,$5->length()); $$->append($5); }
+ | FIXED_ SYSSTRING_ '[' int32 ']' { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_FIXEDSYSSTRING);
+ corEmitInt($$,$4); }
+ | FIXED_ ARRAY_ '[' int32 ']' nativeType
+ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_FIXEDARRAY);
+ corEmitInt($$,$4); $$->append($6); }
+ | VARIANT_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_VARIANT);
+ PASM->report->warn("Deprecated native type 'variant'\n"); }
+ | CURRENCY_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_CURRENCY); }
+ | SYSCHAR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_SYSCHAR);
+ PASM->report->warn("Deprecated native type 'syschar'\n"); }
+ | VOID_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_VOID);
+ PASM->report->warn("Deprecated native type 'void'\n"); }
+ | BOOL_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_BOOLEAN); }
+ | INT8_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_I1); }
+ | INT16_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_I2); }
+ | INT32_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_I4); }
+ | INT64_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_I8); }
+ | FLOAT32_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_R4); }
+ | FLOAT64_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_R8); }
+ | ERROR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_ERROR); }
+ | UNSIGNED_ INT8_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U1); }
+ | UNSIGNED_ INT16_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U2); }
+ | UNSIGNED_ INT32_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U4); }
+ | UNSIGNED_ INT64_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U8); }
+ | UINT8_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U1); }
+ | UINT16_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U2); }
+ | UINT32_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U4); }
+ | UINT64_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_U8); }
+ | nativeType '*' { $$ = $1; $$->insertInt8(NATIVE_TYPE_PTR);
+ PASM->report->warn("Deprecated native type '*'\n"); }
+ | nativeType '[' ']' { $$ = $1; if($$->length()==0) $$->appendInt8(NATIVE_TYPE_MAX);
+ $$->insertInt8(NATIVE_TYPE_ARRAY); }
+ | nativeType '[' int32 ']' { $$ = $1; if($$->length()==0) $$->appendInt8(NATIVE_TYPE_MAX);
+ $$->insertInt8(NATIVE_TYPE_ARRAY);
+ corEmitInt($$,0);
+ corEmitInt($$,$3);
+ corEmitInt($$,0); }
+ | nativeType '[' int32 '+' int32 ']' { $$ = $1; if($$->length()==0) $$->appendInt8(NATIVE_TYPE_MAX);
+ $$->insertInt8(NATIVE_TYPE_ARRAY);
+ corEmitInt($$,$5);
+ corEmitInt($$,$3);
+ corEmitInt($$,ntaSizeParamIndexSpecified); }
+ | nativeType '[' '+' int32 ']' { $$ = $1; if($$->length()==0) $$->appendInt8(NATIVE_TYPE_MAX);
+ $$->insertInt8(NATIVE_TYPE_ARRAY);
+ corEmitInt($$,$4); }
+ | DECIMAL_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_DECIMAL);
+ PASM->report->warn("Deprecated native type 'decimal'\n"); }
+ | DATE_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_DATE);
+ PASM->report->warn("Deprecated native type 'date'\n"); }
+ | BSTR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_BSTR); }
+ | LPSTR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_LPSTR); }
+ | LPWSTR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_LPWSTR); }
+ | LPTSTR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_LPTSTR); }
+ | OBJECTREF_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_OBJECTREF);
+ PASM->report->warn("Deprecated native type 'objectref'\n"); }
+ | IUNKNOWN_ iidParamIndex { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_IUNKNOWN);
+ if($2 != -1) corEmitInt($$,$2); }
+ | IDISPATCH_ iidParamIndex { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_IDISPATCH);
+ if($2 != -1) corEmitInt($$,$2); }
+ | STRUCT_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_STRUCT); }
+ | INTERFACE_ iidParamIndex { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_INTF);
+ if($2 != -1) corEmitInt($$,$2); }
+ | SAFEARRAY_ variantType { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_SAFEARRAY);
+ corEmitInt($$,$2);
+ corEmitInt($$,0);}
+ | SAFEARRAY_ variantType ',' compQstring { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_SAFEARRAY);
+ corEmitInt($$,$2);
+ corEmitInt($$,$4->length()); $$->append($4); }
+
+ | INT_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_INT); }
+ | UNSIGNED_ INT_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_UINT); }
+ | UINT_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_UINT); }
+ | NESTED_ STRUCT_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_NESTEDSTRUCT);
+ PASM->report->warn("Deprecated native type 'nested struct'\n"); }
+ | BYVALSTR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_BYVALSTR); }
+ | ANSI_ BSTR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_ANSIBSTR); }
+ | TBSTR_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_TBSTR); }
+ | VARIANT_ BOOL_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_VARIANTBOOL); }
+ | METHOD_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_FUNC); }
+ | AS_ ANY_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_ASANY); }
+ | LPSTRUCT_ { $$ = new BinStr(); $$->appendInt8(NATIVE_TYPE_LPSTRUCT); }
+ | TYPEDEF_TS { $$ = new BinStr(); $$->append($1->m_pbsTypeSpec); }
+ ;
+
+iidParamIndex : /* EMPTY */ { $$ = -1; }
+ | '(' IIDPARAM_ '=' int32 ')' { $$ = $4; }
+ ;
+
+variantType : /* EMPTY */ { $$ = VT_EMPTY; }
+ | NULL_ { $$ = VT_NULL; }
+ | VARIANT_ { $$ = VT_VARIANT; }
+ | CURRENCY_ { $$ = VT_CY; }
+ | VOID_ { $$ = VT_VOID; }
+ | BOOL_ { $$ = VT_BOOL; }
+ | INT8_ { $$ = VT_I1; }
+ | INT16_ { $$ = VT_I2; }
+ | INT32_ { $$ = VT_I4; }
+ | INT64_ { $$ = VT_I8; }
+ | FLOAT32_ { $$ = VT_R4; }
+ | FLOAT64_ { $$ = VT_R8; }
+ | UNSIGNED_ INT8_ { $$ = VT_UI1; }
+ | UNSIGNED_ INT16_ { $$ = VT_UI2; }
+ | UNSIGNED_ INT32_ { $$ = VT_UI4; }
+ | UNSIGNED_ INT64_ { $$ = VT_UI8; }
+ | UINT8_ { $$ = VT_UI1; }
+ | UINT16_ { $$ = VT_UI2; }
+ | UINT32_ { $$ = VT_UI4; }
+ | UINT64_ { $$ = VT_UI8; }
+ | '*' { $$ = VT_PTR; }
+ | variantType '[' ']' { $$ = $1 | VT_ARRAY; }
+ | variantType VECTOR_ { $$ = $1 | VT_VECTOR; }
+ | variantType '&' { $$ = $1 | VT_BYREF; }
+ | DECIMAL_ { $$ = VT_DECIMAL; }
+ | DATE_ { $$ = VT_DATE; }
+ | BSTR_ { $$ = VT_BSTR; }
+ | LPSTR_ { $$ = VT_LPSTR; }
+ | LPWSTR_ { $$ = VT_LPWSTR; }
+ | IUNKNOWN_ { $$ = VT_UNKNOWN; }
+ | IDISPATCH_ { $$ = VT_DISPATCH; }
+ | SAFEARRAY_ { $$ = VT_SAFEARRAY; }
+ | INT_ { $$ = VT_INT; }
+ | UNSIGNED_ INT_ { $$ = VT_UINT; }
+ | UINT_ { $$ = VT_UINT; }
+ | ERROR_ { $$ = VT_ERROR; }
+ | HRESULT_ { $$ = VT_HRESULT; }
+ | CARRAY_ { $$ = VT_CARRAY; }
+ | USERDEFINED_ { $$ = VT_USERDEFINED; }
+ | RECORD_ { $$ = VT_RECORD; }
+ | FILETIME_ { $$ = VT_FILETIME; }
+ | BLOB_ { $$ = VT_BLOB; }
+ | STREAM_ { $$ = VT_STREAM; }
+ | STORAGE_ { $$ = VT_STORAGE; }
+ | STREAMED_OBJECT_ { $$ = VT_STREAMED_OBJECT; }
+ | STORED_OBJECT_ { $$ = VT_STORED_OBJECT; }
+ | BLOB_OBJECT_ { $$ = VT_BLOB_OBJECT; }
+ | CF_ { $$ = VT_CF; }
+ | CLSID_ { $$ = VT_CLSID; }
+ ;
+
+/* Managed types for signatures */
+type : CLASS_ className { if($2 == PASM->m_tkSysString)
+ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING); }
+ else if($2 == PASM->m_tkSysObject)
+ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_OBJECT); }
+ else
+ $$ = parser->MakeTypeClass(ELEMENT_TYPE_CLASS, $2); }
+ | OBJECT_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_OBJECT); }
+ | VALUE_ CLASS_ className { $$ = parser->MakeTypeClass(ELEMENT_TYPE_VALUETYPE, $3); }
+ | VALUETYPE_ className { $$ = parser->MakeTypeClass(ELEMENT_TYPE_VALUETYPE, $2); }
+ | type '[' ']' { $$ = $1; $$->insertInt8(ELEMENT_TYPE_SZARRAY); }
+ | type '[' bounds1 ']' { $$ = parser->MakeTypeArray(ELEMENT_TYPE_ARRAY, $1, $3); }
+ | type '&' { $$ = $1; $$->insertInt8(ELEMENT_TYPE_BYREF); }
+ | type '*' { $$ = $1; $$->insertInt8(ELEMENT_TYPE_PTR); }
+ | type PINNED_ { $$ = $1; $$->insertInt8(ELEMENT_TYPE_PINNED); }
+ | type MODREQ_ '(' typeSpec ')' { $$ = parser->MakeTypeClass(ELEMENT_TYPE_CMOD_REQD, $4);
+ $$->append($1); }
+ | type MODOPT_ '(' typeSpec ')' { $$ = parser->MakeTypeClass(ELEMENT_TYPE_CMOD_OPT, $4);
+ $$->append($1); }
+ | methodSpec callConv type '*' '(' sigArgs0 ')'
+ { $$ = parser->MakeSig($2, $3, $6);
+ $$->insertInt8(ELEMENT_TYPE_FNPTR);
+ PASM->delArgNameList(PASM->m_firstArgName);
+ PASM->m_firstArgName = parser->m_ANSFirst.POP();
+ PASM->m_lastArgName = parser->m_ANSLast.POP();
+ }
+ | type '<' tyArgs1 '>' { if($3 == NULL) $$ = $1;
+ else {
+ $$ = new BinStr();
+ $$->appendInt8(ELEMENT_TYPE_GENERICINST);
+ $$->append($1);
+ corEmitInt($$, corCountArgs($3));
+ $$->append($3); delete $1; delete $3; }}
+ | '!' '!' int32 { //if(PASM->m_pCurMethod) {
+ // if(($3 < 0)||((DWORD)$3 >= PASM->m_pCurMethod->m_NumTyPars))
+ // PASM->report->error("Invalid method type parameter '%d'\n",$3);
+ $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_MVAR); corEmitInt($$, $3);
+ //} else PASM->report->error("Method type parameter '%d' outside method scope\n",$3);
+ }
+ | '!' int32 { //if(PASM->m_pCurClass) {
+ // if(($2 < 0)||((DWORD)$2 >= PASM->m_pCurClass->m_NumTyPars))
+ // PASM->report->error("Invalid type parameter '%d'\n",$2);
+ $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_VAR); corEmitInt($$, $2);
+ //} else PASM->report->error("Type parameter '%d' outside class scope\n",$2);
+ }
+ | '!' '!' dottedName { int eltype = ELEMENT_TYPE_MVAR;
+ int n=-1;
+ if(PASM->m_pCurMethod) n = PASM->m_pCurMethod->FindTyPar($3);
+ else {
+ if(PASM->m_TyParList) n = PASM->m_TyParList->IndexOf($3);
+ if(n == -1)
+ { n = TyParFixupList.COUNT();
+ TyParFixupList.PUSH($3);
+ eltype = ELEMENT_TYPE_MVARFIXUP;
+ }
+ }
+ if(n == -1) { PASM->report->error("Invalid method type parameter '%s'\n",$3);
+ n = 0x1FFFFFFF; }
+ $$ = new BinStr(); $$->appendInt8(eltype); corEmitInt($$,n);
+ }
+ | '!' dottedName { int eltype = ELEMENT_TYPE_VAR;
+ int n=-1;
+ if(PASM->m_pCurClass && !newclass) n = PASM->m_pCurClass->FindTyPar($2);
+ else {
+ if(PASM->m_TyParList) n = PASM->m_TyParList->IndexOf($2);
+ if(n == -1)
+ { n = TyParFixupList.COUNT();
+ TyParFixupList.PUSH($2);
+ eltype = ELEMENT_TYPE_VARFIXUP;
+ }
+ }
+ if(n == -1) { PASM->report->error("Invalid type parameter '%s'\n",$2);
+ n = 0x1FFFFFFF; }
+ $$ = new BinStr(); $$->appendInt8(eltype); corEmitInt($$,n);
+ }
+ | TYPEDREF_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_TYPEDBYREF); }
+ | VOID_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_VOID); }
+ | NATIVE_ INT_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I); }
+ | NATIVE_ UNSIGNED_ INT_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U); }
+ | NATIVE_ UINT_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U); }
+ | simpleType { $$ = $1; }
+ | ELIPSIS type { $$ = $2; $$->insertInt8(ELEMENT_TYPE_SENTINEL); }
+ ;
+
+simpleType : CHAR_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_CHAR); }
+ | STRING_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_STRING); }
+ | BOOL_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_BOOLEAN); }
+ | INT8_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I1); }
+ | INT16_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I2); }
+ | INT32_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I4); }
+ | INT64_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_I8); }
+ | FLOAT32_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R4); }
+ | FLOAT64_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_R8); }
+ | UNSIGNED_ INT8_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1); }
+ | UNSIGNED_ INT16_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2); }
+ | UNSIGNED_ INT32_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4); }
+ | UNSIGNED_ INT64_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8); }
+ | UINT8_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U1); }
+ | UINT16_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U2); }
+ | UINT32_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U4); }
+ | UINT64_ { $$ = new BinStr(); $$->appendInt8(ELEMENT_TYPE_U8); }
+ | TYPEDEF_TS { $$ = new BinStr(); $$->append($1->m_pbsTypeSpec); }
+ ;
+
+bounds1 : bound { $$ = $1; }
+ | bounds1 ',' bound { $$ = $1; $1->append($3); delete $3; }
+ ;
+
+bound : /* EMPTY */ { $$ = new BinStr(); $$->appendInt32(0x7FFFFFFF); $$->appendInt32(0x7FFFFFFF); }
+ | ELIPSIS { $$ = new BinStr(); $$->appendInt32(0x7FFFFFFF); $$->appendInt32(0x7FFFFFFF); }
+ | int32 { $$ = new BinStr(); $$->appendInt32(0); $$->appendInt32($1); }
+ | int32 ELIPSIS int32 { FAIL_UNLESS($1 <= $3, ("lower bound %d must be <= upper bound %d\n", $1, $3));
+ if ($1 > $3) { YYERROR; };
+ $$ = new BinStr(); $$->appendInt32($1); $$->appendInt32($3-$1+1); }
+ | int32 ELIPSIS { $$ = new BinStr(); $$->appendInt32($1); $$->appendInt32(0x7FFFFFFF); }
+ ;
+
+/* Security declarations */
+secDecl : _PERMISSION secAction typeSpec '(' nameValPairs ')'
+ { PASM->AddPermissionDecl($2, $3, $5); }
+ | _PERMISSION secAction typeSpec '=' '{' customBlobDescr '}'
+ { PASM->AddPermissionDecl($2, $3, $6); }
+ | _PERMISSION secAction typeSpec { PASM->AddPermissionDecl($2, $3, (NVPair *)NULL); }
+ | psetHead bytes ')' { PASM->AddPermissionSetDecl($1, $2); }
+ | _PERMISSIONSET secAction compQstring
+ { PASM->AddPermissionSetDecl($2,BinStrToUnicode($3,true));}
+ | _PERMISSIONSET secAction '=' '{' secAttrSetBlob '}'
+ { BinStr* ret = new BinStr();
+ ret->insertInt8('.');
+ corEmitInt(ret, nSecAttrBlobs);
+ ret->append($5);
+ PASM->AddPermissionSetDecl($2,ret);
+ nSecAttrBlobs = 0; }
+ ;
+
+secAttrSetBlob : /* EMPTY */ { $$ = new BinStr(); nSecAttrBlobs = 0;}
+ | secAttrBlob { $$ = $1; nSecAttrBlobs = 1; }
+ | secAttrBlob ',' secAttrSetBlob { $$ = $1; $$->append($3); nSecAttrBlobs++; }
+ ;
+
+secAttrBlob : typeSpec '=' '{' customBlobNVPairs '}'
+ { $$ = PASM->EncodeSecAttr(PASM->ReflectionNotation($1),$4,nCustomBlobNVPairs);
+ nCustomBlobNVPairs = 0; }
+ | CLASS_ SQSTRING '=' '{' customBlobNVPairs '}'
+ { $$ = PASM->EncodeSecAttr($2,$5,nCustomBlobNVPairs);
+ nCustomBlobNVPairs = 0; }
+ ;
+
+psetHead : _PERMISSIONSET secAction '=' '(' { $$ = $2; bParsingByteArray = TRUE; }
+ | _PERMISSIONSET secAction BYTEARRAY_ '('
+ { $$ = $2; bParsingByteArray = TRUE; }
+ ;
+
+nameValPairs : nameValPair { $$ = $1; }
+ | nameValPair ',' nameValPairs { $$ = $1->Concat($3); }
+ ;
+
+nameValPair : compQstring '=' caValue { $1->appendInt8(0); $$ = new NVPair($1, $3); }
+ ;
+
+truefalse : TRUE_ { $$ = 1; }
+ | FALSE_ { $$ = 0; }
+ ;
+
+caValue : truefalse { $$ = new BinStr();
+ $$->appendInt8(SERIALIZATION_TYPE_BOOLEAN);
+ $$->appendInt8($1); }
+ | int32 { $$ = new BinStr();
+ $$->appendInt8(SERIALIZATION_TYPE_I4);
+ $$->appendInt32($1); }
+ | INT32_ '(' int32 ')' { $$ = new BinStr();
+ $$->appendInt8(SERIALIZATION_TYPE_I4);
+ $$->appendInt32($3); }
+ | compQstring { $$ = new BinStr();
+ $$->appendInt8(SERIALIZATION_TYPE_STRING);
+ $$->append($1); delete $1;
+ $$->appendInt8(0); }
+ | className '(' INT8_ ':' int32 ')' { $$ = new BinStr();
+ $$->appendInt8(SERIALIZATION_TYPE_ENUM);
+ char* sz = PASM->ReflectionNotation($1);
+ strcpy_s((char *)$$->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
+ $$->appendInt8(1);
+ $$->appendInt32($5); }
+ | className '(' INT16_ ':' int32 ')' { $$ = new BinStr();
+ $$->appendInt8(SERIALIZATION_TYPE_ENUM);
+ char* sz = PASM->ReflectionNotation($1);
+ strcpy_s((char *)$$->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
+ $$->appendInt8(2);
+ $$->appendInt32($5); }
+ | className '(' INT32_ ':' int32 ')' { $$ = new BinStr();
+ $$->appendInt8(SERIALIZATION_TYPE_ENUM);
+ char* sz = PASM->ReflectionNotation($1);
+ strcpy_s((char *)$$->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
+ $$->appendInt8(4);
+ $$->appendInt32($5); }
+ | className '(' int32 ')' { $$ = new BinStr();
+ $$->appendInt8(SERIALIZATION_TYPE_ENUM);
+ char* sz = PASM->ReflectionNotation($1);
+ strcpy_s((char *)$$->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
+ $$->appendInt8(4);
+ $$->appendInt32($3); }
+ ;
+
+secAction : REQUEST_ { $$ = dclRequest; }
+ | DEMAND_ { $$ = dclDemand; }
+ | ASSERT_ { $$ = dclAssert; }
+ | DENY_ { $$ = dclDeny; }
+ | PERMITONLY_ { $$ = dclPermitOnly; }
+ | LINKCHECK_ { $$ = dclLinktimeCheck; }
+ | INHERITCHECK_ { $$ = dclInheritanceCheck; }
+ | REQMIN_ { $$ = dclRequestMinimum; }
+ | REQOPT_ { $$ = dclRequestOptional; }
+ | REQREFUSE_ { $$ = dclRequestRefuse; }
+ | PREJITGRANT_ { $$ = dclPrejitGrant; }
+ | PREJITDENY_ { $$ = dclPrejitDenied; }
+ | NONCASDEMAND_ { $$ = dclNonCasDemand; }
+ | NONCASLINKDEMAND_ { $$ = dclNonCasLinkDemand; }
+ | NONCASINHERITANCE_ { $$ = dclNonCasInheritance; }
+ ;
+
+/* External source declarations */
+esHead : _LINE { PASM->ResetLineNumbers(); nCurrPC = PASM->m_CurPC; PENV->bExternSource = TRUE; PENV->bExternSourceAutoincrement = FALSE; }
+ | P_LINE { PASM->ResetLineNumbers(); nCurrPC = PASM->m_CurPC; PENV->bExternSource = TRUE; PENV->bExternSourceAutoincrement = TRUE; }
+ ;
+
+extSourceSpec : esHead int32 SQSTRING { PENV->nExtLine = PENV->nExtLineEnd = $2;
+ PENV->nExtCol = 0; PENV->nExtColEnd = static_cast<unsigned>(-1);
+ PASM->SetSourceFileName($3);}
+ | esHead int32 { PENV->nExtLine = PENV->nExtLineEnd = $2;
+ PENV->nExtCol = 0; PENV->nExtColEnd = static_cast<unsigned>(-1); }
+ | esHead int32 ':' int32 SQSTRING { PENV->nExtLine = PENV->nExtLineEnd = $2;
+ PENV->nExtCol=$4; PENV->nExtColEnd = static_cast<unsigned>(-1);
+ PASM->SetSourceFileName($5);}
+ | esHead int32 ':' int32 { PENV->nExtLine = PENV->nExtLineEnd = $2;
+ PENV->nExtCol=$4; PENV->nExtColEnd = static_cast<unsigned>(-1);}
+ | esHead int32 ':' int32 ',' int32 SQSTRING
+ { PENV->nExtLine = PENV->nExtLineEnd = $2;
+ PENV->nExtCol=$4; PENV->nExtColEnd = $6;
+ PASM->SetSourceFileName($7);}
+ | esHead int32 ':' int32 ',' int32
+ { PENV->nExtLine = PENV->nExtLineEnd = $2;
+ PENV->nExtCol=$4; PENV->nExtColEnd = $6; }
+ | esHead int32 ',' int32 ':' int32 SQSTRING
+ { PENV->nExtLine = $2; PENV->nExtLineEnd = $4;
+ PENV->nExtCol=$6; PENV->nExtColEnd = static_cast<unsigned>(-1);
+ PASM->SetSourceFileName($7);}
+ | esHead int32 ',' int32 ':' int32
+ { PENV->nExtLine = $2; PENV->nExtLineEnd = $4;
+ PENV->nExtCol=$6; PENV->nExtColEnd = static_cast<unsigned>(-1); }
+ | esHead int32 ',' int32 ':' int32 ',' int32 SQSTRING
+ { PENV->nExtLine = $2; PENV->nExtLineEnd = $4;
+ PENV->nExtCol=$6; PENV->nExtColEnd = $8;
+ PASM->SetSourceFileName($9);}
+ | esHead int32 ',' int32 ':' int32 ',' int32
+ { PENV->nExtLine = $2; PENV->nExtLineEnd = $4;
+ PENV->nExtCol=$6; PENV->nExtColEnd = $8; }
+ | esHead int32 QSTRING { PENV->nExtLine = PENV->nExtLineEnd = $2 - 1;
+ PENV->nExtCol = 0; PENV->nExtColEnd = static_cast<unsigned>(-1);
+ PASM->SetSourceFileName($3);}
+ ;
+
+/* Manifest declarations */
+fileDecl : _FILE fileAttr dottedName fileEntry hashHead bytes ')' fileEntry
+ { PASMM->AddFile($3, $2|$4|$8, $6); }
+ | _FILE fileAttr dottedName fileEntry { PASMM->AddFile($3, $2|$4, NULL); }
+ ;
+
+fileAttr : /* EMPTY */ { $$ = (CorFileFlags) 0; }
+ | fileAttr NOMETADATA_ { $$ = (CorFileFlags) ($1 | ffContainsNoMetaData); }
+ ;
+
+fileEntry : /* EMPTY */ { $$ = (CorFileFlags) 0; }
+ | _ENTRYPOINT { $$ = (CorFileFlags) 0x80000000; }
+ ;
+
+hashHead : _HASH '=' '(' { bParsingByteArray = TRUE; }
+ ;
+
+assemblyHead : _ASSEMBLY asmAttr dottedName { PASMM->StartAssembly($3, NULL, (DWORD)$2, FALSE); }
+ ;
+
+asmAttr : /* EMPTY */ { $$ = (CorAssemblyFlags) 0; }
+ | asmAttr RETARGETABLE_ { $$ = (CorAssemblyFlags) ($1 | afRetargetable); }
+ | asmAttr WINDOWSRUNTIME_ { $$ = (CorAssemblyFlags) ($1 | afContentType_WindowsRuntime); }
+ | asmAttr NOPLATFORM_ { $$ = (CorAssemblyFlags) ($1 | afPA_NoPlatform); }
+ | asmAttr LEGACY_ LIBRARY_ { $$ = $1; }
+ | asmAttr CIL_ { SET_PA($$,$1,afPA_MSIL); }
+ | asmAttr X86_ { SET_PA($$,$1,afPA_x86); }
+ | asmAttr IA64_ { SET_PA($$,$1,afPA_IA64); }
+ | asmAttr AMD64_ { SET_PA($$,$1,afPA_AMD64); }
+ | asmAttr ARM_ { SET_PA($$,$1,afPA_ARM); }
+ ;
+
+assemblyDecls : /* EMPTY */
+ | assemblyDecls assemblyDecl
+ ;
+
+assemblyDecl : _HASH ALGORITHM_ int32 { PASMM->SetAssemblyHashAlg($3); }
+ | secDecl
+ | asmOrRefDecl
+ ;
+
+intOrWildcard : int32 { $$ = $1; }
+ | '*' { $$ = 0xFFFF; }
+ ;
+
+asmOrRefDecl : publicKeyHead bytes ')' { PASMM->SetAssemblyPublicKey($2); }
+ | _VER intOrWildcard ':' intOrWildcard ':' intOrWildcard ':' intOrWildcard
+ { PASMM->SetAssemblyVer((USHORT)$2, (USHORT)$4, (USHORT)$6, (USHORT)$8); }
+ | _LOCALE compQstring { $2->appendInt8(0); PASMM->SetAssemblyLocale($2,TRUE); }
+ | localeHead bytes ')' { PASMM->SetAssemblyLocale($2,FALSE); }
+ | customAttrDecl
+ | compControl
+ ;
+
+publicKeyHead : _PUBLICKEY '=' '(' { bParsingByteArray = TRUE; }
+ ;
+
+publicKeyTokenHead : _PUBLICKEYTOKEN '=' '(' { bParsingByteArray = TRUE; }
+ ;
+
+localeHead : _LOCALE '=' '(' { bParsingByteArray = TRUE; }
+ ;
+
+assemblyRefHead : _ASSEMBLY EXTERN_ asmAttr dottedName
+ { PASMM->StartAssembly($4, NULL, $3, TRUE); }
+ | _ASSEMBLY EXTERN_ asmAttr dottedName AS_ dottedName
+ { PASMM->StartAssembly($4, $6, $3, TRUE); }
+ ;
+
+assemblyRefDecls : /* EMPTY */
+ | assemblyRefDecls assemblyRefDecl
+ ;
+
+assemblyRefDecl : hashHead bytes ')' { PASMM->SetAssemblyHashBlob($2); }
+ | asmOrRefDecl
+ | publicKeyTokenHead bytes ')' { PASMM->SetAssemblyPublicKeyToken($2); }
+ | AUTO_ { PASMM->SetAssemblyAutodetect(); }
+ ;
+
+exptypeHead : _CLASS EXTERN_ exptAttr dottedName { PASMM->StartComType($4, $3);}
+ ;
+
+exportHead : _EXPORT exptAttr dottedName /* deprecated */ { PASMM->StartComType($3, $2); }
+ ;
+
+exptAttr : /* EMPTY */ { $$ = (CorTypeAttr) 0; }
+ | exptAttr PRIVATE_ { $$ = (CorTypeAttr) ($1 | tdNotPublic); }
+ | exptAttr PUBLIC_ { $$ = (CorTypeAttr) ($1 | tdPublic); }
+ | exptAttr FORWARDER_ { $$ = (CorTypeAttr) ($1 | tdForwarder); }
+ | exptAttr NESTED_ PUBLIC_ { $$ = (CorTypeAttr) ($1 | tdNestedPublic); }
+ | exptAttr NESTED_ PRIVATE_ { $$ = (CorTypeAttr) ($1 | tdNestedPrivate); }
+ | exptAttr NESTED_ FAMILY_ { $$ = (CorTypeAttr) ($1 | tdNestedFamily); }
+ | exptAttr NESTED_ ASSEMBLY_ { $$ = (CorTypeAttr) ($1 | tdNestedAssembly); }
+ | exptAttr NESTED_ FAMANDASSEM_ { $$ = (CorTypeAttr) ($1 | tdNestedFamANDAssem); }
+ | exptAttr NESTED_ FAMORASSEM_ { $$ = (CorTypeAttr) ($1 | tdNestedFamORAssem); }
+ ;
+
+exptypeDecls : /* EMPTY */
+ | exptypeDecls exptypeDecl
+ ;
+
+exptypeDecl : _FILE dottedName { PASMM->SetComTypeFile($2); }
+ | _CLASS EXTERN_ slashedName { PASMM->SetComTypeComType($3); }
+ | _ASSEMBLY EXTERN_ dottedName { PASMM->SetComTypeAsmRef($3); }
+ | MDTOKEN_ '(' int32 ')' { if(!PASMM->SetComTypeImplementationTok($3))
+ PASM->report->error("Invalid implementation of exported type\n"); }
+ | _CLASS int32 { if(!PASMM->SetComTypeClassTok($2))
+ PASM->report->error("Invalid TypeDefID of exported type\n"); }
+ | customAttrDecl
+ | compControl
+ ;
+
+manifestResHead : _MRESOURCE manresAttr dottedName { PASMM->StartManifestRes($3, $3, $2); }
+ | _MRESOURCE manresAttr dottedName AS_ dottedName
+ { PASMM->StartManifestRes($3, $5, $2); }
+ ;
+
+manresAttr : /* EMPTY */ { $$ = (CorManifestResourceFlags) 0; }
+ | manresAttr PUBLIC_ { $$ = (CorManifestResourceFlags) ($1 | mrPublic); }
+ | manresAttr PRIVATE_ { $$ = (CorManifestResourceFlags) ($1 | mrPrivate); }
+ ;
+
+manifestResDecls : /* EMPTY */
+ | manifestResDecls manifestResDecl
+ ;
+
+manifestResDecl : _FILE dottedName AT_ int32 { PASMM->SetManifestResFile($2, (ULONG)$4); }
+ | _ASSEMBLY EXTERN_ dottedName { PASMM->SetManifestResAsmRef($3); }
+ | customAttrDecl
+ | compControl
+ ;
+
+
+%%
+
+#include "grammar_after.cpp"
diff --git a/src/ilasm/asmtemplates.h b/src/ilasm/asmtemplates.h
new file mode 100644
index 0000000000..eb2b413abf
--- /dev/null
+++ b/src/ilasm/asmtemplates.h
@@ -0,0 +1,845 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#ifndef ASMTEMPLATES_H
+#define ASMTEMPLATES_H
+
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:22008) // "Suppress PREfast warnings about integer overflow"
+#endif
+
+inline ULONG GrowBuffer(ULONG startingSize)
+{
+ int toAdd = startingSize >> 1;
+ if (toAdd < 8)
+ toAdd = 8;
+ if (toAdd > 2048)
+ toAdd = 2048;
+ return startingSize + toAdd;
+}
+
+/*****************************************************************************/
+/* LIFO (stack) and FIFO (queue) templates (must precede #include "method.h")*/
+template <class T>
+class LIST_EL
+{
+public:
+ T* m_Ptr;
+ LIST_EL <T> *m_Next;
+ LIST_EL(T *item) {m_Next = NULL; m_Ptr = item; };
+};
+
+template <class T>
+class LIFO
+{
+public:
+ inline LIFO() { m_pHead = NULL; };
+ inline ~LIFO() {T *val; while((val = POP()) != NULL) delete val; };
+ void PUSH(T *item)
+ {
+ m_pTemp = new LIST_EL <T>(item);
+ m_pTemp->m_Next = m_pHead;
+ m_pHead = m_pTemp;
+ };
+ T* POP()
+ {
+ T* ret = NULL;
+ if((m_pTemp = m_pHead) != NULL)
+ {
+ m_pHead = m_pHead->m_Next;
+ ret = m_pTemp->m_Ptr;
+ delete m_pTemp;
+ }
+ return ret;
+ };
+private:
+ LIST_EL <T> *m_pHead;
+ LIST_EL <T> *m_pTemp;
+};
+
+
+#if (0)
+template <class T>
+class FIFO
+{
+public:
+ inline FIFO() { m_pHead = m_pTail = NULL; m_ulCount = 0;};
+ inline ~FIFO() {T *val; while(val = POP()) delete val; };
+ void PUSH(T *item)
+ {
+ m_pTemp = new LIST_EL <T>(item);
+ if(m_pTail) m_pTail->m_Next = m_pTemp;
+ m_pTail = m_pTemp;
+ if(m_pHead == NULL) m_pHead = m_pTemp;
+ m_ulCount++;
+ };
+ T* POP()
+ {
+ T* ret = NULL;
+ if(m_pTemp = m_pHead)
+ {
+ m_pHead = m_pHead->m_Next;
+ ret = m_pTemp->m_Ptr;
+ delete m_pTemp;
+ if(m_pHead == NULL) m_pTail = NULL;
+ m_ulCount--;
+ }
+ return ret;
+ };
+ ULONG COUNT() { return m_ulCount; };
+ T* PEEK(ULONG idx)
+ {
+ T* ret = NULL;
+ ULONG i;
+ if(idx < m_ulCount)
+ {
+ if(idx == m_ulCount-1) m_pTemp = m_pTail;
+ else for(m_pTemp = m_pHead, i = 0; i < idx; m_pTemp = m_pTemp->m_Next, i++);
+ ret = m_pTemp->m_Ptr;
+ }
+ return ret;
+ };
+private:
+ LIST_EL <T> *m_pHead;
+ LIST_EL <T> *m_pTail;
+ LIST_EL <T> *m_pTemp;
+ ULONG m_ulCount;
+};
+#else
+template <class T>
+class FIFO
+{
+public:
+ FIFO() { m_Arr = NULL; m_ulArrLen = 0; m_ulCount = 0; m_ulOffset = 0; };
+ ~FIFO() {
+ if(m_Arr) {
+ for(ULONG i=0; i < m_ulCount; i++) {
+ if(m_Arr[i+m_ulOffset]) delete m_Arr[i+m_ulOffset];
+ }
+ delete [] m_Arr;
+ }
+ };
+ void RESET(bool DeleteElements = true) {
+ if(m_Arr) {
+ for(ULONG i=0; i < m_ulCount; i++) {
+ if(DeleteElements) delete m_Arr[i+m_ulOffset];
+ m_Arr[i+m_ulOffset] = NULL;
+ }
+ m_ulCount = 0;
+ m_ulOffset= 0;
+ }
+ };
+ void PUSH(T *item)
+ {
+ if(item)
+ {
+ if(m_ulCount+m_ulOffset >= m_ulArrLen)
+ {
+ if(m_ulOffset)
+ {
+ memcpy(m_Arr,&m_Arr[m_ulOffset],m_ulCount*sizeof(T*));
+ m_ulOffset = 0;
+ }
+ else
+ {
+ m_ulArrLen = GrowBuffer(m_ulArrLen);
+ T** tmp = new T*[m_ulArrLen];
+ if(tmp)
+ {
+ if(m_Arr)
+ {
+ memcpy(tmp,m_Arr,m_ulCount*sizeof(T*));
+ delete [] m_Arr;
+ }
+ m_Arr = tmp;
+ }
+ else fprintf(stderr,"\nOut of memory!\n");
+ }
+ }
+ m_Arr[m_ulOffset+m_ulCount] = item;
+ m_ulCount++;
+ }
+ };
+ ULONG COUNT() { return m_ulCount; };
+ T* POP()
+ {
+ T* ret = NULL;
+ if(m_ulCount)
+ {
+ ret = m_Arr[m_ulOffset++];
+ m_ulCount--;
+ }
+ return ret;
+ };
+ T* PEEK(ULONG idx) { return (idx < m_ulCount) ? m_Arr[m_ulOffset+idx] : NULL; };
+private:
+ T** m_Arr;
+ ULONG m_ulCount;
+ ULONG m_ulOffset;
+ ULONG m_ulArrLen;
+};
+#endif
+
+
+template <class T> struct Indx256
+{
+ void* table[256];
+ Indx256() { memset(table,0,sizeof(table)); };
+ ~Indx256()
+ {
+ ClearAll(true);
+ for(int i = 1; i < 256; i++) delete ((Indx256*)(table[i]));
+ };
+ T** IndexString(BYTE* psz, T* pObj)
+ {
+ if(*psz == 0)
+ {
+ table[0] = (void*)pObj;
+ return (T**)table;
+ }
+ else
+ {
+ Indx256* pInd = (Indx256*)(table[*psz]);
+ if(pInd == NULL)
+ {
+ pInd = new Indx256;
+ if(pInd)
+ table[*psz] = pInd;
+ else
+ {
+ _ASSERTE(!"Out of memory in Indx256::IndexString!");
+ fprintf(stderr,"\nOut of memory in Indx256::IndexString!\n");
+ return NULL;
+ }
+ }
+ return pInd->IndexString(psz+1,pObj);
+ }
+ };
+ T* FindString(BYTE* psz)
+ {
+ if(*psz > 0)
+ {
+ Indx256* pInd = (Indx256*)(table[*psz]);
+ return (pInd == NULL) ? NULL : pInd->FindString(psz+1);
+ }
+ return (T*)(table[0]); // if i==0
+ };
+
+ void ClearAll(bool DeleteObj)
+ {
+ if(DeleteObj) delete (T*)(table[0]);
+ table[0] = NULL;
+ for(unsigned i = 1; i < 256; i++)
+ {
+ if(table[i])
+ {
+ Indx256* pInd = (Indx256*)(table[i]);
+ pInd->ClearAll(DeleteObj);
+ //delete pInd;
+ //table[i] = NULL;
+ }
+ }
+ };
+};
+
+//
+// Template intended for named objects, that expose function char* NameOf()
+//
+template <class T>
+class FIFO_INDEXED
+{
+public:
+ FIFO_INDEXED() { m_Arr = NULL; m_ulArrLen = 0; m_ulCount = 0; m_ulOffset = 0; };
+ ~FIFO_INDEXED() {
+ if(m_Arr)
+ {
+ RESET(true);
+ delete [] m_Arr;
+ }
+ };
+ void RESET(bool DeleteElements = true) {
+ if(m_Arr) {
+ unsigned i;
+ if(DeleteElements)
+ {
+ for(i=m_ulOffset; i < m_ulOffset+m_ulCount; i++)
+ {
+ T** ppT = m_Arr[i];
+ delete *ppT;
+ }
+ }
+ for(i=m_ulOffset; i < m_ulOffset+m_ulCount; i++)
+ {
+ *m_Arr[i] = NULL;
+ }
+ memset(&m_Arr[m_ulOffset],0,m_ulCount*sizeof(void*));
+ m_ulCount = 0;
+ m_ulOffset= 0;
+ }
+ };
+ void PUSH(T *item)
+ {
+ if(item)
+ {
+ T** itemaddr = m_Index.IndexString((BYTE*)(item->NameOf()),item);
+ if(m_ulCount+m_ulOffset >= m_ulArrLen)
+ {
+ if(m_ulOffset)
+ {
+ memcpy(m_Arr,&m_Arr[m_ulOffset],m_ulCount*sizeof(T*));
+ m_ulOffset = 0;
+ }
+ else
+ {
+ m_ulArrLen = GrowBuffer(m_ulArrLen);
+ T*** tmp = new T**[m_ulArrLen];
+ if(tmp)
+ {
+ if(m_Arr)
+ {
+ memcpy(tmp,m_Arr,m_ulCount*sizeof(T**));
+ delete [] m_Arr;
+ }
+ m_Arr = tmp;
+ }
+ else fprintf(stderr,"\nOut of memory!\n");
+ }
+ }
+ m_Arr[m_ulOffset+m_ulCount] = itemaddr;
+ m_ulCount++;
+ }
+ };
+ ULONG COUNT() { return m_ulCount; };
+ T* POP()
+ {
+ T* ret = NULL;
+ if(m_ulCount)
+ {
+ ret = *(m_Arr[m_ulOffset]);
+ *m_Arr[m_ulOffset] = NULL;
+ m_ulOffset++;
+ m_ulCount--;
+ }
+ return ret;
+ };
+ T* PEEK(ULONG idx) { return (idx < m_ulCount) ? *(m_Arr[m_ulOffset+idx]) : NULL; };
+ T* FIND(T* item) { return m_Index.FindString((BYTE*)(item->NameOf())); };
+private:
+ T*** m_Arr;
+ ULONG m_ulCount;
+ ULONG m_ulOffset;
+ ULONG m_ulArrLen;
+ Indx256<T> m_Index;
+};
+
+template <class T>
+class SORTEDARRAY
+{
+public:
+ SORTEDARRAY() { m_Arr = NULL; m_ulArrLen = 0; m_ulCount = 0; m_ulOffset = 0; };
+ ~SORTEDARRAY() {
+ if(m_Arr) {
+ for(ULONG i=0; i < m_ulCount; i++) {
+ if(m_Arr[i+m_ulOffset]) delete m_Arr[i+m_ulOffset];
+ }
+ delete [] m_Arr;
+ }
+ };
+ void RESET(bool DeleteElements = true) {
+ if(m_Arr) {
+ if(DeleteElements)
+ {
+ for(ULONG i=0; i < m_ulCount; i++) {
+ delete m_Arr[i+m_ulOffset];
+ }
+ }
+ memset(m_Arr,0,m_ulArrLen*sizeof(T*));
+ m_ulCount = 0;
+ m_ulOffset= 0;
+ }
+ };
+ void PUSH(T *item)
+ {
+ if(item)
+ {
+ if(m_ulCount+m_ulOffset >= m_ulArrLen)
+ {
+ if(m_ulOffset)
+ {
+ memcpy(m_Arr,&m_Arr[m_ulOffset],m_ulCount*sizeof(T*));
+ m_ulOffset = 0;
+ }
+ else
+ {
+ m_ulArrLen = GrowBuffer(m_ulArrLen);
+ T** tmp = new T*[m_ulArrLen];
+ if(tmp)
+ {
+ if(m_Arr)
+ {
+ memcpy(tmp,m_Arr,m_ulCount*sizeof(T*));
+ delete [] m_Arr;
+ }
+ m_Arr = tmp;
+ }
+ else fprintf(stderr,"\nOut of memory!\n");
+ }
+ }
+ if(m_ulCount)
+ {
+ // find 1st arr.element > item
+ T** low = &m_Arr[m_ulOffset];
+ T** high = &m_Arr[m_ulOffset+m_ulCount-1];
+ T** mid;
+
+ if(item->ComparedTo(*high) > 0) mid = high+1;
+ else if(item->ComparedTo(*low) < 0) mid = low;
+ else for(;;)
+ {
+ mid = &low[(high - low) >> 1];
+
+ int cmp = item->ComparedTo(*mid);
+
+ if (mid == low)
+ {
+ if(cmp > 0) mid++;
+ break;
+ }
+
+ if (cmp > 0) low = mid;
+ else high = mid;
+ }
+
+ /////////////////////////////////////////////
+ memmove(mid+1,mid,(BYTE*)&m_Arr[m_ulOffset+m_ulCount]-(BYTE*)mid);
+ *mid = item;
+ }
+ else m_Arr[m_ulOffset+m_ulCount] = item;
+ m_ulCount++;
+ }
+ };
+ ULONG COUNT() { return m_ulCount; };
+ T* POP()
+ {
+ T* ret = NULL;
+ if(m_ulCount)
+ {
+ ret = m_Arr[m_ulOffset++];
+ m_ulCount--;
+ }
+ return ret;
+ };
+ T* PEEK(ULONG idx) { return (idx < m_ulCount) ? m_Arr[m_ulOffset+idx] : NULL; };
+ T* FIND(T* item)
+ {
+ if(m_ulCount)
+ {
+ T** low = &m_Arr[m_ulOffset];
+ T** high = &m_Arr[m_ulOffset+m_ulCount-1];
+ T** mid;
+ if(item->ComparedTo(*high) == 0) return(*high);
+ for(;;)
+ {
+ mid = &low[(high - low) >> 1];
+ int cmp = item->ComparedTo(*mid);
+ if (cmp == 0) return(*mid);
+ if (mid == low) break;
+ if (cmp > 0) low = mid;
+ else high = mid;
+ }
+ }
+ return NULL;
+ };
+ /*
+ T* FIND(U item)
+ {
+ if(m_ulCount)
+ {
+ T** low = &m_Arr[m_ulOffset];
+ T** high = &m_Arr[m_ulOffset+m_ulCount-1];
+ T** mid;
+ if((*high)->Compare(item) == 0) return(*high);
+ for(;;)
+ {
+ mid = &low[(high - low) >> 1];
+ int cmp = (*mid)->Compare(item);
+ if (cmp == 0) return(*mid);
+ if (mid == low) break;
+ if (cmp > 0) low = mid;
+ else high = mid;
+ }
+ }
+ return NULL;
+ };
+ */
+ BOOL DEL(T* item)
+ {
+ if(m_ulCount)
+ {
+ T** low = &m_Arr[m_ulOffset];
+ T** high = &m_Arr[m_ulOffset+m_ulCount-1];
+ T** mid;
+ if(item->ComparedTo(*high) == 0)
+ {
+ delete (*high);
+ m_ulCount--;
+ return TRUE;
+ }
+ for(;;)
+ {
+ mid = &low[(high - low) >> 1];
+ int cmp = item->ComparedTo(*mid);
+ if (cmp == 0)
+ {
+ delete (*mid);
+ memcpy(mid,mid+1,(BYTE*)&m_Arr[m_ulOffset+m_ulCount]-(BYTE*)mid-1);
+ m_ulCount--;
+ return TRUE;
+ }
+ if (mid == low) break;
+ if (cmp > 0) low = mid;
+ else high = mid;
+ }
+ }
+ return FALSE;
+ };
+private:
+ T** m_Arr;
+ ULONG m_ulCount;
+ ULONG m_ulOffset;
+ ULONG m_ulArrLen;
+};
+
+template <class T> struct RBNODE
+{
+private:
+ DWORD dwRed;
+public:
+ DWORD dwInUse;
+ T* tVal;
+ RBNODE<T>* pLeft;
+ RBNODE<T>* pRight;
+ RBNODE<T>* pParent;
+ RBNODE()
+ {
+ pLeft = pRight = pParent = NULL;
+ tVal = NULL;
+ dwRed = dwInUse = 0;
+ };
+ RBNODE(T* pVal, DWORD dwColor)
+ {
+ pLeft = pRight = pParent = NULL;
+ tVal = pVal;
+ dwRed = dwColor;
+ dwInUse = 0;
+ };
+ bool IsRed() { return (dwRed != 0); };
+ void SetRed() { dwRed = 1; };
+ void SetBlack() { dwRed = 0; };
+};
+
+#define BUCKETCOUNT 512
+
+template <class T> class RBNODEBUCKET
+{
+private:
+ RBNODEBUCKET<T>* pNext;
+ RBNODE<T> bucket[BUCKETCOUNT];
+ unsigned alloc_count;
+
+public:
+ RBNODEBUCKET()
+ {
+ alloc_count = 0;
+ pNext = NULL;
+ };
+
+ ~RBNODEBUCKET() { if(pNext) delete pNext; };
+
+ bool CanAlloc() { return (alloc_count < BUCKETCOUNT); };
+
+ RBNODE<T>* AllocNode()
+ {
+ RBNODE<T>* pRet;
+ for(unsigned i = 0; i < BUCKETCOUNT; i++)
+ {
+ if(bucket[i].dwInUse == 0)
+ {
+ alloc_count++;
+ pRet = &bucket[i];
+ memset(pRet, 0, sizeof(RBNODE<T>));
+ pRet->dwInUse = 1;
+ return pRet;
+ }
+ }
+ _ASSERTE(!"AllocNode returns NULL");
+ return NULL;
+ };
+
+ bool FreeNode(RBNODE<T>* ptr)
+ {
+ size_t idx = ((size_t)ptr - (size_t)bucket)/sizeof(RBNODE<T>);
+ if(idx < BUCKETCOUNT)
+ {
+ bucket[idx].dwInUse = 0;
+ alloc_count--;
+ return true;
+ }
+ return false;
+ };
+
+ RBNODEBUCKET<T>* Next() { return pNext; };
+
+ void Append(RBNODEBUCKET<T>* ptr) { pNext = ptr; };
+};
+
+template <class T> class RBNODEPOOL
+{
+private:
+ RBNODEBUCKET<T> base;
+
+public:
+ RBNODEPOOL()
+ {
+ memset(&base,0,sizeof(RBNODEBUCKET<T>));
+ };
+
+ RBNODE<T>* AllocNode()
+ {
+ RBNODEBUCKET<T>* pBucket = &base;
+ RBNODEBUCKET<T>* pLastBucket = &base;
+ do
+ {
+ if(pBucket->CanAlloc())
+ {
+ return pBucket->AllocNode();
+ }
+ pLastBucket = pBucket;
+ pBucket = pBucket->Next();
+ }
+ while (pBucket != NULL);
+ pLastBucket->Append(new RBNODEBUCKET<T>);
+ return pLastBucket->Next()->AllocNode();
+ };
+
+ void FreeNode(RBNODE<T>* ptr)
+ {
+ RBNODEBUCKET<T>* pBucket = &base;
+ do
+ {
+ if(pBucket->FreeNode(ptr))
+ break;
+ pBucket = pBucket->Next();
+ }
+ while (pBucket != NULL);
+ };
+};
+
+template <class T> class RBTREE
+{
+private:
+ RBNODE<T>* pRoot;
+ RBNODE<T>* pNil;
+ RBNODEPOOL<T> NodePool;
+ void RotateLeft(RBNODE<T>* pX)
+ {
+ RBNODE<T>* pY;
+
+ pY = pX->pRight;
+ pX->pRight = pY->pLeft;
+
+ if(pY->pLeft != pNil)
+ pY->pLeft->pParent = pX;
+
+ pY->pParent = pX->pParent;
+
+ if(pX == pX->pParent->pLeft)
+ pX->pParent->pLeft = pY;
+ else
+ pX->pParent->pRight = pY;
+
+ pY->pLeft = pX;
+ pX->pParent = pY;
+ };
+
+ void RotateRight(RBNODE<T>* pX)
+ {
+ RBNODE<T>* pY;
+
+ pY = pX->pLeft;
+ pX->pLeft = pY->pRight;
+
+ if(pY->pRight != pNil)
+ pY->pRight->pParent = pX;
+
+ pY->pParent = pX->pParent;
+
+ if(pX == pX->pParent->pLeft)
+ pX->pParent->pLeft = pY;
+ else
+ pX->pParent->pRight = pY;
+
+ pY->pRight = pX;
+ pX->pParent = pY;
+
+ };
+
+ void InsertNode(RBNODE<T>* pZ)
+ {
+ RBNODE<T>* pX;
+ RBNODE<T>* pY;
+
+ pZ->pLeft = pZ->pRight = pNil;
+ pY = pRoot;
+ pX = pRoot->pLeft;
+
+ if(pX != pY)
+ {
+ while(pX != pNil)
+ {
+ pY = pX;
+ if(pX->tVal->ComparedTo(pZ->tVal) > 0)
+ pX = pX->pLeft;
+ else
+ pX = pX->pRight;
+ }
+ }
+ pZ->pParent = pY;
+ if((pY == pRoot) || (pY->tVal->ComparedTo(pZ->tVal) > 0))
+ pY->pLeft = pZ;
+ else
+ pY->pRight = pZ;
+ };
+
+ void InitSpecNode(RBNODE<T>* pNode)
+ {
+ pNode->pLeft = pNode->pRight = pNode->pParent = pNode;
+ };
+
+ void DeleteNode(RBNODE<T>* pNode, bool DeletePayload = true)
+ {
+ if((pNode != pNil)&&(pNode != pRoot))
+ {
+ DeleteNode(pNode->pLeft, DeletePayload);
+ DeleteNode(pNode->pRight, DeletePayload);
+ if(DeletePayload)
+ delete pNode->tVal;
+ NodePool.FreeNode(pNode);
+ }
+ };
+
+public:
+ RBTREE()
+ {
+ pRoot = NodePool.AllocNode();
+ InitSpecNode(pRoot);
+
+ pNil = NodePool.AllocNode();
+ InitSpecNode(pNil);
+ };
+
+ ~RBTREE()
+ {
+ //RESET(false);
+ //NodePool.FreeNode(pRoot);
+ //NodePool.FreeNode(pNil);
+ };
+
+ void RESET(bool DeletePayload = true)
+ {
+ DeleteNode(pRoot->pLeft, DeletePayload);
+ InitSpecNode(pRoot);
+ InitSpecNode(pNil);
+ };
+
+ void PUSH(T* pT)
+ {
+ RBNODE<T>* pX;
+ RBNODE<T>* pY;
+ RBNODE<T>* pNewNode = NodePool.AllocNode();
+
+ pNewNode->tVal = pT;
+ pNewNode->SetRed();
+
+ InsertNode(pNewNode);
+
+ for(pX = pNewNode; pX->pParent->IsRed();)
+ {
+ if(pX->pParent == pX->pParent->pLeft)
+ {
+ pY = pX->pParent->pRight;
+ if(pY->IsRed())
+ {
+ pX->pParent->SetBlack();
+ pY->SetBlack();
+ pX->pParent->pParent->SetRed();
+ pX = pX->pParent->pParent;
+ }
+ else
+ {
+ if(pX == pX->pParent->pRight)
+ {
+ pX = pX->pParent;
+ RotateLeft(pX);
+ }
+ pX->pParent->SetBlack();
+ pX->pParent->pParent->SetRed();
+ RotateRight(pX->pParent->pParent);
+ }
+ }
+ else // if(pX->pParent == pX->pParent->pRight)
+ {
+ pY = pX->pParent->pParent->pLeft;
+ if(pY->IsRed())
+ {
+ pX->pParent->SetBlack();
+ pY->SetBlack();
+ pX->pParent->pParent->SetRed();
+ pX = pX->pParent->pParent;
+ }
+ else
+ {
+ if(pX == pX->pParent->pLeft)
+ {
+ pX = pX->pParent;
+ RotateRight(pX);
+ }
+ pX->pParent->SetBlack();
+ pX->pParent->pParent->SetRed();
+ RotateLeft(pX->pParent->pParent);
+ }
+ }// end if(pX->pParent == pX->pParent->pLeft) -- else
+ } // end for(pX = pNewNode; pX->pParent->IsRed();)
+ pRoot->pLeft->SetBlack();
+ };
+
+ T* FIND(T* pT)
+ {
+ RBNODE<T>* pX = pRoot->pLeft;
+ if((pX != pNil) && (pX != pRoot))
+ {
+ int cmp = pX->tVal->ComparedTo(pT);
+ while(cmp != 0)
+ {
+ if(cmp > 0)
+ pX = pX->pLeft;
+ else
+ pX = pX->pRight;
+ if(pX == pNil)
+ return NULL;
+ cmp = pX->tVal->ComparedTo(pT);
+ }
+ return pX->tVal;
+ }
+ return NULL;
+ };
+};
+
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+
+#endif //ASMTEMPLATES_H
+
diff --git a/src/ilasm/assem.cpp b/src/ilasm/assem.cpp
new file mode 100644
index 0000000000..8c56bdc047
--- /dev/null
+++ b/src/ilasm/assem.cpp
@@ -0,0 +1,1654 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// File: assem.cpp
+//
+
+//
+// COM+ IL assembler
+//
+#include "ilasmpch.h"
+
+#define INITGUID
+
+#define DECLARE_DATA
+
+#include "assembler.h"
+#ifdef FEATURE_CORECLR
+#ifdef FEATURE_PAL
+#include "coreclrloader.h"
+CoreCLRLoader *g_loader;
+#endif // FEATURE_PAL
+MetaDataGetDispenserFunc metaDataGetDispenser;
+#else
+#include "MscorpeSxS.h"
+#endif // FEATURE_CORECLR
+
+void indexKeywords(Indx* indx); // defined in asmparse.y
+
+unsigned int g_uCodePage = CP_ACP;
+unsigned int g_uConsoleCP = CP_ACP;
+
+char g_szSourceFileName[MAX_FILENAME_LENGTH*3];
+
+WCHAR wzUniBuf[dwUniBuf]; // Unicode conversion global buffer
+
+Assembler::Assembler()
+{
+ m_pDisp = NULL;
+ m_pEmitter = NULL;
+ m_pImporter = NULL;
+
+ m_fCPlusPlus = FALSE;
+ m_fWindowsCE = FALSE;
+ char* pszFQN = new char[16];
+ strcpy_s(pszFQN,16,"<Module>");
+ m_pModuleClass = new Class(pszFQN);
+ m_lstClass.PUSH(m_pModuleClass);
+ m_hshClass.PUSH(m_pModuleClass);
+ m_pModuleClass->m_cl = mdTokenNil;
+ m_pModuleClass->m_bIsMaster = FALSE;
+
+ m_fStdMapping = FALSE;
+ m_fDisplayTraceOutput= FALSE;
+ m_fENCMode = FALSE;
+ m_fTolerateDupMethods = FALSE;
+
+ m_pCurOutputPos = NULL;
+
+ m_CurPC = 0; // PC offset in method
+ m_pCurMethod = NULL;
+ m_pCurClass = NULL;
+ m_pCurEvent = NULL;
+ m_pCurProp = NULL;
+
+ m_wzMetadataVersion = NULL;
+ m_wMSVmajor = 0xFFFF;
+ m_wMSVminor = 0xFFFF;
+
+ m_wSSVersionMajor = 4;
+ m_wSSVersionMinor = 0;
+ m_fAppContainer = FALSE;
+ m_fHighEntropyVA = FALSE;
+
+ m_pCeeFileGen = NULL;
+ m_pCeeFile = 0;
+
+ m_pManifest = NULL;
+
+ m_pCustomDescrList = NULL;
+
+ m_pGlobalDataSection = NULL;
+ m_pILSection = NULL;
+ m_pTLSSection = NULL;
+
+ m_fDidCoInitialise = FALSE;
+
+ m_fDLL = FALSE;
+ m_fEntryPointPresent = FALSE;
+ m_fHaveFieldsWithRvas = FALSE;
+ m_fFoldCode = FALSE;
+ m_dwMethodsFolded = 0;
+
+ m_szScopeName[0] = 0;
+ m_crExtends = mdTypeDefNil;
+
+ m_nImplList = 0;
+ m_TyParList = NULL;
+
+ m_SEHD = NULL;
+ m_firstArgName = NULL;
+ m_lastArgName = NULL;
+ m_szNamespace = new char[2];
+ m_szNamespace[0] = 0;
+ m_NSstack.PUSH(m_szNamespace);
+
+ m_szFullNS = new char[MAX_NAMESPACE_LENGTH];
+ memset(m_szFullNS,0,MAX_NAMESPACE_LENGTH);
+ m_ulFullNSLen = MAX_NAMESPACE_LENGTH;
+
+ m_State = STATE_OK;
+ m_fInitialisedMetaData = FALSE;
+ m_fAutoInheritFromObject = TRUE;
+
+ m_ulLastDebugLine = 0xFFFFFFFF;
+ m_ulLastDebugColumn = 0xFFFFFFFF;
+ m_ulLastDebugLineEnd = 0xFFFFFFFF;
+ m_ulLastDebugColumnEnd = 0xFFFFFFFF;
+ m_pSymWriter = NULL;
+ m_pSymDocument = NULL;
+ m_dwIncludeDebugInfo = 0;
+ m_fGeneratePDB = FALSE;
+ m_fIsMscorlib = FALSE;
+ m_fOptimize = FALSE;
+ m_tkSysObject = 0;
+ m_tkSysString = 0;
+ m_tkSysValue = 0;
+ m_tkSysEnum = 0;
+
+ m_pVTable = NULL;
+ m_pMarshal = NULL;
+ m_pPInvoke = NULL;
+
+ m_fReportProgress = TRUE;
+ m_tkCurrentCVOwner = 1; // module
+ m_pOutputBuffer = NULL;
+
+ m_dwSubsystem = (DWORD)-1;
+ m_dwComImageFlags = COMIMAGE_FLAGS_ILONLY;
+ m_dwFileAlignment = 0;
+ m_stBaseAddress = 0;
+ m_stSizeOfStackReserve = 0;
+ m_dwCeeFileFlags = ICEE_CREATE_FILE_PURE_IL;
+
+ g_szSourceFileName[0] = 0;
+
+ m_guidLang = CorSym_LanguageType_ILAssembly;
+ m_guidLangVendor = CorSym_LanguageVendor_Microsoft;
+ m_guidDoc = CorSym_DocumentType_Text;
+ for(int i=0; i<INSTR_POOL_SIZE; i++) m_Instr[i].opcode = -1;
+ m_wzResourceFile = NULL;
+ m_wzKeySourceName = NULL;
+ OnErrGo = false;
+ bClock = NULL;
+
+ m_pbsMD = NULL;
+
+ m_pOutputBuffer = new BYTE[OUTPUT_BUFFER_SIZE];
+
+ m_pCurOutputPos = m_pOutputBuffer;
+ m_pEndOutputPos = m_pOutputBuffer + OUTPUT_BUFFER_SIZE;
+
+ m_crImplList = new mdTypeRef[MAX_INTERFACES_IMPLEMENTED];
+ m_nImplListSize = MAX_INTERFACES_IMPLEMENTED;
+
+ m_pManifest = new AsmMan((void*)this);
+
+ dummyClass = new Class(NULL);
+ indexKeywords(&indxKeywords);
+}
+
+
+Assembler::~Assembler()
+{
+ if(m_pbsMD) delete m_pbsMD;
+
+ if(m_pMarshal) delete m_pMarshal;
+ if(m_pManifest) delete m_pManifest;
+ if(m_pPInvoke) delete m_pPInvoke;
+
+ if(m_pVTable) delete m_pVTable;
+
+ m_lstGlobalLabel.RESET(true);
+ m_lstGlobalFixup.RESET(true);
+ m_hshClass.RESET(false);
+ m_lstClass.RESET(true);
+ while((m_ClassStack.POP()));
+ while(m_CustomDescrListStack.POP());
+ m_pCurClass = NULL;
+ dummyClass->m_szFQN = NULL;
+ delete dummyClass;
+
+ if (m_pOutputBuffer) delete [] m_pOutputBuffer;
+ if (m_crImplList) delete [] m_crImplList;
+ if (m_TyParList) delete m_TyParList;
+
+ if (m_pCeeFileGen != NULL) {
+ if (m_pCeeFile)
+ m_pCeeFileGen->DestroyCeeFile(&m_pCeeFile);
+#ifdef FEATURE_CORECLR
+ DestroyICeeFileGen(&m_pCeeFileGen);
+#else
+ MscorpeSxS::DestroyICeeFileGen(&m_pCeeFileGen);
+#endif
+ m_pCeeFileGen = NULL;
+ }
+
+ while((m_szNamespace = m_NSstack.POP())) ;
+ delete [] m_szFullNS;
+
+ m_DocWriterList.RESET(true);
+
+ m_MethodBodyList.RESET(true);
+
+ m_TypeDefDList.RESET(true);
+
+ if (m_pSymWriter != NULL)
+ {
+ m_pSymWriter->Close();
+ m_pSymWriter->Release();
+ m_pSymWriter = NULL;
+ }
+ if (m_pImporter != NULL)
+ {
+ m_pImporter->Release();
+ m_pImporter = NULL;
+ }
+ if (m_pEmitter != NULL)
+ {
+ m_pEmitter->Release();
+ m_pEmitter = NULL;
+ }
+
+ if (m_pDisp != NULL)
+ {
+ m_pDisp->Release();
+ m_pDisp = NULL;
+ }
+
+#ifdef FEATURE_CORECLR
+#ifdef FEATURE_PAL
+ if (g_loader != NULL)
+ {
+ g_loader->Finish();
+ }
+#endif
+#else
+ if (m_fDidCoInitialise)
+ CoUninitialize();
+#endif // FEATURE_CORECLR
+
+}
+
+
+BOOL Assembler::Init()
+{
+#ifdef FEATURE_CORECLR
+#ifdef FEATURE_PAL
+ g_loader = CoreCLRLoader::Create(g_pszExeFile);
+ if (g_loader == NULL)
+ {
+ return FALSE;
+ }
+ metaDataGetDispenser = (MetaDataGetDispenserFunc)g_loader->LoadFunction("MetaDataGetDispenser");
+#else
+ metaDataGetDispenser = (MetaDataGetDispenserFunc)MetaDataGetDispenser;
+#endif // FEATURE_PAL
+#else
+ if(!m_fDidCoInitialise)
+ {
+ if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)))
+ return FALSE;
+ m_fDidCoInitialise = TRUE;
+ }
+#endif // FEATURE_CORECLR
+ if (m_pCeeFileGen != NULL) {
+ if (m_pCeeFile)
+ m_pCeeFileGen->DestroyCeeFile(&m_pCeeFile);
+#ifdef FEATURE_CORECLR
+ DestroyICeeFileGen(&m_pCeeFileGen);
+#else
+ MscorpeSxS::DestroyICeeFileGen(&m_pCeeFileGen);
+#endif
+ m_pCeeFileGen = NULL;
+ }
+#ifdef FEATURE_CORECLR
+ if (FAILED(CreateICeeFileGen(&m_pCeeFileGen))) return FALSE;
+#else
+ if (FAILED(MscorpeSxS::CreateICeeFileGen(&m_pCeeFileGen))) return FALSE;
+#endif
+ if (FAILED(m_pCeeFileGen->CreateCeeFileEx(&m_pCeeFile,(ULONG)m_dwCeeFileFlags))) return FALSE;
+
+ if (FAILED(m_pCeeFileGen->GetSectionCreate(m_pCeeFile, ".il", sdReadOnly, &m_pILSection))) return FALSE;
+ if (FAILED(m_pCeeFileGen->GetSectionCreate (m_pCeeFile, ".sdata", sdReadWrite, &m_pGlobalDataSection))) return FALSE;
+ if (FAILED(m_pCeeFileGen->GetSectionCreate (m_pCeeFile, ".tls", sdReadWrite, &m_pTLSSection))) return FALSE;
+
+ return TRUE;
+}
+
+void Assembler::SetDLL(BOOL IsDll)
+{
+ HRESULT OK;
+ OK = m_pCeeFileGen->SetDllSwitch(m_pCeeFile, IsDll);
+ _ASSERTE(SUCCEEDED(OK));
+
+ m_fDLL = IsDll;
+}
+
+void Assembler::SetOBJ(BOOL IsObj)
+{
+ HRESULT OK;
+ OK = m_pCeeFileGen->SetObjSwitch(m_pCeeFile, IsObj);
+ _ASSERTE(SUCCEEDED(OK));
+
+ m_fOBJ = IsObj;
+}
+
+
+void Assembler::ResetArgNameList()
+{
+ if(m_firstArgName) delArgNameList(m_firstArgName);
+ m_firstArgName = NULL;
+ m_lastArgName = NULL;
+}
+
+void Assembler::ResetForNextMethod()
+{
+
+ ResetArgNameList();
+
+ m_CurPC = 0;
+ m_pCurOutputPos = m_pOutputBuffer;
+ m_State = STATE_OK;
+ m_pCurMethod = NULL;
+}
+
+void Assembler::ResetLineNumbers()
+{
+ // reset line number information
+ m_ulLastDebugLine = 0xFFFFFFFF;
+ m_ulLastDebugColumn = 0xFFFFFFFF;
+ m_ulLastDebugLineEnd = 0xFFFFFFFF;
+ m_ulLastDebugColumnEnd = 0xFFFFFFFF;
+}
+
+BOOL Assembler::AddMethod(Method *pMethod)
+{
+ BOOL fIsInterface=FALSE, fIsImport=FALSE;
+ ULONG PEFileOffset=0;
+
+ _ASSERTE(m_pCeeFileGen != NULL);
+ if (pMethod == NULL)
+ {
+ report->error("pMethod == NULL");
+ return FALSE;
+ }
+ if(pMethod->m_pClass != NULL)
+ {
+ fIsInterface = IsTdInterface(pMethod->m_pClass->m_Attr);
+ fIsImport = IsTdImport(pMethod->m_pClass->m_Attr);
+ }
+ if(m_CurPC)
+ {
+ char sz[1024];
+ sz[0] = 0;
+ if(fIsInterface && (!IsMdStatic(pMethod->m_Attr))) strcat_s(sz,1024," non-static declared in interface");
+ if(fIsImport) strcat_s(sz,1024," imported");
+ if(IsMdAbstract(pMethod->m_Attr)) strcat_s(sz,1024," abstract");
+ if(IsMdPinvokeImpl(pMethod->m_Attr)) strcat_s(sz,1024," pinvoke");
+ if(!IsMiIL(pMethod->m_wImplAttr)) strcat_s(sz,1024," non-IL");
+ if(IsMiRuntime(pMethod->m_wImplAttr)) strcat_s(sz,1024," runtime-supplied");
+ if(IsMiInternalCall(pMethod->m_wImplAttr)) strcat_s(sz,1024," an internal call");
+ if(strlen(sz))
+ {
+ report->error("Method cannot have body if it is%s\n",sz);
+ }
+ }
+ else // method has no body
+ {
+ if(fIsImport || IsMdAbstract(pMethod->m_Attr) || IsMdPinvokeImpl(pMethod->m_Attr)
+ || IsMiRuntime(pMethod->m_wImplAttr) || IsMiInternalCall(pMethod->m_wImplAttr)) return TRUE;
+ if(OnErrGo)
+ {
+ report->error("Method has no body\n");
+ return TRUE;
+ }
+ else
+ {
+ report->warn("Method has no body, 'ret' emitted\n");
+ Instr* pIns = GetInstr();
+ if(pIns)
+ {
+ memset(pIns,0,sizeof(Instr));
+ pIns->opcode = CEE_RET;
+ EmitOpcode(pIns);
+ }
+ }
+ }
+
+ if(pMethod->m_Locals.COUNT()) pMethod->m_LocalsSig=0x11000001; // placeholder, the real token 2b defined in EmitMethod
+
+ COR_ILMETHOD_FAT fatHeader;
+ fatHeader.SetFlags(pMethod->m_Flags);
+ fatHeader.SetMaxStack(pMethod->m_MaxStack);
+ fatHeader.SetLocalVarSigTok(pMethod->m_LocalsSig);
+ fatHeader.SetCodeSize(m_CurPC);
+ bool moreSections = (pMethod->m_dwNumExceptions != 0);
+
+ // if max stack is specified <8, force fat header, otherwise (with tiny header) it will default to 8
+ if((fatHeader.GetMaxStack() < 8)&&(fatHeader.GetLocalVarSigTok()==0)&&(fatHeader.GetCodeSize()<64)&&(!moreSections))
+ fatHeader.SetFlags(fatHeader.GetFlags() | CorILMethod_InitLocals); //forces fat header but does nothing else, since LocalVarSigTok==0
+
+ unsigned codeSize = m_CurPC;
+ unsigned codeSizeAligned = codeSize;
+ if (moreSections)
+ codeSizeAligned = (codeSizeAligned + 3) & ~3; // to insure EH section aligned
+
+ unsigned headerSize = COR_ILMETHOD::Size(&fatHeader, moreSections);
+ unsigned ehSize = COR_ILMETHOD_SECT_EH::Size(pMethod->m_dwNumExceptions, pMethod->m_ExceptionList);
+ unsigned totalSize = headerSize + codeSizeAligned + ehSize;
+
+ BYTE* outBuff;
+ BYTE* endbuf;
+ BinStr* pbsBody;
+ if((pbsBody = new BinStr())==NULL) return FALSE;
+ if((outBuff = pbsBody->getBuff(totalSize))==NULL) return FALSE;
+ endbuf = &outBuff[totalSize];
+
+ // Emit the header
+ outBuff += COR_ILMETHOD::Emit(headerSize, &fatHeader, moreSections, outBuff);
+
+ pMethod->m_pCode = outBuff;
+ pMethod->m_headerOffset= PEFileOffset;
+ pMethod->m_methodOffset= PEFileOffset + headerSize;
+ pMethod->m_CodeSize = codeSize;
+
+ // Emit the code
+ if (codeSizeAligned)
+ {
+ memset(outBuff,0,codeSizeAligned);
+ memcpy(outBuff, m_pOutputBuffer, codeSize);
+ outBuff += codeSizeAligned;
+ }
+
+ if(pMethod->m_dwNumExceptions)
+ {
+ // Validate the eh
+ COR_ILMETHOD_SECT_EH_CLAUSE_FAT* pEx;
+ DWORD TryEnd,HandlerEnd, dwEx, dwEf;
+ for(dwEx = 0, pEx = pMethod->m_ExceptionList; dwEx < pMethod->m_dwNumExceptions; dwEx++, pEx++)
+ {
+ if(pEx->GetTryOffset() > m_CurPC) // i.e., pMethod->m_CodeSize
+ {
+ report->error("Invalid SEH clause #%d: Try block starts beyond code size\n",dwEx+1);
+ }
+ TryEnd = pEx->GetTryOffset()+pEx->GetTryLength();
+ if(TryEnd > m_CurPC)
+ {
+ report->error("Invalid SEH clause #%d: Try block ends beyond code size\n",dwEx+1);
+ }
+ if(pEx->GetHandlerOffset() > m_CurPC)
+ {
+ report->error("Invalid SEH clause #%d: Handler block starts beyond code size\n",dwEx+1);
+ }
+ HandlerEnd = pEx->GetHandlerOffset()+pEx->GetHandlerLength();
+ if(HandlerEnd > m_CurPC)
+ {
+ report->error("Invalid SEH clause #%d: Handler block ends beyond code size\n",dwEx+1);
+ }
+ if(pEx->Flags & COR_ILEXCEPTION_CLAUSE_FILTER)
+ {
+ if(!((pEx->GetFilterOffset() >= TryEnd)||(pEx->GetTryOffset() >= HandlerEnd)))
+ {
+ report->error("Invalid SEH clause #%d: Try and Filter/Handler blocks overlap\n",dwEx+1);
+ }
+ for(dwEf = 0; dwEf < pMethod->m_dwNumEndfilters; dwEf++)
+ {
+ if(pMethod->m_EndfilterOffsetList[dwEf] == pEx->GetHandlerOffset()) break;
+ }
+ if(dwEf >= pMethod->m_dwNumEndfilters)
+ {
+ report->error("Invalid SEH clause #%d: Filter block separated from Handler, or not ending with endfilter\n",dwEx+1);
+ }
+ }
+ else
+ if(!((pEx->GetHandlerOffset() >= TryEnd)||(pEx->GetTryOffset() >= HandlerEnd)))
+ {
+ report->error("Invalid SEH clause #%d: Try and Handler blocks overlap\n",dwEx+1);
+ }
+
+ }
+ // Emit the eh
+ outBuff += COR_ILMETHOD_SECT_EH::Emit(ehSize, pMethod->m_dwNumExceptions,
+ pMethod->m_ExceptionList, false, outBuff);
+ }
+ _ASSERTE(outBuff == endbuf);
+
+ pMethod->m_pbsBody = pbsBody;
+
+ LocalMemberRefFixup* pMRF;
+ while((pMRF = pMethod->m_LocalMemberRefFixupList.POP()))
+ {
+ pMRF->offset += (size_t)(pMethod->m_pCode);
+ m_LocalMemberRefFixupList.PUSH(pMRF); // transfer MRF to assembler's list
+ }
+
+ if(m_fReportProgress)
+ {
+ if (pMethod->IsGlobalMethod())
+ report->msg("Assembled global method %s\n", pMethod->m_szName);
+ else report->msg("Assembled method %s::%s\n", pMethod->m_pClass->m_szFQN,
+ pMethod->m_szName);
+ }
+ return TRUE;
+}
+
+
+BOOL Assembler::EmitMethodBody(Method* pMethod, BinStr* pbsOut)
+{
+ if(pMethod)
+ {
+ BinStr* pbsBody = pMethod->m_pbsBody;
+ unsigned totalSize;
+ if(pbsBody && (totalSize = pbsBody->length()))
+ {
+ unsigned headerSize = pMethod->m_methodOffset-pMethod->m_headerOffset;
+ MethodBody* pMB = NULL;
+ // ----------emit locals signature-------------------
+ unsigned uLocals;
+ if((uLocals = pMethod->m_Locals.COUNT()))
+ {
+ VarDescr* pVD;
+ BinStr* pbsSig = new BinStr();
+ unsigned cnt;
+ HRESULT hr;
+ DWORD cSig;
+ const COR_SIGNATURE* mySig;
+
+ pbsSig->appendInt8(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG);
+ cnt = CorSigCompressData(uLocals,pbsSig->getBuff(5));
+ pbsSig->remove(5-cnt);
+ for(cnt = 0; (pVD = pMethod->m_Locals.PEEK(cnt)); cnt++)
+ {
+ if(pVD->pbsSig) pbsSig->append(pVD->pbsSig);
+ else
+ {
+ report->error("Undefined type of local var slot %d in method %s\n",cnt,pMethod->m_szName);
+ pbsSig->appendInt8(ELEMENT_TYPE_I4);
+ }
+ }
+
+ cSig = pbsSig->length();
+ mySig = (const COR_SIGNATURE *)(pbsSig->ptr());
+
+ if (cSig > 1) // non-empty signature
+ {
+ hr = m_pEmitter->GetTokenFromSig(mySig, cSig, &pMethod->m_LocalsSig);
+ _ASSERTE(SUCCEEDED(hr));
+ }
+ delete pbsSig;
+ COR_ILMETHOD_FAT* pFH; // Fat header guaranteed, because there are local vars
+ pFH = (COR_ILMETHOD_FAT*)(pMethod->m_pbsBody->ptr());
+ pFH->SetLocalVarSigTok(pMethod->m_LocalsSig);
+ }
+ //--------------------------------------------------------------------------------
+ if(m_fGeneratePDB && (m_pSymWriter != NULL))
+ {
+ m_pSymWriter->OpenMethod(pMethod->m_Tok);
+ ULONG N = pMethod->m_LinePCList.COUNT();
+ if(pMethod->m_fEntryPoint) m_pSymWriter->SetUserEntryPoint(pMethod->m_Tok);
+ if(N)
+ {
+ LinePC *pLPC;
+ ULONG32 *offsets=new ULONG32[N], *lines = new ULONG32[N], *columns = new ULONG32[N];
+ ULONG32 *endlines=new ULONG32[N], *endcolumns=new ULONG32[N];
+ if(offsets && lines && columns && endlines && endcolumns)
+ {
+ DocWriter* pDW;
+ unsigned j=0;
+ while((pDW = m_DocWriterList.PEEK(j++)))
+ {
+ if((m_pSymDocument = pDW->pWriter))
+ {
+ int i, n;
+ for(i=0, n=0; (pLPC = pMethod->m_LinePCList.PEEK(i)); i++)
+ {
+ if(pLPC->pWriter == m_pSymDocument)
+ {
+ offsets[n] = pLPC->PC;
+ lines[n] = pLPC->Line;
+ columns[n] = pLPC->Column;
+ endlines[n] = pLPC->LineEnd;
+ endcolumns[n] = pLPC->ColumnEnd;
+ n++;
+ }
+ }
+ if(n) m_pSymWriter->DefineSequencePoints(m_pSymDocument,n,
+ offsets,lines,columns,endlines,endcolumns);
+ } // end if(pSymDocument)
+ } // end while(pDW = next doc.writer)
+ pMethod->m_LinePCList.RESET(true);
+ }
+ else report->error("\nOutOfMemory!\n");
+ delete [] offsets;
+ delete [] lines;
+ delete [] columns;
+ delete [] endlines;
+ delete [] endcolumns;
+ }//enf if(N)
+ HRESULT hrr;
+ if(pMethod->m_ulLines[1])
+ hrr = m_pSymWriter->SetMethodSourceRange(m_pSymDocument,pMethod->m_ulLines[0], pMethod->m_ulColumns[0],
+ m_pSymDocument,pMethod->m_ulLines[1], pMethod->m_ulColumns[1]);
+ EmitScope(&(pMethod->m_MainScope)); // recursively emits all nested scopes
+
+ m_pSymWriter->CloseMethod();
+ } // end if(fIncludeDebugInfo)
+ //-----------------------------------------------------
+
+ if(m_fFoldCode)
+ {
+ for(int k=0; (pMB = m_MethodBodyList.PEEK(k)) != NULL; k++)
+ {
+ if((pMB->pbsBody->length() == totalSize)
+ && (memcmp(pMB->pbsBody->ptr(), pbsBody->ptr(),totalSize)==0))
+ break;
+ }
+ if(pMB)
+ {
+ pMethod->m_headerOffset= pMB->RVA;
+ pMethod->m_methodOffset= pMB->RVA + headerSize;
+ pMethod->m_pCode = pMB->pCode;
+ delete pbsBody;
+ pMethod->m_pbsBody = NULL;
+ m_dwMethodsFolded++;
+ }
+ }
+ if(pMB == NULL)
+ {
+ BYTE* outBuff;
+ unsigned align = (headerSize == 1)? 1 : 4;
+ ULONG PEFileOffset, methodRVA;
+ if(m_fENCMode)
+ {
+ if(pbsOut)
+ {
+ PEFileOffset = pbsOut->length();
+ align--;
+ while(PEFileOffset & align)
+ {
+ pbsOut->appendInt8(0);
+ PEFileOffset++;
+ }
+ pbsOut->append(pbsBody);
+ outBuff = (BYTE*)(pbsOut->ptr()) + (pbsOut->length() - pbsBody->length());
+ }
+ else return FALSE;
+
+ }
+ else
+ {
+ if (FAILED(m_pCeeFileGen->GetSectionBlock (m_pILSection, totalSize,
+ align, (void **) &outBuff))) return FALSE;
+ memcpy(outBuff,pbsBody->ptr(),totalSize);
+ // The offset where we start, (not where the alignment bytes start!
+ if (FAILED(m_pCeeFileGen->GetSectionDataLen (m_pILSection, &PEFileOffset)))
+ return FALSE;
+ PEFileOffset -= totalSize;
+ }
+
+ pMethod->m_pCode = outBuff + headerSize;
+ pMethod->m_headerOffset= PEFileOffset;
+ pMethod->m_methodOffset= PEFileOffset + headerSize;
+ DoDeferredILFixups(pMethod);
+
+ if(m_fENCMode) methodRVA = PEFileOffset;
+ else m_pCeeFileGen->GetMethodRVA(m_pCeeFile, PEFileOffset,&methodRVA);
+
+ pMethod->m_headerOffset= methodRVA;
+ pMethod->m_methodOffset= methodRVA + headerSize;
+ if(m_fFoldCode)
+ {
+ if((pMB = new MethodBody)==NULL) return FALSE;
+ pMB->pbsBody = pbsBody;
+ pMB->RVA = methodRVA;
+ pMB->pCode = pMethod->m_pCode;
+ m_MethodBodyList.PUSH(pMB);
+ }
+ //else
+ // delete pbsBody;
+ //pMethod->m_pbsBody = NULL;
+ }
+ m_pEmitter->SetRVA(pMethod->m_Tok,pMethod->m_headerOffset);
+ }
+ return TRUE;
+ }
+ else return FALSE;
+}
+
+ImportDescriptor* Assembler::EmitImport(BinStr* DllName)
+{
+ int i = 0, l = 0;
+ ImportDescriptor* pID;
+ char* sz=NULL;
+
+ if(DllName) l = DllName->length(); // No zero terminator here!
+ if(l)
+ {
+ sz = (char*)DllName->ptr();
+ while((pID=m_ImportList.PEEK(i++)))
+ {
+ if((pID->dwDllName== (DWORD) l)&& !memcmp(pID->szDllName,sz,l)) return pID;
+ }
+ }
+ else
+ {
+ while((pID=m_ImportList.PEEK(i++)))
+ {
+ if(pID->dwDllName==0) return pID;
+ }
+ }
+ if((pID = new ImportDescriptor(sz,l)))
+ {
+ m_ImportList.PUSH(pID);
+ pID->mrDll = TokenFromRid(m_ImportList.COUNT(),mdtModuleRef);
+ return pID;
+ }
+ else report->error("Failed to allocate import descriptor\n");
+ return NULL;
+}
+
+void Assembler::EmitImports()
+{
+ WCHAR* wzDllName=&wzUniBuf[0];
+ ImportDescriptor* pID;
+ int i;
+ mdToken tk;
+ for(i=0; (pID = m_ImportList.PEEK(i)); i++)
+ {
+ WszMultiByteToWideChar(g_uCodePage,0,pID->szDllName,-1,wzDllName,dwUniBuf-1);
+ if(FAILED(m_pEmitter->DefineModuleRef( // S_OK or error.
+ wzDllName, // [IN] DLL name
+ &tk))) // [OUT] returned
+ report->error("Failed to define module ref '%s'\n",pID->szDllName);
+ else
+ _ASSERTE(tk == pID->mrDll);
+ }
+}
+
+HRESULT Assembler::EmitPinvokeMap(mdToken tk, PInvokeDescriptor* pDescr)
+{
+ WCHAR* wzAlias=&wzUniBuf[0];
+
+ if(pDescr->szAlias) WszMultiByteToWideChar(g_uCodePage,0,pDescr->szAlias,-1,wzAlias,dwUniBuf-1);
+
+ return m_pEmitter->DefinePinvokeMap( // Return code.
+ tk, // [IN] FieldDef, MethodDef or MethodImpl.
+ pDescr->dwAttrs, // [IN] Flags used for mapping.
+ (LPCWSTR)wzAlias, // [IN] Import name.
+ pDescr->mrDll); // [IN] ModuleRef token for the target DLL.
+}
+
+void Assembler::EmitScope(Scope* pSCroot)
+{
+ static ULONG32 scopeID;
+ static ARG_NAME_LIST *pVarList;
+ int i;
+ WCHAR* wzVarName=&wzUniBuf[0];
+ char* szPhonyName=(char*)&wzUniBuf[dwUniBuf >> 1];
+ Scope* pSC = pSCroot;
+ if(pSC && m_pSymWriter)
+ {
+ if(SUCCEEDED(m_pSymWriter->OpenScope(pSC->dwStart,&scopeID)))
+ {
+ if(pSC->pLocals)
+ {
+ for(pVarList = pSC->pLocals; pVarList; pVarList = pVarList->pNext)
+ {
+ if(pVarList->pSig)
+ {
+ if((pVarList->szName)&&(*(pVarList->szName))) strcpy_s(szPhonyName,dwUniBuf >> 1,pVarList->szName);
+ else sprintf_s(szPhonyName,(dwUniBuf >> 1),"V_%d",pVarList->dwAttr);
+
+ WszMultiByteToWideChar(g_uCodePage,0,szPhonyName,-1,wzVarName,dwUniBuf >> 1);
+
+ m_pSymWriter->DefineLocalVariable(wzVarName,0,pVarList->pSig->length(),
+ (BYTE*)pVarList->pSig->ptr(),ADDR_IL_OFFSET,pVarList->dwAttr,0,0,0,0);
+ }
+ else
+ {
+ report->error("Local Var '%s' has no signature\n",pVarList->szName);
+ }
+ }
+ }
+ for(i = 0; (pSC = pSCroot->SubScope.PEEK(i)); i++) EmitScope(pSC);
+ m_pSymWriter->CloseScope(pSCroot->dwEnd);
+ }
+ }
+}
+
+BOOL Assembler::EmitMethod(Method *pMethod)
+{
+// Emit the metadata for a method definition
+ BOOL fSuccess = FALSE;
+ WCHAR* wzMemberName=&wzUniBuf[0];
+ BOOL fIsInterface;
+ DWORD cSig;
+ ULONG methodRVA = 0;
+ mdMethodDef MethodToken;
+ mdTypeDef ClassToken = mdTypeDefNil;
+ char *pszMethodName;
+ COR_SIGNATURE *mySig;
+
+ _ASSERTE((m_pCeeFileGen != NULL) && (pMethod != NULL));
+ fIsInterface = ((pMethod->m_pClass != NULL) && IsTdInterface(pMethod->m_pClass->m_Attr));
+
+
+ pszMethodName = pMethod->m_szName;
+ mySig = pMethod->m_pMethodSig;
+ cSig = pMethod->m_dwMethodCSig;
+
+ // If this is an instance method, make certain the signature says so
+
+ if (!(pMethod->m_Attr & mdStatic))
+ *mySig |= IMAGE_CEE_CS_CALLCONV_HASTHIS;
+
+ ClassToken = (pMethod->IsGlobalMethod())? mdTokenNil
+ : pMethod->m_pClass->m_cl;
+ // Convert name to UNICODE
+ WszMultiByteToWideChar(g_uCodePage,0,pszMethodName,-1,wzMemberName,dwUniBuf-1);
+
+ if(IsMdPrivateScope(pMethod->m_Attr))
+ {
+ WCHAR* p = wcsstr(wzMemberName,W("$PST06"));
+ if(p) *p = 0;
+ }
+
+ if (FAILED(m_pEmitter->DefineMethod(ClassToken, // parent class
+ wzMemberName, // member name
+ pMethod->m_Attr & ~mdReservedMask, // member attributes
+ mySig, // member signature
+ cSig,
+ methodRVA, // RVA
+ pMethod->m_wImplAttr, // implflags
+ &MethodToken)))
+ {
+ report->error("Failed to define method '%s'\n",pszMethodName);
+ goto exit;
+ }
+ pMethod->m_Tok = MethodToken;
+ //--------------------------------------------------------------------------------
+ // the only way to set mdRequireSecObject:
+ if(pMethod->m_Attr & mdRequireSecObject)
+ {
+ mdToken tkPseudoClass;
+ if(FAILED(m_pEmitter->DefineTypeRefByName(1, COR_REQUIRES_SECOBJ_ATTRIBUTE, &tkPseudoClass)))
+ report->error("Unable to define type reference '%s'\n", COR_REQUIRES_SECOBJ_ATTRIBUTE_ANSI);
+ else
+ {
+ mdToken tkPseudoCtor;
+ BYTE bSig[3] = {IMAGE_CEE_CS_CALLCONV_HASTHIS,0,ELEMENT_TYPE_VOID};
+ if(FAILED(m_pEmitter->DefineMemberRef(tkPseudoClass, W(".ctor"), (PCCOR_SIGNATURE)bSig, 3, &tkPseudoCtor)))
+ report->error("Unable to define member reference '%s::.ctor'\n", COR_REQUIRES_SECOBJ_ATTRIBUTE_ANSI);
+ else DefineCV(new CustomDescr(MethodToken,tkPseudoCtor,NULL));
+ }
+ }
+
+ if (pMethod->m_NumTyPars)
+ {
+ ULONG i;
+ mdToken* ptk;
+ mdToken tk;
+ for(i = 0; i < pMethod->m_NumTyPars; i++)
+ {
+ //ptk = (pMethod->m_TyParBounds[i] == NULL)? NULL : (mdToken*)(pMethod->m_TyParBounds[i]->ptr());
+ //if(FAILED(m_pEmitter->DefineGenericParam(MethodToken,i,0,pMethod->m_TyParNames[i],0,ptk,&tk)))
+ ptk = (pMethod->m_TyPars[i].Bounds() == NULL)? NULL : (mdToken*)(pMethod->m_TyPars[i].Bounds()->ptr());
+ if(FAILED(m_pEmitter->DefineGenericParam(MethodToken,i,pMethod->m_TyPars[i].Attrs(),pMethod->m_TyPars[i].Name(),0,ptk,&tk)))
+ report->error("Unable to define generic param'\n");
+ else
+ EmitCustomAttributes(tk, pMethod->m_TyPars[i].CAList());
+ }
+ }
+ //--------------------------------------------------------------------------------
+ EmitSecurityInfo(MethodToken,
+ pMethod->m_pPermissions,
+ pMethod->m_pPermissionSets);
+ //--------------------------------------------------------------------------------
+ if (pMethod->m_fEntryPoint)
+ {
+ if(fIsInterface) report->error("Entrypoint in Interface: Method '%s'\n",pszMethodName);
+
+ if (FAILED(m_pCeeFileGen->SetEntryPoint(m_pCeeFile, MethodToken)))
+ {
+ report->error("Failed to set entry point for method '%s'\n",pszMethodName);
+ goto exit;
+ }
+
+ }
+ //--------------------------------------------------------------------------------
+ if(IsMdPinvokeImpl(pMethod->m_Attr))
+ {
+ if(pMethod->m_pPInvoke)
+ {
+ HRESULT hr;
+ if(pMethod->m_pPInvoke->szAlias == NULL) pMethod->m_pPInvoke->szAlias = pszMethodName;
+ hr = EmitPinvokeMap(MethodToken,pMethod->m_pPInvoke);
+ if(pMethod->m_pPInvoke->szAlias == pszMethodName) pMethod->m_pPInvoke->szAlias = NULL;
+
+ if(FAILED(hr))
+ {
+ report->error("Failed to set PInvoke map for method '%s'\n",pszMethodName);
+ goto exit;
+ }
+ }
+ }
+
+ { // add parameters to metadata
+ void const *pValue=NULL;
+ ULONG cbValue;
+ DWORD dwCPlusTypeFlag=0;
+ mdParamDef pdef;
+ WCHAR* wzParName=&wzUniBuf[0];
+ char* szPhonyName=(char*)&wzUniBuf[dwUniBuf >> 1];
+ if(pMethod->m_dwRetAttr || pMethod->m_pRetMarshal || pMethod->m_RetCustDList.COUNT())
+ {
+ if(pMethod->m_pRetValue)
+ {
+ dwCPlusTypeFlag= (DWORD)*(pMethod->m_pRetValue->ptr());
+ pValue = (void const *)(pMethod->m_pRetValue->ptr()+1);
+ cbValue = pMethod->m_pRetValue->length()-1;
+ if(dwCPlusTypeFlag == ELEMENT_TYPE_STRING) cbValue /= sizeof(WCHAR);
+ }
+ else
+ {
+ pValue = NULL;
+ cbValue = (ULONG)-1;
+ dwCPlusTypeFlag=0;
+ }
+ m_pEmitter->DefineParam(MethodToken,0,NULL,pMethod->m_dwRetAttr,dwCPlusTypeFlag,pValue,cbValue,&pdef);
+
+ if(pMethod->m_pRetMarshal)
+ {
+ if(FAILED(m_pEmitter->SetFieldMarshal (
+ pdef, // [IN] given a fieldDef or paramDef token
+ (PCCOR_SIGNATURE)(pMethod->m_pRetMarshal->ptr()), // [IN] native type specification
+ pMethod->m_pRetMarshal->length()))) // [IN] count of bytes of pvNativeType
+ report->error("Failed to set param marshaling for return\n");
+
+ }
+ EmitCustomAttributes(pdef, &(pMethod->m_RetCustDList));
+ }
+ for(ARG_NAME_LIST *pAN=pMethod->m_firstArgName; pAN; pAN = pAN->pNext)
+ {
+ if(pAN->nNum >= 65535)
+ {
+ report->error("Method '%s': Param.sequence number (%d) exceeds 65535, unable to define parameter\n",pszMethodName,pAN->nNum+1);
+ continue;
+ }
+ if(pAN->dwName) strcpy_s(szPhonyName,dwUniBuf >> 1,pAN->szName);
+ else sprintf_s(szPhonyName,(dwUniBuf >> 1),"A_%d",pAN->nNum);
+
+ WszMultiByteToWideChar(g_uCodePage,0,szPhonyName,-1,wzParName,dwUniBuf >> 1);
+
+ if(pAN->pValue)
+ {
+ dwCPlusTypeFlag= (DWORD)*(pAN->pValue->ptr());
+ pValue = (void const *)(pAN->pValue->ptr()+1);
+ cbValue = pAN->pValue->length()-1;
+ if(dwCPlusTypeFlag == ELEMENT_TYPE_STRING) cbValue /= sizeof(WCHAR);
+ }
+ else
+ {
+ pValue = NULL;
+ cbValue = (ULONG)-1;
+ dwCPlusTypeFlag=0;
+ }
+ m_pEmitter->DefineParam(MethodToken,pAN->nNum+1,wzParName,pAN->dwAttr,dwCPlusTypeFlag,pValue,cbValue,&pdef);
+ if(pAN->pMarshal)
+ {
+ if(FAILED(m_pEmitter->SetFieldMarshal (
+ pdef, // [IN] given a fieldDef or paramDef token
+ (PCCOR_SIGNATURE)(pAN->pMarshal->ptr()), // [IN] native type specification
+ pAN->pMarshal->length()))) // [IN] count of bytes of pvNativeType
+ report->error("Failed to set param marshaling for '%s'\n",pAN->szName);
+ }
+ EmitCustomAttributes(pdef, &(pAN->CustDList));
+ }
+ }
+ fSuccess = TRUE;
+ //--------------------------------------------------------------------------------
+ // Update method implementations for this method
+ {
+ MethodImplDescriptor* pMID;
+ int i;
+ for(i=0;(pMID = pMethod->m_MethodImplDList.PEEK(i));i++)
+ {
+ pMID->m_tkImplementingMethod = MethodToken;
+ // don't delete it here, it's still in the general list
+ }
+ }
+ //--------------------------------------------------------------------------------
+ EmitCustomAttributes(MethodToken, &(pMethod->m_CustomDescrList));
+exit:
+ if (fSuccess == FALSE) m_State = STATE_FAIL;
+ return fSuccess;
+}
+
+BOOL Assembler::EmitMethodImpls()
+{
+ MethodImplDescriptor* pMID;
+ BOOL ret = TRUE;
+ int i;
+ for(i=0; (pMID = m_MethodImplDList.PEEK(i)); i++)
+ {
+ if(m_fENCMode && (!pMID->m_fNew)) continue;
+ pMID->m_tkImplementingMethod = ResolveLocalMemberRef(pMID->m_tkImplementingMethod);
+ pMID->m_tkImplementedMethod = ResolveLocalMemberRef(pMID->m_tkImplementedMethod);
+ if(FAILED(m_pEmitter->DefineMethodImpl( pMID->m_tkDefiningClass,
+ pMID->m_tkImplementingMethod,
+ pMID->m_tkImplementedMethod)))
+ {
+ report->error("Failed to define Method Implementation");
+ ret = FALSE;
+ }
+ pMID->m_fNew = FALSE;
+ }// end while
+ return ret;
+}
+
+mdToken Assembler::ResolveLocalMemberRef(mdToken tok)
+{
+ if(TypeFromToken(tok) == 0x99000000)
+ {
+ tok = RidFromToken(tok);
+ if(tok) tok = m_LocalMethodRefDList.PEEK(tok-1)->m_tkResolved;
+ }
+ else if(TypeFromToken(tok) == 0x98000000)
+ {
+ tok = RidFromToken(tok);
+ if(tok) tok = m_LocalFieldRefDList.PEEK(tok-1)->m_tkResolved;
+ }
+ return tok;
+}
+
+BOOL Assembler::EmitEvent(EventDescriptor* pED)
+{
+ mdMethodDef mdAddOn=mdMethodDefNil,
+ mdRemoveOn=mdMethodDefNil,
+ mdFire=mdMethodDefNil,
+ *mdOthers;
+ int nOthers;
+ WCHAR* wzMemberName=&wzUniBuf[0];
+
+ if(!pED) return FALSE;
+
+ WszMultiByteToWideChar(g_uCodePage,0,pED->m_szName,-1,wzMemberName,dwUniBuf-1);
+
+ mdAddOn = ResolveLocalMemberRef(pED->m_tkAddOn);
+ if(TypeFromToken(mdAddOn) != mdtMethodDef)
+ {
+ report->error("Invalid Add method of event '%s'\n",pED->m_szName);
+ return FALSE;
+ }
+ mdRemoveOn = ResolveLocalMemberRef(pED->m_tkRemoveOn);
+ if(TypeFromToken(mdRemoveOn) != mdtMethodDef)
+ {
+ report->error("Invalid Remove method of event '%s'\n",pED->m_szName);
+ return FALSE;
+ }
+ mdFire = ResolveLocalMemberRef(pED->m_tkFire);
+ if((RidFromToken(mdFire)!=0)&&(TypeFromToken(mdFire) != mdtMethodDef))
+ {
+ report->error("Invalid Fire method of event '%s'\n",pED->m_szName);
+ return FALSE;
+ }
+
+ nOthers = pED->m_tklOthers.COUNT();
+ mdOthers = new mdMethodDef[nOthers+1];
+ if(mdOthers == NULL)
+ {
+ report->error("Failed to allocate Others array for event descriptor\n");
+ nOthers = 0;
+ }
+ for(int j=0; j < nOthers; j++)
+ {
+ mdOthers[j] = ResolveLocalMemberRef((mdToken)(UINT_PTR)(pED->m_tklOthers.PEEK(j))); // @WARNING: casting down from 'mdToken*' to 'mdToken'
+ }
+ mdOthers[nOthers] = mdMethodDefNil; // like null-terminator
+
+ if(FAILED(m_pEmitter->DefineEvent( pED->m_tdClass,
+ wzMemberName,
+ pED->m_dwAttr,
+ pED->m_tkEventType,
+ mdAddOn,
+ mdRemoveOn,
+ mdFire,
+ mdOthers,
+ &(pED->m_edEventTok))))
+ {
+ report->error("Failed to define event '%s'.\n",pED->m_szName);
+ delete [] mdOthers;
+ return FALSE;
+ }
+ EmitCustomAttributes(pED->m_edEventTok, &(pED->m_CustomDescrList));
+ return TRUE;
+}
+
+BOOL Assembler::EmitProp(PropDescriptor* pPD)
+{
+ mdMethodDef mdSet, mdGet, *mdOthers;
+ int nOthers;
+ WCHAR* wzMemberName=&wzUniBuf[0];
+
+ if(!pPD) return FALSE;
+
+ WszMultiByteToWideChar(g_uCodePage,0,pPD->m_szName,-1,wzMemberName,dwUniBuf-1);
+
+ mdSet = ResolveLocalMemberRef(pPD->m_tkSet);
+ if((RidFromToken(mdSet)!=0)&&(TypeFromToken(mdSet) != mdtMethodDef))
+ {
+ report->error("Invalid Set method of property '%s'\n",pPD->m_szName);
+ return FALSE;
+ }
+ mdGet = ResolveLocalMemberRef(pPD->m_tkGet);
+ if((RidFromToken(mdGet)!=0)&&(TypeFromToken(mdGet) != mdtMethodDef))
+ {
+ report->error("Invalid Get method of property '%s'\n",pPD->m_szName);
+ return FALSE;
+ }
+
+ nOthers = pPD->m_tklOthers.COUNT();
+ mdOthers = new mdMethodDef[nOthers+1];
+ if(mdOthers == NULL)
+ {
+ report->error("Failed to allocate Others array for prop descriptor\n");
+ nOthers = 0;
+ }
+ for(int j=0; j < nOthers; j++)
+ {
+ mdOthers[j] = ResolveLocalMemberRef((mdToken)(UINT_PTR)(pPD->m_tklOthers.PEEK(j))); // @WARNING: casting down from 'mdToken*' to 'mdToken'
+
+ if((RidFromToken(mdOthers[j])!=0)&&(TypeFromToken(mdOthers[j]) != mdtMethodDef))
+ {
+ report->error("Invalid Other method of property '%s'\n",pPD->m_szName);
+ delete [] mdOthers;
+ return FALSE;
+ }
+
+ }
+ mdOthers[nOthers] = mdMethodDefNil; // like null-terminator
+
+ if(FAILED(m_pEmitter->DefineProperty( pPD->m_tdClass,
+ wzMemberName,
+ pPD->m_dwAttr,
+ pPD->m_pSig,
+ pPD->m_dwCSig,
+ pPD->m_dwCPlusTypeFlag,
+ pPD->m_pValue,
+ pPD->m_cbValue,
+ mdSet,
+ mdGet,
+ mdOthers,
+ &(pPD->m_pdPropTok))))
+ {
+ report->error("Failed to define property '%s'.\n",pPD->m_szName);
+ delete [] mdOthers;
+ return FALSE;
+ }
+ EmitCustomAttributes(pPD->m_pdPropTok, &(pPD->m_CustomDescrList));
+ return TRUE;
+}
+
+Class *Assembler::FindCreateClass(__in __nullterminated const char *pszFQN)
+{
+ Class *pSearch = NULL;
+
+ if(pszFQN)
+ {
+ dummyClass->m_szFQN = pszFQN;
+ dummyClass->m_Hash = hash((BYTE*)pszFQN, (unsigned)strlen(pszFQN), 10);
+ pSearch = m_hshClass.FIND(dummyClass);
+ dummyClass->m_szFQN = NULL;
+ dummyClass->m_Hash = 0;
+
+ if(!pSearch)
+ {
+ char* pch;
+ DWORD dwFQN = (DWORD)strlen(pszFQN);
+
+ Class *pEncloser = NULL;
+ char* pszNewFQN = new char[dwFQN+1];
+ strcpy_s(pszNewFQN,dwFQN+1,pszFQN);
+ if((pch = strrchr(pszNewFQN, NESTING_SEP)) != NULL)
+ {
+ *pch = 0;
+ pEncloser = FindCreateClass(pszNewFQN);
+ *pch = NESTING_SEP;
+ }
+ pSearch = new Class(pszNewFQN);
+ if (pSearch == NULL)
+ report->error("Failed to create class '%s'\n",pszNewFQN);
+ else
+ {
+ pSearch->m_pEncloser = pEncloser;
+ m_lstClass.PUSH(pSearch);
+ pSearch->m_cl = mdtTypeDef | m_lstClass.COUNT();
+ m_hshClass.PUSH(pSearch);
+ }
+ }
+ }
+
+ return pSearch;
+}
+
+
+BOOL Assembler::EmitClass(Class *pClass)
+{
+ LPCUTF8 szFullName;
+ WCHAR* wzFullName=&wzUniBuf[0];
+ HRESULT hr = E_FAIL;
+ GUID guid;
+ size_t L;
+ mdToken tok;
+
+ if(pClass == NULL) return FALSE;
+
+ hr = CoCreateGuid(&guid);
+ if (FAILED(hr))
+ {
+ printf("Unable to create GUID\n");
+ m_State = STATE_FAIL;
+ return FALSE;
+ }
+
+ if(pClass->m_pEncloser)
+ szFullName = strrchr(pClass->m_szFQN,NESTING_SEP) + 1;
+ else
+ szFullName = pClass->m_szFQN;
+
+ WszMultiByteToWideChar(g_uCodePage,0,szFullName,-1,wzFullName,dwUniBuf);
+
+ L = wcslen(wzFullName);
+ if((L==0)||(wzFullName[L-1]==L'.')) // Missing class name!
+ {
+ wcscat_s(wzFullName,dwUniBuf,W("$UNNAMED_TYPE$"));
+ }
+
+ pClass->m_Attr = CheckClassFlagsIfNested(pClass->m_pEncloser, pClass->m_Attr);
+
+ if (pClass->m_pEncloser)
+ {
+ hr = m_pEmitter->DefineNestedType( wzFullName,
+ pClass->m_Attr, // attributes
+ pClass->m_crExtends, // CR extends class
+ pClass->m_crImplements,// implements
+ pClass->m_pEncloser->m_cl, // Enclosing class.
+ &tok);
+ }
+ else
+ {
+ hr = m_pEmitter->DefineTypeDef( wzFullName,
+ pClass->m_Attr, // attributes
+ pClass->m_crExtends, // CR extends class
+ pClass->m_crImplements,// implements
+ &tok);
+ }
+ _ASSERTE(tok == pClass->m_cl);
+ if (FAILED(hr)) goto exit;
+ if (pClass->m_NumTyPars)
+ {
+ ULONG i;
+ mdToken* ptk;
+ mdToken tk;
+ for(i = 0; i < pClass->m_NumTyPars; i++)
+ {
+ //ptk = (pClass->m_TyParBounds[i] == NULL)? NULL : (mdToken*)(pClass->m_TyParBounds[i]->ptr());
+ //if(FAILED(m_pEmitter->DefineGenericParam(pClass->m_cl,i,pClass->m_TyParAttrs[i],pClass->m_TyParNames[i],0,ptk,&tk)))
+ ptk = (pClass->m_TyPars[i].Bounds() == NULL)? NULL : (mdToken*)(pClass->m_TyPars[i].Bounds()->ptr());
+ if(FAILED(m_pEmitter->DefineGenericParam(pClass->m_cl,i,pClass->m_TyPars[i].Attrs(),pClass->m_TyPars[i].Name(),0,ptk,&tk)))
+ report->error("Unable to define generic param'\n");
+ else
+ EmitCustomAttributes(tk, pClass->m_TyPars[i].CAList());
+ }
+ }
+
+
+ EmitCustomAttributes(pClass->m_cl, &(pClass->m_CustDList));
+ hr = S_OK;
+
+exit:
+ return SUCCEEDED(hr);
+}
+
+BOOL Assembler::DoGlobalFixups()
+{
+ GlobalFixup *pSearch;
+
+ for (int i=0; (pSearch = m_lstGlobalFixup.PEEK(i)); i++)
+ {
+ GlobalLabel * pLabel = FindGlobalLabel(pSearch->m_szLabel);
+ if (pLabel == NULL)
+ {
+ report->error("Unable to find forward reference global label '%s'\n",
+ pSearch->m_szLabel);
+
+ m_State = STATE_FAIL;
+ return FALSE;
+ }
+ //BYTE * pReference = pSearch->m_pReference;
+ //DWORD GlobalOffset = pLabel->m_GlobalOffset;
+ //memcpy(pReference,&GlobalOffset,4);
+ SET_UNALIGNED_VAL32(pSearch->m_pReference,pLabel->m_GlobalOffset);
+ }
+
+ return TRUE;
+}
+
+state_t Assembler::AddGlobalLabel(__in __nullterminated char *pszName, HCEESECTION section)
+{
+ if (FindGlobalLabel(pszName) != NULL)
+ {
+ report->error("Duplicate global label '%s'\n", pszName);
+ m_State = STATE_FAIL;
+ return m_State;
+ }
+
+ ULONG GlobalOffset;
+
+ HRESULT hr;
+ hr = m_pCeeFileGen->GetSectionDataLen(section, &GlobalOffset);
+ _ASSERTE(SUCCEEDED(hr));
+
+ GlobalLabel *pNew = new GlobalLabel(pszName, GlobalOffset, section);
+ if (pNew == 0)
+ {
+ report->error("Failed to allocate global label '%s'\n",pszName);
+ m_State = STATE_FAIL;
+ return m_State;
+ }
+
+ m_lstGlobalLabel.PUSH(pNew);
+ return m_State;
+}
+
+void Assembler::AddLabel(DWORD CurPC, __in __nullterminated char *pszName)
+{
+ if (m_pCurMethod->FindLabel(pszName) != NULL)
+ {
+ report->error("Duplicate label: '%s'\n", pszName);
+
+ m_State = STATE_FAIL;
+ }
+ else
+ {
+ Label *pNew = new Label(pszName, CurPC);
+
+ if (pNew != NULL)
+ //m_pCurMethod->m_lstLabel.PUSH(pNew);
+ m_lstLabel.PUSH(pNew);
+ else
+ {
+ report->error("Failed to allocate label '%s'\n",pszName);
+ m_State = STATE_FAIL;
+ }
+ }
+}
+
+void Assembler::DoDeferredILFixups(Method* pMethod)
+{ // Now that we know where in the file the code bytes will wind up,
+ // we can update the RVAs and offsets.
+ ILFixup *pSearch;
+ HRESULT hr;
+ GlobalFixup *Fix = NULL;
+ int i;
+ for (i=0;(pSearch = pMethod->m_lstILFixup.PEEK(i));i++)
+ {
+ switch(pSearch->m_Kind)
+ {
+ case ilGlobal:
+ Fix = pSearch->m_Fixup;
+ _ASSERTE(Fix != NULL);
+ Fix->m_pReference = pMethod->m_pCode+pSearch->m_OffsetInMethod;
+ break;
+
+ case ilToken:
+ hr = m_pCeeFileGen->AddSectionReloc(m_pILSection,
+ pSearch->m_OffsetInMethod+pMethod->m_methodOffset,
+ m_pILSection,
+ srRelocMapToken);
+ _ASSERTE(SUCCEEDED(hr));
+ break;
+
+ case ilRVA:
+ hr = m_pCeeFileGen->AddSectionReloc(m_pILSection,
+ pSearch->m_OffsetInMethod+pMethod->m_methodOffset,
+ m_pGlobalDataSection,
+ srRelocAbsolute);
+ _ASSERTE(SUCCEEDED(hr));
+ break;
+
+ default:
+ ;
+ }
+ }
+}
+/**************************************************************************/
+BOOL Assembler::DoFixups(Method* pMethod)
+{
+ Fixup *pSearch;
+
+ for (int i=0; (pSearch = pMethod->m_lstFixup.PEEK(i)); i++)
+ {
+ Label * pLabel = pMethod->FindLabel(pSearch->m_szLabel);
+ long offset;
+
+ if (pLabel == NULL)
+ {
+ report->error("Unable to find forward reference label '%s' called from PC=%d\n",
+ pSearch->m_szLabel, pSearch->m_RelativeToPC);
+
+ //m_State = STATE_FAIL;
+ return FALSE;
+ }
+
+ offset = pLabel->m_PC - pSearch->m_RelativeToPC;
+
+ if (pSearch->m_FixupSize == 1)
+ {
+ if (offset > 127 || offset < -128)
+ {
+ report->error("Offset of forward reference label '%s' called from PC=%d is too large for 1 byte pcrel\n",
+ pLabel->m_szName, pSearch->m_RelativeToPC);
+
+ //m_State = STATE_FAIL;
+ return FALSE;
+ }
+
+ *pSearch->m_pBytes = (BYTE) offset;
+ }
+ else if (pSearch->m_FixupSize == 4)
+ {
+ SET_UNALIGNED_VAL32(pSearch->m_pBytes,offset);
+ }
+ }
+
+ return TRUE;
+}
+
+
+OPCODE Assembler::DecodeOpcode(const BYTE *pCode, DWORD *pdwLen)
+{
+ OPCODE opcode;
+
+ *pdwLen = 1;
+ opcode = OPCODE(pCode[0]);
+ switch(opcode) {
+ case CEE_PREFIX1:
+ opcode = OPCODE(pCode[1] + 256);
+ if (opcode < 0 || opcode >= CEE_COUNT)
+ return CEE_COUNT;
+ *pdwLen = 2;
+ break;
+
+ case CEE_PREFIXREF:
+ case CEE_PREFIX2:
+ case CEE_PREFIX3:
+ case CEE_PREFIX4:
+ case CEE_PREFIX5:
+ case CEE_PREFIX6:
+ case CEE_PREFIX7:
+ return CEE_COUNT;
+ default:
+ break;
+ }
+ return opcode;
+}
+
+char* Assembler::ReflectionNotation(mdToken tk)
+{
+ char *sz = (char*)&wzUniBuf[dwUniBuf>>1], *pc;
+ *sz=0;
+ switch(TypeFromToken(tk))
+ {
+ case mdtTypeDef:
+ {
+ Class *pClass = m_lstClass.PEEK(RidFromToken(tk)-1);
+ if(pClass)
+ {
+ strcpy_s(sz,dwUniBuf>>1,pClass->m_szFQN);
+ pc = sz;
+ while((pc = strchr(pc,NESTING_SEP)) != NULL)
+ {
+ *pc = '+';
+ pc++;
+ }
+ }
+ }
+ break;
+
+ case mdtTypeRef:
+ {
+ ULONG N;
+ mdToken tkResScope;
+ if(SUCCEEDED(m_pImporter->GetTypeRefProps(tk,&tkResScope,wzUniBuf,dwUniBuf>>1,&N)))
+ {
+ WszWideCharToMultiByte(CP_UTF8,0,wzUniBuf,-1,sz,dwUniBuf>>1,NULL,NULL);
+ if(TypeFromToken(tkResScope)==mdtAssemblyRef)
+ {
+ AsmManAssembly *pAsmRef = m_pManifest->m_AsmRefLst.PEEK(RidFromToken(tkResScope)-1);
+ if(pAsmRef)
+ {
+ pc = &sz[strlen(sz)];
+ pc+=sprintf_s(pc,(dwUniBuf >> 1),", %s, Version=%d.%d.%d.%d, Culture=",pAsmRef->szName,
+ pAsmRef->usVerMajor,pAsmRef->usVerMinor,pAsmRef->usBuild,pAsmRef->usRevision);
+ ULONG L=0;
+ if(pAsmRef->pLocale && (L=pAsmRef->pLocale->length()))
+ {
+ memcpy(wzUniBuf,pAsmRef->pLocale->ptr(),L);
+ wzUniBuf[L>>1] = 0;
+ WszWideCharToMultiByte(CP_UTF8,0,wzUniBuf,-1,pc,dwUniBuf>>1,NULL,NULL);
+ }
+ else pc+=sprintf_s(pc,(dwUniBuf >> 1),"neutral");
+ pc = &sz[strlen(sz)];
+ if(pAsmRef->pPublicKeyToken && (L=pAsmRef->pPublicKeyToken->length()))
+ {
+ pc+=sprintf_s(pc,(dwUniBuf >> 1),", Publickeytoken=");
+ BYTE* pb = (BYTE*)(pAsmRef->pPublicKeyToken->ptr());
+ for(N=0; N<L; N++,pb++) pc+=sprintf_s(pc,(dwUniBuf >> 1),"%2.2x",*pb);
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+ return sz;
+}
+
+/*
+--------------------------------------------------------------------
+mix -- mix 3 32-bit values reversibly.
+For every delta with one or two bits set, and the deltas of all three
+ high bits or all three low bits, whether the original value of a,b,c
+ is almost all zero or is uniformly distributed,
+* If mix() is run forward or backward, at least 32 bits in a,b,c
+ have at least 1/4 probability of changing.
+* If mix() is run forward, every bit of c will change between 1/3 and
+ 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
+mix() was built out of 36 single-cycle latency instructions in a
+ structure that could supported 2x parallelism, like so:
+ a -= b;
+ a -= c; x = (c>>13);
+ b -= c; a ^= x;
+ b -= a; x = (a<<8);
+ c -= a; b ^= x;
+ c -= b; x = (b>>13);
+ ...
+ Unfortunately, superscalar Pentiums and Sparcs can't take advantage
+ of that parallelism. They've also turned some of those single-cycle
+ latency instructions into multi-cycle latency instructions. Still,
+ this is the fastest good hash I could find. There were about 2^^68
+ to choose from. I only looked at a billion or so.
+--------------------------------------------------------------------
+*/
+#define mix(a,b,c) \
+{ \
+ a -= b; a -= c; a ^= (c >> 13); \
+ b -= c; b -= a; b ^= (a << 8); \
+ c -= a; c -= b; c ^= (b >> 13); \
+ a -= b; a -= c; a ^= (c >> 12); \
+ b -= c; b -= a; b ^= (a << 16); \
+ c -= a; c -= b; c ^= (b >> 5); \
+ a -= b; a -= c; a ^= (c >> 3); \
+ b -= c; b -= a; b ^= (a << 10); \
+ c -= a; c -= b; c ^= (b >> 15); \
+}
+
+/*
+--------------------------------------------------------------------
+hash() -- hash a variable-length key into a 32-bit value
+ k : the key (the unaligned variable-length array of bytes)
+ len : the length of the key, counting by bytes
+ initval : can be any 4-byte value
+Returns a 32-bit value. Every bit of the key affects every bit of
+the return value. Every 1-bit and 2-bit delta achieves avalanche.
+About 6*len+35 instructions.
+
+The best hash table sizes are powers of 2. There is no need to do
+mod a prime (mod is sooo slow!). If you need less than 32 bits,
+use a bitmask. For example, if you need only 10 bits, do
+ h = (h & hashmask(10));
+In which case, the hash table should have hashsize(10) elements.
+
+If you are hashing n strings (ub1 **)k, do it like this:
+ for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
+
+By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
+code any way you wish, private, educational, or commercial. It's free.
+
+See http://burtleburtle.net/bob/hash/evahash.html
+Use for hash table lookup, or anything where one collision in 2^^32 is
+acceptable. Do NOT use for cryptographic purposes.
+--------------------------------------------------------------------
+*/
+
+unsigned hash(
+ __in_ecount(length) const BYTE *k, /* the key */
+ unsigned length, /* the length of the key */
+ unsigned initval) /* the previous hash, or an arbitrary value */
+{
+ register unsigned a,b,c,len;
+
+ /* Set up the internal state */
+ len = length;
+ a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
+ c = initval; /* the previous hash value */
+
+ /*---------------------------------------- handle most of the key */
+ while (len >= 12)
+ {
+ a += (k[0] + ((unsigned)k[1] << 8) + ((unsigned)k[2] << 16) + ((unsigned)k[3] << 24));
+ b += (k[4] + ((unsigned)k[5] << 8) + ((unsigned)k[6] << 16) + ((unsigned)k[7] << 24));
+ c += (k[8] + ((unsigned)k[9] << 8) + ((unsigned)k[10] << 16) + ((unsigned)k[11] << 24));
+ mix(a,b,c);
+ k += 12; len -= 12;
+ }
+
+ /*------------------------------------- handle the last 11 bytes */
+ c += length;
+ switch(len) /* all the case statements fall through */
+ {
+ case 11: c+=((unsigned)k[10] << 24);
+ case 10: c+=((unsigned)k[9] << 16);
+ case 9 : c+=((unsigned)k[8] << 8);
+ /* the first byte of c is reserved for the length */
+ case 8 : b+=((unsigned)k[7] << 24);
+ case 7 : b+=((unsigned)k[6] << 16);
+ case 6 : b+=((unsigned)k[5] << 8);
+ case 5 : b+=k[4];
+ case 4 : a+=((unsigned)k[3] << 24);
+ case 3 : a+=((unsigned)k[2] << 16);
+ case 2 : a+=((unsigned)k[1] << 8);
+ case 1 : a+=k[0];
+ /* case 0: nothing left to add */
+ }
+ mix(a,b,c);
+ /*-------------------------------------------- report the result */
+ return c;
+}
+
diff --git a/src/ilasm/assembler.cpp b/src/ilasm/assembler.cpp
new file mode 100644
index 0000000000..690da64890
--- /dev/null
+++ b/src/ilasm/assembler.cpp
@@ -0,0 +1,2462 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// File: assembler.cpp
+//
+
+//
+
+#include "ilasmpch.h"
+
+#include "assembler.h"
+#include "binstr.h"
+#include "nvpair.h"
+
+#define FAIL_UNLESS(x, y) if (!(x)) { report->error y; return; }
+
+/**************************************************************************/
+void Assembler::StartNameSpace(__in __nullterminated char* name)
+{
+ m_NSstack.PUSH(m_szNamespace);
+ m_szNamespace = name;
+ unsigned L = (unsigned)strlen(m_szFullNS);
+ unsigned l = (unsigned)strlen(name);
+ if(L+l+1 >= m_ulFullNSLen)
+ {
+ char* pch = new char[((L+l)/MAX_NAMESPACE_LENGTH + 1)*MAX_NAMESPACE_LENGTH];
+ if(pch)
+ {
+ memcpy(pch,m_szFullNS,L+1);
+ delete [] m_szFullNS;
+ m_szFullNS = pch;
+ m_ulFullNSLen = ((L+l)/MAX_NAMESPACE_LENGTH + 1)*MAX_NAMESPACE_LENGTH;
+ }
+ else report->error("Failed to reallocate the NameSpace buffer\n");
+ }
+ if(L) m_szFullNS[L] = NAMESPACE_SEPARATOR_CHAR;
+ else L = 0xFFFFFFFF;
+ memcpy(&m_szFullNS[L+1],m_szNamespace, l+1);
+}
+
+/**************************************************************************/
+void Assembler::EndNameSpace()
+{
+ char *p = &m_szFullNS[strlen(m_szFullNS)-strlen(m_szNamespace)];
+ if(p > m_szFullNS) p--;
+ *p = 0;
+ delete [] m_szNamespace;
+ if((m_szNamespace = m_NSstack.POP())==NULL)
+ {
+ m_szNamespace = new char[2];
+ m_szNamespace[0] = 0;
+ }
+}
+
+/**************************************************************************/
+void Assembler::ClearImplList(void)
+{
+ while(m_nImplList) m_crImplList[--m_nImplList] = mdTypeRefNil;
+}
+/**************************************************************************/
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:22008) // "Suppress PREfast warnings about integer overflow"
+#endif
+void Assembler::AddToImplList(mdToken tk)
+{
+ if(m_nImplList+1 >= m_nImplListSize)
+ {
+ mdToken *ptr = new mdToken[m_nImplListSize + MAX_INTERFACES_IMPLEMENTED];
+ if(ptr == NULL)
+ {
+ report->error("Failed to reallocate Impl List from %d to %d bytes\n",
+ m_nImplListSize*sizeof(mdToken),
+ (m_nImplListSize+MAX_INTERFACES_IMPLEMENTED)*sizeof(mdToken));
+ return;
+ }
+ memcpy(ptr,m_crImplList,m_nImplList*sizeof(mdToken));
+ delete m_crImplList;
+ m_crImplList = ptr;
+ m_nImplListSize += MAX_INTERFACES_IMPLEMENTED;
+ }
+ m_crImplList[m_nImplList++] = tk;
+ m_crImplList[m_nImplList] = mdTypeRefNil;
+}
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+
+void Assembler::ClearBoundList(void)
+{
+ m_TyParList = NULL;
+}
+/**************************************************************************/
+mdToken Assembler::ResolveClassRef(mdToken tkResScope, __in __nullterminated const char *pszFullClassName, Class** ppClass)
+{
+ Class *pClass = NULL;
+ mdToken tkRet = mdTokenNil;
+ mdToken *ptkSpecial = NULL;
+
+ if(pszFullClassName == NULL) return mdTokenNil;
+#if (0)
+ if (m_fInitialisedMetaData == FALSE)
+ {
+ if (FAILED(InitMetaData())) // impl. see WRITER.CPP
+ {
+ _ASSERTE(0);
+ if(ppClass) *ppClass = NULL;
+ return mdTokenNil;
+ }
+ }
+#endif
+
+ switch(strlen(pszFullClassName))
+ {
+ case 11:
+ if(strcmp(pszFullClassName,"System.Enum")==0) ptkSpecial = &m_tkSysEnum;
+ break;
+ case 13:
+ if(strcmp(pszFullClassName,"System.Object")==0) ptkSpecial = &m_tkSysObject;
+ else if(strcmp(pszFullClassName,"System.String")==0) ptkSpecial = &m_tkSysString;
+ break;
+ case 16:
+ if(strcmp(pszFullClassName,"System.ValueType")==0) ptkSpecial = &m_tkSysValue;
+ break;
+ }
+ if(ptkSpecial) // special token
+ {
+ if(*ptkSpecial) // already resolved
+ {
+ tkRet = *ptkSpecial;
+ if(ppClass)
+ {
+ if(TypeFromToken(tkRet)==mdtTypeDef)
+ *ppClass = m_lstClass.PEEK(RidFromToken(tkRet)-1);
+ else *ppClass = NULL;
+ }
+ return tkRet;
+ }
+ else // needs to be resolved
+ if(!m_fIsMscorlib) tkResScope = GetBaseAsmRef();
+ }
+ if(tkResScope == 1)
+ {
+ if((pClass = FindCreateClass(pszFullClassName)) != NULL) tkRet = pClass->m_cl;
+ }
+ else
+ {
+ tkRet = MakeTypeRef(tkResScope, pszFullClassName);
+ pClass = NULL;
+ }
+ if(ppClass) *ppClass = pClass;
+ if(ptkSpecial) *ptkSpecial = tkRet;
+ return tkRet;
+}
+
+class TypeSpecContainer
+{
+private:
+ // Contain a BinStr
+ unsigned __int8 *ptr_;
+ unsigned len_;
+ // Hash the BinStr, just for speed of lookup
+ unsigned hash_;
+ // The value we're looking for
+ mdToken token_;
+public:
+ // Constructor for a 'lookup' object
+ TypeSpecContainer(BinStr *typeSpec) :
+ ptr_(typeSpec->ptr()),
+ len_(typeSpec->length()),
+ hash_(typeSpec->length()),
+ token_(mdTokenNil)
+ {
+ for (unsigned i = 0; i < len_; i++)
+ hash_ = (hash_ * 257) ^ ((i + 1) * (ptr_[i] ^ 0xA5));
+ }
+ // Constructor for a 'permanent' object
+ // Don't bother re-hashing, since we will always have already constructed the lookup object
+ TypeSpecContainer(const TypeSpecContainer &t, mdToken tk) :
+ ptr_(new unsigned __int8[t.len_]),
+ len_(t.len_),
+ hash_(t.hash_),
+ token_(tk)
+ {
+ _ASSERT(tk != mdTokenNil);
+ _ASSERT(t.token_ == mdTokenNil);
+ memcpy(ptr_, t.ptr_, len_);
+ }
+ ~TypeSpecContainer()
+ {
+ if (token_ != mdTokenNil)
+ // delete any memory for a 'permanent' object
+ delete[] ptr_;
+ }
+ // this is the operator for a RBTREE
+ int ComparedTo(TypeSpecContainer *t) const
+ {
+ // If they don't hash the same, just diff the hashes
+ if (hash_ != t->hash_)
+ return hash_ - t->hash_;
+ if (len_ != t->len_)
+ return len_ - t->len_;
+ return memcmp(ptr_, t->ptr_, len_);
+ }
+ // The only public data we need
+ const mdToken Token() const { return token_; }
+};
+
+static RBTREE<TypeSpecContainer> typeSpecCache;
+
+extern FIFO<char> TyParFixupList;
+
+/**************************************************************************/
+mdToken Assembler::ResolveTypeSpec(BinStr* typeSpec)
+{
+ mdToken tk;
+
+ // It is safe to use the cache only if there are no pending fixups
+ if (TyParFixupList.COUNT() != 0)
+ {
+ if (FAILED(m_pEmitter->GetTokenFromTypeSpec(typeSpec->ptr(), typeSpec->length(), &tk)))
+ return mdTokenNil;
+ return tk;
+ }
+
+ TypeSpecContainer tsc(typeSpec);
+
+ // GetTokenFromTypeSpec is a linear search through an unsorted list
+ // Instead of doing that all the time, look this thing up in a cache
+ TypeSpecContainer *res = typeSpecCache.FIND(&tsc);
+ if (res != NULL)
+ {
+#ifdef _DEBUG
+ // Verify that the cache is in sync with the master copy in metadata
+ PCOR_SIGNATURE pSig;
+ ULONG cSig;
+ m_pImporter->GetTypeSpecFromToken(res->Token(),(PCCOR_SIGNATURE*)&pSig,&cSig);
+ _ASSERTE(typeSpec->length() == cSig);
+ _ASSERTE(memcmp(typeSpec->ptr(), pSig, cSig) == 0);
+#endif
+
+ return res->Token();
+ }
+
+ if (FAILED(m_pEmitter->GetTokenFromTypeSpec(typeSpec->ptr(), typeSpec->length(), &tk)))
+ return mdTokenNil;
+
+ typeSpecCache.PUSH(new TypeSpecContainer(tsc, tk));
+ return tk;
+}
+
+/**************************************************************************/
+mdToken Assembler::GetAsmRef(__in __nullterminated const char* szName)
+{
+ mdToken tkResScope = 0;
+ if(strcmp(szName,"*")==0) tkResScope = mdTokenNil;
+ else
+ {
+ tkResScope = m_pManifest->GetAsmRefTokByName(szName);
+ if(RidFromToken(tkResScope)==0)
+ {
+ // emit the AssemblyRef
+ // if it's not self, try to get attributes with Autodetect
+ unsigned L = (unsigned)strlen(szName)+1;
+ char *sz = new char[L];
+ if(sz)
+ {
+ memcpy(sz,szName,L);
+ AsmManAssembly *pAsmRef = m_pManifest->m_pCurAsmRef;
+ m_pManifest->StartAssembly(sz,NULL,0,TRUE);
+ if(RidFromToken(m_pManifest->GetAsmTokByName(szName))==0)
+ {
+ report->warn("Reference to undeclared extern assembly '%s'. Attempting autodetect\n",szName);
+ m_pManifest->SetAssemblyAutodetect();
+ }
+ m_pManifest->EndAssembly();
+ tkResScope = m_pManifest->GetAsmRefTokByName(szName);
+ m_pManifest->m_pCurAsmRef = pAsmRef;
+ }
+ else
+ report->error("\nOut of memory!\n");
+ }
+ }
+ return tkResScope;
+}
+
+mdToken Assembler::GetBaseAsmRef()
+{
+ if(RidFromToken(m_pManifest->GetAsmRefTokByName("System.Runtime")) != 0)
+ {
+ return GetAsmRef("System.Runtime");
+ }
+
+ return GetAsmRef("mscorlib");
+}
+
+mdToken Assembler::GetInterfaceImpl(mdToken tsClass, mdToken tsInterface)
+{
+ mdToken result = mdTokenNil;
+ HCORENUM iiEnum = 0;
+ ULONG actualInterfaces;
+ mdInterfaceImpl impls;
+
+ while (SUCCEEDED(m_pImporter->EnumInterfaceImpls(&iiEnum, tsClass, &impls, 1, &actualInterfaces)))
+ {
+ if (actualInterfaces == 1)
+ {
+ mdToken classToken, interfaceToken;
+ if (FAILED(m_pImporter->GetInterfaceImplProps(impls, &classToken, &interfaceToken)))
+ break;
+ if (classToken == tsClass && interfaceToken == tsInterface)
+ {
+ result = impls;
+ break;
+ }
+ }
+ }
+ m_pImporter->CloseEnum(iiEnum);
+ return result;
+}
+
+/**************************************************************************/
+mdToken Assembler::GetModRef(__in __nullterminated char* szName)
+{
+ mdToken tkResScope = 0;
+ if(!strcmp(szName,m_szScopeName))
+ tkResScope = 1; // scope is "this module"
+ else
+ {
+ ImportDescriptor* pID;
+ int i = 0;
+ tkResScope = mdModuleRefNil;
+ DWORD L = (DWORD)strlen(szName);
+ while((pID=m_ImportList.PEEK(i++)))
+ {
+ if(pID->dwDllName != L) continue;
+ if((L > 0) && (strcmp(pID->szDllName,szName)!=0)) continue;
+ tkResScope = pID->mrDll;
+ break;
+ }
+ if(RidFromToken(tkResScope)==0)
+ report->error("Undefined module ref '%s'\n",szName);
+ }
+ return tkResScope;
+}
+/**************************************************************************/
+mdToken Assembler::MakeTypeRef(mdToken tkResScope, LPCUTF8 pszFullClassName)
+{
+ mdToken tkRet = mdTokenNil;
+ if(pszFullClassName && *pszFullClassName)
+ {
+ LPCUTF8 pc;
+ if((pc = strrchr(pszFullClassName,NESTING_SEP))) // scope: enclosing class
+ {
+ LPUTF8 szScopeName;
+ DWORD L = (DWORD)(pc-pszFullClassName);
+ if((szScopeName = new char[L+1]) != NULL)
+ {
+ memcpy(szScopeName,pszFullClassName,L);
+ szScopeName[L] = 0;
+ tkResScope = MakeTypeRef(tkResScope,szScopeName);
+ delete [] szScopeName;
+ }
+ else
+ report->error("\nOut of memory!\n");
+ pc++;
+ }
+ else pc = pszFullClassName;
+ if(*pc)
+ {
+ // convert name to widechar
+ WszMultiByteToWideChar(g_uCodePage,0,pc,-1,wzUniBuf,dwUniBuf);
+ if(FAILED(m_pEmitter->DefineTypeRefByName(tkResScope, wzUniBuf, &tkRet))) tkRet = mdTokenNil;
+ }
+ }
+ return tkRet;
+}
+/**************************************************************************/
+
+DWORD Assembler::CheckClassFlagsIfNested(Class* pEncloser, DWORD attr)
+{
+ DWORD wasAttr = attr;
+ if(pEncloser && (!IsTdNested(attr)))
+ {
+ if(OnErrGo)
+ report->error("Nested class has non-nested visibility (0x%08X)\n",attr);
+ else
+ {
+ attr &= ~tdVisibilityMask;
+ attr |= (IsTdPublic(wasAttr) ? tdNestedPublic : tdNestedPrivate);
+ report->warn("Nested class has non-nested visibility (0x%08X), changed to nested (0x%08X)\n",wasAttr,attr);
+ }
+ }
+ else if((pEncloser==NULL) && IsTdNested(attr))
+ {
+ if(OnErrGo)
+ report->error("Non-nested class has nested visibility (0x%08X)\n",attr);
+ else
+ {
+ attr &= ~tdVisibilityMask;
+ attr |= (IsTdNestedPublic(wasAttr) ? tdPublic : tdNotPublic);
+ report->warn("Non-nested class has nested visibility (0x%08X), changed to non-nested (0x%08X)\n",wasAttr,attr);
+ }
+ }
+ return attr;
+}
+
+/**************************************************************************/
+
+void Assembler::StartClass(__in __nullterminated char* name, DWORD attr, TyParList *typars)
+{
+ Class *pEnclosingClass = m_pCurClass;
+ char *szFQN;
+ ULONG LL;
+
+ m_TyParList = typars;
+
+ if (m_pCurMethod != NULL)
+ {
+ report->error("Class cannot be declared within a method scope\n");
+ }
+ if(pEnclosingClass)
+ {
+ LL = pEnclosingClass->m_dwFQN+(ULONG)strlen(name)+2;
+ if((szFQN = new char[LL]))
+ sprintf_s(szFQN,LL,"%s%c%s",pEnclosingClass->m_szFQN,NESTING_SEP,name);
+ else
+ report->error("\nOut of memory!\n");
+ }
+ else
+ {
+ unsigned L = (unsigned)strlen(m_szFullNS);
+ unsigned LLL = (unsigned)strlen(name);
+ LL = L + LLL + (L ? 2 : 1);
+ if((szFQN = new char[LL]))
+ {
+ if(L) sprintf_s(szFQN,LL,"%s.%s",m_szFullNS,name);
+ else memcpy(szFQN,name,LL);
+ if(LL > MAX_CLASSNAME_LENGTH)
+ {
+ report->error("Full class name too long (%d characters, %d allowed).\n",LL-1,MAX_CLASSNAME_LENGTH-1);
+ }
+ }
+ else
+ report->error("\nOut of memory!\n");
+ }
+ if(szFQN == NULL) return;
+
+ mdToken tkThis;
+ if(m_fIsMscorlib)
+ tkThis = ResolveClassRef(1,szFQN,&m_pCurClass); // boils down to FindCreateClass(szFQN)
+ else
+ {
+ m_pCurClass = FindCreateClass(szFQN);
+ tkThis = m_pCurClass->m_cl;
+ }
+ if(m_pCurClass->m_bIsMaster)
+ {
+ m_pCurClass->m_Attr = CheckClassFlagsIfNested(pEnclosingClass, attr);
+
+ if (m_TyParList)
+ {
+ //m_pCurClass->m_NumTyPars = m_TyParList->ToArray(&m_pCurClass->m_TyParBounds, &m_pCurClass->m_TyParNames, &m_pCurClass->m_TyParAttrs);
+ m_pCurClass->m_NumTyPars = m_TyParList->ToArray(&(m_pCurClass->m_TyPars));
+ delete m_TyParList;
+ m_TyParList = NULL;
+ }
+ else m_pCurClass->m_NumTyPars = 0;
+ m_pCurClass->m_pEncloser = pEnclosingClass;
+ } // end if(old class) else
+ m_tkCurrentCVOwner = 0;
+ m_CustomDescrListStack.PUSH(m_pCustomDescrList);
+ m_pCustomDescrList = &(m_pCurClass->m_CustDList);
+
+ m_ClassStack.PUSH(pEnclosingClass);
+ ClearBoundList();
+}
+
+/**************************************************************************/
+
+void Assembler::AddClass()
+{
+ mdTypeRef crExtends = mdTypeRefNil;
+ BOOL bIsEnum = FALSE;
+ BOOL bIsValueType = FALSE;
+
+ if(m_pCurClass->m_bIsMaster)
+ {
+ DWORD attr = m_pCurClass->m_Attr;
+ if(!IsNilToken(m_crExtends))
+ {
+ // has a superclass
+ if(IsTdInterface(attr)) report->error("Base class in interface\n");
+ bIsValueType = (m_crExtends == m_tkSysValue)&&(m_pCurClass->m_cl != m_tkSysEnum);
+ bIsEnum = (m_crExtends == m_tkSysEnum);
+ crExtends = m_crExtends;
+ }
+ else
+ {
+ bIsEnum = ((attr & 0x40000000) != 0);
+ bIsValueType = ((attr & 0x80000000) != 0);
+ }
+ attr &= 0x3FFFFFFF;
+ if (m_fAutoInheritFromObject && (crExtends == mdTypeRefNil) && (!IsTdInterface(attr)))
+ {
+ mdToken tkMscorlib = m_fIsMscorlib ? 1 : GetBaseAsmRef();
+ crExtends = bIsEnum ?
+ ResolveClassRef(tkMscorlib,"System.Enum",NULL)
+ :( bIsValueType ?
+ ResolveClassRef(tkMscorlib,"System.ValueType",NULL)
+ : ResolveClassRef(tkMscorlib, "System.Object",NULL));
+ }
+ m_pCurClass->m_Attr = attr;
+ m_pCurClass->m_crExtends = (m_pCurClass->m_cl == m_tkSysObject)? mdTypeRefNil : crExtends;
+
+ if ((m_pCurClass->m_dwNumInterfaces = m_nImplList) != NULL)
+ {
+ if(bIsEnum) report->error("Enum implementing interface(s)\n");
+ if((m_pCurClass->m_crImplements = new mdTypeRef[m_nImplList+1]) != NULL)
+ memcpy(m_pCurClass->m_crImplements, m_crImplList, (m_nImplList+1)*sizeof(mdTypeRef));
+ else
+ {
+ report->error("Failed to allocate Impl List for class '%s'\n", m_pCurClass->m_szFQN);
+ m_pCurClass->m_dwNumInterfaces = 0;
+ }
+ }
+ else m_pCurClass->m_crImplements = NULL;
+ if(bIsValueType)
+ {
+ if(!IsTdSealed(attr))
+ {
+ if(OnErrGo) report->error("Non-sealed value class\n");
+ else
+ {
+ report->warn("Non-sealed value class, made sealed\n");
+ m_pCurClass->m_Attr |= tdSealed;
+ }
+ }
+ }
+ m_pCurClass->m_bIsMaster = FALSE;
+ } // end if(old class) else
+ ClearImplList();
+ m_crExtends = mdTypeRefNil;
+}
+
+/**************************************************************************/
+void Assembler::EndClass()
+{
+ m_pCurClass = m_ClassStack.POP();
+ m_tkCurrentCVOwner = 0;
+ m_pCustomDescrList = m_CustomDescrListStack.POP();
+}
+
+/**************************************************************************/
+void Assembler::SetPinvoke(BinStr* DllName, int Ordinal, BinStr* Alias, int Attrs)
+{
+ if(m_pPInvoke) delete m_pPInvoke;
+ if(DllName->length())
+ {
+ if((m_pPInvoke = new PInvokeDescriptor))
+ {
+ unsigned l;
+ ImportDescriptor* pID;
+ if((pID = EmitImport(DllName)))
+ {
+ m_pPInvoke->mrDll = pID->mrDll;
+ m_pPInvoke->szAlias = NULL;
+ if(Alias)
+ {
+ l = Alias->length();
+ if((m_pPInvoke->szAlias = new char[l+1]))
+ {
+ memcpy(m_pPInvoke->szAlias,Alias->ptr(),l);
+ m_pPInvoke->szAlias[l] = 0;
+ }
+ else report->error("\nOut of memory!\n");
+ }
+ m_pPInvoke->dwAttrs = (DWORD)Attrs;
+ }
+ else
+ {
+ delete m_pPInvoke;
+ m_pPInvoke = NULL;
+ report->error("PInvoke refers to undefined imported DLL\n");
+ }
+ }
+ else
+ report->error("Failed to allocate PInvokeDescriptor\n");
+ }
+ else
+ {
+ m_pPInvoke = NULL; // No DLL name, it's "local" (IJW) PInvoke
+ report->error("Local (embedded native) PInvoke method, the resulting PE file is unusable\n");
+ }
+ if(DllName) delete DllName;
+ if(Alias) delete Alias;
+}
+
+/**************************************************************************/
+void Assembler::StartMethod(__in __nullterminated char* name, BinStr* sig, CorMethodAttr flags, BinStr* retMarshal, DWORD retAttr, TyParList *typars)
+{
+ if (m_pCurMethod != NULL)
+ {
+ report->error("Cannot declare a method '%s' within another method\n",name);
+ }
+ if (!m_fInitialisedMetaData)
+ {
+ if (FAILED(InitMetaData())) // impl. see WRITER.CPP
+ {
+ _ASSERTE(0);
+ }
+ }
+ size_t namelen = strlen(name);
+ if(namelen >= MAX_CLASSNAME_LENGTH)
+ {
+ char c = name[MAX_CLASSNAME_LENGTH-1];
+ name[MAX_CLASSNAME_LENGTH-1] = 0;
+ report->error("Method '%s...' -- name too long (%d characters).\n",name,namelen);
+ name[MAX_CLASSNAME_LENGTH-1] = c;
+ }
+ if (!(flags & mdStatic))
+ *(sig->ptr()) |= IMAGE_CEE_CS_CALLCONV_HASTHIS;
+ else if(*(sig->ptr()) & (IMAGE_CEE_CS_CALLCONV_HASTHIS | IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS))
+ {
+ if(OnErrGo) report->error("Method '%s' -- both static and instance\n", name);
+ else
+ {
+ report->warn("Method '%s' -- both static and instance, set to static\n", name);
+ *(sig->ptr()) &= ~(IMAGE_CEE_CS_CALLCONV_HASTHIS | IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS);
+ }
+ }
+
+ if(!IsMdPrivateScope(flags))
+ {
+ Method* pMethod;
+ Class* pClass = (m_pCurClass ? m_pCurClass : m_pModuleClass);
+ DWORD L = (DWORD)strlen(name);
+ for(int j=0; (pMethod = pClass->m_MethodList.PEEK(j)); j++)
+ {
+ if( (pMethod->m_dwName == L) &&
+ (!strcmp(pMethod->m_szName,name)) &&
+ (pMethod->m_dwMethodCSig == sig->length()) &&
+ (!memcmp(pMethod->m_pMethodSig,sig->ptr(),sig->length()))
+ &&(!IsMdPrivateScope(pMethod->m_Attr)))
+ {
+ if(m_fTolerateDupMethods)
+ {
+ // reset for new body
+ pMethod->m_lstFixup.RESET(true);
+ //pMethod->m_lstLabel.RESET(true);
+ m_lstLabel.RESET(true);
+ pMethod->m_Locals.RESET(true);
+ delArgNameList(pMethod->m_firstArgName);
+ delArgNameList(pMethod->m_firstVarName);
+ pMethod->m_pCurrScope = &(pMethod->m_MainScope);
+ pMethod->m_pCurrScope->Reset();
+ pMethod->m_firstArgName = getArgNameList();
+ pMethod->m_dwNumExceptions = 0;
+ pMethod->m_dwNumEndfilters = 0;
+ if(pMethod->m_pRetMarshal) delete pMethod->m_pRetMarshal;
+ if(pMethod->m_pRetValue) delete pMethod->m_pRetValue;
+
+ pMethod->m_MethodImplDList.RESET(false); // ptrs in m_MethodImplDList are dups of those in Assembler
+
+ pMethod->m_CustomDescrList.RESET(true);
+
+ if(pMethod->m_fEntryPoint)
+ {
+ pMethod->m_fEntryPoint = FALSE;
+ m_fEntryPointPresent = FALSE;
+ }
+
+ if(pMethod->m_pbsBody)
+ {
+ // no need to remove relevant MemberRef Fixups from the Assembler list:
+ // their m_fNew flag is set to FALSE anyway.
+ // Just get rid of old method body
+ delete pMethod->m_pbsBody;
+ pMethod->m_pbsBody = NULL;
+ }
+
+ pMethod->m_fNewBody = TRUE;
+ m_pCurMethod = pMethod;
+ }
+ else
+ report->error("Duplicate method declaration\n");
+ break;
+ }
+ }
+ }
+ if(m_pCurMethod == NULL)
+ {
+ if(m_pCurClass)
+ { // instance method
+ if(IsMdAbstract(flags) && !IsTdAbstract(m_pCurClass->m_Attr))
+ {
+ report->error("Abstract method '%s' in non-abstract class '%s'\n",name,m_pCurClass->m_szFQN);
+ }
+ if(m_pCurClass->m_crExtends == m_tkSysEnum) report->error("Method in enum\n");
+
+ if(!strcmp(name,COR_CTOR_METHOD_NAME))
+ {
+ flags = (CorMethodAttr)(flags | mdSpecialName);
+ if(IsTdInterface(m_pCurClass->m_Attr)) report->error("Instance constructor in interface\n");
+
+ }
+ if(!IsMdStatic(flags))
+ {
+ if(IsTdInterface(m_pCurClass->m_Attr))
+ {
+ if(!IsMdPublic(flags)) report->error("Non-public instance method in interface\n");
+ if((!(IsMdVirtual(flags) && IsMdAbstract(flags))))
+ {
+ if(OnErrGo) report->error("Non-virtual, non-abstract instance method in interface\n");
+ else
+ {
+ report->warn("Non-virtual, non-abstract instance method in interface, set to such\n");
+ flags = (CorMethodAttr)(flags |mdVirtual | mdAbstract);
+ }
+ }
+
+ }
+ }
+ m_pCurMethod = new Method(this, m_pCurClass, name, sig, flags);
+ }
+ else
+ {
+ if(IsMdAbstract(flags))
+ {
+ if(OnErrGo) report->error("Global method '%s' can't be abstract\n",name);
+ else
+ {
+ report->warn("Global method '%s' can't be abstract, flag removed\n",name);
+ flags = (CorMethodAttr)(((int) flags) &~mdAbstract);
+ }
+ }
+ if(!IsMdStatic(flags))
+ {
+ if(OnErrGo) report->error("Non-static global method '%s'\n",name);
+ else
+ {
+ report->warn("Non-static global method '%s', made static\n",name);
+ flags = (CorMethodAttr)(flags | mdStatic);
+ *((BYTE*)(sig->ptr())) &= ~(IMAGE_CEE_CS_CALLCONV_HASTHIS | IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS);
+ }
+ }
+ m_pCurMethod = new Method(this, m_pCurClass, name, sig, flags);
+ if (m_pCurMethod)
+ {
+ m_pCurMethod->SetIsGlobalMethod();
+ if (m_fInitialisedMetaData == FALSE) InitMetaData();
+ }
+ }
+ if(m_pCurMethod)
+ {
+ if(!OnErrGo)
+ {
+ if(m_pCurMethod->m_firstArgName)
+ {
+ for(ARG_NAME_LIST *pAN=m_pCurMethod->m_firstArgName; pAN; pAN = pAN->pNext)
+ {
+ if(pAN->dwName)
+ {
+ int k = m_pCurMethod->findArgNum(pAN->pNext,pAN->szName,pAN->dwName);
+ if(k >= 0)
+ report->warn("Duplicate param name '%s' in method '%s'\n",pAN->szName,name);
+ }
+ }
+ }
+ }
+ m_pCurMethod->m_pRetMarshal = retMarshal;
+ m_pCurMethod->m_dwRetAttr = retAttr;
+ m_tkCurrentCVOwner = 0;
+ m_CustomDescrListStack.PUSH(m_pCustomDescrList);
+ m_pCustomDescrList = &(m_pCurMethod->m_CustomDescrList);
+ m_pCurMethod->m_MainScope.dwStart = m_CurPC;
+ if (typars)
+ {
+ //m_pCurMethod->m_NumTyPars = typars->ToArray(&m_pCurMethod->m_TyParBounds,
+ //&m_pCurMethod->m_TyParNames, NULL);
+ m_pCurMethod->m_NumTyPars = typars->ToArray(&(m_pCurMethod->m_TyPars));
+ delete typars;
+ m_TyParList = NULL;
+ }
+ else m_pCurMethod->m_NumTyPars = 0;
+ }
+ else report->error("Failed to allocate Method class\n");
+ } // end if new method
+}
+
+/**************************************************************************/
+void Assembler::EndMethod()
+{
+
+ if(m_pCurMethod->m_pCurrScope != &(m_pCurMethod->m_MainScope))
+ {
+ report->error("Invalid lexical scope structure in method %s\n",m_pCurMethod->m_szName);
+ }
+ m_pCurMethod->m_pCurrScope->dwEnd = m_CurPC;
+ if (DoFixups(m_pCurMethod)) AddMethod(m_pCurMethod); //AddMethod - see ASSEM.CPP
+ else
+ {
+ report->error("Method '%s' compilation failed.\n",m_pCurMethod->m_szName);
+ }
+ //m_pCurMethod->m_lstLabel.RESET(true);
+ m_lstLabel.RESET(true);
+ m_tkCurrentCVOwner = 0;
+ m_pCustomDescrList = m_CustomDescrListStack.POP();
+ ResetForNextMethod(); // see ASSEM.CPP
+}
+/**************************************************************************/
+/* rvaLabel is the optional label that indicates this field points at a particular RVA */
+void Assembler::AddField(__inout_z __inout char* name, BinStr* sig, CorFieldAttr flags, __in __nullterminated char* rvaLabel, BinStr* pVal, ULONG ulOffset)
+{
+ FieldDescriptor* pFD;
+ ULONG i,n;
+ mdToken tkParent = mdTokenNil;
+ Class* pClass;
+
+ if (m_pCurMethod)
+ report->error("Field cannot be declared within a method\n");
+
+ if(strlen(name) >= MAX_CLASSNAME_LENGTH)
+ {
+ char c = name[MAX_CLASSNAME_LENGTH-1];
+ name[MAX_CLASSNAME_LENGTH-1] = 0;
+ report->error("Field '%s...' -- name too long (%d characters).\n",name,strlen(name));
+ name[MAX_CLASSNAME_LENGTH-1] = c;
+ }
+
+ if(sig && (sig->length() >= 2))
+ {
+ if(sig->ptr()[1] == ELEMENT_TYPE_VOID)
+ report->error("Illegal use of type 'void'\n");
+ }
+
+ if (m_pCurClass)
+ {
+ tkParent = m_pCurClass->m_cl;
+
+ if(IsTdInterface(m_pCurClass->m_Attr))
+ {
+ if(!IsFdStatic(flags))
+ {
+ report->warn("Instance field in interface (CLS violation)\n");
+ if(!IsFdPublic(flags)) report->error("Non-public instance field in interface\n");
+ }
+ }
+ }
+ else
+ {
+ if(ulOffset != 0xFFFFFFFF)
+ {
+ report->warn("Offset in global field '%s' is ignored\n",name);
+ ulOffset = 0xFFFFFFFF;
+ }
+ if(!IsFdStatic(flags))
+ {
+ if(OnErrGo) report->error("Non-static global field\n");
+ else
+ {
+ report->warn("Non-static global field, made static\n");
+ flags = (CorFieldAttr)(flags | fdStatic);
+ }
+ }
+ }
+ pClass = (m_pCurClass ? m_pCurClass : m_pModuleClass);
+ n = pClass->m_FieldDList.COUNT();
+ DWORD L = (DWORD)strlen(name);
+ for(i = 0; i < n; i++)
+ {
+ pFD = pClass->m_FieldDList.PEEK(i);
+ if((pFD->m_tdClass == tkParent)&&(L==pFD->m_dwName)&&(!strcmp(pFD->m_szName,name))
+ &&(pFD->m_pbsSig->length() == sig->length())
+ &&(memcmp(pFD->m_pbsSig->ptr(),sig->ptr(),sig->length())==0))
+ {
+ report->error("Duplicate field declaration: '%s'\n",name);
+ break;
+ }
+ }
+ if (rvaLabel && !IsFdStatic(flags))
+ report->error("Only static fields can have 'at' clauses\n");
+
+ if(i >= n)
+ {
+ if((pFD = new FieldDescriptor))
+ {
+ pFD->m_tdClass = tkParent;
+ pFD->m_szName = name;
+ pFD->m_dwName = L;
+ pFD->m_fdFieldTok = mdTokenNil;
+ if((pFD->m_ulOffset = ulOffset) != 0xFFFFFFFF) pClass->m_dwNumFieldsWithOffset++;
+ pFD->m_rvaLabel = rvaLabel;
+ pFD->m_pbsSig = sig;
+ pFD->m_pClass = pClass;
+ pFD->m_pbsValue = pVal;
+ pFD->m_pbsMarshal = m_pMarshal;
+ pFD->m_pPInvoke = m_pPInvoke;
+ pFD->m_dwAttr = flags;
+
+ m_tkCurrentCVOwner = 0;
+ m_pCustomDescrList = &(pFD->m_CustomDescrList);
+
+ pClass->m_FieldDList.PUSH(pFD);
+ pClass->m_fNewMembers = TRUE;
+ }
+ else
+ report->error("Failed to allocate Field Descriptor\n");
+ }
+ else
+ {
+ if(pVal) delete pVal;
+ if(m_pPInvoke) delete m_pPInvoke;
+ if(m_pMarshal) delete m_pMarshal;
+ delete name;
+ }
+ m_pPInvoke = NULL;
+ m_pMarshal = NULL;
+}
+
+BOOL Assembler::EmitField(FieldDescriptor* pFD)
+{
+ WCHAR* wzFieldName=&wzUniBuf[0];
+ HRESULT hr;
+ DWORD cSig;
+ COR_SIGNATURE* mySig;
+ mdFieldDef mb;
+ BYTE ValType = ELEMENT_TYPE_VOID;
+ void * pValue = NULL;
+ unsigned lVal = 0;
+ BOOL ret = TRUE;
+
+ cSig = pFD->m_pbsSig->length();
+ mySig = (COR_SIGNATURE*)(pFD->m_pbsSig->ptr());
+
+ WszMultiByteToWideChar(g_uCodePage,0,pFD->m_szName,-1,wzFieldName,dwUniBuf); //int)cFieldNameLength);
+ if(IsFdPrivateScope(pFD->m_dwAttr))
+ {
+ WCHAR* p = wcsstr(wzFieldName,W("$PST04"));
+ if(p) *p = 0;
+ }
+
+ if(pFD->m_pbsValue && pFD->m_pbsValue->length())
+ {
+ ValType = *(pFD->m_pbsValue->ptr());
+ lVal = pFD->m_pbsValue->length() - 1; // 1 is type byte
+ pValue = (void*)(pFD->m_pbsValue->ptr() + 1);
+ if(ValType == ELEMENT_TYPE_STRING)
+ {
+ //while(lVal % sizeof(WCHAR)) { pFD->m_pbsValue->appendInt8(0); lVal++; }
+ lVal /= sizeof(WCHAR);
+
+#if defined(ALIGN_ACCESS) || BIGENDIAN
+ void* pValueTemp = _alloca(lVal * sizeof(WCHAR));
+ memcpy(pValueTemp, pValue, lVal * sizeof(WCHAR));
+ pValue = pValueTemp;
+
+ SwapStringLength((WCHAR*)pValue, lVal);
+#endif
+ }
+ }
+
+ hr = m_pEmitter->DefineField(
+ pFD->m_tdClass,
+ wzFieldName,
+ pFD->m_dwAttr,
+ mySig,
+ cSig,
+ ValType,
+ pValue,
+ lVal,
+ &mb
+ );
+ if (FAILED(hr))
+ {
+ report->error("Failed to define field '%s' (HRESULT=0x%08X)\n",pFD->m_szName,hr);
+ ret = FALSE;
+ }
+ else
+ {
+ //--------------------------------------------------------------------------------
+ if(IsFdPinvokeImpl(pFD->m_dwAttr)&&(pFD->m_pPInvoke))
+ {
+ if(pFD->m_pPInvoke->szAlias == NULL) pFD->m_pPInvoke->szAlias = pFD->m_szName;
+ if(FAILED(EmitPinvokeMap(mb,pFD->m_pPInvoke)))
+ {
+ report->error("Failed to define PInvoke map of .field '%s'\n",pFD->m_szName);
+ ret = FALSE;
+ }
+ }
+ //--------------------------------------------------------------------------
+ if(pFD->m_pbsMarshal)
+ {
+ if(FAILED(hr = m_pEmitter->SetFieldMarshal (
+ mb, // [IN] given a fieldDef or paramDef token
+ (PCCOR_SIGNATURE)(pFD->m_pbsMarshal->ptr()), // [IN] native type specification
+ pFD->m_pbsMarshal->length()))) // [IN] count of bytes of pvNativeType
+ {
+ report->error("Failed to set field marshaling for '%s' (HRESULT=0x%08X)\n",pFD->m_szName,hr);
+ ret = FALSE;
+ }
+ }
+ //--------------------------------------------------------------------------------
+ // Set the the RVA to a dummy value. later it will be fixed
+ // up to be something correct, but if we don't emit something
+ // the size of the meta-data will not be correct
+ if (pFD->m_rvaLabel)
+ {
+ m_fHaveFieldsWithRvas = TRUE;
+ hr = m_pEmitter->SetFieldRVA(mb, 0xCCCCCCCC);
+ if (FAILED(hr))
+ {
+ report->error("Failed to set RVA for field '%s' (HRESULT=0x%08X)\n",pFD->m_szName,hr);
+ ret = FALSE;
+ }
+ }
+ //--------------------------------------------------------------------------------
+ EmitCustomAttributes(mb, &(pFD->m_CustomDescrList));
+
+ }
+ pFD->m_fdFieldTok = mb;
+ return ret;
+}
+
+/**************************************************************************/
+void Assembler::EmitByte(int val)
+{
+ char ch = (char)val;
+ //if((val < -128)||(val > 127))
+ // report->warn("Emitting 0x%X as a byte: data truncated to 0x%X\n",(unsigned)val,(BYTE)ch);
+ EmitBytes((BYTE *)&ch,1);
+}
+
+/**************************************************************************/
+void Assembler::NewSEHDescriptor(void) //sets m_SEHD
+{
+ m_SEHDstack.PUSH(m_SEHD);
+ m_SEHD = new SEH_Descriptor;
+ if(m_SEHD == NULL) report->error("Failed to allocate SEH descriptor\n");
+}
+/**************************************************************************/
+void Assembler::SetTryLabels(__in __nullterminated char * szFrom, __in __nullterminated char *szTo)
+{
+ if(!m_SEHD) return;
+ Label *pLbl = m_pCurMethod->FindLabel(szFrom);
+ if(pLbl)
+ {
+ m_SEHD->tryFrom = pLbl->m_PC;
+ if((pLbl = m_pCurMethod->FindLabel(szTo))) m_SEHD->tryTo = pLbl->m_PC; //FindLabel: Method.CPP
+ else report->error("Undefined 2nd label in 'try <label> to <label>'\n");
+ }
+ else report->error("Undefined 1st label in 'try <label> to <label>'\n");
+}
+/**************************************************************************/
+void Assembler::SetFilterLabel(__in __nullterminated char *szFilter)
+{
+ if(!m_SEHD) return;
+ Label *pLbl = m_pCurMethod->FindLabel(szFilter);
+ if(pLbl) m_SEHD->sehFilter = pLbl->m_PC;
+ else report->error("Undefined label in 'filter <label>'\n");
+}
+/**************************************************************************/
+void Assembler::SetCatchClass(mdToken catchClass)
+{
+ if(!m_SEHD) return;
+ m_SEHD->cException = catchClass;
+
+}
+/**************************************************************************/
+void Assembler::SetHandlerLabels(__in __nullterminated char *szHandlerFrom, __in __nullterminated char *szHandlerTo)
+{
+ if(!m_SEHD) return;
+ Label *pLbl = m_pCurMethod->FindLabel(szHandlerFrom);
+ if(pLbl)
+ {
+ m_SEHD->sehHandler = pLbl->m_PC;
+ if(szHandlerTo)
+ {
+ pLbl = m_pCurMethod->FindLabel(szHandlerTo);
+ if(pLbl)
+ {
+ m_SEHD->sehHandlerTo = pLbl->m_PC;
+ return;
+ }
+ }
+ else
+ {
+ m_SEHD->sehHandlerTo = m_SEHD->sehHandler - 1;
+ return;
+ }
+ }
+ report->error("Undefined label in 'handler <label> to <label>'\n");
+}
+/**************************************************************************/
+void Assembler::EmitTry(void) //enum CorExceptionFlag kind, char* beginLabel, char* endLabel, char* handleLabel, char* filterOrClass)
+{
+ if(m_SEHD)
+ {
+ bool isFilter=(m_SEHD->sehClause == COR_ILEXCEPTION_CLAUSE_FILTER),
+ isFault=(m_SEHD->sehClause == COR_ILEXCEPTION_CLAUSE_FAULT),
+ isFinally=(m_SEHD->sehClause == COR_ILEXCEPTION_CLAUSE_FINALLY);
+
+ AddException(m_SEHD->tryFrom, m_SEHD->tryTo, m_SEHD->sehHandler, m_SEHD->sehHandlerTo,
+ m_SEHD->cException, isFilter, isFault, isFinally);
+ }
+ else report->error("Attempt to EmitTry with NULL SEH descriptor\n");
+}
+/**************************************************************************/
+
+void Assembler::AddException(DWORD pcStart, DWORD pcEnd, DWORD pcHandler, DWORD pcHandlerTo, mdTypeRef crException, BOOL isFilter, BOOL isFault, BOOL isFinally)
+{
+ if (m_pCurMethod == NULL)
+ {
+ report->error("Exceptions can be declared only when in a method scope\n");
+ return;
+ }
+
+ if (m_pCurMethod->m_dwNumExceptions >= m_pCurMethod->m_dwMaxNumExceptions)
+ {
+ COR_ILMETHOD_SECT_EH_CLAUSE_FAT *ptr =
+ new COR_ILMETHOD_SECT_EH_CLAUSE_FAT[m_pCurMethod->m_dwMaxNumExceptions+MAX_EXCEPTIONS];
+ if(ptr == NULL)
+ {
+ report->error("Failed to reallocate SEH buffer\n");
+ return;
+ }
+ memcpy(ptr,m_pCurMethod->m_ExceptionList,m_pCurMethod->m_dwNumExceptions*sizeof(COR_ILMETHOD_SECT_EH_CLAUSE_FAT));
+ delete [] m_pCurMethod->m_ExceptionList;
+ m_pCurMethod->m_ExceptionList = ptr;
+ m_pCurMethod->m_dwMaxNumExceptions += MAX_EXCEPTIONS;
+ }
+
+ COR_ILMETHOD_SECT_EH_CLAUSE_FAT *clause = &m_pCurMethod->m_ExceptionList[m_pCurMethod->m_dwNumExceptions];
+ clause->SetTryOffset(pcStart);
+ clause->SetTryLength(pcEnd - pcStart);
+ clause->SetHandlerOffset(pcHandler);
+ clause->SetHandlerLength(pcHandlerTo - pcHandler);
+ clause->SetClassToken(crException);
+
+ int flags = COR_ILEXCEPTION_CLAUSE_OFFSETLEN;
+ if (isFilter) {
+ flags |= COR_ILEXCEPTION_CLAUSE_FILTER;
+ }
+ if (isFault) {
+ flags |= COR_ILEXCEPTION_CLAUSE_FAULT;
+ }
+ if (isFinally) {
+ flags |= COR_ILEXCEPTION_CLAUSE_FINALLY;
+ }
+ clause->SetFlags((CorExceptionFlag)flags);
+
+ m_pCurMethod->m_dwNumExceptions++;
+}
+
+/**************************************************************************/
+void Assembler::EmitMaxStack(unsigned val)
+{
+ if(val > 0xFFFF) report->warn(".maxstack parameter exceeds 65535, truncated to %d\n",val&0xFFFF);
+ if (m_pCurMethod) m_pCurMethod->m_MaxStack = val&0xFFFF;
+ else report->error(".maxstack can be used only within a method scope\n");
+}
+
+/**************************************************************************/
+void Assembler::EmitLocals(BinStr* sig)
+{
+ if(sig)
+ {
+ if (m_pCurMethod)
+ {
+ ARG_NAME_LIST *pAN, *pList= getArgNameList();
+ if(pList)
+ {
+ VarDescr* pVD;
+ for(pAN=pList; pAN; pAN = pAN->pNext)
+ {
+ if(pAN->dwAttr == 0) pAN->dwAttr = m_pCurMethod->m_Locals.COUNT() +1;
+ (pAN->dwAttr)--;
+ if((pVD = m_pCurMethod->m_Locals.PEEK(pAN->dwAttr)))
+ {
+ if(pVD->bInScope)
+ {
+ report->warn("Local var slot %d is in use\n",pAN->dwAttr);
+ }
+ if(pVD->pbsSig && ((pVD->pbsSig->length() != pAN->pSig->length()) ||
+ (memcmp(pVD->pbsSig->ptr(),pAN->pSig->ptr(),pVD->pbsSig->length()))))
+ {
+ report->error("Local var slot %d: type conflict\n",pAN->dwAttr);
+ }
+ }
+ else
+ { // create new entry:
+ for(unsigned n = m_pCurMethod->m_Locals.COUNT(); n <= pAN->dwAttr; n++)
+ {
+ pVD = new VarDescr;
+ if(pVD != NULL) m_pCurMethod->m_Locals.PUSH(pVD);
+ else
+ {
+ report->error("Out of memory allocating local var descriptor\n");
+ delete sig;
+ return;
+ }
+ }
+ }
+ pVD->dwSlot = pAN->dwAttr;
+ pVD->pbsSig = pAN->pSig;
+ pVD->bInScope = TRUE;
+ }
+ if(pVD->pbsSig && (pVD->pbsSig->length() == 1))
+ {
+ if(pVD->pbsSig->ptr()[0] == ELEMENT_TYPE_VOID)
+ report->error("Illegal local var type: 'void'\n");
+ }
+ m_pCurMethod->m_pCurrScope->pLocals =
+ m_pCurMethod->catArgNameList(m_pCurMethod->m_pCurrScope->pLocals, pList);
+ }
+ }
+ else report->error(".locals can be used only within a method scope\n");
+ delete sig;
+ }
+ else report->error("Attempt to EmitLocals with NULL argument\n");
+}
+
+/**************************************************************************/
+void Assembler::EmitEntryPoint()
+{
+ if (m_pCurMethod)
+ {
+ if(!m_fEntryPointPresent)
+ {
+ if(IsMdStatic(m_pCurMethod->m_Attr))
+ {
+ m_pCurMethod->m_fEntryPoint = TRUE;
+ m_fEntryPointPresent = TRUE;
+ }
+ else report->error("Non-static method as entry point\n");
+ }
+ else report->error("Multiple .entrypoint declarations\n");
+ }
+ else report->error(".entrypoint can be used only within a method scope\n");
+}
+
+/**************************************************************************/
+void Assembler::EmitZeroInit()
+{
+ if (m_pCurMethod) m_pCurMethod->m_Flags |= CorILMethod_InitLocals;
+ else report->error(".zeroinit can be used only within a method scope\n");
+}
+
+/**************************************************************************/
+void Assembler::SetImplAttr(unsigned short attrval)
+{
+ if (m_pCurMethod)
+ {
+ if(IsMiNative(attrval)||IsMiOPTIL(attrval)||IsMiUnmanaged(attrval))
+ report->error("Cannot compile native/unmanaged method\n");
+ m_pCurMethod->m_wImplAttr = attrval;
+ }
+}
+
+/**************************************************************************/
+void Assembler::EmitData(__in_opt void *buffer, unsigned len)
+{
+ if (len != 0)
+ {
+ void* ptr;
+ HRESULT hr = m_pCeeFileGen->GetSectionBlock(m_pCurSection, len, 1, &ptr);
+ if (FAILED(hr))
+ {
+ report->error("Could not extend data section (out of memory?)");
+ exit(1);
+ }
+
+ if (buffer != NULL)
+ {
+ memcpy(ptr, buffer, len);
+ }
+ else
+ {
+ memset(ptr, 0, len);
+ }
+ }
+}
+
+/**************************************************************************/
+void Assembler::EmitDD(__in __nullterminated char *str)
+{
+ DWORD dwAddr = 0;
+ GlobalLabel *pLabel = FindGlobalLabel(str);
+
+ ULONG loc;
+ HRESULT hr = m_pCeeFileGen->GetSectionDataLen(m_pCurSection, &loc);
+ _ASSERTE(SUCCEEDED(hr));
+
+ DWORD* ptr;
+ DWORD sizeofptr = (DWORD)((m_dwCeeFileFlags & ICEE_CREATE_FILE_PE32) ? sizeof(DWORD) : sizeof(__int64));
+ hr = m_pCeeFileGen->GetSectionBlock(m_pCurSection, sizeofptr, 1, (void**) &ptr);
+ if (FAILED(hr))
+ {
+ report->error("Could not extend data section (out of memory?)");
+ exit(1);
+ }
+
+ if (pLabel != 0) {
+ dwAddr = pLabel->m_GlobalOffset;
+ if (pLabel->m_Section != m_pGlobalDataSection) {
+ report->error("For '&label', label must be in data section");
+ m_State = STATE_FAIL;
+ }
+ }
+ else
+ AddDeferredGlobalFixup(str, (BYTE*) ptr);
+
+ hr = m_pCeeFileGen->AddSectionReloc(m_pCurSection, loc, m_pGlobalDataSection, srRelocHighLow);
+ _ASSERTE(SUCCEEDED(hr));
+ if(m_dwCeeFileFlags & ICEE_CREATE_FILE_STRIP_RELOCS)
+ {
+ report->error("Base relocations are emitted, while /STRIPRELOC option has been specified");
+ }
+ if(m_dwCeeFileFlags & ICEE_CREATE_FILE_PE32)
+ {
+ m_dwComImageFlags &= ~COMIMAGE_FLAGS_ILONLY;
+ if (m_dwCeeFileFlags & ICEE_CREATE_MACHINE_I386)
+ COR_SET_32BIT_REQUIRED(m_dwComImageFlags);
+ *ptr = dwAddr;
+ }
+ else
+ {
+ m_dwComImageFlags &= ~COMIMAGE_FLAGS_ILONLY;
+ *((__int64*)ptr) = (__int64)dwAddr;
+ }
+}
+
+/**************************************************************************/
+GlobalLabel *Assembler::FindGlobalLabel(LPCUTF8 pszName)
+{
+ GlobalLabel lSearch(pszName,0,NULL), *pL;
+ pL = m_lstGlobalLabel.FIND(&lSearch);
+ lSearch.m_szName = NULL;
+ return pL;
+ //return m_lstGlobalLabel.FIND(pszName);
+}
+
+/**************************************************************************/
+
+GlobalFixup *Assembler::AddDeferredGlobalFixup(__in __nullterminated char *pszLabel, BYTE* pReference)
+{
+ GlobalFixup *pNew = new GlobalFixup(pszLabel, (BYTE*) pReference);
+ if (pNew == NULL)
+ {
+ report->error("Failed to allocate global fixup\n");
+ m_State = STATE_FAIL;
+ }
+ else
+ m_lstGlobalFixup.PUSH(pNew);
+
+ return pNew;
+}
+
+/**************************************************************************/
+void Assembler::AddDeferredILFixup(ILFixupType Kind)
+{
+ _ASSERTE(Kind != ilGlobal);
+ AddDeferredILFixup(Kind, NULL);
+}
+/**************************************************************************/
+
+void Assembler::AddDeferredILFixup(ILFixupType Kind,
+ GlobalFixup *GFixup)
+{
+ ILFixup *pNew = new ILFixup(m_CurPC, Kind, GFixup);
+
+ _ASSERTE(m_pCurMethod != NULL);
+ if (pNew == NULL)
+ {
+ report->error("Failed to allocate IL fixup\n");
+ m_State = STATE_FAIL;
+ }
+ else
+ m_pCurMethod->m_lstILFixup.PUSH(pNew);
+}
+
+/**************************************************************************/
+void Assembler::EmitDataString(BinStr* str)
+{
+ if(str)
+ {
+ str->appendInt8(0);
+ DWORD DataLen = str->length();
+ char *pb = (char*)(str->ptr());
+ WCHAR *UnicodeString = (DataLen >= dwUniBuf) ? new WCHAR[DataLen] : &wzUniBuf[0];
+
+ if(UnicodeString)
+ {
+ WszMultiByteToWideChar(g_uCodePage,0,pb,-1,UnicodeString,DataLen);
+ EmitData(UnicodeString,DataLen*sizeof(WCHAR));
+ if(DataLen >= dwUniBuf) delete [] UnicodeString;
+ }
+ else report->error("\nOut of memory!\n");
+ delete str;
+ }
+}
+
+
+
+/**************************************************************************/
+unsigned Assembler::OpcodeLen(Instr* instr)
+{
+ return (m_fStdMapping ? OpcodeInfo[instr->opcode].Len : 3);
+}
+/**************************************************************************/
+void Assembler::EmitOpcode(Instr* instr)
+{
+ if(m_fGeneratePDB &&
+ ((instr->linenum != m_ulLastDebugLine)
+ ||(instr->column != m_ulLastDebugColumn)
+ ||(instr->linenum_end != m_ulLastDebugLineEnd)
+ ||(instr->column_end != m_ulLastDebugColumnEnd)))
+ {
+ if(m_pCurMethod)
+ {
+ LinePC *pLPC = new LinePC;
+ if(pLPC)
+ {
+ pLPC->Line = instr->linenum;
+ pLPC->Column = instr->column;
+ pLPC->LineEnd = instr->linenum_end;
+ pLPC->ColumnEnd = instr->column_end;
+ pLPC->PC = m_CurPC;
+ pLPC->pWriter = instr->pWriter;
+ m_pCurMethod->m_LinePCList.PUSH(pLPC);
+ }
+ else report->error("\nOut of memory!\n");
+ }
+ m_ulLastDebugLine = instr->linenum;
+ m_ulLastDebugColumn = instr->column;
+ m_ulLastDebugLineEnd = instr->linenum_end;
+ m_ulLastDebugColumnEnd = instr->column_end;
+ }
+ if(instr->opcode == CEE_ENDFILTER)
+ {
+ if(m_pCurMethod)
+ {
+ if(m_pCurMethod->m_dwNumEndfilters >= m_pCurMethod->m_dwMaxNumEndfilters)
+ {
+ DWORD *pdw = new DWORD[m_pCurMethod->m_dwMaxNumEndfilters+MAX_EXCEPTIONS];
+ if(pdw == NULL)
+ {
+ report->error("Failed to reallocate auxiliary SEH buffer\n");
+ instr->opcode = -1;
+ return;
+ }
+ memcpy(pdw,m_pCurMethod->m_EndfilterOffsetList,m_pCurMethod->m_dwNumEndfilters*sizeof(DWORD));
+ delete m_pCurMethod->m_EndfilterOffsetList;
+ m_pCurMethod->m_EndfilterOffsetList = pdw;
+ m_pCurMethod->m_dwMaxNumEndfilters += MAX_EXCEPTIONS;
+ }
+ m_pCurMethod->m_EndfilterOffsetList[m_pCurMethod->m_dwNumEndfilters++] = m_CurPC+2;
+ }
+ }
+ if (m_fStdMapping)
+ {
+ if (OpcodeInfo[instr->opcode].Len == 2)
+ EmitByte(OpcodeInfo[instr->opcode].Std1);
+ EmitByte(OpcodeInfo[instr->opcode].Std2);
+ }
+ else
+ {
+ unsigned short us = (unsigned short)instr->opcode;
+ EmitByte(REFPRE);
+ EmitBytes((BYTE *)&us,2);
+ }
+ instr->opcode = -1;
+}
+
+/**************************************************************************/
+//void Assembler::OptimizeInstr(Instr* instr, int var)
+//{
+
+//}
+/**************************************************************************/
+unsigned Assembler::ShortOf(unsigned opcode)
+{
+ unsigned retcode;
+ switch(opcode)
+ {
+ case CEE_LDARG: retcode=CEE_LDARG_S; break;
+ case CEE_LDARGA: retcode=CEE_LDARGA_S; break;
+ case CEE_STARG: retcode=CEE_STARG_S; break;
+
+ case CEE_LDLOC: retcode=CEE_LDLOC_S; break;
+ case CEE_LDLOCA: retcode=CEE_LDLOCA_S; break;
+ case CEE_STLOC: retcode=CEE_STLOC_S; break;
+
+ case CEE_BR: retcode=CEE_BR_S; break;
+ case CEE_BRFALSE: retcode=CEE_BRFALSE_S; break;
+ case CEE_BRTRUE: retcode=CEE_BRTRUE_S; break;
+ case CEE_BEQ: retcode=CEE_BEQ_S; break;
+ case CEE_BGE: retcode=CEE_BGE_S; break;
+ case CEE_BGT: retcode=CEE_BGT_S; break;
+ case CEE_BLE: retcode=CEE_BLE_S; break;
+ case CEE_BLT: retcode=CEE_BLT_S; break;
+ case CEE_BNE_UN: retcode=CEE_BNE_UN_S; break;
+ case CEE_BGE_UN: retcode=CEE_BGE_UN_S; break;
+ case CEE_BGT_UN: retcode=CEE_BGT_UN_S; break;
+ case CEE_BLE_UN: retcode=CEE_BLE_UN_S; break;
+ case CEE_BLT_UN: retcode=CEE_BLT_UN_S; break;
+ case CEE_LEAVE: retcode=CEE_LEAVE_S; break;
+
+ case CEE_LDC_I4: retcode=CEE_LDC_I4_S; break;
+ case CEE_LDC_R8: retcode=CEE_LDC_R4; break;
+
+
+ default: retcode = opcode; break;
+ }
+ return retcode;
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrVar(Instr* instr, int var)
+{
+ unsigned opc = instr->opcode;
+ if(m_fOptimize)
+ {
+ if(var < 4)
+ {
+ switch(opc)
+ {
+ case CEE_LDARG:
+ case CEE_LDARG_S: opc = CEE_LDARG_0 + var; break;
+
+ case CEE_LDLOC:
+ case CEE_LDLOC_S: opc = CEE_LDLOC_0 + var; break;
+
+ case CEE_STLOC:
+ case CEE_STLOC_S: opc = CEE_STLOC_0 + var; break;
+
+ default: break;
+ }
+ if(opc != (unsigned) instr->opcode)
+ {
+ instr->opcode = opc;
+ EmitOpcode(instr);
+ return;
+ }
+ }
+ if(var <= 0xFF)
+ {
+ opc = instr->opcode = ShortOf(opc);
+ }
+ }
+ EmitOpcode(instr);
+ if (isShort(opc))
+ {
+ EmitByte(var);
+ }
+ else
+ {
+ short sh = (short)var;
+ EmitBytes((BYTE *)&sh,2);
+ }
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrVarByName(Instr* instr, __in __nullterminated char* label)
+{
+ int idx = -1, nArgVarFlag=0;
+ switch(instr->opcode)
+ {
+ case CEE_LDARGA:
+ case CEE_LDARGA_S:
+ case CEE_LDARG:
+ case CEE_LDARG_S:
+ case CEE_STARG:
+ case CEE_STARG_S:
+ nArgVarFlag++;
+ case CEE_LDLOCA:
+ case CEE_LDLOCA_S:
+ case CEE_LDLOC:
+ case CEE_LDLOC_S:
+ case CEE_STLOC:
+ case CEE_STLOC_S:
+
+ if(m_pCurMethod)
+ {
+ DWORD L = (DWORD)strlen(label);
+ if(nArgVarFlag == 1)
+ {
+ idx = m_pCurMethod->findArgNum(m_pCurMethod->m_firstArgName,label,L);
+ }
+ else
+ {
+ for(Scope* pSC = m_pCurMethod->m_pCurrScope; pSC; pSC=pSC->pSuperScope)
+ {
+ idx = m_pCurMethod->findLocSlot(pSC->pLocals,label,L);
+ if(idx >= 0) break;
+ }
+ }
+ if(idx >= 0) EmitInstrVar(instr,
+ ((nArgVarFlag==0)||(m_pCurMethod->m_Attr & mdStatic))? idx : idx+1);
+ else report->error("Undeclared identifier %s\n",label);
+ }
+ else
+ report->error("Instructions can be used only when in a method scope\n");
+ break;
+ default:
+ report->error("Named argument illegal for this instruction\n");
+ }
+ instr->opcode = -1; // in case we got here with error
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrI(Instr* instr, int val)
+{
+ int opc = instr->opcode;
+ if(m_fOptimize)
+ {
+ if((val >= -1)&&(val <= 8))
+ {
+ switch(opc)
+ {
+ case CEE_LDC_I4:
+ case CEE_LDC_I4_S: opc = CEE_LDC_I4_M1 + (val+1); break;
+
+ default: break;
+ }
+ if(opc != instr->opcode)
+ {
+ instr->opcode = opc;
+ EmitOpcode(instr);
+ return;
+ }
+ }
+ if((-128 <= val)&&(val <= 127))
+ {
+ opc = instr->opcode = ShortOf(opc);
+ }
+ }
+ EmitOpcode(instr);
+ if (isShort(opc))
+ {
+ EmitByte(val);
+ }
+ else
+ {
+ int i = val;
+ EmitBytes((BYTE *)&i,sizeof(int));
+ }
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrI8(Instr* instr, __int64* val)
+{
+ EmitOpcode(instr);
+ EmitBytes((BYTE *)val, sizeof(__int64));
+ delete val;
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrR(Instr* instr, double* pval)
+{
+ unsigned opc = instr->opcode;
+ EmitOpcode(instr);
+ if (isShort(opc))
+ {
+ float val = (float)*pval;
+ EmitBytes((BYTE *)&val, sizeof(float));
+ }
+ else
+ EmitBytes((BYTE *)pval, sizeof(double));
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrBrTarget(Instr* instr, __in __nullterminated char* label)
+{
+ Label * pLabel = m_pCurMethod->FindLabel(label);
+ int offset=0;
+ if (pLabel == NULL) // branching forward -- no optimization
+ {
+ int pcrelsize = 1+(isShort(instr->opcode) ? 1 : 4); //size of the instruction plus argument
+ AddDeferredFixup(label, m_pCurOutputPos+1,
+ (m_CurPC + pcrelsize), pcrelsize-1);
+ }
+ else
+ {
+ offset = pLabel->m_PC - m_CurPC;
+ if(m_fOptimize)
+ {
+ if((-128 <= offset-5)&&(offset-2 <= 127)) //need to take into account the argument size (worst cases)
+ {
+ instr->opcode = ShortOf(instr->opcode);
+ }
+ }
+ if(isShort(instr->opcode))
+ {
+ offset -= 2;
+ if((-128 > offset)||(offset > 127))
+ report->error("Offset too large for short branching instruction, truncated\n");
+ }
+ else
+ offset -= 5;
+ delete [] label;
+ }
+ int opc = instr->opcode;
+ EmitOpcode(instr);
+ if(isShort(opc)) EmitByte(offset);
+ else EmitBytes((BYTE *)&offset,4);
+}
+/**************************************************************************/
+void Assembler::AddDeferredFixup(__in __nullterminated char *pszLabel, BYTE *pBytes, DWORD RelativeToPC, BYTE FixupSize)
+{
+ Fixup *pNew = new Fixup(pszLabel, pBytes, RelativeToPC, FixupSize);
+
+ if (pNew == NULL)
+ {
+ report->error("Failed to allocate deferred fixup\n");
+ m_State = STATE_FAIL;
+ }
+ else
+ m_pCurMethod->m_lstFixup.PUSH(pNew);
+}
+/**************************************************************************/
+void Assembler::EmitInstrBrOffset(Instr* instr, int offset)
+{
+ unsigned opc=instr->opcode;
+ if(m_fOptimize)
+ {
+ if((-128 >= offset)&&(offset <= 127))
+ {
+ opc = instr->opcode = ShortOf(opc);
+ }
+ }
+ EmitOpcode(instr);
+ if(isShort(opc)) EmitByte(offset);
+ else
+ {
+ int i = offset;
+ EmitBytes((BYTE *)&i,4);
+ }
+}
+
+/**************************************************************************/
+mdToken Assembler::MakeMemberRef(mdToken cr, __in __nullterminated char* pszMemberName, BinStr* sig)
+{
+ DWORD cSig = sig->length();
+ COR_SIGNATURE* mySig = (COR_SIGNATURE *)(sig->ptr());
+ mdToken mr = mdMemberRefNil;
+ Class* pClass = NULL;
+ if(cr == 0x00000001) cr = mdTokenNil; // Module -> nil for globals
+ if(TypeFromToken(cr) == mdtTypeDef) pClass = m_lstClass.PEEK(RidFromToken(cr)-1);
+ if((TypeFromToken(cr) == mdtTypeDef)||(cr == mdTokenNil))
+ {
+ MemberRefDescriptor* pMRD = new MemberRefDescriptor;
+ if(pMRD)
+ {
+ pMRD->m_tdClass = cr;
+ pMRD->m_pClass = pClass;
+ pMRD->m_szName = pszMemberName;
+ pMRD->m_dwName = (DWORD)strlen(pszMemberName);
+ pMRD->m_pSigBinStr = sig;
+ pMRD->m_tkResolved = 0;
+ if(*(sig->ptr())== IMAGE_CEE_CS_CALLCONV_FIELD)
+ {
+ m_LocalFieldRefDList.PUSH(pMRD);
+ mr = 0x98000000 | m_LocalFieldRefDList.COUNT();
+ }
+ else
+ {
+ m_LocalMethodRefDList.PUSH(pMRD);
+ mr = 0x99000000 | m_LocalMethodRefDList.COUNT();
+ }
+ }
+ else
+ {
+ report->error("Failed to allocate MemberRef Descriptor\n");
+ return 0;
+ }
+ }
+ else
+ {
+ WszMultiByteToWideChar(g_uCodePage,0,pszMemberName,-1,wzUniBuf,dwUniBuf);
+
+ if(cr == mdTokenNil) cr = mdTypeRefNil;
+ if(TypeFromToken(cr) == mdtAssemblyRef)
+ {
+ report->error("Cross-assembly global references are not supported ('%s')\n", pszMemberName);
+ mr = 0;
+ }
+ else
+ {
+ HRESULT hr = m_pEmitter->DefineMemberRef(cr, wzUniBuf, mySig, cSig, &mr);
+ if(FAILED(hr))
+ {
+ report->error("Unable to define member reference '%s'\n", pszMemberName);
+ mr = 0;
+ }
+ }
+ //if(m_fOBJ) m_pCurMethod->m_TRDList.PUSH(new TokenRelocDescr(m_CurPC,mr));
+ delete pszMemberName;
+ delete sig;
+ }
+ return mr;
+}
+/**************************************************************************/
+void Assembler::SetMemberRefFixup(mdToken tk, unsigned opcode_len)
+{
+ if(opcode_len)
+ {
+ switch(TypeFromToken(tk))
+ {
+ case 0x98000000:
+ case 0x99000000:
+ case 0x9A000000:
+ if(m_pCurMethod != NULL)
+ m_pCurMethod->m_LocalMemberRefFixupList.PUSH(
+ new LocalMemberRefFixup(tk,(size_t)(m_CurPC + opcode_len)));
+ break;
+ }
+ }
+}
+
+/**************************************************************************/
+mdToken Assembler::MakeMethodSpec(mdToken tkParent, BinStr* sig)
+{
+ DWORD cSig = sig->length();
+ COR_SIGNATURE* mySig = (COR_SIGNATURE *)(sig->ptr());
+ mdMethodSpec mi = mdMethodSpecNil;
+ if(TypeFromToken(tkParent) == 0x99000000) // Local MemberRef: postpone until resolved
+ {
+ MemberRefDescriptor* pMRD = new MemberRefDescriptor;
+ if(pMRD)
+ {
+ memset(pMRD,0,sizeof(MemberRefDescriptor));
+ pMRD->m_tdClass = tkParent;
+ pMRD->m_pSigBinStr = sig;
+ m_MethodSpecList.PUSH(pMRD);
+ mi = 0x9A000000 | m_MethodSpecList.COUNT();
+ }
+ else
+ {
+ report->error("Failed to allocate MemberRef Descriptor\n");
+ return 0;
+ }
+ }
+ else
+ {
+ HRESULT hr = m_pEmitter->DefineMethodSpec(tkParent, mySig, cSig, &mi);
+ if(FAILED(hr))
+ {
+ report->error("Unable to define method instantiation");
+ return 0;
+ }
+ }
+ return mi;
+}
+
+/**************************************************************************/
+void Assembler::EndEvent(void)
+{
+ Class* pClass = (m_pCurClass ? m_pCurClass : m_pModuleClass);
+ if(m_pCurEvent->m_tkAddOn == 0)
+ report->error("Event %s of class %s has no Add method. Event not emitted.",
+ m_pCurEvent->m_szName,pClass->m_szFQN);
+ else if(m_pCurEvent->m_tkRemoveOn == 0)
+ report->error("Event %s of class %s has no Remove method. Event not emitted.",
+ m_pCurEvent->m_szName,pClass->m_szFQN);
+ else
+ {
+ pClass->m_EventDList.PUSH(m_pCurEvent);
+ pClass->m_fNewMembers = TRUE;
+ }
+ m_pCurEvent = NULL;
+ m_tkCurrentCVOwner = 0;
+ m_pCustomDescrList = m_CustomDescrListStack.POP();
+}
+
+void Assembler::ResetEvent(__inout_z __inout char* szName, mdToken typeSpec, DWORD dwAttr)
+{
+ if(strlen(szName) >= MAX_CLASSNAME_LENGTH)
+ {
+ char c = szName[MAX_CLASSNAME_LENGTH-1];
+ szName[MAX_CLASSNAME_LENGTH-1] = 0;
+ report->error("Event '%s...' -- name too long (%d characters).\n",szName,strlen(szName));
+ szName[MAX_CLASSNAME_LENGTH-1] = c;
+ }
+ if((m_pCurEvent = new EventDescriptor))
+ {
+ memset(m_pCurEvent,0,sizeof(EventDescriptor));
+ m_pCurEvent->m_tdClass = m_pCurClass->m_cl;
+ m_pCurEvent->m_szName = szName;
+ m_pCurEvent->m_dwAttr = dwAttr;
+ m_pCurEvent->m_tkEventType = typeSpec;
+ m_pCurEvent->m_fNew = TRUE;
+ m_tkCurrentCVOwner = 0;
+ m_CustomDescrListStack.PUSH(m_pCustomDescrList);
+ m_pCustomDescrList = &(m_pCurEvent->m_CustomDescrList);
+ }
+ else report->error("Failed to allocate Event Descriptor\n");
+}
+
+void Assembler::SetEventMethod(int MethodCode, mdToken tk)
+{
+ switch(MethodCode)
+ {
+ case 0:
+ m_pCurEvent->m_tkAddOn = tk;
+ break;
+ case 1:
+ m_pCurEvent->m_tkRemoveOn = tk;
+ break;
+ case 2:
+ m_pCurEvent->m_tkFire = tk;
+ break;
+ case 3:
+ m_pCurEvent->m_tklOthers.PUSH((mdToken*)(UINT_PTR)tk);
+ break;
+ }
+}
+/**************************************************************************/
+
+void Assembler::EndProp(void)
+{
+ Class* pClass = (m_pCurClass ? m_pCurClass : m_pModuleClass);
+ pClass->m_PropDList.PUSH(m_pCurProp);
+ pClass->m_fNewMembers = TRUE;
+ m_pCurProp = NULL;
+ m_tkCurrentCVOwner = 0;
+ m_pCustomDescrList = m_CustomDescrListStack.POP();
+}
+
+void Assembler::ResetProp(__inout_z __inout char * szName, BinStr* bsType, DWORD dwAttr, BinStr* pValue)
+{
+ DWORD cSig = bsType->length();
+ COR_SIGNATURE* mySig = (COR_SIGNATURE *)(bsType->ptr());
+
+ if(strlen(szName) >= MAX_CLASSNAME_LENGTH)
+ {
+ char c = szName[MAX_CLASSNAME_LENGTH-1];
+ szName[MAX_CLASSNAME_LENGTH-1] = 0;
+ report->error("Property '%s...' -- name too long (%d characters).\n",szName,strlen(szName));
+ szName[MAX_CLASSNAME_LENGTH-1] = c;
+ }
+ m_pCurProp = new PropDescriptor;
+ if(m_pCurProp == NULL)
+ {
+ report->error("Failed to allocate Property Descriptor\n");
+ return;
+ }
+ memset(m_pCurProp,0,sizeof(PropDescriptor));
+ m_pCurProp->m_tdClass = m_pCurClass->m_cl;
+ m_pCurProp->m_szName = szName;
+ m_pCurProp->m_dwAttr = dwAttr;
+ m_pCurProp->m_fNew = TRUE;
+
+ m_pCurProp->m_pSig = new COR_SIGNATURE[cSig];
+ if(m_pCurProp->m_pSig == NULL)
+ {
+ report->error("\nOut of memory!\n");
+ return;
+ }
+ memcpy(m_pCurProp->m_pSig,mySig,cSig);
+ m_pCurProp->m_dwCSig = cSig;
+
+ if(pValue && pValue->length())
+ {
+ BYTE* pch = pValue->ptr();
+ m_pCurProp->m_dwCPlusTypeFlag = (DWORD)(*pch);
+ m_pCurProp->m_cbValue = pValue->length() - 1;
+ m_pCurProp->m_pValue = (PVOID)(pch+1);
+ if(m_pCurProp->m_dwCPlusTypeFlag == ELEMENT_TYPE_STRING) m_pCurProp->m_cbValue /= sizeof(WCHAR);
+ m_pCurProp->m_dwAttr |= prHasDefault;
+ }
+ else
+ {
+ m_pCurProp->m_dwCPlusTypeFlag = ELEMENT_TYPE_VOID;
+ m_pCurProp->m_pValue = NULL;
+ m_pCurProp->m_cbValue = 0;
+ }
+ m_tkCurrentCVOwner = 0;
+ m_CustomDescrListStack.PUSH(m_pCustomDescrList);
+ m_pCustomDescrList = &(m_pCurProp->m_CustomDescrList);
+}
+
+void Assembler::SetPropMethod(int MethodCode, mdToken tk)
+{
+ switch(MethodCode)
+ {
+ case 0:
+ m_pCurProp->m_tkSet = tk;
+ break;
+ case 1:
+ m_pCurProp->m_tkGet = tk;
+ break;
+ case 2:
+ m_pCurProp->m_tklOthers.PUSH((mdToken*)(UINT_PTR)tk);
+ break;
+ }
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrStringLiteral(Instr* instr, BinStr* literal, BOOL ConvertToUnicode, BOOL Swap /*=FALSE*/)
+{
+ DWORD DataLen = literal->length(),L;
+ unsigned __int8 *pb = literal->ptr();
+ HRESULT hr = S_OK;
+ mdToken tk;
+ WCHAR *UnicodeString;
+ if(DataLen == 0)
+ {
+ //report->warn("Zero length string emitted\n");
+ ConvertToUnicode = FALSE;
+ }
+ if(ConvertToUnicode)
+ {
+ UnicodeString = (DataLen >= dwUniBuf) ? new WCHAR[DataLen+1] : &wzUniBuf[0];
+ literal->appendInt8(0);
+ pb = literal->ptr();
+ // convert string to Unicode
+ L = UnicodeString ? WszMultiByteToWideChar(g_uCodePage,0,(char*)pb,-1,UnicodeString,DataLen+1) : 0;
+ if(L == 0)
+ {
+ const char* sz=NULL;
+ DWORD dw;
+ switch(dw=GetLastError())
+ {
+ case ERROR_INSUFFICIENT_BUFFER: sz = "ERROR_INSUFFICIENT_BUFFER"; break;
+ case ERROR_INVALID_FLAGS: sz = "ERROR_INVALID_FLAGS"; break;
+ case ERROR_INVALID_PARAMETER: sz = "ERROR_INVALID_PARAMETER"; break;
+ case ERROR_NO_UNICODE_TRANSLATION: sz = "ERROR_NO_UNICODE_TRANSLATION"; break;
+ }
+ if(sz) report->error("Failed to convert string '%s' to Unicode: %s\n",(char*)pb,sz);
+ else report->error("Failed to convert string '%s' to Unicode: error 0x%08X\n",(char*)pb,dw);
+ delete instr;
+ goto OuttaHere;
+ }
+ L--;
+ }
+ else
+ {
+ if(DataLen & 1)
+ {
+ literal->appendInt8(0);
+ pb = literal->ptr();
+ DataLen++;
+ }
+ UnicodeString = (WCHAR*)pb;
+ L = DataLen/sizeof(WCHAR);
+
+#if BIGENDIAN
+ if (Swap)
+ SwapStringLength(UnicodeString, L);
+#endif
+ }
+ // Add the string data to the metadata, which will fold dupes.
+ hr = m_pEmitter->DefineUserString(
+ UnicodeString,
+ L,
+ &tk
+ );
+ if (FAILED(hr))
+ {
+ report->error("Failed to add user string using DefineUserString, hr=0x%08x, data: '%S'\n",
+ hr, UnicodeString);
+ delete instr;
+ }
+ else
+ {
+ EmitOpcode(instr);
+ if(m_fOBJ) m_pCurMethod->m_TRDList.PUSH(new TokenRelocDescr(m_CurPC,tk));
+
+ EmitBytes((BYTE *)&tk,sizeof(mdToken));
+ }
+OuttaHere:
+ delete literal;
+ if(((void*)UnicodeString != (void*)pb)&&(DataLen >= dwUniBuf)) delete [] UnicodeString;
+ instr->opcode = -1; // in case we got here with error
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrSig(Instr* instr, BinStr* sig)
+{
+ mdSignature MetadataToken;
+ DWORD cSig = sig->length();
+ COR_SIGNATURE* mySig = (COR_SIGNATURE *)(sig->ptr());
+
+ if (FAILED(m_pEmitter->GetTokenFromSig(mySig, cSig, &MetadataToken)))
+ {
+ report->error("Unable to convert signature to metadata token.\n");
+ delete instr;
+ }
+ else
+ {
+ EmitOpcode(instr);
+ if(m_fOBJ) m_pCurMethod->m_TRDList.PUSH(new TokenRelocDescr(m_CurPC,MetadataToken));
+ EmitBytes((BYTE *)&MetadataToken, sizeof(mdSignature));
+ }
+ delete sig;
+ instr->opcode = -1; // in case we got here with error
+}
+
+/**************************************************************************/
+void Assembler::EmitInstrSwitch(Instr* instr, Labels* targets)
+{
+ Labels *pLbls;
+ int NumLabels;
+ Label *pLabel;
+ UINT offset;
+
+ EmitOpcode(instr);
+
+ // count # labels
+ for(pLbls = targets, NumLabels = 0; pLbls; pLbls = pLbls->Next, NumLabels++);
+
+ EmitBytes((BYTE *)&NumLabels,sizeof(int));
+ DWORD PC_nextInstr = m_CurPC + 4*NumLabels;
+ for(pLbls = targets; pLbls; pLbls = pLbls->Next)
+ {
+ if(pLbls->isLabel)
+ {
+ if((pLabel = m_pCurMethod->FindLabel(pLbls->Label)))
+ {
+ offset = pLabel->m_PC - PC_nextInstr;
+ if (m_fDisplayTraceOutput) report->msg("%d\n", offset);
+ }
+ else
+ {
+ // defer until we find the label
+ AddDeferredFixup(pLbls->Label, m_pCurOutputPos, PC_nextInstr, 4 /* pcrelsize */ );
+ offset = 0;
+ pLbls->Label = NULL;
+ if (m_fDisplayTraceOutput) report->msg("forward label %s\n", pLbls->Label);
+ }
+ }
+ else
+ {
+ offset = (UINT)(UINT_PTR)pLbls->Label;
+ if (m_fDisplayTraceOutput) report->msg("%d\n", offset);
+ }
+ EmitBytes((BYTE *)&offset, sizeof(UINT));
+ }
+ delete targets;
+}
+
+/**************************************************************************/
+void Assembler::EmitLabel(__in __nullterminated char* label)
+{
+ _ASSERTE(m_pCurMethod);
+ AddLabel(m_CurPC, label);
+}
+/**************************************************************************/
+void Assembler::EmitDataLabel(__in __nullterminated char* label)
+{
+ AddGlobalLabel(label, m_pCurSection);
+}
+
+/**************************************************************************/
+void Assembler::EmitBytes(BYTE *p, unsigned len)
+{
+ if(m_pCurOutputPos + len >= m_pEndOutputPos)
+ {
+ size_t buflen = m_pEndOutputPos - m_pOutputBuffer;
+ size_t newlen = buflen+(len/OUTPUT_BUFFER_INCREMENT + 1)*OUTPUT_BUFFER_INCREMENT;
+ BYTE *pb = new BYTE[newlen];
+ if(pb == NULL)
+ {
+ report->error("Failed to extend output buffer from %d to %d bytes. Aborting\n",
+ buflen, newlen);
+ exit(1);
+ }
+ size_t delta = pb - m_pOutputBuffer;
+ int i;
+ Fixup* pSearch;
+ GlobalFixup *pGSearch;
+ for (i=0; (pSearch = m_pCurMethod->m_lstFixup.PEEK(i)); i++) pSearch->m_pBytes += delta;
+ for (i=0; (pGSearch = m_lstGlobalFixup.PEEK(i)); i++) //need to move only those pointing to output buffer
+ {
+ if((pGSearch->m_pReference >= m_pOutputBuffer)&&(pGSearch->m_pReference <= m_pEndOutputPos))
+ pGSearch->m_pReference += delta;
+ }
+
+
+ memcpy(pb,m_pOutputBuffer,m_CurPC);
+ delete m_pOutputBuffer;
+ m_pOutputBuffer = pb;
+ m_pCurOutputPos = &m_pOutputBuffer[m_CurPC];
+ m_pEndOutputPos = &m_pOutputBuffer[newlen];
+
+ }
+
+ switch (len)
+ {
+ case 1:
+ *m_pCurOutputPos = *p;
+ break;
+ case 2:
+ SET_UNALIGNED_VAL16(m_pCurOutputPos, GET_UNALIGNED_16(p));
+ break;
+ case 4:
+ SET_UNALIGNED_VAL32(m_pCurOutputPos, GET_UNALIGNED_32(p));
+ break;
+ case 8:
+ SET_UNALIGNED_VAL64(m_pCurOutputPos, GET_UNALIGNED_64(p));
+ break;
+ default:
+ _ASSERTE(!"NYI");
+ break;
+ }
+
+ m_pCurOutputPos += len;
+ m_CurPC += len;
+}
+/**************************************************************************/
+BinStr* Assembler::EncodeSecAttr(__in __nullterminated char* szReflName, BinStr* pbsSecAttrBlob, unsigned nProps)
+{
+ unsigned cnt;
+#if (0)
+ // Emit MemberRef for .ctor
+ mdToken tkMscorlib = m_fIsMscorlib ? 1 : GetAsmRef("mscorlib");
+ char buffer[64];
+ BinStr *pbsSig = new BinStr();
+
+ strcpy(buffer,"System.Security.Permissions.SecurityAction");
+ mdToken tkSecAction = ResolveClassRef(tkMscorlib,buffer, NULL);
+
+ pbsSig->appendInt8(IMAGE_CEE_CS_CALLCONV_HASTHIS);
+ pbsSig->appendInt8(1); //corEmitInt(pbsSig,1);
+ pbsSig->appendInt8(ELEMENT_TYPE_VOID);
+ pbsSig->appendInt8(ELEMENT_TYPE_VALUETYPE);
+ cnt = CorSigCompressToken(tkSecAction, pbsSig->getBuff(5));
+ pbsSig->remove(5 - cnt);
+
+ char* szName = new char[16];
+ strcpy(szName,".ctor");
+ MakeMemberRef(tkSecAttr,szName,pbsSig);
+#endif
+
+ // build the blob As BinStr
+ unsigned L = (unsigned) strlen(szReflName);
+ BYTE* pb = NULL;
+ BinStr* pbsRet = new BinStr();
+ // encode the Reflection name length
+ cnt = CorSigCompressData(L, pbsRet->getBuff(5));
+ pbsRet->remove(5 - cnt);
+ //put the name in
+ if((pb = pbsRet->getBuff(L)) != NULL)
+ memcpy(pb,szReflName,L);
+ // find out the size of compressed nProps
+ cnt = CorSigCompressData(nProps, pbsRet->getBuff(5));
+ pbsRet->remove(5);
+ // encode blob size
+ unsigned nSize = cnt + pbsSecAttrBlob->length();
+ cnt = CorSigCompressData(nSize, pbsRet->getBuff(5));
+ pbsRet->remove(5 - cnt);
+ // actually encode nProps
+ cnt = CorSigCompressData(nProps, pbsRet->getBuff(5));
+ pbsRet->remove(5 - cnt);
+ // append the props/values blob
+ pbsRet->append(pbsSecAttrBlob);
+ delete pbsSecAttrBlob;
+ return pbsRet;
+}
+/**************************************************************************/
+void Assembler::EmitSecurityInfo(mdToken token,
+ PermissionDecl* pPermissions,
+ PermissionSetDecl* pPermissionSets)
+{
+ PermissionDecl *pPerm, *pPermNext;
+ PermissionSetDecl *pPset, *pPsetNext;
+ unsigned uCount = 0;
+ COR_SECATTR *pAttrs;
+ unsigned i;
+ unsigned uLength;
+ mdTypeRef tkTypeRef;
+ BinStr *pSig;
+ char *szMemberName;
+ DWORD dwErrorIndex = 0;
+
+ if (pPermissions) {
+
+ for (pPerm = pPermissions; pPerm; pPerm = pPerm->m_Next)
+ uCount++;
+
+ _ASSERTE(uCount > 0);
+ // uCount is expected to be positive all the time. The if statement is here to please prefast.
+ if (uCount > 0)
+ {
+ if((pAttrs = new COR_SECATTR[uCount])==NULL)
+ {
+ report->error("\nOut of memory!\n");
+ return;
+ }
+
+ mdToken tkMscorlib = m_fIsMscorlib ? 1 : GetAsmRef("mscorlib");
+ tkTypeRef = ResolveClassRef(tkMscorlib,"System.Security.Permissions.SecurityAction", NULL);
+ for (pPerm = pPermissions, i = 0; pPerm; pPerm = pPermNext, i++) {
+ pPermNext = pPerm->m_Next;
+
+ pSig = new BinStr();
+ pSig->appendInt8(IMAGE_CEE_CS_CALLCONV_DEFAULT_HASTHIS);
+ pSig->appendInt8(1);
+ pSig->appendInt8(ELEMENT_TYPE_VOID);
+ pSig->appendInt8(ELEMENT_TYPE_VALUETYPE);
+ uLength = CorSigCompressToken(tkTypeRef, pSig->getBuff(5));
+ pSig->remove(5 - uLength);
+
+ uLength = (unsigned)strlen(COR_CTOR_METHOD_NAME) + 1;
+ if((szMemberName = new char[uLength]))
+ {
+ memcpy(szMemberName, COR_CTOR_METHOD_NAME, uLength);
+ pAttrs[i].tkCtor = MakeMemberRef(pPerm->m_TypeSpec, szMemberName, pSig);
+ pAttrs[i].pCustomAttribute = (const void *)pPerm->m_Blob;
+ pAttrs[i].cbCustomAttribute = pPerm->m_BlobLength;
+ }
+ else report->error("\nOut of memory!\n");
+ }
+
+ if (FAILED(m_pEmitter->DefineSecurityAttributeSet(token,
+ pAttrs,
+ uCount,
+ &dwErrorIndex)))
+ {
+ _ASSERT(uCount >= dwErrorIndex);
+ if (dwErrorIndex == uCount)
+ {
+ report->error("Failed to define security attribute set for 0x%08X\n", token);
+ }
+ else
+ {
+ report->error("Failed to define security attribute set for 0x%08X\n (error in permission %u)\n",
+ token, uCount - dwErrorIndex);
+ }
+ }
+ delete [] pAttrs;
+ for (pPerm = pPermissions, i = 0; pPerm; pPerm = pPermNext, i++) {
+ pPermNext = pPerm->m_Next;
+ delete pPerm;
+ }
+ }
+ }
+
+ for (pPset = pPermissionSets; pPset; pPset = pPsetNext) {
+ pPsetNext = pPset->m_Next;
+ if(FAILED(m_pEmitter->DefinePermissionSet(token,
+ pPset->m_Action,
+ pPset->m_Value->ptr(),
+ pPset->m_Value->length(),
+ NULL)))
+ report->error("Failed to define security permission set for 0x%08X\n", token);
+ delete pPset;
+ }
+}
+
+void Assembler::AddMethodImpl(mdToken tkImplementedTypeSpec, __in __nullterminated char* szImplementedName, BinStr* pImplementedSig,
+ mdToken tkImplementingTypeSpec, __in_opt __nullterminated char* szImplementingName, BinStr* pImplementingSig)
+{
+ if(m_pCurClass)
+ {
+ MethodImplDescriptor* pMID = new MethodImplDescriptor;
+ pMID->m_fNew = TRUE;
+ if(pMID == NULL)
+ {
+ report->error("Failed to allocate MethodImpl Descriptor\n");
+ return;
+ }
+ pMID->m_tkDefiningClass = m_pCurClass->m_cl;
+ if(szImplementingName) //called from class scope, overriding method specified
+ {
+ pMID->m_tkImplementedMethod = MakeMemberRef(tkImplementedTypeSpec,szImplementedName,pImplementedSig);
+ pMID->m_tkImplementingMethod = MakeMemberRef(tkImplementingTypeSpec,szImplementingName,pImplementingSig);
+ }
+ else //called from method scope, use current method as overriding
+ {
+ if(m_pCurMethod)
+ {
+ if (pImplementedSig == NULL)
+ {
+ pImplementedSig = new BinStr();
+ memcpy(pImplementedSig->getBuff(m_pCurMethod->m_dwMethodCSig), m_pCurMethod->m_pMethodSig,m_pCurMethod->m_dwMethodCSig);
+ }
+ pMID->m_tkImplementedMethod = MakeMemberRef(tkImplementedTypeSpec,szImplementedName,pImplementedSig);
+ pMID->m_tkImplementingMethod = 0;
+
+ m_pCurMethod->m_MethodImplDList.PUSH(pMID); // copy goes to method's own list (ptr only)
+ }
+ else
+ {
+ report->error("No overriding method specified");
+ delete pMID;
+ return;
+ }
+ }
+ m_MethodImplDList.PUSH(pMID);
+ }
+ else
+ report->error(".override directive outside class scope");
+}
+// source file name paraphernalia
+void Assembler::SetSourceFileName(__in __nullterminated char* szName)
+{
+ if(szName)
+ {
+ if(*szName)
+ {
+ if(strcmp(m_szSourceFileName,szName))
+ {
+ strcpy_s(m_szSourceFileName,MAX_FILENAME_LENGTH*3+1,szName);
+ WszMultiByteToWideChar(g_uCodePage,0,szName,-1,m_wzSourceFileName,MAX_FILENAME_LENGTH);
+ }
+ if(m_fGeneratePDB)
+ {
+ DocWriter* pDW;
+ unsigned i=0;
+ while((pDW = m_DocWriterList.PEEK(i++)) != NULL)
+ {
+ if(!strcmp(szName,pDW->Name)) break;
+ }
+ if(pDW)
+ {
+ m_pSymDocument = pDW->pWriter;
+ delete [] szName;
+ }
+ else if(m_pSymWriter)
+ {
+ HRESULT hr;
+ WszMultiByteToWideChar(g_uCodePage,0,szName,-1,wzUniBuf,dwUniBuf);
+ if(FAILED(hr=m_pSymWriter->DefineDocument(wzUniBuf,&m_guidLang,
+ &m_guidLangVendor,&m_guidDoc,&m_pSymDocument)))
+ {
+ m_pSymDocument = NULL;
+ report->error("Failed to define a document writer");
+ }
+ if((pDW = new DocWriter()) != NULL)
+ {
+ pDW->Name = szName;
+ pDW->pWriter = m_pSymDocument;
+ m_DocWriterList.PUSH(pDW);
+ }
+ else
+ {
+ report->error("Out of memory");
+ delete [] szName;
+ }
+ }
+ else delete [] szName;
+ }
+ else delete [] szName;
+ }
+ else delete [] szName;
+ }
+}
+void Assembler::SetSourceFileName(BinStr* pbsName)
+{
+ ULONG L;
+ if(pbsName && (L = (ULONG)(pbsName->length())))
+ {
+ pbsName->appendInt8(0);
+ char* sz = new char[L+1];
+ memcpy(sz,pbsName->ptr(),L+1);
+ SetSourceFileName(sz);
+ delete pbsName;
+ }
+}
diff --git a/src/ilasm/assembler.h b/src/ilasm/assembler.h
new file mode 100644
index 0000000000..cbb591ac1c
--- /dev/null
+++ b/src/ilasm/assembler.h
@@ -0,0 +1,1203 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+/************************************************************************/
+/* Assembler.h */
+/************************************************************************/
+
+#ifndef Assember_h
+#define Assember_h
+
+#define NEW_INLINE_NAMES
+
+#include "binstr.h"
+
+#include "specstrings.h"
+
+#include "asmenum.h"
+#include "asmtemplates.h"
+
+// Disable the "initialization of static local vars is no thread safe" error
+#ifdef _MSC_VER
+#pragma warning(disable : 4640)
+#endif
+
+#ifdef ResetEvent
+#undef ResetEvent
+#endif
+
+#define OUTPUT_BUFFER_SIZE 8192 // initial size of asm code for a single method
+#define OUTPUT_BUFFER_INCREMENT 1024 // size of code buffer increment when it's full
+#define MAX_FILENAME_LENGTH 2048 //256
+#define MAX_SIGNATURE_LENGTH 256 // unused
+#define MAX_LABEL_SIZE 256 //64
+#define MAX_CALL_SIG_SIZE 32 // unused
+#define MAX_SCOPE_LENGTH _MAX_PATH // follow the RegMeta::SetModuleProps limitation
+
+#define MAX_NAMESPACE_LENGTH 1024 //256 //64
+#define MAX_MEMBER_NAME_LENGTH 1024 //256 //64
+
+#define MAX_INTERFACES_IMPLEMENTED 16 // initial number; extended by 16 when needed
+#define GLOBAL_DATA_SIZE 8192 // initial size of global data buffer
+#define GLOBAL_DATA_INCREMENT 1024 // size of global data buffer increment when it's full
+#define MAX_METHODS 1024 // unused
+#define MAX_INPUT_LINE_LEN 1024 // unused
+#define MAX_TYPAR 8
+#define BASE_OBJECT_CLASSNAME "System.Object"
+#define MAX_MANIFEST_RESOURCES 1024
+
+// Fully-qualified class name separators:
+#define NESTING_SEP ((char)0xF8)
+
+#define dwUniBuf 16384
+
+#ifdef FEATURE_PAL
+#include "coreclrloader.h"
+extern CoreCLRLoader *g_loader;
+extern char *g_pszExeFile;
+#endif
+typedef int(*MetaDataGetDispenserFunc) (
+ REFCLSID rclsid, // The class to desired.
+ REFIID riid, // Interface wanted on class factory.
+ LPVOID FAR *ppv); // Return interface pointer here.
+
+extern MetaDataGetDispenserFunc metaDataGetDispenser;
+
+extern WCHAR wzUniBuf[]; // Unicode conversion global buffer (assem.cpp)
+
+class Class;
+class Method;
+class PermissionDecl;
+class PermissionSetDecl;
+
+unsigned hash( // defined in assem.cpp
+ __in_ecount(length) const BYTE *k, /* the key */
+ unsigned length, /* the length of the key */
+ unsigned initval); /* the previous hash, or an arbitrary value */
+
+struct MemberRefDescriptor
+{
+ mdToken m_tdClass;
+ Class* m_pClass;
+ char* m_szName;
+ DWORD m_dwName;
+ BinStr* m_pSigBinStr;
+ mdToken m_tkResolved;
+};
+typedef FIFO<MemberRefDescriptor> MemberRefDList;
+
+
+struct MethodImplDescriptor
+{
+ mdToken m_tkImplementedMethod;
+ mdToken m_tkImplementingMethod;
+ mdToken m_tkDefiningClass;
+ BOOL m_fNew;
+};
+typedef FIFO<MethodImplDescriptor> MethodImplDList;
+
+struct LocalMemberRefFixup
+{
+ mdToken tk;
+ size_t offset;
+ BOOL m_fNew;
+ LocalMemberRefFixup(mdToken TK, size_t Offset)
+ {
+ tk = TK;
+ offset = Offset;
+ m_fNew = TRUE;
+ }
+};
+typedef FIFO<LocalMemberRefFixup> LocalMemberRefFixupList;
+
+struct CustomDescr
+{
+ mdToken tkType;
+ mdToken tkOwner;
+ mdToken tkInterfacePair; // Needed for InterfaceImpl CA's
+ BinStr* pBlob;
+ CustomDescr(mdToken tko, mdToken tk, BinStr* pblob) { tkType = tk; pBlob = pblob; tkOwner = tko; tkInterfacePair = 0; };
+ CustomDescr(mdToken tk, BinStr* pblob) { tkType = tk; pBlob = pblob; tkOwner = 0; tkInterfacePair = 0;};
+ CustomDescr(CustomDescr* pOrig) { tkType = pOrig->tkType; pBlob = new BinStr(); pBlob->append(pOrig->pBlob); tkOwner = pOrig->tkOwner; tkInterfacePair = pOrig->tkInterfacePair; };
+ ~CustomDescr() { if(pBlob) delete pBlob; };
+};
+typedef FIFO<CustomDescr> CustomDescrList;
+typedef LIFO<CustomDescrList> CustomDescrListStack;
+/**************************************************************************/
+#include "typar.hpp"
+#include "method.hpp"
+#include "iceefilegen.h"
+#include "asmman.hpp"
+
+#include "nvpair.h"
+
+
+typedef enum
+{
+ STATE_OK,
+ STATE_FAIL,
+ STATE_ENDMETHOD,
+ STATE_ENDFILE
+} state_t;
+
+
+class GlobalLabel
+{
+public:
+ LPCUTF8 m_szName;
+ DWORD m_GlobalOffset;
+ HCEESECTION m_Section;
+ unsigned m_Hash;
+
+ GlobalLabel(LPCUTF8 pszName, DWORD GlobalOffset, HCEESECTION section)
+ {
+ m_GlobalOffset = GlobalOffset;
+ m_Section = section;
+ m_szName = pszName;
+ m_Hash = hash((const BYTE*)pszName, (unsigned)strlen(pszName),10);
+ }
+
+ ~GlobalLabel(){ delete [] m_szName; }
+
+ int ComparedTo(GlobalLabel* L)
+ {
+ return (m_Hash == L->m_Hash) ? strcmp(m_szName, L->m_szName)
+ : ((m_Hash > L->m_Hash) ? 1 : -1);
+ }
+
+ //int ComparedTo(GlobalLabel* L) { return strcmp(m_szName,L->m_szName); };
+ //int Compare(char* L) { return strcmp(L, m_szNam); };
+ //char* NameOf() { return m_szName; };
+};
+//typedef SORTEDARRAY<GlobalLabel> GlobalLabelList;
+typedef RBTREE<GlobalLabel> GlobalLabelList;
+//typedef FIFO_INDEXED<GlobalLabel> GlobalLabelList;
+
+class CeeFileGenWriter;
+class CeeSection;
+
+class BinStr;
+
+/************************************************************************/
+/* represents an object that knows how to report errors back to the user */
+
+class ErrorReporter
+{
+public:
+ virtual void error(const char* fmt, ...) = 0;
+ virtual void warn(const char* fmt, ...) = 0;
+ virtual void msg(const char* fmt, ...) = 0;
+};
+
+/**************************************************************************/
+/* represents a switch table before the lables are bound */
+
+struct Labels {
+ Labels(__in __nullterminated char* aLabel, Labels* aNext, bool aIsLabel) : Label(aLabel), Next(aNext), isLabel(aIsLabel) {}
+ ~Labels() { if(isLabel && Label) delete [] Label; delete Next; }
+
+ char* Label;
+ Labels* Next;
+ bool isLabel;
+};
+
+/**************************************************************************/
+/* descriptor of the structured exception handling construct */
+struct SEH_Descriptor
+{
+ DWORD sehClause; // catch/filter/finally
+ DWORD tryFrom; // start of try block
+ DWORD tryTo; // end of try block
+ DWORD sehHandler; // start of exception handler
+ DWORD sehHandlerTo; // end of exception handler
+ union {
+ DWORD sehFilter; // start of filter block
+ mdTypeRef cException; // what to catch
+ };
+
+ SEH_Descriptor()
+ {
+ memset(this, 0, sizeof(*this));
+ }
+};
+
+
+typedef LIFO<char> StringStack;
+typedef LIFO<SEH_Descriptor> SEHD_Stack;
+
+typedef FIFO<Method> MethodList;
+//typedef SORTEDARRAY<Method> MethodSortedList;
+typedef FIFO<mdToken> TokenList;
+/**************************************************************************/
+/* The field, event and property descriptor structures */
+
+struct FieldDescriptor
+{
+ mdTypeDef m_tdClass;
+ char* m_szName;
+ DWORD m_dwName;
+ mdFieldDef m_fdFieldTok;
+ ULONG m_ulOffset;
+ char* m_rvaLabel; // if field has RVA associated with it, label for it goes here.
+ BinStr* m_pbsSig;
+ Class* m_pClass;
+ BinStr* m_pbsValue;
+ BinStr* m_pbsMarshal;
+ PInvokeDescriptor* m_pPInvoke;
+ CustomDescrList m_CustomDescrList;
+ DWORD m_dwAttr;
+ BOOL m_fNew;
+ // Security attributes
+ PermissionDecl* m_pPermissions;
+ PermissionSetDecl* m_pPermissionSets;
+ FieldDescriptor() { m_szName = NULL; m_pbsSig = NULL; m_fNew = TRUE; };
+ ~FieldDescriptor() { if(m_szName) delete [] m_szName; if(m_pbsSig) delete m_pbsSig; };
+};
+typedef FIFO<FieldDescriptor> FieldDList;
+
+struct EventDescriptor
+{
+ mdTypeDef m_tdClass;
+ char* m_szName;
+ DWORD m_dwAttr;
+ mdToken m_tkEventType;
+ mdToken m_tkAddOn;
+ mdToken m_tkRemoveOn;
+ mdToken m_tkFire;
+ TokenList m_tklOthers;
+ mdEvent m_edEventTok;
+ BOOL m_fNew;
+ CustomDescrList m_CustomDescrList;
+ ~EventDescriptor() { m_tklOthers.RESET(false); };
+};
+typedef FIFO<EventDescriptor> EventDList;
+
+struct PropDescriptor
+{
+ mdTypeDef m_tdClass;
+ char* m_szName;
+ DWORD m_dwAttr;
+ COR_SIGNATURE* m_pSig;
+ DWORD m_dwCSig;
+ DWORD m_dwCPlusTypeFlag;
+ PVOID m_pValue;
+ DWORD m_cbValue;
+ mdToken m_tkSet;
+ mdToken m_tkGet;
+ TokenList m_tklOthers;
+ mdProperty m_pdPropTok;
+ BOOL m_fNew;
+ CustomDescrList m_CustomDescrList;
+ ~PropDescriptor() { m_tklOthers.RESET(false); };
+};
+typedef FIFO<PropDescriptor> PropDList;
+
+struct ImportDescriptor
+{
+ char* szDllName;
+// char szDllName[MAX_FILENAME_LENGTH];
+ DWORD dwDllName;
+ mdModuleRef mrDll;
+ ImportDescriptor(__in __nullterminated char* sz, DWORD l)
+ {
+ if((sz != NULL)&&(l > 0))
+ {
+ szDllName = new char[l+1];
+ if(szDllName != NULL)
+ {
+ memcpy(szDllName,sz,l);
+ szDllName[l] = 0;
+ dwDllName = l;
+ }
+ }
+ else
+ {
+ szDllName = NULL;
+ dwDllName = 0;
+ }
+ };
+ ~ImportDescriptor() { delete [] szDllName; };
+};
+typedef FIFO<ImportDescriptor> ImportList;
+
+
+/**************************************************************************/
+#include "class.hpp"
+typedef LIFO<Class> ClassStack;
+typedef FIFO<Class> ClassList;
+//typedef SORTEDARRAY<Class> ClassHash;
+typedef RBTREE<Class> ClassHash;
+//typedef FIFO_INDEXED<Class> ClassHash;
+
+/**************************************************************************/
+/* Classes to hold lists of security permissions and permission sets. We build
+ these lists as we find security directives in the input stream and drain
+ them every time we see a class or method declaration (to which the
+ security info is attached). */
+
+class PermissionDecl
+{
+public:
+ PermissionDecl(CorDeclSecurity action, mdToken type, NVPair *pairs)
+ {
+ m_Action = action;
+ m_TypeSpec = type;
+ m_pbsBlob = NULL;
+ BuildConstructorBlob(action, pairs);
+ m_Next = NULL;
+ }
+
+ PermissionDecl(CorDeclSecurity action, mdToken type, BinStr* pbsPairs)
+ {
+ m_Action = action;
+ m_TypeSpec = type;
+
+ m_pbsBlob = new BinStr();
+ m_pbsBlob->appendInt16(VAL16(1)); // prolog 0x01 0x00
+ m_pbsBlob->appendInt32((int)action); // 4-byte action
+ if(pbsPairs) // name-value pairs if any
+ {
+ if(pbsPairs->length() > 2)
+ m_pbsBlob->appendFrom(pbsPairs,2);
+ delete pbsPairs;
+ }
+ if(m_pbsBlob->length() == 6) // no pairs added
+ m_pbsBlob->appendInt16(0);
+ m_Blob = m_pbsBlob->ptr();
+ m_BlobLength = m_pbsBlob->length();
+ m_Next = NULL;
+ }
+
+ ~PermissionDecl()
+ {
+ if(m_pbsBlob) delete m_pbsBlob;
+ else delete [] m_Blob;
+ }
+
+ CorDeclSecurity m_Action;
+ mdToken m_TypeSpec;
+ BYTE *m_Blob;
+ BinStr *m_pbsBlob;
+ long m_BlobLength;
+ PermissionDecl *m_Next;
+
+private:
+ void BuildConstructorBlob(CorDeclSecurity action, NVPair *pairs)
+ {
+ NVPair *p = pairs;
+ int count = 0;
+ int bytes = 8;
+ int length;
+ int i;
+ BYTE *pBlob;
+
+ // Calculate number of name/value pairs and the memory required for the
+ // custom attribute blob.
+ while (p) {
+ BYTE *pVal = (BYTE*)p->Value()->ptr();
+ count++;
+ bytes += 2; // One byte field/property specifier, one byte type code
+
+ length = (int)strlen((const char *)p->Name()->ptr());
+ bytes += CPackedLen::Size(length) + length;
+
+ switch (pVal[0]) {
+ case SERIALIZATION_TYPE_BOOLEAN:
+ bytes += 1;
+ break;
+ case SERIALIZATION_TYPE_I4:
+ bytes += 4;
+ break;
+ case SERIALIZATION_TYPE_STRING:
+ length = (int)strlen((const char *)&pVal[1]);
+ bytes += CPackedLen::Size(length) + length;
+ break;
+ case SERIALIZATION_TYPE_ENUM:
+ length = (int)strlen((const char *)&pVal[1]);
+ bytes += CPackedLen::Size((ULONG)length) + length;
+ bytes += 4;
+ break;
+ }
+ p = p->Next();
+ }
+
+ m_Blob = new BYTE[bytes];
+ if(m_Blob==NULL)
+ {
+ fprintf(stderr,"\nOut of memory!\n");
+ return;
+ }
+
+ m_Blob[0] = 0x01; // Version
+ m_Blob[1] = 0x00;
+ m_Blob[2] = (BYTE)action; // Constructor arg (security action code)
+ m_Blob[3] = 0x00;
+ m_Blob[4] = 0x00;
+ m_Blob[5] = 0x00;
+ m_Blob[6] = (BYTE)count; // Property/field count
+ m_Blob[7] = (BYTE)(count >> 8);
+
+ for (i = 0, pBlob = &m_Blob[8], p = pairs; i < count; i++, p = p->Next()) {
+ BYTE *pVal = (BYTE*)p->Value()->ptr();
+ char *szType;
+
+ // Set field/property setter type.
+ *pBlob++ = SERIALIZATION_TYPE_PROPERTY;
+
+ // Set type code. There's additional info for enums (the enum class
+ // name).
+ *pBlob++ = pVal[0];
+ if (pVal[0] == SERIALIZATION_TYPE_ENUM) {
+ szType = (char *)&pVal[1];
+ length = (int)strlen(szType);
+ pBlob = (BYTE*)CPackedLen::PutLength(pBlob, length);
+ strcpy_s((char *)pBlob, bytes, szType);
+ pBlob += length;
+ }
+
+ // Record the field/property name.
+ length = (int)strlen((const char *)p->Name()->ptr());
+ pBlob = (BYTE*)CPackedLen::PutLength(pBlob, length);
+ strcpy_s((char *)pBlob, bytes-(pBlob-m_Blob), (const char *)p->Name()->ptr());
+ pBlob += length;
+
+ // Record the serialized value.
+ switch (pVal[0]) {
+ case SERIALIZATION_TYPE_BOOLEAN:
+ *pBlob++ = pVal[1];
+ break;
+ case SERIALIZATION_TYPE_I4:
+ *(__int32*)pBlob = *(__int32*)&pVal[1];
+ pBlob += 4;
+ break;
+ case SERIALIZATION_TYPE_STRING:
+ length = (int)strlen((const char *)&pVal[1]);
+ pBlob = (BYTE*)CPackedLen::PutLength(pBlob, length);
+ strcpy_s((char *)pBlob, bytes-(pBlob-m_Blob), (const char *)&pVal[1]);
+ pBlob += length;
+ break;
+ case SERIALIZATION_TYPE_ENUM:
+ length = (int)strlen((const char *)&pVal[1]);
+ // We can have enums with base type of I1, I2 and I4.
+ switch (pVal[1 + length + 1]) {
+ case 1:
+ *(__int8*)pBlob = *(__int8*)&pVal[1 + length + 2];
+ pBlob += 1;
+ break;
+ case 2:
+ *(__int16*)pBlob = *(__int16*)&pVal[1 + length + 2];
+ pBlob += 2;
+ break;
+ case 4:
+ *(__int32*)pBlob = *(__int32*)&pVal[1 + length + 2];
+ pBlob += 4;
+ break;
+ default:
+ _ASSERTE(!"Invalid enum size");
+ }
+ break;
+ }
+
+ }
+
+ _ASSERTE((pBlob - m_Blob) == bytes);
+
+ m_BlobLength = (long)bytes;
+ }
+};
+
+class PermissionSetDecl
+{
+public:
+ PermissionSetDecl(CorDeclSecurity action, BinStr *value)
+ {
+ m_Action = action;
+ m_Value = value;
+ m_Next = NULL;
+ }
+
+ ~PermissionSetDecl()
+ {
+ delete m_Value;
+ }
+
+ CorDeclSecurity m_Action;
+ BinStr *m_Value;
+ PermissionSetDecl *m_Next;
+};
+
+struct VTFEntry
+{
+ char* m_szLabel;
+ WORD m_wCount;
+ WORD m_wType;
+ VTFEntry(WORD wCount, WORD wType, __in __nullterminated char* szLabel) { m_wCount = wCount; m_wType = wType; m_szLabel = szLabel; }
+ ~VTFEntry() { delete m_szLabel; }
+};
+typedef FIFO<VTFEntry> VTFList;
+
+struct EATEntry
+{
+ DWORD dwStubRVA;
+ DWORD dwOrdinal;
+ char* szAlias;
+};
+typedef FIFO<EATEntry> EATList;
+
+struct DocWriter
+{
+ char* Name;
+ ISymUnmanagedDocumentWriter* pWriter;
+ DocWriter() { Name=NULL; pWriter=NULL; };
+ ~DocWriter() { delete [] Name; if(pWriter) pWriter->Release();};
+};
+typedef FIFO<DocWriter> DocWriterList;
+/**************************************************************************/
+/* The assembler object does all the code generation (dealing with meta-data)
+ writing a PE file etc etc. But does NOT deal with syntax (that is what
+ AsmParse is for). Thus the API below is how AsmParse 'controls' the
+ Assember. Note that the Assembler object does know about the
+ AsmParse object (that is Assember is more fundamental than AsmParse) */
+struct Instr
+{
+ int opcode;
+ unsigned linenum;
+ unsigned column;
+ unsigned linenum_end;
+ unsigned column_end;
+ unsigned pc;
+ ISymUnmanagedDocumentWriter* pWriter;
+};
+#define INSTR_POOL_SIZE 16
+
+// For code folding:
+struct MethodBody
+{
+ BinStr* pbsBody;
+ unsigned RVA;
+ BYTE* pCode;
+};
+typedef FIFO<MethodBody> MethodBodyList;
+
+struct Clockwork
+{
+ DWORD cBegin;
+ DWORD cEnd;
+ DWORD cParsBegin;
+ DWORD cParsEnd;
+ DWORD cMDInitBegin;
+ DWORD cMDInitEnd;
+ DWORD cMDEmitBegin;
+ DWORD cMDEmitEnd;
+ DWORD cMDEmit1;
+ DWORD cMDEmit2;
+ DWORD cMDEmit3;
+ DWORD cMDEmit4;
+ DWORD cRef2DefBegin;
+ DWORD cRef2DefEnd;
+ DWORD cFilegenBegin;
+ DWORD cFilegenEnd;
+};
+
+struct TypeDefDescr
+{
+ char* m_szName;
+ union
+ {
+ BinStr* m_pbsTypeSpec;
+ CustomDescr* m_pCA;
+ };
+ mdToken m_tkTypeSpec;
+ TypeDefDescr(__in_opt __nullterminated char *pszName, BinStr* pbsTypeSpec, mdToken tkTypeSpec)
+ {
+ m_szName = pszName;
+ m_pbsTypeSpec = pbsTypeSpec;
+ m_tkTypeSpec = tkTypeSpec;
+ };
+ ~TypeDefDescr() { delete [] m_szName; delete m_pbsTypeSpec; };
+ int ComparedTo(TypeDefDescr* T) { return strcmp(m_szName,T->m_szName); };
+ //int Compare(char* T) { return strcmp(T,m_szName); };
+};
+typedef SORTEDARRAY<TypeDefDescr> TypeDefDList;
+
+struct Indx
+{
+ void* table[128];
+ Indx() { memset(table,0,sizeof(table)); };
+ ~Indx()
+ {
+ for(int i = 1; i < 128; i++) delete ((Indx*)(table[i]));
+ };
+ void IndexString(__in_z __in char* psz, void* pkywd)
+ {
+ int i = (int) *psz;
+ if(i == 0)
+ table[0] = pkywd;
+ else
+ {
+ _ASSERTE((i > 0)&&(i <= 127));
+ Indx* pInd = (Indx*)(table[i]);
+ if(pInd == NULL)
+ {
+ pInd = new Indx;
+ _ASSERTE(pInd);
+ table[i] = pInd;
+ }
+ pInd->IndexString(psz+1,pkywd);
+ }
+ }
+ void* FindString(__in __nullterminated char* psz)
+ {
+ if(*psz > 0)
+ {
+ unsigned char uch = (unsigned char) *psz;
+ if(table[uch] != NULL)
+ return ((Indx*)(table[uch]))->FindString(psz+1);
+ }
+ else if(*psz == 0) return table[0];
+ return NULL;
+ }
+};
+
+class Assembler {
+public:
+ Assembler();
+ ~Assembler();
+ //--------------------------------------------------------
+ GlobalLabelList m_lstGlobalLabel;
+ GlobalFixupList m_lstGlobalFixup;
+
+ LabelList m_lstLabel;
+
+ Class * m_pModuleClass;
+ ClassList m_lstClass;
+ ClassHash m_hshClass;
+
+ Indx indxKeywords;
+
+ BYTE * m_pOutputBuffer;
+ BYTE * m_pCurOutputPos;
+ BYTE * m_pEndOutputPos;
+
+
+ DWORD m_CurPC;
+ BOOL m_fStdMapping;
+ BOOL m_fDisplayTraceOutput;
+ BOOL m_fInitialisedMetaData;
+ BOOL m_fAutoInheritFromObject;
+ BOOL m_fReportProgress;
+ BOOL m_fIsMscorlib;
+ BOOL m_fTolerateDupMethods;
+ BOOL m_fENCMode;
+ BOOL m_fOptimize;
+ mdToken m_tkSysObject;
+ mdToken m_tkSysString;
+ mdToken m_tkSysValue;
+ mdToken m_tkSysEnum;
+ BOOL m_fDidCoInitialise;
+
+ IMetaDataDispenserEx *m_pDisp;
+ IMetaDataEmit2 *m_pEmitter;
+ ICeeFileGen *m_pCeeFileGen;
+ IMetaDataImport2 *m_pImporter; // Import interface.
+ HCEEFILE m_pCeeFile;
+ HCEESECTION m_pGlobalDataSection;
+ HCEESECTION m_pILSection;
+ HCEESECTION m_pTLSSection;
+ HCEESECTION m_pCurSection; // The section EmitData* things go to
+
+ AsmMan* m_pManifest;
+
+ char m_szScopeName[MAX_SCOPE_LENGTH];
+ char *m_szNamespace; //[MAX_NAMESPACE_LENGTH];
+ char *m_szFullNS; //[MAX_NAMESPACE_LENGTH];
+ unsigned m_ulFullNSLen;
+
+ WCHAR *m_wzMetadataVersion;
+
+ StringStack m_NSstack;
+ mdTypeSpec m_crExtends;
+
+ // char m_szExtendsClause[MAX_CLASSNAME_LENGTH];
+
+ // The (resizable) array of "implements" types
+ mdToken *m_crImplList;
+ int m_nImplList;
+ int m_nImplListSize;
+
+ TyParList *m_TyParList;
+
+ Method *m_pCurMethod;
+ Class *m_pCurClass;
+ ClassStack m_ClassStack; // for nested classes
+ Class *dummyClass; // for FindCreateClass
+
+ // moved to Class
+ //MethodList m_MethodList;
+
+ BOOL m_fCPlusPlus;
+ BOOL m_fWindowsCE;
+ BOOL m_fDLL;
+ BOOL m_fOBJ;
+ BOOL m_fEntryPointPresent;
+ BOOL m_fHaveFieldsWithRvas;
+ BOOL m_fFoldCode;
+ DWORD m_dwMethodsFolded;
+
+ state_t m_State;
+
+ BinStr* m_pbsMD;
+
+ Instr m_Instr[INSTR_POOL_SIZE]; // 16
+ inline Instr* GetInstr()
+ {
+ int i;
+ for(i=0; (i<INSTR_POOL_SIZE)&&(m_Instr[i].opcode != -1); i++);
+ if(i<INSTR_POOL_SIZE) return &m_Instr[i];
+ report->error("Instruction pool exhausted: source contains invalid instructions\n");
+ return NULL;
+ }
+ // Labels, fixups and IL fixups are defined in Method.hpp,.cpp
+ void AddLabel(DWORD CurPC, __in __nullterminated char *pszName);
+ void AddDeferredFixup(__in __nullterminated char *pszLabel, BYTE *pBytes, DWORD RelativeToPC, BYTE FixupSize);
+ void AddDeferredILFixup(ILFixupType Kind);
+ void AddDeferredILFixup(ILFixupType Kind, GlobalFixup *GFixup);
+ void DoDeferredILFixups(Method* pMethod);
+ BOOL DoFixups(Method* pMethod);
+ //--------------------------------------------------------------------------------
+ void ClearImplList(void);
+ void AddToImplList(mdToken);
+ void ClearBoundList(void);
+ //--------------------------------------------------------------------------------
+ BOOL Init();
+ void ProcessLabel(__in_z __in char *pszName);
+ GlobalLabel *FindGlobalLabel(LPCUTF8 pszName);
+ GlobalFixup *AddDeferredGlobalFixup(__in __nullterminated char *pszLabel, BYTE* reference);
+ //void AddDeferredDescrFixup(__in __nullterminated char *pszLabel);
+ BOOL DoGlobalFixups();
+ BOOL DoDescrFixups();
+ OPCODE DecodeOpcode(const BYTE *pCode, DWORD *pdwLen);
+ BOOL AddMethod(Method *pMethod);
+ void SetTLSSection() { m_pCurSection = m_pTLSSection; }
+ void SetILSection() { m_pCurSection = m_pILSection; }
+ void SetDataSection() { m_pCurSection = m_pGlobalDataSection; }
+ BOOL EmitMethod(Method *pMethod);
+ BOOL EmitMethodBody(Method* pMethod, BinStr* pbsOut);
+ BOOL EmitClass(Class *pClass);
+ HRESULT CreatePEFile(__in __nullterminated WCHAR *pwzOutputFilename);
+ HRESULT CreateTLSDirectory();
+ HRESULT CreateDebugDirectory();
+ HRESULT InitMetaData();
+ Class *FindCreateClass(__in __nullterminated const char *pszFQN);
+ BOOL EmitFieldRef(__in_z __in char *pszArg, int opcode);
+ BOOL EmitSwitchData(__in_z __in char *pszArg);
+ mdToken ResolveClassRef(mdToken tkResScope, __in __nullterminated const char *pszClassName, Class** ppClass);
+ mdToken ResolveTypeSpec(BinStr* typeSpec);
+ mdToken GetBaseAsmRef();
+ mdToken GetAsmRef(__in __nullterminated const char* szName);
+ mdToken GetModRef(__in __nullterminated char* szName);
+ mdToken GetInterfaceImpl(mdToken tsClass, mdToken tsInterface);
+ char* ReflectionNotation(mdToken tk);
+ HRESULT ConvLocalSig(__in char* localsSig, CQuickBytes* corSig, DWORD* corSigLen, BYTE*& localTypes);
+ DWORD GetCurrentILSectionOffset();
+ BOOL EmitCALLISig(__in char *p);
+ void AddException(DWORD pcStart, DWORD pcEnd, DWORD pcHandler, DWORD pcHandlerTo, mdTypeRef crException, BOOL isFilter, BOOL isFault, BOOL isFinally);
+ state_t CheckLocalTypeConsistancy(int instr, unsigned arg);
+ state_t AddGlobalLabel(__in __nullterminated char *pszName, HCEESECTION section);
+ void SetDLL(BOOL);
+ void SetOBJ(BOOL);
+ void ResetForNextMethod();
+ void ResetLineNumbers();
+ void SetStdMapping(BOOL val = TRUE) { m_fStdMapping = val; };
+
+ //--------------------------------------------------------------------------------
+ BOOL isShort(unsigned instr) { return ((OpcodeInfo[instr].Type & 16) != 0); };
+ unsigned ShortOf(unsigned opcode);
+ void SetErrorReporter(ErrorReporter* aReport) { report = aReport; if(m_pManifest) m_pManifest->SetErrorReporter(aReport); }
+
+ void StartNameSpace(__in __nullterminated char* name);
+ void EndNameSpace();
+ void StartClass(__in __nullterminated char* name, DWORD attr, TyParList *typars);
+ DWORD CheckClassFlagsIfNested(Class* pEncloser, DWORD attr);
+ void AddClass();
+ void EndClass();
+ void StartMethod(__in __nullterminated char* name, BinStr* sig, CorMethodAttr flags, BinStr* retMarshal, DWORD retAttr, TyParList *typars = NULL);
+ void EndMethod();
+
+ void AddField(__inout_z __inout char* name, BinStr* sig, CorFieldAttr flags, __in __nullterminated char* rvaLabel, BinStr* pVal, ULONG ulOffset);
+ BOOL EmitField(FieldDescriptor* pFD);
+ void EmitByte(int val);
+ //void EmitTry(enum CorExceptionFlag kind, char* beginLabel, char* endLabel, char* handleLabel, char* filterOrClass);
+ void EmitMaxStack(unsigned val);
+ void EmitLocals(BinStr* sig);
+ void EmitEntryPoint();
+ void EmitZeroInit();
+ void SetImplAttr(unsigned short attrval);
+
+ // Emits zeros if the buffer parameter is NULL.
+ void EmitData(__in_opt void *buffer, unsigned len);
+
+ void EmitDD(__in __nullterminated char *str);
+ void EmitDataString(BinStr* str);
+
+ void EmitInstrVar(Instr* instr, int var);
+ void EmitInstrVarByName(Instr* instr, __in __nullterminated char* label);
+ void EmitInstrI(Instr* instr, int val);
+ void EmitInstrI8(Instr* instr, __int64* val);
+ void EmitInstrR(Instr* instr, double* val);
+ void EmitInstrBrOffset(Instr* instr, int offset);
+ void EmitInstrBrTarget(Instr* instr, __in __nullterminated char* label);
+ mdToken MakeMemberRef(mdToken typeSpec, __in __nullterminated char* name, BinStr* sig);
+ mdToken MakeMethodSpec(mdToken tkParent, BinStr* sig);
+ void SetMemberRefFixup(mdToken tk, unsigned opcode_len);
+ mdToken MakeTypeRef(mdToken tkResScope, LPCUTF8 szFullName);
+ void EmitInstrStringLiteral(Instr* instr, BinStr* literal, BOOL ConvertToUnicode, BOOL Swap = FALSE);
+ void EmitInstrSig(Instr* instr, BinStr* sig);
+ void EmitInstrSwitch(Instr* instr, Labels* targets);
+ void EmitLabel(__in __nullterminated char* label);
+ void EmitDataLabel(__in __nullterminated char* label);
+
+ unsigned OpcodeLen(Instr* instr); //returns opcode length
+ // Emit just the opcode (no parameters to the instruction stream.
+ void EmitOpcode(Instr* instr);
+
+ // Emit primitive types to the instruction stream.
+ void EmitBytes(BYTE*, unsigned len);
+
+ ErrorReporter* report;
+
+ BOOL EmitFieldsMethods(Class* pClass);
+ BOOL EmitEventsProps(Class* pClass);
+
+ // named args/vars paraphernalia:
+public:
+ void addArgName(__in_opt __nullterminated char *szNewName, BinStr* pbSig, BinStr* pbMarsh, DWORD dwAttr)
+ {
+ if(pbSig && (*(pbSig->ptr()) == ELEMENT_TYPE_VOID))
+ report->error("Illegal use of type 'void'\n");
+ if(m_lastArgName)
+ {
+ m_lastArgName->pNext = new ARG_NAME_LIST(m_lastArgName->nNum+1,szNewName,pbSig,pbMarsh,dwAttr);
+ m_lastArgName = m_lastArgName->pNext;
+ }
+ else
+ {
+ m_lastArgName = new ARG_NAME_LIST(0,szNewName,pbSig,pbMarsh,dwAttr);
+ m_firstArgName = m_lastArgName;
+ }
+ };
+ ARG_NAME_LIST *getArgNameList(void)
+ { ARG_NAME_LIST *pRet = m_firstArgName; m_firstArgName=NULL; m_lastArgName=NULL; return pRet;};
+ // Added because recursive destructor of ARG_NAME_LIST may overflow the system stack
+ void delArgNameList(ARG_NAME_LIST *pFirst)
+ {
+ ARG_NAME_LIST *pArgList=pFirst, *pArgListNext;
+ for(; pArgList; pArgListNext=pArgList->pNext,
+ delete pArgList,
+ pArgList=pArgListNext);
+ };
+
+ ARG_NAME_LIST *findArg(ARG_NAME_LIST *pFirst, int num)
+ {
+ ARG_NAME_LIST *pAN;
+ for(pAN=pFirst; pAN; pAN = pAN->pNext)
+ {
+ if(pAN->nNum == num) return pAN;
+ }
+ return NULL;
+ };
+ ARG_NAME_LIST *m_firstArgName;
+ ARG_NAME_LIST *m_lastArgName;
+ void ResetArgNameList();
+
+ // Structured exception handling paraphernalia:
+public:
+ SEH_Descriptor *m_SEHD; // current descriptor ptr
+ void NewSEHDescriptor(void); //sets m_SEHD
+ void SetTryLabels(__in __nullterminated char * szFrom, __in __nullterminated char *szTo);
+ void SetFilterLabel(__in __nullterminated char *szFilter);
+ void SetCatchClass(mdToken catchClass);
+ void SetHandlerLabels(__in __nullterminated char *szHandlerFrom, __in __nullterminated char *szHandlerTo);
+ void EmitTry(void); //uses m_SEHD
+
+//private:
+ SEHD_Stack m_SEHDstack;
+
+ // Events and Properties paraphernalia:
+public:
+ void EndEvent(void); //emits event definition
+ void EndProp(void); //emits property definition
+ void ResetEvent(__inout_z __inout char * szName, mdToken typeSpec, DWORD dwAttr);
+ void ResetProp(__inout_z __inout char * szName, BinStr* bsType, DWORD dwAttr, BinStr* bsValue);
+ void SetEventMethod(int MethodCode, mdToken tk);
+ void SetPropMethod(int MethodCode, mdToken tk);
+ BOOL EmitEvent(EventDescriptor* pED); // impl. in ASSEM.CPP
+ BOOL EmitProp(PropDescriptor* pPD); // impl. in ASSEM.CPP
+ EventDescriptor* m_pCurEvent;
+ PropDescriptor* m_pCurProp;
+
+private:
+ MemberRefDList m_LocalMethodRefDList;
+ MemberRefDList m_LocalFieldRefDList;
+ LocalMemberRefFixupList m_LocalMemberRefFixupList;
+ MethodBodyList m_MethodBodyList;
+ MemberRefDList m_MethodSpecList;
+public:
+ HRESULT ResolveLocalMemberRefs();
+ HRESULT DoLocalMemberRefFixups();
+ mdToken ResolveLocalMemberRef(mdToken tok);
+
+ // PInvoke paraphernalia
+public:
+ PInvokeDescriptor* m_pPInvoke;
+ ImportList m_ImportList;
+ void SetPinvoke(BinStr* DllName, int Ordinal, BinStr* Alias, int Attrs);
+ HRESULT EmitPinvokeMap(mdToken tk, PInvokeDescriptor* pDescr);
+ ImportDescriptor* EmitImport(BinStr* DllName);
+ void EmitImports();
+
+ // Debug metadata paraphernalia
+public:
+ ISymUnmanagedWriter* m_pSymWriter;
+ ISymUnmanagedDocumentWriter* m_pSymDocument;
+ DocWriterList m_DocWriterList;
+ ULONG m_ulCurLine; // set by Parser
+ ULONG m_ulCurColumn; // set by Parser
+ ULONG m_ulLastDebugLine;
+ ULONG m_ulLastDebugColumn;
+ ULONG m_ulLastDebugLineEnd;
+ ULONG m_ulLastDebugColumnEnd;
+ DWORD m_dwIncludeDebugInfo;
+ BOOL m_fGeneratePDB;
+ char m_szSourceFileName[MAX_FILENAME_LENGTH*3+1];
+ WCHAR m_wzOutputFileName[MAX_FILENAME_LENGTH];
+ WCHAR m_wzSourceFileName[MAX_FILENAME_LENGTH];
+ GUID m_guidLang;
+ GUID m_guidLangVendor;
+ GUID m_guidDoc;
+
+ // Security paraphernalia
+public:
+ void AddPermissionDecl(CorDeclSecurity action, mdToken type, NVPair *pairs)
+ {
+ PermissionDecl *decl = new PermissionDecl(action, type, pairs);
+ if(decl==NULL)
+ {
+ report->error("\nOut of memory!\n");
+ return;
+ }
+ if (m_pCurMethod) {
+ decl->m_Next = m_pCurMethod->m_pPermissions;
+ m_pCurMethod->m_pPermissions = decl;
+ } else if (m_pCurClass) {
+ decl->m_Next = m_pCurClass->m_pPermissions;
+ m_pCurClass->m_pPermissions = decl;
+ } else if (m_pManifest && m_pManifest->m_pAssembly) {
+ decl->m_Next = m_pManifest->m_pAssembly->m_pPermissions;
+ m_pManifest->m_pAssembly->m_pPermissions = decl;
+ } else {
+ report->error("Cannot declare security permissions without the owner\n");
+ delete decl;
+ }
+ };
+
+ void AddPermissionDecl(CorDeclSecurity action, mdToken type, BinStr *pbsPairs)
+ {
+ PermissionDecl *decl = new PermissionDecl(action, type, pbsPairs);
+ if(decl==NULL)
+ {
+ report->error("\nOut of memory!\n");
+ return;
+ }
+ if (m_pCurMethod) {
+ decl->m_Next = m_pCurMethod->m_pPermissions;
+ m_pCurMethod->m_pPermissions = decl;
+ } else if (m_pCurClass) {
+ decl->m_Next = m_pCurClass->m_pPermissions;
+ m_pCurClass->m_pPermissions = decl;
+ } else if (m_pManifest && m_pManifest->m_pAssembly) {
+ decl->m_Next = m_pManifest->m_pAssembly->m_pPermissions;
+ m_pManifest->m_pAssembly->m_pPermissions = decl;
+ } else {
+ report->error("Cannot declare security permissions without the owner\n");
+ delete decl;
+ }
+ };
+
+ void AddPermissionSetDecl(CorDeclSecurity action, BinStr *value)
+ {
+ PermissionSetDecl *decl = new PermissionSetDecl(action, value);
+ if(decl==NULL)
+ {
+ report->error("\nOut of memory!\n");
+ return;
+ }
+ if (m_pCurMethod) {
+ decl->m_Next = m_pCurMethod->m_pPermissionSets;
+ m_pCurMethod->m_pPermissionSets = decl;
+ } else if (m_pCurClass) {
+ decl->m_Next = m_pCurClass->m_pPermissionSets;
+ m_pCurClass->m_pPermissionSets = decl;
+ } else if (m_pManifest && m_pManifest->m_pAssembly) {
+ decl->m_Next = m_pManifest->m_pAssembly->m_pPermissionSets;
+ m_pManifest->m_pAssembly->m_pPermissionSets = decl;
+ } else {
+ report->error("Cannot declare security permission sets without the owner\n");
+ delete decl;
+ }
+ };
+ void EmitSecurityInfo(mdToken token,
+ PermissionDecl* pPermissions,
+ PermissionSetDecl*pPermissionSets);
+#ifndef FEATURE_CORECLR
+ HRESULT AllocateStrongNameSignature();
+ HRESULT StrongNameSign();
+#endif
+ BinStr* EncodeSecAttr(__in __nullterminated char* szReflName, BinStr* pbsSecAttrBlob, unsigned nProps);
+
+ // Custom values paraphernalia:
+public:
+ mdToken m_tkCurrentCVOwner;
+ CustomDescrList* m_pCustomDescrList;
+ CustomDescrListStack m_CustomDescrListStack;
+ CustomDescrList m_CustomDescrList;
+
+ void DefineCV(CustomDescr* pCD)
+ {
+ if(pCD)
+ {
+ ULONG cTemp = 0;
+ void * pBlobBody = NULL;
+ mdToken cv;
+ mdToken tkOwnerType, tkTypeType = TypeFromToken(pCD->tkType);
+
+ if((tkTypeType != 0x99000000)&&(tkTypeType != 0x98000000))
+ {
+ tkOwnerType = TypeFromToken(pCD->tkOwner);
+ if((tkOwnerType != 0x99000000)&&(tkOwnerType != 0x98000000))
+ {
+ if(pCD->pBlob)
+ {
+ pBlobBody = (void *)(pCD->pBlob->ptr());
+ cTemp = pCD->pBlob->length();
+ }
+ if (pCD->tkInterfacePair)
+ {
+ pCD->tkOwner = GetInterfaceImpl(pCD->tkOwner, pCD->tkInterfacePair);
+ }
+ m_pEmitter->DefineCustomAttribute(pCD->tkOwner,pCD->tkType,pBlobBody,cTemp,&cv);
+
+ delete pCD;
+ return;
+ }
+ }
+ m_CustomDescrList.PUSH(pCD);
+ }
+ };
+ void EmitCustomAttributes(mdToken tok, CustomDescrList* pCDL)
+ {
+ CustomDescr *pCD;
+ if(pCDL == NULL || RidFromToken(tok)==0) return;
+ while((pCD = pCDL->POP()))
+ {
+ pCD->tkOwner = tok;
+ DefineCV(pCD);
+ }
+ };
+
+ void EmitUnresolvedCustomAttributes(); // implementation: writer.cpp
+ // VTable blob (if any)
+public:
+ BinStr *m_pVTable;
+ // Field marshaling
+ BinStr *m_pMarshal;
+ // VTable fixup list
+ VTFList m_VTFList;
+ // Export Address Table entries list
+ EATList m_EATList;
+ HRESULT CreateExportDirectory();
+ DWORD EmitExportStub(DWORD dwVTFSlotRVA);
+
+ // Method implementation paraphernalia:
+private:
+ MethodImplDList m_MethodImplDList;
+public:
+ void AddMethodImpl(mdToken tkImplementedTypeSpec, __in __nullterminated char* szImplementedName, BinStr* pImplementedSig,
+ mdToken tkImplementingTypeSpec, __in_opt __nullterminated char* szImplementingName, BinStr* pImplementingSig);
+ BOOL EmitMethodImpls();
+ // lexical scope handling paraphernalia:
+ void EmitScope(Scope* pSCroot); // struct Scope - see Method.hpp
+ // source file name paraphernalia
+ BOOL m_fSourceFileSet;
+ void SetSourceFileName(__in __nullterminated char* szName);
+ void SetSourceFileName(BinStr* pbsName);
+ // header flags
+ DWORD m_dwSubsystem;
+ WORD m_wSSVersionMajor;
+ WORD m_wSSVersionMinor;
+ DWORD m_dwComImageFlags;
+ DWORD m_dwFileAlignment;
+ ULONGLONG m_stBaseAddress;
+ size_t m_stSizeOfStackReserve;
+ DWORD m_dwCeeFileFlags;
+ WORD m_wMSVmajor;
+ WORD m_wMSVminor;
+ BOOL m_fAppContainer;
+ BOOL m_fHighEntropyVA;
+
+ // Former globals
+ WCHAR *m_wzResourceFile;
+ WCHAR *m_wzKeySourceName;
+ bool OnErrGo;
+ void SetCodePage(unsigned val) { g_uCodePage = val; };
+ Clockwork* bClock;
+ void SetClock(Clockwork* val) { bClock = val; };
+ // ENC paraphernalia
+ HRESULT InitMetaDataForENC(__in __nullterminated WCHAR* wzOrigFileName);
+ BOOL EmitFieldsMethodsENC(Class* pClass);
+ BOOL EmitEventsPropsENC(Class* pClass);
+ HRESULT CreateDeltaFiles(__in __nullterminated WCHAR *pwzOutputFilename);
+
+ // Syntactic sugar paraphernalia
+private:
+ TypeDefDList m_TypeDefDList;
+public:
+ void AddTypeDef(BinStr* pbsTypeSpec, __in_z __in char* szName)
+ {
+ m_TypeDefDList.PUSH(new TypeDefDescr(szName, pbsTypeSpec, ResolveTypeSpec(pbsTypeSpec)));
+ };
+ void AddTypeDef(mdToken tkTypeSpec, __in_z __in char* szName)
+ {
+ m_TypeDefDList.PUSH(new TypeDefDescr(szName, NULL, tkTypeSpec));
+ };
+ void AddTypeDef(CustomDescr* pCA, __in_z __in char* szName)
+ {
+ TypeDefDescr* pNew = new TypeDefDescr(szName,NULL,mdtCustomAttribute);
+ pNew->m_pCA = pCA;
+ m_TypeDefDList.PUSH(pNew);
+ };
+ TypeDefDescr* FindTypeDef(__in_z __in char* szName)
+ {
+ CHECK_LOCAL_STATIC_VAR(static TypeDefDescr X(NULL, NULL, 0));
+
+ X.m_szName = szName;
+ TypeDefDescr* Y = m_TypeDefDList.FIND(&X);
+ X.m_szName = NULL; // to avoid deletion when X goes out of scope
+ return Y;
+ //return m_TypeDefDList.FIND(szName);
+ };
+ unsigned NumTypeDefs() {return m_TypeDefDList.COUNT();};
+private:
+ HRESULT GetCAName(mdToken tkCA, __out LPWSTR *ppszName);
+#ifndef FEATURE_CORECLR
+ HRESULT GetSignatureKey();
+#endif
+};
+
+#endif // Assember_h
+
+#ifdef _MSC_VER
+#pragma warning(default : 4640)
+#endif
+
+
diff --git a/src/ilasm/binstr.h b/src/ilasm/binstr.h
new file mode 100644
index 0000000000..275b810a5c
--- /dev/null
+++ b/src/ilasm/binstr.h
@@ -0,0 +1,77 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+/**************************************************************************/
+/* a binary string (blob) class */
+
+#ifndef BINSTR_H
+#define BINSTR_H
+
+#include <string.h> // for memmove, memcpy ...
+
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:22008) // "Suppress PREfast warnings about integer overflow"
+#endif
+
+class BinStr {
+public:
+ BinStr() { len = 0L; max = 8L; ptr_ = buff; }
+ BinStr(BYTE* pb, DWORD cb) { len = cb; max = cb+8; ptr_ = pb; }
+ ~BinStr() { if (ptr_ != buff) delete [] ptr_; }
+
+ void insertInt8(int val) { if (len >= max) Realloc(); memmove(ptr_+1, ptr_, len); *ptr_ = val; len++; }
+ void insertInt32(int val) { if (len + 4 > max) Realloc(); memmove(ptr_+4, ptr_, len); SET_UNALIGNED_32(&ptr_[0], val); len+=4; }
+ void appendInt8(int val) { if (len >= max) Realloc(); ptr_[len++] = val; }
+ void appendInt16(int val) { if (len + 2 > max) Realloc(); SET_UNALIGNED_16(&ptr_[len], val); len += 2; }
+ void appendInt32(int val) { if (len + 4 > max) Realloc(); SET_UNALIGNED_32(&ptr_[len], val); len += 4; }
+ void appendInt64(__int64 *pval) { if (len + 8 > max) Realloc(8); SET_UNALIGNED_64(&ptr_[len],(*pval)); len += 8; }
+ unsigned __int8* getBuff(unsigned size) {
+ if (len + size > max) Realloc(size);
+ _ASSERTE(len + size <= max);
+ unsigned __int8* ret = &ptr_[len];
+ len += size;
+ return(ret);
+ }
+ void append(BinStr* str) {
+ memcpy(getBuff(str->length()), str->ptr(), str->length());
+ }
+
+ void appendFrom(BinStr* str, unsigned ix) {
+ _ASSERTE(str->length() >= ix);
+ if (str->length() >= ix)
+ {
+ memcpy(getBuff(str->length()-ix), str->ptr()+ix, str->length()-ix);
+ }
+ }
+
+ void remove(unsigned size) { _ASSERTE(len >= size); len -= size; }
+
+ unsigned __int8* ptr() { return(ptr_); }
+ unsigned length() { return(len); }
+
+private:
+ void Realloc(unsigned atLeast = 4) {
+ max = max * 2;
+ if (max < atLeast + len)
+ max = atLeast + len;
+ _ASSERTE(max >= len + atLeast);
+ unsigned __int8* newPtr = new unsigned __int8[max];
+ memcpy(newPtr, ptr_, len);
+ if (ptr_ != buff) delete [] ptr_;
+ ptr_ = newPtr;
+ }
+
+private:
+ unsigned len;
+ unsigned max;
+ unsigned __int8 *ptr_;
+ unsigned __int8 buff[8];
+};
+BinStr* BinStrToUnicode(BinStr* pSource, bool Swap = false);
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+
+#endif
+
diff --git a/src/ilasm/class.hpp b/src/ilasm/class.hpp
new file mode 100644
index 0000000000..f281c77f5a
--- /dev/null
+++ b/src/ilasm/class.hpp
@@ -0,0 +1,118 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// class.hpp
+//
+
+#ifndef _CLASS_HPP
+#define _CLASS_HPP
+
+class PermissionDecl;
+class PermissionSetDecl;
+
+extern unsigned int g_uCodePage;
+extern WCHAR wzUniBuf[];
+
+class Class
+{
+public:
+ Class * m_pEncloser;
+ LPCUTF8 m_szFQN;
+ DWORD m_dwFQN;
+ unsigned m_Hash;
+ mdTypeDef m_cl;
+ mdTypeRef m_crExtends;
+ mdTypeRef *m_crImplements;
+ TyParDescr* m_TyPars;
+ DWORD m_NumTyPars;
+ DWORD m_Attr;
+ DWORD m_dwNumInterfaces;
+ DWORD m_dwNumFieldsWithOffset;
+ PermissionDecl* m_pPermissions;
+ PermissionSetDecl* m_pPermissionSets;
+ ULONG m_ulSize;
+ ULONG m_ulPack;
+ BOOL m_bIsMaster;
+ BOOL m_fNew;
+ BOOL m_fNewMembers;
+
+ MethodList m_MethodList;
+ //MethodSortedList m_MethodSList;
+ FieldDList m_FieldDList;
+ EventDList m_EventDList;
+ PropDList m_PropDList;
+ CustomDescrList m_CustDList;
+
+ Class(LPCUTF8 pszFQN)
+ {
+ m_pEncloser = NULL;
+ m_cl = mdTypeDefNil;
+ m_crExtends = mdTypeRefNil;
+ m_NumTyPars = 0;
+ m_TyPars = NULL;
+ m_dwNumInterfaces = 0;
+ m_dwNumFieldsWithOffset = 0;
+ m_crImplements = NULL;
+ m_szFQN = pszFQN;
+ m_dwFQN = pszFQN ? (DWORD)strlen(pszFQN) : 0;
+ m_Hash = pszFQN ? hash((const BYTE*)pszFQN, m_dwFQN, 10) : 0;
+
+ m_Attr = tdPublic;
+
+ m_bIsMaster = TRUE;
+ m_fNew = TRUE;
+
+ m_pPermissions = NULL;
+ m_pPermissionSets = NULL;
+
+ m_ulPack = 0;
+ m_ulSize = 0xFFFFFFFF;
+ }
+
+ ~Class()
+ {
+ delete [] m_szFQN;
+ delete [] m_crImplements;
+ delete [] m_TyPars;
+ }
+
+ int FindTyPar(LPCWSTR wz)
+ {
+ int i,retval=-1;
+ for(i=0; i < (int)m_NumTyPars; i++)
+ {
+ if(!wcscmp(wz,m_TyPars[i].Name()))
+ {
+ retval = i;
+ break;
+ }
+ }
+ return retval;
+ };
+ int FindTyPar(LPCUTF8 sz)
+ {
+ if(sz)
+ {
+ wzUniBuf[0] = 0;
+ WszMultiByteToWideChar(g_uCodePage,0,sz,-1,wzUniBuf,dwUniBuf);
+ return FindTyPar(wzUniBuf);
+ }
+ else return -1;
+ };
+ int ComparedTo(Class* T)
+ {
+ if (m_Hash == T->m_Hash)
+ {
+ // Properly handle hash conflict
+ return (m_szFQN == T->m_szFQN) ? 0 : strcmp(m_szFQN, T->m_szFQN);
+ } else
+ {
+ return (m_Hash > T->m_Hash) ? 1 : -1;
+ }
+ }
+};
+
+
+#endif /* _CLASS_HPP */
+
diff --git a/src/ilasm/extractGrammar.pl b/src/ilasm/extractGrammar.pl
new file mode 100644
index 0000000000..0fac9b5804
--- /dev/null
+++ b/src/ilasm/extractGrammar.pl
@@ -0,0 +1,60 @@
+# Licensed to the .NET Foundation under one or more agreements.
+# The .NET Foundation licenses this file to you under the MIT license.
+# See the LICENSE file in the project root for more information.
+#
+# a simple script that extracts the grammar from a yacc file
+
+undef $/; # read in the whole file
+my $file = <>;
+$file =~ /^(.*)%%(.*)%%/s || die "Could not find %% markers";
+my $prefix = $1;
+my $grammar = $2;
+
+#my $line;
+#foreach $line (split /\n/s, $prefix) {
+# if ($line =~ /^\s*%token/) {
+# $line =~ s/\s*<.*>//g;
+# print "$line\n"
+# }
+#}
+
+ # remove any text in {}
+while ($grammar =~ s/\s*([^']){[^{}]*}/$1/sg) {}
+
+ # change keyword identifiers into the string they represent
+$grammar =~ s/\b([A-Z0-9_]+)_\b/'\L$1\E'/sg;
+
+ # change assembler directives into their string
+$grammar =~ s/\b_([A-Z0-9]+)\b/'\L.$1\E'/sg;
+
+ # do the special punctuation by hand
+$grammar =~ s/\bELIPSIS\b/'...'/sg;
+$grammar =~ s/\bDCOLON\b/'::'/sg;
+
+#<STRIP>
+ # remove TODO comments
+$grammar =~ s/\n\s*\/\*[^\n]*TODO[^\n]*\*\/\s*\n/\n/sg;
+#</STRIP>
+
+print "Lexical tokens\n";
+print " ID - C style alphaNumeric identifier (e.g. Hello_There2)\n";
+print " DOTTEDNAME - Sequence of dot-separated IDs (e.g. System.Object)\n";
+print " QSTRING - C style quoted string (e.g. \"hi\\n\")\n";
+print " SQSTRING - C style singlely quoted string(e.g. 'hi')\n";
+print " INT32 - C style 32 bit integer (e.g. 235, 03423, 0x34FFF)\n";
+print " INT64 - C style 64 bit integer (e.g. -2353453636235234, 0x34FFFFFFFFFF)\n";
+print " FLOAT64 - C style floating point number (e.g. -0.2323, 354.3423, 3435.34E-5)\n";
+print " INSTR_* - IL instructions of a particular class (see opcode.def).\n";
+print " HEXBYTE - 1- or 2-digit hexadecimal number (e.g., A2, F0).\n";
+print "Auxiliary lexical tokens\n";
+print " TYPEDEF_T - Aliased class (TypeDef or TypeRef).\n";
+print " TYPEDEF_M - Aliased method.\n";
+print " TYPEDEF_F - Aliased field.\n";
+print " TYPEDEF_TS - Aliased type specification (TypeSpec).\n";
+print " TYPEDEF_MR - Aliased field/method reference (MemberRef).\n";
+print " TYPEDEF_CA - Aliased Custom Attribute.\n";
+print "----------------------------------------------------------------------------------\n";
+print "START : decls\n";
+print " ;";
+
+print $grammar;
diff --git a/src/ilasm/grammar_after.cpp b/src/ilasm/grammar_after.cpp
new file mode 100644
index 0000000000..c8634801c7
--- /dev/null
+++ b/src/ilasm/grammar_after.cpp
@@ -0,0 +1,1722 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+/********************************************************************************/
+/* Code goes here */
+
+/********************************************************************************/
+extern int yyparse();
+
+struct Keywords {
+ const char* name;
+ unsigned short token;
+ unsigned short tokenVal;// this holds the instruction enumeration for those keywords that are instrs
+ size_t stname;
+};
+
+#define NO_VALUE ((unsigned short)-1) // The token has no value
+
+static Keywords keywords[] = {
+// Attention! Because of aliases, the instructions MUST go first!
+// Redefine all the instructions (defined in assembler.h <- asmenum.h <- opcode.def)
+#undef InlineNone
+#undef InlineVar
+#undef ShortInlineVar
+#undef InlineI
+#undef ShortInlineI
+#undef InlineI8
+#undef InlineR
+#undef ShortInlineR
+#undef InlineBrTarget
+#undef ShortInlineBrTarget
+#undef InlineMethod
+#undef InlineField
+#undef InlineType
+#undef InlineString
+#undef InlineSig
+#undef InlineTok
+#undef InlineSwitch
+#undef InlineVarTok
+
+
+#define InlineNone INSTR_NONE
+#define InlineVar INSTR_VAR
+#define ShortInlineVar INSTR_VAR
+#define InlineI INSTR_I
+#define ShortInlineI INSTR_I
+#define InlineI8 INSTR_I8
+#define InlineR INSTR_R
+#define ShortInlineR INSTR_R
+#define InlineBrTarget INSTR_BRTARGET
+#define ShortInlineBrTarget INSTR_BRTARGET
+#define InlineMethod INSTR_METHOD
+#define InlineField INSTR_FIELD
+#define InlineType INSTR_TYPE
+#define InlineString INSTR_STRING
+#define InlineSig INSTR_SIG
+#define InlineTok INSTR_TOK
+#define InlineSwitch INSTR_SWITCH
+
+#define InlineVarTok 0
+#define NEW_INLINE_NAMES
+ // The volatile instruction collides with the volatile keyword, so
+ // we treat it as a keyword everywhere and modify the grammar accordingly (Yuck!)
+#define OPDEF(c,s,pop,push,args,type,l,s1,s2,ctrl) { s, args, c, lengthof(s)-1 },
+#define OPALIAS(alias_c, s, c) { s, NO_VALUE, c, lengthof(s)-1 },
+#include "opcode.def"
+#undef OPALIAS
+#undef OPDEF
+
+ /* keywords */
+#define KYWD(name, sym, val) { name, sym, val, lengthof(name)-1 },
+#include "il_kywd.h"
+#undef KYWD
+
+};
+
+/********************************************************************************/
+/* File encoding-dependent functions */
+/*--------------------------------------------------------------------------*/
+char* nextcharA(__in __nullterminated char* pos)
+{
+ return (*pos > 0) ? ++pos : (char *)_mbsinc((const unsigned char *)pos);
+}
+
+char* nextcharU(__in __nullterminated char* pos)
+{
+ return ++pos;
+}
+
+char* nextcharW(__in __nullterminated char* pos)
+{
+ return (pos+2);
+}
+/*--------------------------------------------------------------------------*/
+unsigned SymAU(__in __nullterminated char* curPos)
+{
+ return (unsigned)*curPos;
+}
+
+unsigned SymW(__in __nullterminated char* curPos)
+{
+ return (unsigned)*((WCHAR*)curPos);
+}
+/*--------------------------------------------------------------------------*/
+char* NewStrFromTokenAU(__in_ecount(tokLen) char* curTok, size_t tokLen)
+{
+ char *nb = new char[tokLen+1];
+ if(nb != NULL)
+ {
+ memcpy(nb, curTok, tokLen);
+ nb[tokLen] = 0;
+ }
+ return nb;
+}
+char* NewStrFromTokenW(__in_ecount(tokLen) char* curTok, size_t tokLen)
+{
+ WCHAR* wcurTok = (WCHAR*)curTok;
+ char *nb = new char[(tokLen<<1) + 2];
+ if(nb != NULL)
+ {
+ tokLen = WszWideCharToMultiByte(CP_UTF8,0,(LPCWSTR)wcurTok,(int)(tokLen >> 1),nb,(int)(tokLen<<1) + 2,NULL,NULL);
+ nb[tokLen] = 0;
+ }
+ return nb;
+}
+/*--------------------------------------------------------------------------*/
+char* NewStaticStrFromTokenAU(__in_ecount(tokLen) char* curTok, size_t tokLen, __out_ecount(bufSize) char* staticBuf, size_t bufSize)
+{
+ if(tokLen >= bufSize) return NULL;
+ memcpy(staticBuf, curTok, tokLen);
+ staticBuf[tokLen] = 0;
+ return staticBuf;
+}
+char* NewStaticStrFromTokenW(__in_ecount(tokLen) char* curTok, size_t tokLen, __out_ecount(bufSize) char* staticBuf, size_t bufSize)
+{
+ WCHAR* wcurTok = (WCHAR*)curTok;
+ if(tokLen >= bufSize/2) return NULL;
+ tokLen = WszWideCharToMultiByte(CP_UTF8,0,(LPCWSTR)wcurTok,(int)(tokLen >> 1),staticBuf,(int)bufSize,NULL,NULL);
+ staticBuf[tokLen] = 0;
+ return staticBuf;
+}
+/*--------------------------------------------------------------------------*/
+unsigned GetDoubleAU(__in __nullterminated char* begNum, unsigned L, double** ppRes)
+{
+ static char dbuff[128];
+ char* pdummy;
+ if(L > 127) L = 127;
+ memcpy(dbuff,begNum,L);
+ dbuff[L] = 0;
+ *ppRes = new double(strtod(dbuff, &pdummy));
+ return ((unsigned)(pdummy - dbuff));
+}
+
+unsigned GetDoubleW(__in __nullterminated char* begNum, unsigned L, double** ppRes)
+{
+ static char dbuff[256];
+ char* pdummy;
+ if(L > 254) L = 254;
+ memcpy(dbuff,begNum,L);
+ dbuff[L] = 0;
+ dbuff[L+1] = 0;
+ *ppRes = new double(wcstod((const wchar_t*)dbuff, (wchar_t**)&pdummy));
+ return ((unsigned)(pdummy - dbuff));
+}
+/*--------------------------------------------------------------------------*/
+char* yygetline(int Line)
+{
+ static char buff[0x4000];
+ char *pLine=NULL, *pNextLine=NULL;
+ char *pBegin=NULL, *pEnd = NULL;
+ unsigned uCount = parser->getAll(&pBegin);
+ pEnd = pBegin + uCount;
+ buff[0] = 0;
+ for(uCount=0, pLine=pBegin; pLine < pEnd; pLine = nextchar(pLine))
+ {
+ if(Sym(pLine) == '\n') uCount++;
+ if(uCount == (unsigned int)(Line-1)) break;
+ }
+ pLine = nextchar(pLine);
+ if(pLine < pEnd)
+ {
+ for(pNextLine = pLine; pNextLine < pEnd; pNextLine = nextchar(pNextLine))
+ {
+ if(Sym(pNextLine) == '\n') break;
+ }
+ if(Sym == SymW) // Unicode file
+ {
+ if(*((WCHAR*)pNextLine - 1) == '\r') pNextLine -= 2;
+ uCount = (unsigned)(pNextLine - pLine);
+ uCount &= 0x1FFF; // limit: 8K wchars
+ WCHAR* wzBuff = (WCHAR*)buff;
+ memcpy(buff,pLine,uCount);
+ wzBuff[uCount >> 1] = 0;
+ }
+ else
+ {
+ if(*(pNextLine-1)=='\r') pNextLine--;
+ uCount = (unsigned)(pNextLine - pLine);
+ uCount &= 0x3FFF; // limit: 16K chars
+ memcpy(buff,pLine,uCount);
+ buff[uCount]=0;
+ }
+ }
+ return buff;
+}
+
+void yyerror(__in __nullterminated const char* str) {
+ char tokBuff[64];
+ WCHAR *wzfile = (WCHAR*)(PENV->in->namew());
+ int iline = PENV->curLine;
+
+ size_t len = PENV->curPos - PENV->curTok;
+ if (len > 62) len = 62;
+ memcpy(tokBuff, PENV->curTok, len);
+ tokBuff[len] = 0;
+ tokBuff[len+1] = 0;
+ if(PENV->bExternSource)
+ {
+ wzfile = PASM->m_wzSourceFileName;
+ iline = PENV->nExtLine;
+ }
+ if(Sym == SymW) // Unicode file
+ fprintf(stderr, "%S(%d) : error : %s at token '%S' in: %S\n",
+ wzfile, iline, str, (WCHAR*)tokBuff, (WCHAR*)yygetline(PENV->curLine));
+ else
+ fprintf(stderr, "%S(%d) : error : %s at token '%s' in: %s\n",
+ wzfile, iline, str, tokBuff, yygetline(PENV->curLine));
+ parser->success = false;
+}
+
+/********************************************************************************/
+/* looks up the typedef 'name' of length 'nameLen' (name does not need to be
+ null terminated) Returns 0 on failure */
+TypeDefDescr* findTypedef(__in_ecount(NameLen) char* name, size_t NameLen)
+{
+ TypeDefDescr* pRet = NULL;
+ static char Name[4096];
+ if(PASM->NumTypeDefs())
+ {
+ if(NewStaticStrFromToken(name,NameLen,Name,4096))
+ pRet = PASM->FindTypeDef(Name);
+ }
+ return pRet;
+}
+
+int TYPEDEF(TypeDefDescr* pTDD)
+{
+ switch(TypeFromToken(pTDD->m_tkTypeSpec))
+ {
+ case mdtTypeDef:
+ case mdtTypeRef:
+ return TYPEDEF_T;
+ case mdtMethodDef:
+ case 0x99000000:
+ return TYPEDEF_M;
+ case mdtFieldDef:
+ case 0x98000000:
+ return TYPEDEF_F;
+ case mdtMemberRef:
+ return TYPEDEF_MR;
+ case mdtTypeSpec:
+ return TYPEDEF_TS;
+ case mdtCustomAttribute:
+ return TYPEDEF_CA;
+ }
+ return ERROR_;
+
+}
+
+/********************************************************************************/
+void indexKeywords(Indx* indx) // called in Assembler constructor (assem.cpp)
+{
+ Keywords* low = keywords;
+ Keywords* high = keywords + (sizeof(keywords) / sizeof(Keywords));
+ Keywords* mid;
+ for(mid = low; mid < high; mid++)
+ {
+ indx->IndexString((char*)(mid->name),mid);
+ }
+}
+
+Instr* SetupInstr(unsigned short opcode)
+{
+ Instr* pVal = NULL;
+ if((pVal = PASM->GetInstr()))
+ {
+ pVal->opcode = opcode;
+ if((pVal->pWriter = PASM->m_pSymDocument)!=NULL)
+ {
+ if(PENV->bExternSource)
+ {
+ pVal->linenum = PENV->nExtLine;
+ pVal->column = PENV->nExtCol;
+ pVal->linenum_end = PENV->nExtLineEnd;
+ pVal->column_end = PENV->nExtColEnd;
+ pVal->pc = nCurrPC;
+ }
+ else
+ {
+ pVal->linenum = PENV->curLine;
+ pVal->column = 1;
+ pVal->linenum_end = PENV->curLine;
+ pVal->column_end = 0;
+ pVal->pc = PASM->m_CurPC;
+ }
+ }
+ }
+ return pVal;
+}
+/* looks up the keyword 'name' of length 'nameLen' (name does not need to be
+ null terminated) Returns 0 on failure */
+int findKeyword(const char* name, size_t nameLen, unsigned short* pOpcode)
+{
+ static char Name[128];
+ Keywords* mid;
+
+ if(NULL == NewStaticStrFromToken((char*)name,nameLen,Name,128)) return 0; // can't be a keyword
+ mid = (Keywords*)(PASM->indxKeywords.FindString(Name));
+ if(mid == NULL) return 0;
+ *pOpcode = mid->tokenVal;
+
+ return(mid->token);
+}
+
+/********************************************************************************/
+/* convert str to a uint64 */
+unsigned digits[128];
+void Init_str2uint64()
+{
+ int i;
+ memset(digits,255,sizeof(digits));
+ for(i='0'; i <= '9'; i++) digits[i] = i - '0';
+ for(i='A'; i <= 'Z'; i++) digits[i] = i + 10 - 'A';
+ for(i='a'; i <= 'z'; i++) digits[i] = i + 10 - 'a';
+}
+static unsigned __int64 str2uint64(const char* str, const char** endStr, unsigned radix)
+{
+ unsigned __int64 ret = 0;
+ unsigned digit,ix;
+ _ASSERTE(radix <= 36);
+ for(;;str = nextchar((char*)str))
+ {
+ ix = Sym((char*)str);
+ if(ix <= 0x7F)
+ {
+ digit = digits[ix];
+ if(digit < radix)
+ {
+ ret = ret * radix + digit;
+ continue;
+ }
+ }
+ *endStr = str;
+ return(ret);
+ }
+}
+/********************************************************************************/
+/* Append an UTF-8 string preceded by compressed length, no zero terminator, to a BinStr */
+static void AppendStringWithLength(BinStr* pbs, __in __nullterminated char* sz)
+{
+ if((pbs != NULL) && (sz != NULL))
+ {
+ unsigned L = (unsigned) strlen(sz);
+ BYTE* pb = NULL;
+ corEmitInt(pbs,L);
+ if((pb = pbs->getBuff(L)) != NULL)
+ memcpy(pb,sz,L);
+ }
+}
+
+/********************************************************************************/
+/* fetch the next token, and return it Also set the yylval.union if the
+ lexical token also has a value */
+
+#if (0)
+
+#define IsAlpha(x) ((('A' <= (x))&&((x) <= 'Z'))||(('a' <= (x))&&((x) <= 'z')))
+#define IsDigit(x) (('0' <= (x))&&((x) <= '9'))
+#define IsAlNum(x) (IsAlpha(x) || IsDigit(x))
+#define IsValidStartingSymbol(x) (IsAlpha(x)||((x)=='#')||((x)=='_')||((x)=='@')||((x)=='$'))
+#define IsValidContinuingSymbol(x) (IsAlNum(x)||((x)=='_')||((x)=='@')||((x)=='$')||((x)=='?'))
+void SetSymbolTables() { ; }
+
+#else
+
+BOOL _Alpha[128];
+BOOL _Digit[128];
+BOOL _AlNum[128];
+BOOL _ValidSS[128];
+BOOL _ValidCS[128];
+void SetSymbolTables()
+{
+ unsigned i;
+ memset(_Alpha,0,sizeof(_Alpha));
+ memset(_Digit,0,sizeof(_Digit));
+ memset(_AlNum,0,sizeof(_AlNum));
+ memset(_ValidSS,0,sizeof(_ValidSS));
+ memset(_ValidCS,0,sizeof(_ValidCS));
+ for(i = 'A'; i <= 'Z'; i++)
+ {
+ _Alpha[i] = TRUE;
+ _AlNum[i] = TRUE;
+ _ValidSS[i] = TRUE;
+ _ValidCS[i] = TRUE;
+ }
+ for(i = 'a'; i <= 'z'; i++)
+ {
+ _Alpha[i] = TRUE;
+ _AlNum[i] = TRUE;
+ _ValidSS[i] = TRUE;
+ _ValidCS[i] = TRUE;
+ }
+ for(i = '0'; i <= '9'; i++)
+ {
+ _Digit[i] = TRUE;
+ _AlNum[i] = TRUE;
+ _ValidCS[i] = TRUE;
+ }
+ _ValidSS[(unsigned char)'_'] = TRUE;
+ _ValidSS[(unsigned char)'#'] = TRUE;
+ _ValidSS[(unsigned char)'$'] = TRUE;
+ _ValidSS[(unsigned char)'@'] = TRUE;
+
+ _ValidCS[(unsigned char)'_'] = TRUE;
+ _ValidCS[(unsigned char)'?'] = TRUE;
+ _ValidCS[(unsigned char)'$'] = TRUE;
+ _ValidCS[(unsigned char)'@'] = TRUE;
+ _ValidCS[(unsigned char)'`'] = TRUE;
+}
+BOOL IsAlpha(unsigned x) { return (x < 128)&&_Alpha[x]; }
+BOOL IsDigit(unsigned x) { return (x < 128)&&_Digit[x]; }
+BOOL IsAlNum(unsigned x) { return (x < 128)&&_AlNum[x]; }
+BOOL IsValidStartingSymbol(unsigned x) { return (x < 128)&&_ValidSS[x]; }
+BOOL IsValidContinuingSymbol(unsigned x) { return (x < 128)&&_ValidCS[x]; }
+
+#endif
+
+char* nextBlank(__in __nullterminated char* curPos)
+{
+ for(;;)
+ {
+ switch(Sym(curPos))
+ {
+ case '/' :
+ if ((Sym(nextchar(curPos)) == '/')|| (Sym(nextchar(curPos)) == '*'))
+ return curPos;
+ else
+ {
+ curPos = nextchar(curPos);
+ break;
+ }
+ case 0:
+ case '\n':
+ case '\r':
+ case ' ' :
+ case '\t':
+ case '\f':
+ return curPos;
+
+ default:
+ curPos = nextchar(curPos);
+ }
+ }
+}
+
+char* skipBlanks(__in __nullterminated char* curPos, unsigned* pstate)
+{
+ const unsigned eolComment = 1;
+ const unsigned multiComment = 2;
+ unsigned nextSym, state = *pstate;
+ char* nextPos;
+ for(;;)
+ { // skip whitespace and comments
+ if (curPos >= PENV->endPos)
+ {
+ *pstate = state;
+ return NULL;
+ }
+ switch(Sym(curPos))
+ {
+ case 0:
+ return NULL; // EOF
+ case '\n':
+ state &= ~eolComment;
+ PENV->curLine++;
+ if(PENV->bExternSource)
+ {
+ if(PENV->bExternSourceAutoincrement) PENV->nExtLine++;
+ PASM->m_ulCurLine = PENV->nExtLine;
+ PASM->m_ulCurColumn = PENV->nExtCol;
+ }
+ else
+ {
+ PASM->m_ulCurLine = PENV->curLine;
+ PASM->m_ulCurColumn = 1;
+ }
+ break;
+ case '\r':
+ case ' ' :
+ case '\t':
+ case '\f':
+ break;
+
+ case '*' :
+ if(state == 0) goto PAST_WHITESPACE;
+ if(state & multiComment)
+ {
+ nextPos = nextchar(curPos);
+ if (Sym(nextPos) == '/')
+ {
+ curPos = nextPos;
+ state &= ~multiComment;
+ }
+ }
+ break;
+
+ case '/' :
+ if(state == 0)
+ {
+ nextPos = nextchar(curPos);
+ nextSym = Sym(nextPos);
+ if (nextSym == '/')
+ {
+ curPos = nextPos;
+ state |= eolComment;
+ }
+ else if (nextSym == '*')
+ {
+ curPos = nextPos;
+ state |= multiComment;
+ }
+ else goto PAST_WHITESPACE;
+ }
+ break;
+
+ default:
+ if (state == 0) goto PAST_WHITESPACE;
+ }
+ curPos = nextchar(curPos);
+ }
+PAST_WHITESPACE:
+ *pstate = state;
+ return curPos;
+}
+
+char* FullFileName(__in __nullterminated WCHAR* wzFileName, unsigned uCodePage);
+
+int ProcessEOF()
+{
+ PARSING_ENVIRONMENT* prev_penv = parser->PEStack.POP();
+ if(prev_penv != NULL)
+ {
+ //delete [] (WCHAR*)(PENV->in->namew());
+ delete PENV->in;
+ delete PENV;
+ parser->penv = prev_penv;
+ SetFunctionPtrs();
+ char* szFileName = new char[strlen(PENV->szFileName)+1];
+ strcpy_s(szFileName,strlen(PENV->szFileName)+1,PENV->szFileName);
+ PASM->SetSourceFileName(szFileName); // deletes the argument!
+ return ';';
+ }
+ //PENV->in = NULL;
+ return 0;
+}
+
+#define NEXT_TOKEN {state=0; curPos=PENV->curPos; goto NextToken;}
+
+int parse_literal(unsigned curSym, __inout __nullterminated char* &curPos, BOOL translate_escapes)
+{
+ unsigned quote = curSym;
+ curPos = nextchar(curPos);
+ char* fromPtr = curPos;
+ bool escape = false;
+
+ for(;;)
+ { // Find matching quote
+ curSym = (curPos >= PENV->endPos) ? 0 : Sym(curPos);
+ if(curSym == 0)
+ {
+ PENV->curPos = curPos;
+ return(BAD_LITERAL_);
+ }
+ else if(curSym == '\\')
+ escape = !escape;
+ else
+ {
+ if(curSym == '\n')
+ {
+ PENV->curLine++;
+ if(PENV->bExternSource)
+ {
+ if(PENV->bExternSourceAutoincrement) PENV->nExtLine++;
+ PASM->m_ulCurLine = PENV->nExtLine;
+ PASM->m_ulCurColumn = PENV->nExtCol;
+ }
+ else
+ {
+ PASM->m_ulCurLine = PENV->curLine;
+ PASM->m_ulCurColumn = 1;
+ }
+ if (!escape) { PENV->curPos = curPos; return(BAD_LITERAL_); }
+ }
+ else if ((curSym == quote) && (!escape)) break;
+ escape = false;
+ }
+ curPos = nextchar(curPos);
+ }
+ // translate escaped characters
+ unsigned tokLen = (unsigned)(curPos - fromPtr);
+ char* newstr = NewStrFromToken(fromPtr, tokLen);
+ char* toPtr;
+ curPos = nextchar(curPos); // skip closing quote
+ if(translate_escapes)
+ {
+ fromPtr = newstr;
+ //_ASSERTE(0);
+ tokLen = (unsigned)strlen(newstr);
+ toPtr = new char[tokLen+1];
+ if(toPtr==NULL) return BAD_LITERAL_;
+ yylval.string = toPtr;
+ char* endPtr = fromPtr+tokLen;
+ while(fromPtr < endPtr)
+ {
+ if (*fromPtr == '\\')
+ {
+ fromPtr++;
+ switch(*fromPtr)
+ {
+ case 't':
+ *toPtr++ = '\t';
+ break;
+ case 'n':
+ *toPtr++ = '\n';
+ break;
+ case 'b':
+ *toPtr++ = '\b';
+ break;
+ case 'f':
+ *toPtr++ = '\f';
+ break;
+ case 'v':
+ *toPtr++ = '\v';
+ break;
+ case '?':
+ *toPtr++ = '\?';
+ break;
+ case 'r':
+ *toPtr++ = '\r';
+ break;
+ case 'a':
+ *toPtr++ = '\a';
+ break;
+ case '\n':
+ do fromPtr++;
+ while(isspace(*fromPtr));
+ --fromPtr; // undo the increment below
+ break;
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ if (IsDigit(fromPtr[1]) && IsDigit(fromPtr[2]))
+ {
+ *toPtr++ = ((fromPtr[0] - '0') * 8 + (fromPtr[1] - '0')) * 8 + (fromPtr[2] - '0');
+ fromPtr+= 2;
+ }
+ else if(*fromPtr == '0') *toPtr++ = 0;
+ else *toPtr++ = *fromPtr;
+ break;
+ default:
+ *toPtr++ = *fromPtr;
+ }
+ fromPtr++;
+ }
+ else
+ // *toPtr++ = *fromPtr++;
+ {
+ char* tmpPtr = fromPtr;
+ fromPtr = (nextchar == nextcharW) ? nextcharU(fromPtr) : nextchar(fromPtr);
+ while(tmpPtr < fromPtr) *toPtr++ = *tmpPtr++;
+ }
+
+ } //end while(fromPtr < endPtr)
+ *toPtr = 0; // terminate string
+ delete [] newstr;
+ }
+ else
+ {
+ yylval.string = newstr;
+ toPtr = newstr + strlen(newstr);
+ }
+
+ PENV->curPos = curPos;
+ if(quote == '"')
+ {
+ BinStr* pBS = new BinStr();
+ unsigned size = (unsigned)(toPtr - yylval.string);
+ memcpy(pBS->getBuff(size),yylval.string,size);
+ delete [] yylval.string;
+ yylval.binstr = pBS;
+ return QSTRING;
+ }
+ else
+ {
+ if(PASM->NumTypeDefs())
+ {
+ TypeDefDescr* pTDD = PASM->FindTypeDef(yylval.string);
+ if(pTDD != NULL)
+ {
+ delete [] yylval.string;
+ yylval.tdd = pTDD;
+ return(TYPEDEF(pTDD));
+ }
+ }
+ return SQSTRING;
+ }
+}
+
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:21000) // Suppress PREFast warning about overly large function
+#endif
+int yylex()
+{
+ char* curPos = PENV->curPos;
+ unsigned state = 0;
+ const unsigned multiComment = 2;
+ unsigned curSym;
+
+ char* newstr;
+
+NextToken:
+ // Skip any leading whitespace and comments
+ curPos = skipBlanks(curPos, &state);
+ if(curPos == NULL)
+ {
+ if (state & multiComment) return (BAD_COMMENT_);
+ if(ProcessEOF() == 0) return 0; // EOF
+ NEXT_TOKEN;
+ }
+ char* curTok = curPos;
+ PENV->curTok = curPos;
+ PENV->curPos = curPos;
+ int tok = ERROR_;
+ yylval.string = 0;
+
+ curSym = Sym(curPos);
+ if(bParsingByteArray) // only hexadecimals w/o 0x, ')' and white space allowed!
+ {
+ int i,s=0;
+ for(i=0; i<2; i++, curPos = nextchar(curPos), curSym = Sym(curPos))
+ {
+ if(('0' <= curSym)&&(curSym <= '9')) s = s*16+(curSym - '0');
+ else if(('A' <= curSym)&&(curSym <= 'F')) s = s*16+(curSym - 'A' + 10);
+ else if(('a' <= curSym)&&(curSym <= 'f')) s = s*16+(curSym - 'a' + 10);
+ else break; // don't increase curPos!
+ }
+ if(i)
+ {
+ tok = HEXBYTE;
+ yylval.int32 = s;
+ }
+ else
+ {
+ if(curSym == ')' || curSym == '}')
+ {
+ bParsingByteArray = FALSE;
+ goto Just_A_Character;
+ }
+ }
+ PENV->curPos = curPos;
+ return(tok);
+ }
+ if(curSym == '?') // '?' may be part of an identifier, if it's not followed by punctuation
+ {
+ if(IsValidContinuingSymbol(Sym(nextchar(curPos)))) goto Its_An_Id;
+ goto Just_A_Character;
+ }
+
+ if (IsValidStartingSymbol(curSym))
+ { // is it an ID
+Its_An_Id:
+ size_t offsetDot = (size_t)-1; // first appearance of '.'
+ size_t offsetDotDigit = (size_t)-1; // first appearance of '.<digit>' (not DOTTEDNAME!)
+ do
+ {
+ curPos = nextchar(curPos);
+ if (Sym(curPos) == '.')
+ {
+ if (offsetDot == (size_t)-1) offsetDot = curPos - curTok;
+ curPos = nextchar(curPos);
+ if((offsetDotDigit==(size_t)-1)&&(Sym(curPos) >= '0')&&(Sym(curPos) <= '9'))
+ offsetDotDigit = curPos - curTok - 1;
+ }
+ } while(IsValidContinuingSymbol(Sym(curPos)));
+
+ size_t tokLen = curPos - curTok;
+ // check to see if it is a keyword
+ int token = findKeyword(curTok, tokLen, &yylval.opcode);
+ if (token != 0)
+ {
+ //printf("yylex: TOK = %d, curPos=0x%8.8X\n",token,curPos);
+ PENV->curPos = curPos;
+ PENV->curTok = curTok;
+ if(!SkipToken)
+ {
+ switch(token)
+ {
+ case P_INCLUDE:
+ //if(include_first_pass)
+ //{
+ // PENV->curPos = curTok;
+ // include_first_pass = FALSE;
+ // return ';';
+ //}
+ //include_first_pass = TRUE;
+ curPos = skipBlanks(curPos,&state);
+ if(curPos == NULL)
+ {
+ if (state & multiComment) return (BAD_COMMENT_);
+ if(ProcessEOF() == 0) return 0; // EOF
+ NEXT_TOKEN;
+ }
+ if(Sym(curPos) != '"') return ERROR_;
+ curPos = nextchar(curPos);
+ curTok = curPos;
+ PENV->curTok = curPos;
+ while(Sym(curPos) != '"')
+ {
+ curPos = nextchar(curPos);
+ if(curPos >= PENV->endPos) return ERROR_;
+ PENV->curPos = curPos;
+ }
+ tokLen = PENV->curPos - curTok;
+ curPos = nextchar(curPos);
+ PENV->curPos = curPos;
+ {
+ WCHAR* wzFile=NULL;
+ if(Sym == SymW)
+ {
+ if((wzFile = new WCHAR[tokLen/2 + 1]) != NULL)
+ {
+ memcpy(wzFile,curTok,tokLen);
+ wzFile[tokLen/2] = 0;
+ }
+ }
+ else
+ {
+ if((wzFile = new WCHAR[tokLen+1]) != NULL)
+ {
+ tokLen = WszMultiByteToWideChar(g_uCodePage,0,curTok,(int)tokLen,wzFile,(int)tokLen+1);
+ wzFile[tokLen] = 0;
+ }
+ }
+ if(wzFile != NULL)
+ {
+ if((parser->wzIncludePath != NULL)
+ &&(wcschr(wzFile,'\\')==NULL)&&(wcschr(wzFile,':')==NULL))
+ {
+ PathString wzFullName;
+
+ WCHAR* pwz;
+ DWORD dw = WszSearchPath(parser->wzIncludePath,wzFile,NULL,
+ TRUE, wzFullName,&pwz);
+ if(dw != 0)
+ {
+ wzFullName.CloseBuffer((COUNT_T)(dw));
+ delete [] wzFile;
+
+ wzFile = wzFullName.GetCopyOfUnicodeString();
+ }
+
+ }
+ if(PASM->m_fReportProgress)
+ parser->msg("\nIncluding '%S'\n",wzFile);
+ MappedFileStream *pIn = new MappedFileStream(wzFile);
+ if((pIn != NULL)&&pIn->IsValid())
+ {
+ parser->PEStack.PUSH(PENV);
+ PASM->SetSourceFileName(FullFileName(wzFile,CP_UTF8)); // deletes the argument!
+ parser->CreateEnvironment(pIn);
+ NEXT_TOKEN;
+ }
+ else
+ {
+ delete [] wzFile;
+ PASM->report->error("#include failed\n");
+ return ERROR_;
+ }
+ }
+ else
+ {
+ PASM->report->error("Out of memory\n");
+ return ERROR_;
+ }
+ }
+ curPos = PENV->curPos;
+ curTok = PENV->curTok;
+ break;
+ case P_IFDEF:
+ case P_IFNDEF:
+ case P_DEFINE:
+ case P_UNDEF:
+ curPos = skipBlanks(curPos,&state);
+ if(curPos == NULL)
+ {
+ if (state & multiComment) return (BAD_COMMENT_);
+ if(ProcessEOF() == 0) return 0; // EOF
+ NEXT_TOKEN;
+ }
+ curTok = curPos;
+ PENV->curTok = curPos;
+ PENV->curPos = curPos;
+ if (!IsValidStartingSymbol(Sym(curPos))) return ERROR_;
+ do
+ {
+ curPos = nextchar(curPos);
+ } while(IsValidContinuingSymbol(Sym(curPos)));
+ tokLen = curPos - curTok;
+
+ newstr = NewStrFromToken(curTok, tokLen);
+ if((token==P_DEFINE)||(token==P_UNDEF))
+ {
+ if(token == P_DEFINE)
+ {
+ curPos = skipBlanks(curPos,&state);
+ if ((curPos == NULL) && (ProcessEOF() == 0))
+ {
+ DefineVar(newstr, NULL);
+ return 0;
+ }
+ curSym = Sym(curPos);
+ if(curSym != '"')
+ DefineVar(newstr, NULL);
+ else
+ {
+ tok = parse_literal(curSym, curPos, FALSE);
+ if(tok == QSTRING)
+ {
+ // if not ANSI, then string is in UTF-8,
+ // insert prefix
+ if(nextchar != nextcharA)
+ {
+ yylval.binstr->insertInt8(0xEF);
+ yylval.binstr->insertInt8(0xBB);
+ yylval.binstr->insertInt8(0xBF);
+ }
+ yylval.binstr->appendInt8(' ');
+ DefineVar(newstr, yylval.binstr);
+ }
+ else
+ return tok;
+ }
+ }
+ else UndefVar(newstr);
+ }
+ else
+ {
+ SkipToken = IsVarDefined(newstr);
+ if(token == P_IFDEF) SkipToken = !SkipToken;
+ IfEndif++;
+ if(SkipToken) IfEndifSkip=IfEndif;
+ }
+ break;
+ case P_ELSE:
+ SkipToken = TRUE;
+ IfEndifSkip=IfEndif;
+ break;
+ case P_ENDIF:
+ if(IfEndif == 0)
+ {
+ PASM->report->error("Unmatched #endif\n");
+ return ERROR_;
+ }
+ IfEndif--;
+ break;
+ default:
+ return(token);
+ }
+ goto NextToken;
+ }
+ if(SkipToken)
+ {
+ switch(token)
+ {
+ case P_IFDEF:
+ case P_IFNDEF:
+ IfEndif++;
+ break;
+ case P_ELSE:
+ if(IfEndif == IfEndifSkip) SkipToken = FALSE;
+ break;
+ case P_ENDIF:
+ if(IfEndif == IfEndifSkip) SkipToken = FALSE;
+ IfEndif--;
+ break;
+ default:
+ break;
+ }
+ //if(yylval.instr) yylval.instr->opcode = -1;
+ goto NextToken;
+ }
+ return(token);
+ } // end if token != 0
+ if(SkipToken) { curPos = nextBlank(curPos); goto NextToken; }
+
+ VarName* pVarName = FindVarDef(NewStrFromToken(curTok, tokLen));
+ if(pVarName != NULL)
+ {
+ if(pVarName->pbody != NULL)
+ {
+ BinStrStream *pIn = new BinStrStream(pVarName->pbody);
+ if((pIn != NULL)&&pIn->IsValid())
+ {
+ PENV->curPos = curPos;
+ parser->PEStack.PUSH(PENV);
+ parser->CreateEnvironment(pIn);
+ NEXT_TOKEN;
+ }
+ }
+ }
+
+ TypeDefDescr* pTDD = findTypedef(curTok,tokLen);
+
+ if(pTDD != NULL)
+ {
+ yylval.tdd = pTDD;
+ PENV->curPos = curPos;
+ PENV->curTok = curTok;
+ return(TYPEDEF(pTDD));
+ }
+ if(Sym(curTok) == '#')
+ {
+ PENV->curPos = curPos;
+ PENV->curTok = curTok;
+ return(ERROR_);
+ }
+ // Not a keyword, normal identifiers don't have '.' in them
+ if (offsetDot < (size_t)-1)
+ {
+ if(offsetDotDigit < (size_t)-1)
+ {
+ curPos = curTok+offsetDotDigit;
+ tokLen = offsetDotDigit;
+ }
+ // protection against something like Foo.Bar..123 or Foo.Bar.
+ unsigned D = (Sym == SymW) ? 2 : 1; // Unicode or ANSI/UTF8!
+ while((Sym(curPos-D)=='.')&&(tokLen))
+ {
+ curPos -= D;
+ tokLen -= D;
+ }
+ }
+ if((yylval.string = NewStrFromToken(curTok,tokLen)))
+ {
+ tok = (offsetDot == (size_t)(-1))? ID : DOTTEDNAME;
+ //printf("yylex: ID = '%s', curPos=0x%8.8X\n",yylval.string,curPos);
+ }
+ else return BAD_LITERAL_;
+ }
+ else if(SkipToken) { curPos = nextBlank(curPos); goto NextToken; }
+ else if (IsDigit(curSym)
+ || (curSym == '.' && IsDigit(Sym(nextchar(curPos))))
+ || (curSym == '-' && IsDigit(Sym(nextchar(curPos)))))
+ {
+ const char* begNum = curPos;
+ unsigned radix = 10;
+
+ neg = (curSym == '-'); // always make it unsigned
+ if (neg) curPos = nextchar(curPos);
+
+ if (Sym(curPos) == '0' && Sym(nextchar(curPos)) != '.')
+ {
+ curPos = nextchar(curPos);
+ radix = 8;
+ if (Sym(curPos) == 'x' || Sym(curPos) == 'X')
+ {
+ curPos = nextchar(curPos);
+ radix = 16;
+ }
+ }
+ begNum = curPos;
+ {
+ unsigned __int64 i64 = str2uint64(begNum, const_cast<const char**>(&curPos), radix);
+ unsigned __int64 mask64 = neg ? UI64(0xFFFFFFFF80000000) : UI64(0xFFFFFFFF00000000);
+ unsigned __int64 largestNegVal32 = UI64(0x0000000080000000);
+ if ((i64 & mask64) && (i64 != largestNegVal32))
+ {
+ yylval.int64 = new __int64(i64);
+ tok = INT64;
+ if (neg) *yylval.int64 = -*yylval.int64;
+ }
+ else
+ {
+ yylval.int32 = (__int32)i64;
+ tok = INT32;
+ if(neg) yylval.int32 = -yylval.int32;
+ }
+ }
+ if (radix == 10 && ((Sym(curPos) == '.' && Sym(nextchar(curPos)) != '.') || Sym(curPos) == 'E' || Sym(curPos) == 'e'))
+ {
+ unsigned L = (unsigned)(PENV->endPos - begNum);
+ curPos = (char*)begNum + GetDouble((char*)begNum,L,&yylval.float64);
+ if (neg) *yylval.float64 = -*yylval.float64;
+ tok = FLOAT64;
+ }
+ }
+ else
+ { // punctuation
+ if (curSym == '"' || curSym == '\'')
+ {
+ return parse_literal(curSym, curPos, TRUE);
+ } // end if (*curPos == '"' || *curPos == '\'')
+ else if (curSym==':' && Sym(nextchar(curPos))==':')
+ {
+ curPos = nextchar(nextchar(curPos));
+ tok = DCOLON;
+ }
+ else if(curSym == '.')
+ {
+ if (Sym(nextchar(curPos))=='.' && Sym(nextchar(nextchar(curPos)))=='.')
+ {
+ curPos = nextchar(nextchar(nextchar(curPos)));
+ tok = ELIPSIS;
+ }
+ else
+ {
+ do
+ {
+ curPos = nextchar(curPos);
+ if (curPos >= PENV->endPos)
+ return ERROR_;
+ curSym = Sym(curPos);
+ }
+ while(IsAlNum(curSym) || curSym == '_' || curSym == '$'|| curSym == '@'|| curSym == '?');
+ size_t tokLen = curPos - curTok;
+
+ // check to see if it is a keyword
+ int token = findKeyword(curTok, tokLen, &yylval.opcode);
+ if(token)
+ {
+ //printf("yylex: TOK = %d, curPos=0x%8.8X\n",token,curPos);
+ PENV->curPos = curPos;
+ PENV->curTok = curTok;
+ return(token);
+ }
+ tok = '.';
+ curPos = nextchar(curTok);
+ }
+ }
+ else
+ {
+Just_A_Character:
+ tok = curSym;
+ curPos = nextchar(curPos);
+ }
+ //printf("yylex: PUNCT curPos=0x%8.8X\n",curPos);
+ }
+ dbprintf((" Line %d token %d (%c) val = %s\n", PENV->curLine, tok,
+ (tok < 128 && isprint(tok)) ? tok : ' ',
+ (tok > 255 && tok != INT32 && tok != INT64 && tok!= FLOAT64) ? yylval.string : ""));
+
+ PENV->curPos = curPos;
+ PENV->curTok = curTok;
+ return(tok);
+}
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+
+/**************************************************************************/
+static char* newString(__in __nullterminated const char* str1)
+{
+ char* ret = new char[strlen(str1)+1];
+ if(ret) strcpy_s(ret, strlen(str1)+1, str1);
+ return(ret);
+}
+
+/**************************************************************************/
+/* concatenate strings and release them */
+
+static char* newStringWDel(__in __nullterminated char* str1, char delimiter, __in __nullterminated char* str3)
+{
+ size_t len1 = strlen(str1);
+ size_t len = len1+2;
+ if (str3) len += strlen(str3);
+ char* ret = new char[len];
+ if(ret)
+ {
+ strcpy_s(ret, len, str1);
+ delete [] str1;
+ ret[len1] = delimiter;
+ ret[len1+1] = 0;
+ if (str3)
+ {
+ strcat_s(ret, len, str3);
+ delete [] str3;
+ }
+ }
+ return(ret);
+}
+
+/**************************************************************************/
+static void corEmitInt(BinStr* buff, unsigned data)
+{
+ unsigned cnt = CorSigCompressData(data, buff->getBuff(5));
+ buff->remove(5 - cnt);
+}
+
+
+/**************************************************************************/
+/* move 'ptr past the exactly one type description */
+
+unsigned __int8* skipType(unsigned __int8* ptr, BOOL fFixupType)
+{
+ mdToken tk;
+AGAIN:
+ switch(*ptr++) {
+ case ELEMENT_TYPE_VOID :
+ case ELEMENT_TYPE_BOOLEAN :
+ case ELEMENT_TYPE_CHAR :
+ case ELEMENT_TYPE_I1 :
+ case ELEMENT_TYPE_U1 :
+ case ELEMENT_TYPE_I2 :
+ case ELEMENT_TYPE_U2 :
+ case ELEMENT_TYPE_I4 :
+ case ELEMENT_TYPE_U4 :
+ case ELEMENT_TYPE_I8 :
+ case ELEMENT_TYPE_U8 :
+ case ELEMENT_TYPE_R4 :
+ case ELEMENT_TYPE_R8 :
+ case ELEMENT_TYPE_U :
+ case ELEMENT_TYPE_I :
+ case ELEMENT_TYPE_STRING :
+ case ELEMENT_TYPE_OBJECT :
+ case ELEMENT_TYPE_TYPEDBYREF :
+ case ELEMENT_TYPE_SENTINEL :
+ /* do nothing */
+ break;
+
+ case ELEMENT_TYPE_VALUETYPE :
+ case ELEMENT_TYPE_CLASS :
+ ptr += CorSigUncompressToken(ptr, &tk);
+ break;
+
+ case ELEMENT_TYPE_CMOD_REQD :
+ case ELEMENT_TYPE_CMOD_OPT :
+ ptr += CorSigUncompressToken(ptr, &tk);
+ goto AGAIN;
+
+ case ELEMENT_TYPE_ARRAY :
+ {
+ ptr = skipType(ptr, fFixupType); // element Type
+ unsigned rank = CorSigUncompressData((PCCOR_SIGNATURE&) ptr);
+ if (rank != 0)
+ {
+ unsigned numSizes = CorSigUncompressData((PCCOR_SIGNATURE&) ptr);
+ while(numSizes > 0)
+ {
+ CorSigUncompressData((PCCOR_SIGNATURE&) ptr);
+ --numSizes;
+ }
+ unsigned numLowBounds = CorSigUncompressData((PCCOR_SIGNATURE&) ptr);
+ while(numLowBounds > 0)
+ {
+ CorSigUncompressData((PCCOR_SIGNATURE&) ptr);
+ --numLowBounds;
+ }
+ }
+ }
+ break;
+
+ // Modifiers or depedant types
+ case ELEMENT_TYPE_PINNED :
+ case ELEMENT_TYPE_PTR :
+ case ELEMENT_TYPE_BYREF :
+ case ELEMENT_TYPE_SZARRAY :
+ // tail recursion optimization
+ // ptr = skipType(ptr, fFixupType);
+ // break
+ goto AGAIN;
+
+ case ELEMENT_TYPE_VAR:
+ case ELEMENT_TYPE_MVAR:
+ CorSigUncompressData((PCCOR_SIGNATURE&) ptr); // bound
+ break;
+
+ case ELEMENT_TYPE_VARFIXUP:
+ case ELEMENT_TYPE_MVARFIXUP:
+ if(fFixupType)
+ {
+ BYTE* pb = ptr-1; // ptr incremented in switch
+ unsigned __int8* ptr_save = ptr;
+ int n = CorSigUncompressData((PCCOR_SIGNATURE&) ptr); // fixup #
+ int compressed_size_n = (int)(ptr - ptr_save); // ptr was updated by CorSigUncompressData()
+ int m = -1;
+ if(PASM->m_TyParList)
+ m = PASM->m_TyParList->IndexOf(TyParFixupList.PEEK(n));
+ if(m == -1)
+ {
+ PASM->report->error("(fixupType) Invalid %stype parameter '%s'\n",
+ (*pb == ELEMENT_TYPE_MVARFIXUP)? "method ": "",
+ TyParFixupList.PEEK(n));
+ m = 0;
+ }
+ *pb = (*pb == ELEMENT_TYPE_MVARFIXUP)? ELEMENT_TYPE_MVAR : ELEMENT_TYPE_VAR;
+ int compressed_size_m = (int)CorSigCompressData(m,pb+1);
+
+ // Note that CorSigCompressData() (and hence, CorSigUncompressData()) store a number
+ // 0 <= x <= 0x1FFFFFFF in 1, 2, or 4 bytes. Above, 'n' is the fixup number being read,
+ // and 'm' is the generic parameter number being written out (in the same place where 'n'
+ // came from). If 'n' takes more space to compress than 'm' (e.g., 0x80 <= n <= 0x3fff so
+ // it takes 2 bytes, and m < 0x80 so it takes one byte), then when we overwrite the fixup
+ // number with the generic parameter number, we'll leave extra bytes in the signature following
+ // the written generic parameter number. Thus, we do something of a hack to ensure that the
+ // compressed number is correctly readable even if 'm' compresses smaller than 'n' did: we
+ // recompress 'm' to use the same amount of space as 'n' used. This is possible because smaller
+ // numbers can still be compressed in a larger amount of space, even though it's not optimal (and
+ // CorSigCompressData() would never do it). If, however, the compressed sizes are the other
+ // way around (m takes more space to compress than n), then we've already corrupted the
+ // signature that we're reading by writing beyond what we should (is there some reason why
+ // this is not possible?).
+ // Note that 'ptr' has already been adjusted, above, to point to the next type after this one.
+ // There is no need to update it when recompressing the data.
+
+ if (compressed_size_m > compressed_size_n)
+ {
+ // We've got a problem: we just corrupted the rest of the signature!
+ // (Can this ever happen in practice?)
+ PASM->report->error("(fixupType) Too many %stype parameters\n",
+ (*pb == ELEMENT_TYPE_MVARFIXUP)? "method ": "");
+ }
+ else if (compressed_size_m < compressed_size_n)
+ {
+ // We didn't write out as much data as we read. This will leave extra bytes in the
+ // signature that will be incorrectly recognized. Ideally, we would just shrink the
+ // signature. That's not easy to do here. Instead, pad the bytes to force it to use
+ // a larger encoding than needed. This assumes knowledge of the CorSigCompressData()
+ // encoding.
+ //
+ // The cases:
+ // compressed_size_m m bytes compressed_size_n result bytes
+ // 1 m1 2 0x80 m1
+ // 1 m1 4 0xC0 0x00 0x00 m1
+ // 2 m1 m2 4 0xC0 0x00 (m1 & 0x7f) m2
+
+ _ASSERTE((compressed_size_m == 1) || (compressed_size_m == 2) || (compressed_size_m == 4));
+ _ASSERTE((compressed_size_n == 1) || (compressed_size_n == 2) || (compressed_size_n == 4));
+
+ if ((compressed_size_m == 1) &&
+ (compressed_size_n == 2))
+ {
+ unsigned __int8 m1 = *(pb + 1);
+ _ASSERTE(m1 < 0x80);
+ *(pb + 1) = 0x80;
+ *(pb + 2) = m1;
+ }
+ else
+ if ((compressed_size_m == 1) &&
+ (compressed_size_n == 4))
+ {
+ unsigned __int8 m1 = *(pb + 1);
+ _ASSERTE(m1 < 0x80);
+ *(pb + 1) = 0xC0;
+ *(pb + 2) = 0x00;
+ *(pb + 3) = 0x00;
+ *(pb + 4) = m1;
+ }
+ else
+ if ((compressed_size_m == 2) &&
+ (compressed_size_n == 4))
+ {
+ unsigned __int8 m1 = *(pb + 1);
+ unsigned __int8 m2 = *(pb + 2);
+ _ASSERTE(m1 >= 0x80);
+ m1 &= 0x7f; // strip the bit indicating it's a 2-byte thing
+ *(pb + 1) = 0xC0;
+ *(pb + 2) = 0x00;
+ *(pb + 3) = m1;
+ *(pb + 4) = m2;
+ }
+ }
+ }
+ else
+ CorSigUncompressData((PCCOR_SIGNATURE&) ptr); // bound
+ break;
+
+ case ELEMENT_TYPE_FNPTR:
+ {
+ CorSigUncompressData((PCCOR_SIGNATURE&) ptr); // calling convention
+ unsigned argCnt = CorSigUncompressData((PCCOR_SIGNATURE&) ptr); // arg count
+ ptr = skipType(ptr, fFixupType); // return type
+ while(argCnt > 0)
+ {
+ ptr = skipType(ptr, fFixupType);
+ --argCnt;
+ }
+ }
+ break;
+
+ case ELEMENT_TYPE_GENERICINST:
+ {
+ ptr = skipType(ptr, fFixupType); // type constructor
+ unsigned argCnt = CorSigUncompressData((PCCOR_SIGNATURE&)ptr); // arg count
+ while(argCnt > 0) {
+ ptr = skipType(ptr, fFixupType);
+ --argCnt;
+ }
+ }
+ break;
+
+ default:
+ case ELEMENT_TYPE_END :
+ _ASSERTE(!"Unknown Type");
+ break;
+ }
+ return(ptr);
+}
+
+/**************************************************************************/
+void FixupTyPars(PCOR_SIGNATURE pSig, ULONG cSig)
+{
+ if(TyParFixupList.COUNT() > 0)
+ {
+ BYTE* ptr = (BYTE*)pSig;
+ BYTE* ptrEnd = ptr + cSig;
+ while(ptr < ptrEnd)
+ {
+ ptr = skipType(ptr, TRUE);
+ } // end while
+ } // end if(COUNT>0)
+}
+void FixupTyPars(BinStr* pbstype)
+{
+ FixupTyPars((PCOR_SIGNATURE)(pbstype->ptr()),(ULONG)(pbstype->length()));
+}
+/**************************************************************************/
+static unsigned corCountArgs(BinStr* args)
+{
+ unsigned __int8* ptr = args->ptr();
+ unsigned __int8* end = &args->ptr()[args->length()];
+ unsigned ret = 0;
+ while(ptr < end)
+ {
+ if (*ptr != ELEMENT_TYPE_SENTINEL)
+ {
+ ptr = skipType(ptr, FALSE);
+ ret++;
+ }
+ else ptr++;
+ }
+ return(ret);
+}
+
+/********************************************************************************/
+AsmParse::AsmParse(ReadStream* aIn, Assembler *aAssem)
+{
+#ifdef DEBUG_PARSING
+ extern int yydebug;
+ yydebug = 1;
+#endif
+
+ assem = aAssem;
+ assem->SetErrorReporter((ErrorReporter *)this);
+
+ assem->m_ulCurLine = 1;
+ assem->m_ulCurColumn = 1;
+
+ wzIncludePath = NULL;
+ penv = NULL;
+
+ hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ hstderr = GetStdHandle(STD_ERROR_HANDLE);
+
+ success = true;
+ _ASSERTE(parser == 0); // Should only be one parser instance at a time
+
+ // Resolve aliases
+ for (unsigned int i = 0; i < sizeof(keywords) / sizeof(Keywords); i++)
+ {
+ if (keywords[i].token == NO_VALUE)
+ keywords[i].token = keywords[keywords[i].tokenVal].token;
+ }
+ SetSymbolTables();
+ Init_str2uint64();
+ parser = this;
+ //yyparse();
+}
+
+/********************************************************************************/
+AsmParse::~AsmParse()
+{
+ parser = 0;
+ delete penv;
+ while(m_ANSLast.POP());
+}
+
+/**************************************************************************/
+DWORD AsmParse::IsItUnicode(CONST LPVOID pBuff, int cb, LPINT lpi)
+{
+ return IsTextUnicode(pBuff,cb,lpi);
+}
+
+/**************************************************************************/
+void AsmParse::CreateEnvironment(ReadStream* stream)
+{
+ penv = new PARSING_ENVIRONMENT;
+ memset(penv,0,sizeof(PARSING_ENVIRONMENT));
+ penv->in = stream;
+ penv->curLine = 1;
+ strcpy_s(penv->szFileName, MAX_FILENAME_LENGTH*3+1,assem->m_szSourceFileName);
+
+ penv->curPos = fillBuff(NULL);
+ penv->uCodePage = g_uCodePage;
+
+ SetFunctionPtrs();
+};
+
+/**************************************************************************/
+void AsmParse::ParseFile(ReadStream* stream)
+{
+ CreateEnvironment(stream);
+ yyparse();
+ penv->in = NULL;
+};
+
+/**************************************************************************/
+char* AsmParse::fillBuff(__in_opt __nullterminated char* pos)
+{
+ int iPutToBuffer;
+ int iOptions = IS_TEXT_UNICODE_UNICODE_MASK;
+ g_uCodePage = CP_ACP;
+ iPutToBuffer = (int)penv->in->getAll(&(penv->curPos));
+
+ penv->endPos = penv->curPos + iPutToBuffer;
+ if(iPutToBuffer > 128) iPutToBuffer = 128;
+ if(IsItUnicode(penv->curPos,iPutToBuffer,&iOptions))
+ {
+ g_uCodePage = CP_UTF8;
+ if(iOptions & IS_TEXT_UNICODE_SIGNATURE)
+ {
+ penv->curPos += 2;
+ }
+ if(assem->m_fReportProgress) printf("Source file is UNICODE\n\n");
+ penv->pfn_Sym = SymW;
+ penv->pfn_nextchar = nextcharW;
+ penv->pfn_NewStrFromToken = NewStrFromTokenW;
+ penv->pfn_NewStaticStrFromToken = NewStaticStrFromTokenW;
+ penv->pfn_GetDouble = GetDoubleW;
+ }
+ else
+ {
+ if(((penv->curPos[0]&0xFF)==0xEF)&&((penv->curPos[1]&0xFF)==0xBB)&&((penv->curPos[2]&0xFF)==0xBF))
+ {
+ g_uCodePage = CP_UTF8;
+ penv->curPos += 3;
+ if(assem->m_fReportProgress) printf("Source file is UTF-8\n\n");
+ penv->pfn_nextchar = nextcharU;
+ }
+ else
+ {
+ if(assem->m_fReportProgress) printf("Source file is ANSI\n\n");
+ penv->pfn_nextchar = nextcharA;
+ }
+ penv->pfn_Sym = SymAU;
+ penv->pfn_NewStrFromToken = NewStrFromTokenAU;
+ penv->pfn_NewStaticStrFromToken = NewStaticStrFromTokenAU;
+ penv->pfn_GetDouble = GetDoubleAU;
+ }
+ return(penv->curPos);
+}
+
+/********************************************************************************/
+BinStr* AsmParse::MakeSig(unsigned callConv, BinStr* retType, BinStr* args, int ntyargs)
+{
+ _ASSERTE((ntyargs != 0) == ((callConv & IMAGE_CEE_CS_CALLCONV_GENERIC) != 0));
+ BinStr* ret = new BinStr();
+ if(ret)
+ {
+ //if (retType != 0)
+ ret->insertInt8(callConv);
+ if (ntyargs != 0)
+ corEmitInt(ret, ntyargs);
+ corEmitInt(ret, corCountArgs(args));
+
+ if (retType != 0)
+ {
+ ret->append(retType);
+ delete retType;
+ }
+ ret->append(args);
+ }
+ else
+ error("\nOut of memory!\n");
+
+ delete args;
+ return(ret);
+}
+
+/********************************************************************************/
+BinStr* AsmParse::MakeTypeArray(CorElementType kind, BinStr* elemType, BinStr* bounds)
+{
+ // 'bounds' is a binary buffer, that contains an array of 'struct Bounds'
+ struct Bounds {
+ int lowerBound;
+ unsigned numElements;
+ };
+
+ _ASSERTE(bounds->length() % sizeof(Bounds) == 0);
+ unsigned boundsLen = bounds->length() / sizeof(Bounds);
+ _ASSERTE(boundsLen > 0);
+ Bounds* boundsArr = (Bounds*) bounds->ptr();
+
+ BinStr* ret = new BinStr();
+
+ ret->appendInt8(kind);
+ ret->append(elemType);
+ corEmitInt(ret, boundsLen); // emit the rank
+
+ unsigned lowerBoundsDefined = 0;
+ unsigned numElementsDefined = 0;
+ unsigned i;
+ for(i=0; i < boundsLen; i++)
+ {
+ if(boundsArr[i].lowerBound < 0x7FFFFFFF) lowerBoundsDefined = i+1;
+ else boundsArr[i].lowerBound = 0;
+
+ if(boundsArr[i].numElements < 0x7FFFFFFF) numElementsDefined = i+1;
+ else boundsArr[i].numElements = 0;
+ }
+
+ corEmitInt(ret, numElementsDefined); // emit number of bounds
+
+ for(i=0; i < numElementsDefined; i++)
+ {
+ _ASSERTE (boundsArr[i].numElements >= 0); // enforced at rule time
+ corEmitInt(ret, boundsArr[i].numElements);
+
+ }
+
+ corEmitInt(ret, lowerBoundsDefined); // emit number of lower bounds
+ for(i=0; i < lowerBoundsDefined; i++)
+ {
+ unsigned cnt = CorSigCompressSignedInt(boundsArr[i].lowerBound, ret->getBuff(5));
+ ret->remove(5 - cnt);
+ }
+ delete elemType;
+ delete bounds;
+ return(ret);
+}
+
+/********************************************************************************/
+BinStr* AsmParse::MakeTypeClass(CorElementType kind, mdToken tk)
+{
+
+ BinStr* ret = new BinStr();
+ _ASSERTE(kind == ELEMENT_TYPE_CLASS || kind == ELEMENT_TYPE_VALUETYPE ||
+ kind == ELEMENT_TYPE_CMOD_REQD || kind == ELEMENT_TYPE_CMOD_OPT);
+ ret->appendInt8(kind);
+ unsigned cnt = CorSigCompressToken(tk, ret->getBuff(5));
+ ret->remove(5 - cnt);
+ return(ret);
+}
+/**************************************************************************/
+void PrintANSILine(FILE* pF, __in __nullterminated char* sz)
+{
+ WCHAR *wz = &wzUniBuf[0];
+ if(g_uCodePage != CP_ACP)
+ {
+ memset(wz,0,dwUniBuf); // dwUniBuf/2 WCHARs = dwUniBuf bytes
+ WszMultiByteToWideChar(g_uCodePage,0,sz,-1,wz,(dwUniBuf >> 1)-1);
+
+ memset(sz,0,dwUniBuf);
+ WszWideCharToMultiByte(g_uConsoleCP,0,wz,-1,sz,dwUniBuf-1,NULL,NULL);
+ }
+ fprintf(pF,"%s",sz);
+}
+/**************************************************************************/
+void AsmParse::error(const char* fmt, ...)
+{
+ char *sz = (char*)(&wzUniBuf[(dwUniBuf >> 1)]);
+ char *psz=&sz[0];
+ FILE* pF = ((!assem->m_fReportProgress)&&(assem->OnErrGo)) ? stdout : stderr;
+ success = false;
+ va_list args;
+ va_start(args, fmt);
+
+ if((penv) && (penv->in)) psz+=sprintf_s(psz, (dwUniBuf >> 1), "%S(%d) : ", penv->in->namew(), penv->curLine);
+ psz+=sprintf_s(psz, (dwUniBuf >> 1), "error : ");
+ _vsnprintf_s(psz, (dwUniBuf >> 1),(dwUniBuf >> 1)-strlen(sz)-1, fmt, args);
+ PrintANSILine(pF,sz);
+}
+
+/**************************************************************************/
+void AsmParse::warn(const char* fmt, ...)
+{
+ char *sz = (char*)(&wzUniBuf[(dwUniBuf >> 1)]);
+ char *psz=&sz[0];
+ FILE* pF = ((!assem->m_fReportProgress)&&(assem->OnErrGo)) ? stdout : stderr;
+ va_list args;
+ va_start(args, fmt);
+
+ if((penv) && (penv->in)) psz+=sprintf_s(psz, (dwUniBuf >> 1), "%S(%d) : ", penv->in->namew(), penv->curLine);
+ psz+=sprintf_s(psz, (dwUniBuf >> 1), "warning : ");
+ _vsnprintf_s(psz, (dwUniBuf >> 1),(dwUniBuf >> 1)-strlen(sz)-1, fmt, args);
+ PrintANSILine(pF,sz);
+}
+/**************************************************************************/
+void AsmParse::msg(const char* fmt, ...)
+{
+ char *sz = (char*)(&wzUniBuf[(dwUniBuf >> 1)]);
+ va_list args;
+ va_start(args, fmt);
+
+ _vsnprintf_s(sz, (dwUniBuf >> 1),(dwUniBuf >> 1)-1, fmt, args);
+ PrintANSILine(stdout,sz);
+}
+
+#ifdef _MSC_VER
+#pragma warning(default : 4640)
+#endif
diff --git a/src/ilasm/grammar_before.cpp b/src/ilasm/grammar_before.cpp
new file mode 100644
index 0000000000..42d2927fa5
--- /dev/null
+++ b/src/ilasm/grammar_before.cpp
@@ -0,0 +1,150 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+#include <asmparse.h>
+#include <assembler.h>
+
+// Disable the "initialization of static local vars is no thread safe" error
+#ifdef _MSC_VER
+#pragma warning(disable : 4640)
+#endif
+
+#define YYMAXDEPTH 0x80000
+#define YYLOCAL int
+//#define YYRECURSIVE
+
+//#define DEBUG_PARSING
+#ifdef DEBUG_PARSING
+bool parseDBFlag = true;
+#define dbprintf(x) if (parseDBFlag) printf x
+#define YYDEBUG 1
+#else
+#define dbprintf(x)
+#endif
+
+#define FAIL_UNLESS(cond, msg) if (!(cond)) { parser->success = false; parser->error msg; }
+
+static AsmParse* parser = 0;
+#define PASM (parser->assem)
+#define PASMM (parser->assem->m_pManifest)
+#define PENV (parser->penv)
+
+#if (0)
+
+#define nextchar parser->penv->pfn_nextchar
+#define Sym parser->penv->pfn_Sym
+#define NewStrFromToken parser->penv->pfn_NewStrFromToken
+#define NewStaticStrFromToken parser->penv->pfn_NewStaticStrFromToken
+#define GetDouble parser->penv->pfn_GetDouble
+
+void SetFunctionPtrs() {;}
+
+#else
+
+
+PFN_NEXTCHAR nextchar;
+PFN_SYM Sym;
+PFN_NEWSTRFROMTOKEN NewStrFromToken;
+PFN_NEWSTATICSTRFROMTOKEN NewStaticStrFromToken;
+PFN_GETDOUBLE GetDouble;
+
+void SetFunctionPtrs()
+{
+ nextchar = PENV->pfn_nextchar;
+ Sym = PENV->pfn_Sym;
+ NewStrFromToken = PENV->pfn_NewStrFromToken;
+ NewStaticStrFromToken = PENV->pfn_NewStaticStrFromToken;
+ GetDouble = PENV->pfn_GetDouble;
+}
+
+#endif
+
+static char* newStringWDel(__in __nullterminated char* str1, char delimiter, __in __nullterminated char* str3 = 0);
+static char* newString(__in __nullterminated const char* str1);
+static void corEmitInt(BinStr* buff, unsigned data);
+static void AppendStringWithLength(BinStr* pbs, __in __nullterminated char* sz);
+bool bParsingByteArray = FALSE;
+int iOpcodeLen = 0;
+int iCallConv = 0;
+unsigned IfEndif = 0;
+unsigned IfEndifSkip = 0;
+unsigned nCustomBlobNVPairs = 0;
+unsigned nSecAttrBlobs = 0;
+unsigned nCurrPC = 0;
+BOOL SkipToken = FALSE;
+BOOL neg = FALSE;
+BOOL newclass = FALSE;
+
+extern unsigned int g_uConsoleCP;
+
+struct VarName
+{
+ char* name;
+ BinStr* pbody;
+ VarName(__in_opt __nullterminated char* sz, BinStr* pbs) { name = sz; pbody = pbs; };
+ ~VarName() { delete [] name; delete pbody; };
+ int ComparedTo(VarName* pN) { return strcmp(name,pN->name); };
+};
+SORTEDARRAY<VarName> VarNameList;
+void DefineVar(__in __nullterminated char* sz, BinStr* pbs) { VarNameList.PUSH(new VarName(sz,pbs)); };
+void UndefVar(__in __nullterminated char* sz)
+{
+ CHECK_LOCAL_STATIC_VAR(static VarName VN(NULL,NULL));
+
+ VN.name = sz;
+ VarNameList.DEL(&VN);
+ VN.name = NULL;
+ delete [] sz;
+}
+VarName* FindVarDef(__in __nullterminated char* sz)
+{
+ CHECK_LOCAL_STATIC_VAR(static VarName VN(NULL,NULL));
+
+ VarName* Ret = NULL;
+ VN.name = sz;
+ Ret = VarNameList.FIND(&VN);
+ VN.name = NULL;
+ delete [] sz;
+ return Ret;
+}
+BOOL IsVarDefined(__in __nullterminated char* sz)
+{
+ return (FindVarDef(sz) != NULL);
+}
+
+int nTemp=0;
+
+unsigned int uMethodBeginLine,uMethodBeginColumn;
+
+#define ELEMENT_TYPE_VARFIXUP ELEMENT_TYPE_MAX+2
+#define ELEMENT_TYPE_MVARFIXUP ELEMENT_TYPE_MAX+3
+
+FIFO<char> TyParFixupList;
+void FixupTyPars(PCOR_SIGNATURE pSig, ULONG cSig);
+void FixupTyPars(BinStr* pbstype);
+void FixupConstraints()
+{
+ if((TyParFixupList.COUNT()) && (PASM->m_TyParList))
+ {
+ TyParList* pTPL;
+ for(pTPL = PASM->m_TyParList; pTPL; pTPL=pTPL->Next())
+ {
+ mdToken* ptk;
+ for(ptk = (mdToken*)(pTPL->Bound()->ptr()); *ptk; ptk++)
+ {
+ if(TypeFromToken(*ptk)==mdtTypeSpec)
+ {
+ PCOR_SIGNATURE pSig;
+ ULONG cSig;
+ PASM->m_pImporter->GetTypeSpecFromToken(*ptk,(PCCOR_SIGNATURE*)&pSig,&cSig);
+ if((pSig)&&(cSig))
+ {
+ FixupTyPars(pSig,cSig);
+ } // end if((pSig)&&(cSig))
+ } // end if(TypeFromToken(*ptk)==mdtTypeSpec)
+ } //end for(ptk
+ } // end for(pTPL
+ } //end if((TyParFixupList.COUNT())
+}
+
+#define SET_PA(x,y,z) {x = (CorAssemblyFlags)(((y) & ~afPA_FullMask)|(z)|afPA_Specified);}
diff --git a/src/ilasm/ilasm.nativeproj b/src/ilasm/ilasm.nativeproj
new file mode 100644
index 0000000000..1250159460
--- /dev/null
+++ b/src/ilasm/ilasm.nativeproj
@@ -0,0 +1,88 @@
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="dogfood">
+ <!--*****************************************************-->
+ <!--This MSBuild project file was automatically generated-->
+ <!--from the original SOURCES/DIRS file by the KBC tool.-->
+ <!--*****************************************************-->
+ <!--Import the settings-->
+ <Import Project="$(_NTDRIVE)$(_NTROOT)\ndp\clr\clr.props" />
+ <!--Leaf project Properties-->
+ <PropertyGroup>
+ <IsDesktopTool>true</IsDesktopTool>
+ <LibCLib>$(ClrCrtLib)</LibCLib>
+ <CDefines>$(CDefines);UNICODE;_UNICODE;FEATURE_NO_HOST;SELF_NO_HOST;NO_HOST_CPP_EH_ONLY</CDefines>
+ <CDefines>$(CDefines);__TODO_PORT_TO_WRAPPERS__</CDefines>
+ <OutputName>ilasm</OutputName>
+ <FileToMarkForSigning>$(BinariesDirectory)\$(OutputName).exe</FileToMarkForSigning>
+ <TargetType>PROGRAM</TargetType>
+ <LinkSubsystem>console</LinkSubsystem>
+ <EntryPoint>wmain</EntryPoint>
+ <LinkLibIgnore>$(LinkLibIgnore),4078</LinkLibIgnore>
+ <LinkGenerateManifest>true</LinkGenerateManifest>
+ <LinkAdditionalOptions>$(LinkAdditionalOptions) /MANIFEST -HEAP:4194304 </LinkAdditionalOptions>
+ <LinkStackReserve>4194304</LinkStackReserve>
+
+ <!-- PCH baloney -->
+ <EnableCxxPCHHeaders>true</EnableCxxPCHHeaders>
+ <PCHCompile>ilasmpch.cpp</PCHCompile>
+ <PCHHeader>ilasmpch.h</PCHHeader>
+
+ </PropertyGroup>
+ <!--Leaf Project Items-->
+ <ItemGroup>
+ <ProjectReference Include="$(ClrSrcDirectory)utilcode\dyncrtnohost\dyncrtnohost.nativeproj" />
+ <LinkPreCrtLibs Include="$(ClrLibPath)\utilcodenohost.lib" />
+ <ProjectReference Include="$(ClrSrcDirectory)md\hotdata\full\mdhotdata.nativeproj" />
+ <LinkPreCrtLibs Include="$(ClrLibPath)\MDHotData.lib" />
+ </ItemGroup>
+ <ItemGroup>
+ <TargetLib Include="$(ClrLibPath)\corguids.lib">
+ <ProjectReference>$(ClrSrcDirectory)inc\corguids.nativeproj</ProjectReference>
+ </TargetLib>
+ <TargetLib Include="$(ClrLibPath)\fusion.lib">
+ <ProjectReference>$(ClrSrcDirectory)dlls\fusion\fusion.nativeproj</ProjectReference>
+ </TargetLib>
+ <TargetLib Include="$(SdkLibPath)\mscoree.lib" />
+ <TargetLib Include="$(SdkLibPath)\ole32.lib" />
+ <TargetLib Include="$(SdkLibPath)\oleaut32.lib" />
+ <TargetLib Include="$(SdkLibPath)\user32.lib" />
+ <TargetLib Include="$(SdkLibPath)\uuid.lib" />
+ </ItemGroup>
+ <ItemGroup>
+ <RCResourceFile Include="native.rc" />
+ </ItemGroup>
+ <ItemGroup>
+ <CppCompile Include="assem.cpp" />
+ <CppCompile Include="writer.cpp" />
+ <CppCompile Include="writer_enc.cpp" />
+ <CppCompile Include="method.cpp" />
+ <CppCompile Include="asmman.cpp" />
+ <CppCompile Include="main.cpp" />
+ <CppCompile Include="assembler.cpp" />
+ <CppCompile Include="MscorpeSxS.cpp" />
+ <CppCompile Include="$(IntermediateOutputDirectory)\asmparse.c" />
+ </ItemGroup>
+ <ItemGroup>
+ <DataFile Include="$(IntermediateOutputDirectory)\asmparse.grammar" />
+ </ItemGroup>
+ <!--Import the targets-->
+ <Import Project="$(_NTDRIVE)$(_NTROOT)\ndp\clr\clr.targets" />
+
+ <PropertyGroup>
+ <BuildGeneratedDependsOn>
+ $(BuildGeneratedDependsOn);
+ GenerateAsmParseC
+ </BuildGeneratedDependsOn>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Clean Include="$O\asmparse.c" />
+ <Clean Include="$O\asmparse.grammar" />
+ </ItemGroup>
+ <Target Name="GenerateAsmParseC"
+ Inputs="asmparse.y;asmparse.h;$(ClrSrcDirectory)inc\openum.h"
+ Outputs="$(IntermediateOutputDirectory)\asmparse.c;$(IntermediateOutputDirectory)\asmparse.grammar">
+ <Delete Files="$(IntermediateOutputDirectory)\asmparse.c;$(IntermediateOutputDirectory)\asmparse.grammar" />
+ <Exec Command="$(DevDivToolsBinPath)\yacc_ms.exe -o $(IntermediateOutputDirectory)\asmparse -i asmparse.y" StandardOutputImportance="Normal" />
+ <Exec Command="$(PerlCommand) extractGrammar.pl asmparse.y &gt; $(IntermediateOutputDirectory)\asmparse.grammar" StandardOutputImportance="Normal" />
+ </Target>
+</Project>
diff --git a/src/ilasm/ilasmpch.cpp b/src/ilasm/ilasmpch.cpp
new file mode 100644
index 0000000000..96e6eb9bf0
--- /dev/null
+++ b/src/ilasm/ilasmpch.cpp
@@ -0,0 +1,5 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#include "ilasmpch.h"
diff --git a/src/ilasm/ilasmpch.h b/src/ilasm/ilasmpch.h
new file mode 100644
index 0000000000..6e9df46910
--- /dev/null
+++ b/src/ilasm/ilasmpch.h
@@ -0,0 +1,27 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+#if !defined(_ILASMPCH_H)
+#define _ILASMPCH_H
+#define NEW_INLINE_NAMES
+
+#include "cor.h" // for CorMethodAttr ...
+#include <crtdbg.h> // For _ASSERTE
+#include <corsym.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <assert.h>
+#include "utilcode.h"
+#include "debugmacros.h"
+#include "corpriv.h"
+
+#include "specstrings.h"
+#include <string.h> // for strcmp
+#include <mbstring.h> // for _mbsinc
+#include <ctype.h> // for isspace
+#include "openum.h" // for CEE_*
+#include <stdarg.h> // for vararg macros
+
+#endif
diff --git a/src/ilasm/main.cpp b/src/ilasm/main.cpp
new file mode 100644
index 0000000000..811c65640e
--- /dev/null
+++ b/src/ilasm/main.cpp
@@ -0,0 +1,966 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+// File: main.cpp
+//
+
+//
+
+#include "ilasmpch.h"
+
+#include "asmparse.h"
+#include "ndpversion.h"
+#include "shimload.h"
+
+#include "strsafe.h"
+#define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS(__FILE__, (expr))
+
+WCHAR* EqualOrColon(__in __nullterminated WCHAR* szArg)
+{
+ WCHAR* pchE = wcschr(szArg,L'=');
+ WCHAR* pchC = wcschr(szArg,L':');
+ WCHAR* ret;
+ if(pchE == NULL) ret = pchC;
+ else if(pchC == NULL) ret = pchE;
+ else ret = (pchE < pchC)? pchE : pchC;
+ return ret;
+}
+
+static DWORD g_dwSubsystem=(DWORD)-1,g_dwComImageFlags=(DWORD)-1,g_dwFileAlignment=0,g_dwTestRepeat=0;
+static ULONGLONG g_stBaseAddress=0;
+static size_t g_stSizeOfStackReserve=0;
+extern unsigned int g_uConsoleCP;
+#ifdef FEATURE_PAL
+char * g_pszExeFile;
+#endif
+
+void MakeTestFile(__in __nullterminated char* szFileName)
+{
+ if(g_dwTestRepeat)
+ {
+ FILE* pF = NULL;
+ if(fopen_s(&pF,szFileName,"wt")==0 && pF != NULL)
+ {
+ printf("Making test file\n");
+ fprintf(pF,".assembly extern mscorlib {}\n");
+ fprintf(pF,".assembly test%d {}\n",g_dwTestRepeat);
+ fprintf(pF,".module test%d.exe\n",g_dwTestRepeat);
+ fprintf(pF,".method public static void Exec() { .entrypoint\n");
+ for(unsigned i=0; i<g_dwTestRepeat*1000; i++)
+ {
+ fprintf(pF,"ldc.i4.1\ncall void [mscorlib]System.Console::WriteLine(int32)\n");
+ }
+ fprintf(pF,"ret }\n");
+ fclose(pF);
+ }
+ }
+}
+
+void MakeProperSourceFileName(__in __nullterminated WCHAR* wzOrigName,
+ unsigned uCodePage,
+ __out_ecount(MAX_FILENAME_LENGTH) WCHAR* wzProperName,
+ __out_ecount(MAX_FILENAME_LENGTH*3) char* szProperName)
+{
+ wcscpy_s(wzProperName,MAX_FILENAME_LENGTH, wzOrigName);
+ size_t j = wcslen(wzProperName);
+ do
+ {
+ j--;
+ if(wzProperName[j] == '.') break;
+ if((wzProperName[j] == '\\')||(j == 0))
+ {
+ wcscat_s(wzProperName,MAX_FILENAME_LENGTH,W(".il"));
+ break;
+ }
+ }
+ while(j);
+ WszWideCharToMultiByte(uCodePage,0,wzProperName,-1,szProperName,MAX_FILENAME_LENGTH*3-1,NULL,NULL);
+}
+
+char* FullFileName(__in __nullterminated WCHAR* wzFileName, unsigned uCodePage)
+{
+ static WCHAR wzFullPath[MAX_FILENAME_LENGTH];
+ WCHAR* pwz;
+ WszGetFullPathName(wzFileName,MAX_FILENAME_LENGTH,wzFullPath,&pwz);
+ char szFullPath[MAX_FILENAME_LENGTH*3];
+ WszWideCharToMultiByte(uCodePage,0,wzFullPath,-1,szFullPath,MAX_FILENAME_LENGTH*3-1,NULL,NULL);
+ char* sz = new char[strlen(szFullPath)+1];
+ if(sz) strcpy_s(sz,strlen(szFullPath)+1,szFullPath);
+ return sz;
+}
+
+WCHAR *pwzInputFiles[1024];
+WCHAR *pwzDeltaFiles[1024];
+
+char szInputFilename[MAX_FILENAME_LENGTH*3];
+WCHAR wzInputFilename[MAX_FILENAME_LENGTH];
+WCHAR wzOutputFilename[MAX_FILENAME_LENGTH];
+
+
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:21000) // Suppress PREFast warning about overly large function
+#endif
+
+extern "C" int _cdecl wmain(int argc, __in WCHAR **argv)
+{
+ int i, NumFiles = 0, NumDeltaFiles = 0;
+ bool IsDLL = false, IsOBJ = false;
+ char szOpt[128];
+ Assembler *pAsm;
+ MappedFileStream *pIn;
+ AsmParse *pParser;
+ int exitval=1;
+ bool bLogo = TRUE;
+ bool bReportProgress = TRUE;
+ BOOL bNoDebug = TRUE;
+ WCHAR* wzIncludePath = NULL;
+ int exitcode = 0;
+ unsigned uCodePage;
+
+ bool bClock = false;
+ Clockwork cw;
+
+ // SWI has requested that the exact form of the function call below be used. For details
+ // see http://swi/SWI%20Docs/Detecting%20Heap%20Corruption.doc
+ (void)HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
+
+ memset(pwzInputFiles,0,1024*sizeof(WCHAR*));
+ memset(pwzDeltaFiles,0,1024*sizeof(WCHAR*));
+ memset(&cw,0,sizeof(Clockwork));
+ cw.cBegin = GetTickCount();
+
+ g_uConsoleCP = GetConsoleOutputCP();
+ memset(wzOutputFilename,0,sizeof(wzOutputFilename));
+
+#ifdef _DEBUG
+ DisableThrowCheck();
+ //CONTRACT_VIOLATION(ThrowsViolation);
+#endif
+
+ if(argc < 2) goto ErrorExit;
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:26000) // "Suppress prefast warning about index overflow"
+#endif
+ if (! wcscmp(argv[1], W("/?")) || ! wcscmp(argv[1],W("-?")))
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+ {
+ printf("\nMicrosoft (R) .NET Framework IL Assembler version " VER_FILEVERSION_STR);
+ printf("\n%S\n\n", VER_LEGALCOPYRIGHT_LOGO_STR_L);
+ goto PrintUsageAndExit;
+
+ ErrorExit:
+ exitcode = 1;
+ PrintUsageAndExit:
+ printf("\n\nUsage: ilasm [Options] <sourcefile> [Options]");
+ printf("\n\nOptions:");
+ printf("\n/NOLOGO Don't type the logo");
+ printf("\n/QUIET Don't report assembly progress");
+ printf("\n/NOAUTOINHERIT Disable inheriting from System.Object by default");
+ printf("\n/DLL Compile to .dll");
+ printf("\n/EXE Compile to .exe (default)");
+ printf("\n/PDB Create the PDB file without enabling debug info tracking");
+ printf("\n/APPCONTAINER Create an AppContainer exe or dll");
+ printf("\n/DEBUG Disable JIT optimization, create PDB file, use sequence points from PDB");
+ printf("\n/DEBUG=IMPL Disable JIT optimization, create PDB file, use implicit sequence points");
+ printf("\n/DEBUG=OPT Enable JIT optimization, create PDB file, use implicit sequence points");
+ printf("\n/OPTIMIZE Optimize long instructions to short");
+ printf("\n/FOLD Fold the identical method bodies into one");
+ printf("\n/CLOCK Measure and report compilation times");
+// printf("\n/ERROR Try to create .exe or .dll file despite errors reported");
+// printf("\n Warning! Results are unpredictable, use this option at your own risk!");
+ printf("\n/RESOURCE=<res_file> Link the specified resource file (*.res) \n\t\t\tinto resulting .exe or .dll");
+ printf("\n/OUTPUT=<targetfile> Compile to file with specified name \n\t\t\t(user must provide extension, if any)");
+ printf("\n/KEY=<keyfile> Compile with strong signature \n\t\t\t(<keyfile> contains private key)");
+ printf("\n/KEY=@<keysource> Compile with strong signature \n\t\t\t(<keysource> is the private key source name)");
+ printf("\n/INCLUDE=<path> Set path to search for #include'd files");
+ printf("\n/SUBSYSTEM=<int> Set Subsystem value in the NT Optional header");
+ printf("\n/SSVER=<int>.<int> Set Subsystem version number in the NT Optional header");
+ printf("\n/FLAGS=<int> Set CLR ImageFlags value in the CLR header");
+ printf("\n/ALIGNMENT=<int> Set FileAlignment value in the NT Optional header");
+ printf("\n/BASE=<int> Set ImageBase value in the NT Optional header (max 2GB for 32-bit images)");
+ printf("\n/STACK=<int> Set SizeOfStackReserve value in the NT Optional header");
+ printf("\n/MDV=<version_string> Set Metadata version string");
+ printf("\n/MSV=<int>.<int> Set Metadata stream version (<major>.<minor>)");
+ printf("\n/PE64 Create a 64bit image (PE32+)");
+ printf("\n/HIGHENTROPYVA Set High Entropy Virtual Address capable PE32+ images (default for /APPCONTAINER)");
+ printf("\n/NOCORSTUB Suppress generation of CORExeMain stub");
+ printf("\n/STRIPRELOC Indicate that no base relocations are needed");
+ printf("\n/ITANIUM Target processor: Intel Itanium");
+ printf("\n/X64 Target processor: 64bit AMD processor");
+ printf("\n/ARM Target processor: ARM processor");
+ printf("\n/32BITPREFERRED Create a 32BitPreferred image (PE32)");
+ printf("\n/ENC=<file> Create Edit-and-Continue deltas from specified source file");
+
+ printf("\n\nKey may be '-' or '/'\nOptions are recognized by first 3 characters\nDefault source file extension is .il\n");
+
+ printf("\nTarget defaults:");
+ printf("\n/PE64 => /PE64 /ITANIUM");
+ printf("\n/ITANIUM => /PE64 /ITANIUM");
+ printf("\n/X64 => /PE64 /X64");
+
+ printf("\n\n");
+ exit(exitcode);
+ }
+
+ uCodePage = CP_UTF8;
+ WszSetEnvironmentVariable(W("COMP_ENC_OPENSCOPE"), W(""));
+ WszSetEnvironmentVariable(W("COMP_ENC_EMIT"), W(""));
+ if((pAsm = new Assembler()))
+ {
+ pAsm->SetCodePage(uCodePage);
+ //if(pAsm->Init())
+ {
+ pAsm->SetStdMapping(1);
+ //-------------------------------------------------
+ for (i = 1; i < argc; i++)
+ {
+#ifdef FEATURE_PAL
+ if(argv[i][0] == L'-')
+#else
+ if((argv[i][0] == L'/') || (argv[i][0] == L'-'))
+#endif
+ {
+ memset(szOpt,0,sizeof(szOpt));
+ WszWideCharToMultiByte(uCodePage,0,&argv[i][1],-1,szOpt,sizeof(szOpt),NULL,NULL);
+ szOpt[3] = 0;
+ if (!_stricmp(szOpt,"NOA"))
+ {
+ pAsm->m_fAutoInheritFromObject = FALSE;
+ }
+ else if (!_stricmp(szOpt,"QUI"))
+ {
+ pAsm->m_fReportProgress = FALSE;
+ bReportProgress = FALSE;
+ bLogo = FALSE;
+ }
+ else if (!_stricmp(szOpt, "NOL"))
+ {
+ bLogo = FALSE;
+ }
+ else if (!_stricmp(szOpt, "FOL"))
+ {
+ pAsm->m_fFoldCode = TRUE;
+ }
+ else if (!_stricmp(szOpt, "DEB"))
+ {
+ pAsm->m_dwIncludeDebugInfo = 0x101;
+#ifdef FEATURE_CORECLR
+ // PDB is ignored under 'DEB' option for ilasm on CoreCLR.
+ // https://github.com/dotnet/coreclr/issues/2982
+#else
+ pAsm->m_fGeneratePDB = TRUE;
+#endif
+ bNoDebug = FALSE;
+
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr != NULL)
+ {
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no suboption
+ else
+ {
+ WCHAR wzSubOpt[8];
+ wcsncpy_s(wzSubOpt,8,pStr,3);
+ wzSubOpt[3] = 0;
+ if(0 == _wcsicmp(wzSubOpt,W("OPT")))
+ pAsm->m_dwIncludeDebugInfo = 0x3;
+ else if(0 == _wcsicmp(wzSubOpt,W("IMP")))
+ pAsm->m_dwIncludeDebugInfo = 0x103;
+ else
+ {
+ const WCHAR *pFmt =((*pStr == '0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
+ if(swscanf_s(pStr,pFmt,&(pAsm->m_dwIncludeDebugInfo))!=1)
+ goto InvalidOption; // bad subooption
+ }
+ }
+ }
+ }
+ else if (!_stricmp(szOpt, "PDB"))
+ {
+#ifdef FEATURE_CORECLR
+ // 'PDB' option is ignored for ilasm on CoreCLR.
+ // https://github.com/dotnet/coreclr/issues/2982
+#else
+ pAsm->m_fGeneratePDB = TRUE;
+#endif
+ bNoDebug = FALSE;
+ }
+ else if (!_stricmp(szOpt, "CLO"))
+ {
+ bClock = true;
+ pAsm->SetClock(&cw);
+ }
+ else if (!_stricmp(szOpt, "DLL"))
+ {
+ IsDLL = true; IsOBJ = false;
+ }
+ else if (!_stricmp(szOpt, "OBJ"))
+ {
+ //IsOBJ = true; IsDLL = false;
+ printf("Option /OBJECT is not supported.\n");
+ goto ErrorExit;
+ }
+ else if (!_stricmp(szOpt, "ERR"))
+ {
+ pAsm->OnErrGo = true;
+ }
+ else if (!_stricmp(szOpt, "EXE"))
+ {
+ IsDLL = false;
+ }
+ else if (!_stricmp(szOpt, "APP"))
+ {
+ pAsm->m_fAppContainer = TRUE;
+ }
+ else if (!_stricmp(szOpt, "HIG"))
+ {
+ pAsm->m_fHighEntropyVA = TRUE;
+ }
+ else if (!_stricmp(szOpt, "OPT"))
+ {
+ pAsm->m_fOptimize = TRUE;
+ }
+ else if (!_stricmp(szOpt, "ITA"))
+ {
+ pAsm->m_dwCeeFileFlags &= ~ICEE_CREATE_MACHINE_MASK;
+ pAsm->m_dwCeeFileFlags |= ICEE_CREATE_MACHINE_IA64;
+ }
+ else if (!_stricmp(szOpt, "X64"))
+ {
+ pAsm->m_dwCeeFileFlags &= ~ICEE_CREATE_MACHINE_MASK;
+ pAsm->m_dwCeeFileFlags |= ICEE_CREATE_MACHINE_AMD64;
+ }
+ else if (!_stricmp(szOpt, "ARM"))
+ {
+ pAsm->m_dwCeeFileFlags &= ~ICEE_CREATE_MACHINE_MASK;
+ pAsm->m_dwCeeFileFlags |= ICEE_CREATE_MACHINE_ARM;
+ }
+ else if (!_stricmp(szOpt, "32B"))
+ {
+ if (g_dwComImageFlags == (DWORD)-1)
+ g_dwComImageFlags = pAsm->m_dwComImageFlags;
+ COR_SET_32BIT_PREFERRED(g_dwComImageFlags);
+ }
+ else if (!_stricmp(szOpt, "PE6"))
+ {
+ pAsm->m_dwCeeFileFlags &= ~ICEE_CREATE_FILE_PE32;
+ pAsm->m_dwCeeFileFlags |= ICEE_CREATE_FILE_PE64;
+ }
+ else if (!_stricmp(szOpt, "NOC"))
+ {
+ pAsm->m_dwCeeFileFlags &= ~ICEE_CREATE_FILE_CORMAIN_STUB;
+ }
+ else if (!_stricmp(szOpt, "STR"))
+ {
+ pAsm->m_dwCeeFileFlags |= ICEE_CREATE_FILE_STRIP_RELOCS;
+ }
+ else if (!_stricmp(szOpt, "OPT"))
+ {
+ pAsm->m_fOptimize = TRUE;
+ }
+ else if (!_stricmp(szOpt, "LIS"))
+ {
+ printf("Option /LISTING is not supported, use ILDASM.EXE\n");
+ }
+ else if (!_stricmp(szOpt, "RES"))
+ {
+ if(pAsm->m_wzResourceFile==NULL)
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto ErrorExit;
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no file name
+ pAsm->m_wzResourceFile = pStr;
+ }
+ else
+ printf("Multiple resource files not allowed. Option %ls skipped\n",argv[i]);
+ }
+ else if (!_stricmp(szOpt, "KEY"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no file name
+ pAsm->m_wzKeySourceName = pStr;
+ }
+ else if (!_stricmp(szOpt, "INC"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no file name
+ wzIncludePath = pStr;
+ }
+ else if (!_stricmp(szOpt, "OUT"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no file name
+ if(wcslen(pStr) >= MAX_FILENAME_LENGTH)
+ {
+ fprintf(stderr,"\nError: Output file name exceeds %d characters\n",MAX_FILENAME_LENGTH-1);
+ goto ErrorExit;
+ }
+ wcscpy_s(wzOutputFilename,MAX_FILENAME_LENGTH,pStr);
+ }
+ else if (!_stricmp(szOpt, "MDV"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no version string
+ pAsm->m_wzMetadataVersion = pStr;
+ }
+ else if (!_stricmp(szOpt, "MSV"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no version
+ {
+ int major=-1,minor=-1;
+ if(swscanf_s(pStr,W("%d.%d"),&major, &minor)==2)
+ {
+ if((major >= 0)&&(major < 0xFF))
+ pAsm->m_wMSVmajor = (WORD)major;
+ if((minor >= 0)&&(minor < 0xFF))
+ pAsm->m_wMSVminor = (WORD)minor;
+ }
+ }
+ }
+ else if (!_stricmp(szOpt, "ENC"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no file name
+ pwzDeltaFiles[NumDeltaFiles++] = pStr;
+ pAsm->m_fTolerateDupMethods = TRUE;
+ }
+ else if (!_stricmp(szOpt, "SUB"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ pStr++;
+ const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
+ if(swscanf_s(pStr,pFmt,&g_dwSubsystem)!=1) goto InvalidOption;
+ }
+ else if (!_stricmp(szOpt, "SSV"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ for(pStr++; *pStr == L' '; pStr++); //skip the blanks
+ if(wcslen(pStr)==0) goto InvalidOption; //if no version
+ {
+ int major=-1,minor=-1;
+ if(swscanf_s(pStr,W("%d.%d"),&major, &minor)==2)
+ {
+ if((major >= 0)&&(major < 0xFFFF))
+ pAsm->m_wSSVersionMajor = (WORD)major;
+ if((minor >= 0)&&(minor < 0xFFFF))
+ pAsm->m_wSSVersionMinor = (WORD)minor;
+ } else
+ goto InvalidOption;
+ }
+ }
+ else if (!_stricmp(szOpt, "ALI"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ pStr++;
+ const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
+ if(swscanf_s(pStr,pFmt,&g_dwFileAlignment)!=1) goto InvalidOption;
+ if((g_dwFileAlignment & (g_dwFileAlignment-1))
+ || (g_dwFileAlignment < 0x200) || (g_dwFileAlignment > 0x10000))
+ {
+ fprintf(stderr,"\nFile Alignment must be power of 2 from 0x200 to 0x10000\n");
+ if(!pAsm->OnErrGo) goto InvalidOption;
+ }
+ }
+ else if (!_stricmp(szOpt, "FLA"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ pStr++;
+ const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
+ if(swscanf_s(pStr,pFmt,&g_dwComImageFlags)!=1) goto InvalidOption;
+ }
+ else if (!_stricmp(szOpt, "BAS"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ pStr++;
+ const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%I64x") : W("%I64d");
+ if(swscanf_s(pStr,pFmt,&g_stBaseAddress)!=1) goto InvalidOption;
+ if(g_stBaseAddress & 0xFFFF)
+ {
+ fprintf(stderr,"\nBase address must be 0x10000-aligned\n");
+ if(!pAsm->OnErrGo) goto InvalidOption;
+ }
+ }
+ else if (!_stricmp(szOpt, "STA"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ pStr++;
+ const WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? W("%lx") : W("%ld");
+ if(swscanf_s(pStr,pFmt,&g_stSizeOfStackReserve)!=1) goto InvalidOption;
+ }
+#ifdef _SPECIAL_INTERNAL_USE_ONLY
+ else if (!_stricmp(szOpt, "TES"))
+ {
+ WCHAR *pStr = EqualOrColon(argv[i]);
+ if(pStr == NULL) goto InvalidOption;
+ pStr++;
+ WCHAR *pFmt = ((*pStr=='0')&&(*(pStr+1) == 'x'))? L"%lx" : L"%ld";
+ if(swscanf_s(pStr,pFmt,&g_dwTestRepeat)!=1) goto InvalidOption;
+ }
+#endif
+ else
+ {
+ InvalidOption:
+ fprintf(stderr, "Error : Invalid Option: %LS\n", argv[i]);
+ goto ErrorExit;
+ }
+ }
+ else
+ {
+ if(wcslen(argv[i]) >= MAX_FILENAME_LENGTH)
+ {
+ printf("\nError: Input file name exceeds %d characters\n",MAX_FILENAME_LENGTH-1);
+ goto ErrorExit;
+ }
+ pwzInputFiles[NumFiles++] = argv[i];
+ if(NumFiles == 1)
+ {
+ MakeProperSourceFileName(argv[i], uCodePage, wzInputFilename, szInputFilename);
+ }
+ }
+
+ }
+ if(NumFiles == 0)
+ {
+ delete pAsm;
+ goto ErrorExit;
+ }
+ if(pAsm->m_dwCeeFileFlags & ICEE_CREATE_FILE_PE64)
+ {
+ if((pAsm->m_dwCeeFileFlags & ICEE_CREATE_MACHINE_I386)
+ ||(pAsm->m_dwCeeFileFlags & ICEE_CREATE_MACHINE_ARM))
+ {
+ printf("\nMachine type /ITANIUM or /X64 must be specified for 64 bit targets.");
+ if(!pAsm->OnErrGo)
+ {
+ pAsm->m_dwCeeFileFlags &= ~ICEE_CREATE_MACHINE_MASK;
+ pAsm->m_dwCeeFileFlags |= ICEE_CREATE_MACHINE_IA64;
+ printf(" Type set to ITANIUM.");
+ }
+ printf("\n");
+ }
+ }
+ else
+ {
+ if((pAsm->m_dwCeeFileFlags & ICEE_CREATE_MACHINE_IA64)
+ ||(pAsm->m_dwCeeFileFlags & ICEE_CREATE_MACHINE_AMD64))
+ {
+ printf("\n64 bit target must be specified for machine type /ITANIUM or /X64.");
+ if(!pAsm->OnErrGo)
+ {
+ pAsm->m_dwCeeFileFlags &= ~ICEE_CREATE_FILE_PE32;
+ pAsm->m_dwCeeFileFlags |= ICEE_CREATE_FILE_PE64;
+ printf(" Target set to 64 bit.");
+ }
+ printf("\n");
+ }
+ }
+ if((pAsm->m_dwCeeFileFlags & ICEE_CREATE_MACHINE_IA64))
+ {
+ pAsm->m_dwComImageFlags &= ~COMIMAGE_FLAGS_ILONLY;
+ }
+ if(pAsm->m_dwCeeFileFlags & ICEE_CREATE_FILE_PE32)
+ {
+ if(g_stBaseAddress > 0x80000000)
+ {
+ fprintf(stderr,"Invalid Image Base specified for 32-bit target\n");
+ delete pAsm;
+ goto ErrorExit;
+ }
+ }
+ if (COR_IS_32BIT_PREFERRED(pAsm->m_dwComImageFlags) &&
+ ((pAsm->m_dwCeeFileFlags & ICEE_CREATE_FILE_PE64) ||
+ ((pAsm->m_dwCeeFileFlags & ICEE_CREATE_FILE_PE32) == 0) ||
+ ((pAsm->m_dwCeeFileFlags & ICEE_CREATE_MACHINE_I386) == 0) ||
+ ((pAsm->m_dwComImageFlags & COMIMAGE_FLAGS_ILONLY) == 0)))
+ {
+ fprintf(stderr,"/32BITPREFERRED valid only with PE32/X86/ILONLY images\n");
+ delete pAsm;
+ goto ErrorExit;
+ }
+ if(!pAsm->Init())
+ {
+ fprintf(stderr,"Failed to initialize Assembler\n");
+ delete pAsm;
+ goto ErrorExit;
+ }
+ if(g_dwTestRepeat)
+ MakeTestFile(szInputFilename);
+
+ if(wzOutputFilename[0] == 0)
+ {
+ wcscpy_s(wzOutputFilename,MAX_FILENAME_LENGTH,pwzInputFiles[0]);
+ size_t j = wcslen(wzOutputFilename);
+ do
+ {
+ j--;
+ if(wzOutputFilename[j] == L'.')
+ {
+ wzOutputFilename[j] = 0;
+ break;
+ }
+ }
+ while(j);
+ wcscat_s(wzOutputFilename, MAX_FILENAME_LENGTH,(IsDLL ? W(".dll") : (IsOBJ ? W(".obj") : W(".exe"))));
+ }
+ if(wzIncludePath == NULL)
+ {
+ PathString wzIncludePathBuffer;
+ if (0 != WszGetEnvironmentVariable(W("ILASM_INCLUDE"), wzIncludePathBuffer))
+ {
+ wzIncludePath = wzIncludePathBuffer.GetCopyOfUnicodeString();
+
+ }
+ }
+ //------------ Assembler initialization done. Now, to business -----------------------
+ if((pParser = new AsmParse(NULL, pAsm)))
+ {
+ uCodePage = CP_UTF8;
+ pAsm->SetCodePage(uCodePage);
+ pParser->SetIncludePath(wzIncludePath);
+ //======================================================================
+ if(bLogo)
+ {
+ printf("\nMicrosoft (R) .NET Framework IL Assembler. Version " VER_FILEVERSION_STR);
+ printf("\n%S", VER_LEGALCOPYRIGHT_LOGO_STR_L);
+ }
+
+ pAsm->SetDLL(IsDLL);
+ pAsm->SetOBJ(IsOBJ);
+ wcscpy_s(pAsm->m_wzOutputFileName,MAX_FILENAME_LENGTH,wzOutputFilename);
+ strcpy_s(pAsm->m_szSourceFileName,MAX_FILENAME_LENGTH*3+1,szInputFilename);
+
+ if (SUCCEEDED(pAsm->InitMetaData()))
+ {
+ int iFile;
+ BOOL fAllFilesPresent = TRUE;
+ if(bClock) cw.cParsBegin = GetTickCount();
+ for(iFile = 0; iFile < NumFiles; iFile++)
+ {
+ uCodePage = CP_UTF8;
+ pAsm->SetCodePage(uCodePage);
+ if(iFile) // for the first file, it's already done
+ {
+ MakeProperSourceFileName(pwzInputFiles[iFile], uCodePage, wzInputFilename, szInputFilename);
+ }
+ if(pAsm->m_fReportProgress)
+ {
+ pParser->msg("\nAssembling '%s' ", szInputFilename);
+ if(pAsm->m_fCPlusPlus) pParser->msg(" C++");
+ if(pAsm->m_fWindowsCE) pParser->msg(" WINCE");
+ if(!pAsm->m_fAutoInheritFromObject) pParser->msg(" NOAUTOINHERIT");
+ pParser->msg(IsDLL ? " to DLL" : (IsOBJ? " to OBJ" : " to EXE"));
+ //======================================================================
+ if (pAsm->m_fStdMapping == FALSE)
+ pParser->msg(", with REFERENCE mapping");
+
+ {
+ char szOutputFilename[MAX_FILENAME_LENGTH*3];
+ memset(szOutputFilename,0,sizeof(szOutputFilename));
+ WszWideCharToMultiByte(uCodePage,0,wzOutputFilename,-1,szOutputFilename,MAX_FILENAME_LENGTH*3-1,NULL,NULL);
+ pParser->msg(" --> '%s'\n", szOutputFilename);
+ }
+ }
+
+ pIn = new MappedFileStream(wzInputFilename);
+
+ if ((!pIn) || !(pIn->IsValid()))
+ {
+ pParser->msg("Could not open %s\n", szInputFilename);
+ fAllFilesPresent = FALSE;
+ }
+ else
+ {
+#ifndef FEATURE_PAL
+ DWORD dwBinType;
+ if(GetBinaryTypeA(szInputFilename,&dwBinType))
+ {
+ pParser->msg("%s is not a text file\n",szInputFilename);
+ fAllFilesPresent = FALSE;
+ }
+ else
+#endif
+ {
+ pAsm->SetSourceFileName(FullFileName(wzInputFilename,uCodePage)); // deletes the argument!
+
+ pParser->ParseFile(pIn);
+ }
+ }
+ if(pIn)
+ {
+ pIn->set_namew(NULL);
+ delete pIn;
+ }
+ } // end for(iFile)
+ if(bClock) cw.cParsEnd = GetTickCount();
+ if ((pParser->Success() && fAllFilesPresent) || pAsm->OnErrGo)
+ {
+ HRESULT hr;
+ if(g_dwSubsystem != (DWORD)-1) pAsm->m_dwSubsystem = g_dwSubsystem;
+ if(g_dwComImageFlags != (DWORD)-1) pAsm->m_dwComImageFlags = g_dwComImageFlags;
+ if(g_dwFileAlignment) pAsm->m_dwFileAlignment = g_dwFileAlignment;
+ if(g_stBaseAddress) pAsm->m_stBaseAddress = g_stBaseAddress;
+ if(g_stSizeOfStackReserve) pAsm->m_stSizeOfStackReserve = g_stSizeOfStackReserve;
+ if(FAILED(hr=pAsm->CreatePEFile(wzOutputFilename)))
+ pParser->msg("Could not create output file, error code=0x%08X\n",hr);
+ else
+ {
+ if(pAsm->m_fFoldCode && pAsm->m_fReportProgress)
+ pParser->msg("%d methods folded\n",pAsm->m_dwMethodsFolded);
+ if(pParser->Success() && fAllFilesPresent) exitval = 0;
+ else
+ {
+ pParser->msg("Output file contains errors\n");
+ if(pAsm->OnErrGo) exitval = 0;
+ }
+ if(exitval == 0) // Write the output file
+ {
+ if(bClock) cw.cFilegenEnd = GetTickCount();
+ if(pAsm->m_fReportProgress) pParser->msg("Writing %s file\n", pAsm->m_fOBJ ? "COFF" : "PE");
+ // Generate the file
+ if (FAILED(hr = pAsm->m_pCeeFileGen->GenerateCeeFile(pAsm->m_pCeeFile)))
+ {
+ exitval = 1;
+ pParser->msg("Failed to write output file, error code=0x%08X\n",hr);
+ }
+#ifndef FEATURE_CORECLR
+ else if (pAsm->m_pManifest->m_sStrongName.m_fFullSign)
+ {
+ // Strong name sign the resultant assembly.
+ if(pAsm->m_fReportProgress) pParser->msg("Signing file with strong name\n");
+ if (FAILED(hr=pAsm->StrongNameSign()))
+ {
+ exitval = 1;
+ pParser->msg("Failed to strong name sign output file, error code=0x%08X\n",hr);
+ }
+ }
+#endif
+ if(bClock) cw.cEnd = GetTickCount();
+#define ENC_ENABLED
+#ifdef ENC_ENABLED
+ if(exitval==0)
+ {
+ pAsm->m_fENCMode = TRUE;
+ WCHAR wzNewOutputFilename[MAX_FILENAME_LENGTH+16];
+ for(iFile = 0; iFile < NumDeltaFiles; iFile++)
+ {
+ wcscpy_s(wzNewOutputFilename,MAX_FILENAME_LENGTH+16,wzOutputFilename);
+ exitval = (int)StringCchPrintfW(&wzNewOutputFilename[wcslen(wzNewOutputFilename)], 32,
+ W(".%d"),iFile+1);
+ MakeProperSourceFileName(pwzDeltaFiles[iFile], uCodePage, wzInputFilename, szInputFilename);
+ if(pAsm->m_fReportProgress)
+ {
+ pParser->msg("\nAssembling delta '%s' ", szInputFilename);
+ if(pAsm->m_fCPlusPlus) pParser->msg(" C++");
+ if(pAsm->m_fWindowsCE) pParser->msg(" WINCE");
+ if(!pAsm->m_fAutoInheritFromObject) pParser->msg(" NOAUTOINHERIT");
+ pParser->msg(" to DMETA,DIL");
+ //======================================================================
+ if (pAsm->m_fStdMapping == FALSE)
+ pParser->msg(", with REFERENCE mapping");
+
+ pParser->msg(" --> '%S.*'\n", wzNewOutputFilename);
+ }
+ exitval = 0;
+ pIn = new MappedFileStream(wzInputFilename);
+
+ if ((!pIn) || !(pIn->IsValid()))
+ {
+ pParser->msg("Could not open %s\n", szInputFilename);
+ fAllFilesPresent = FALSE;
+ }
+ else
+ {
+#ifndef FEATURE_PAL
+ DWORD dwBinType;
+ if(GetBinaryTypeA(szInputFilename,&dwBinType))
+ {
+ pParser->msg("%s is not a text file\n",szInputFilename);
+ fAllFilesPresent = FALSE;
+ }
+ else
+#endif
+ if (SUCCEEDED(pAsm->InitMetaDataForENC(wzNewOutputFilename)))
+ {
+ pAsm->SetSourceFileName(FullFileName(wzInputFilename,uCodePage)); // deletes the argument!
+
+ pParser->ParseFile(pIn);
+ if (pParser->Success() || pAsm->OnErrGo)
+ {
+ exitval = 1;
+ if(FAILED(hr=pAsm->CreateDeltaFiles(wzNewOutputFilename)))
+ pParser->msg("Could not create output delta files, error code=0x%08X\n",hr);
+ else
+ {
+ if(pAsm->m_fFoldCode && pAsm->m_fReportProgress)
+ pParser->msg("%d methods folded\n",pAsm->m_dwMethodsFolded);
+ if(pParser->Success()) exitval = 0;
+ else pParser->msg("Output delta files contain errors\n");
+
+#ifdef GENERATE_SUMMARY_PE_FILE
+ if(pAsm->OnErrGo) exitval = 0;
+
+ //if(FAILED(hr=pAsm->CreatePEFile(wzOutputFilename)))
+ // pParser->msg("Could not create output file, error code=0x%08X\n",hr);
+ //else
+ {
+ if(pAsm->m_fReportProgress) pParser->msg("Writing %s file\n", pAsm->m_fOBJ ? "COFF" : "PE");
+ // Generate the file
+ if (FAILED(hr = pAsm->m_pCeeFileGen->GenerateCeeFile(pAsm->m_pCeeFile)))
+ {
+ exitval = 1;
+ pParser->msg("Failed to write output file, error code=0x%08X\n",hr);
+ }
+ else if (pAsm->m_pManifest->m_sStrongName.m_fFullSign)
+ {
+ // Strong name sign the resultant assembly.
+ if(pAsm->m_fReportProgress) pParser->msg("Signing file with strong name\n");
+ if (FAILED(hr=pAsm->StrongNameSign()))
+ {
+ exitval = 1;
+ pParser->msg("Failed to strong name sign output file, error code=0x%08X\n",hr);
+ }
+ }
+ }
+#endif
+ }
+ } // end if (pParser->Success() || pAsm->OnErrGo)
+ } //end if (SUCCEEDED(pAsm->InitMetaDataForENC()))
+ } // end if ((!pIn) || !(pIn->IsValid())) -- else
+ if(pIn)
+ {
+ pIn->set_namew(NULL);
+ delete pIn;
+ }
+ } // end for(iFile)
+ } // end if(exitval==0)
+#endif
+ }
+
+ }
+ }
+ }
+ else pParser->msg("Failed to initialize Meta Data\n");
+ delete pParser;
+ }
+ else printf("Could not create parser\n");
+ }
+ //else printf("Failed to initialize Assembler\n");
+ delete pAsm;
+ }
+ else printf("Insufficient memory\n");
+
+ WszSetEnvironmentVariable(W("COMP_ENC_OPENSCOPE"), W(""));
+ WszSetEnvironmentVariable(W("COMP_ENC_EMIT"), W(""));
+
+ if(exitval || bNoDebug)
+ {
+ // PE file was not created, or no debug info required. Kill PDB if any
+ WCHAR* pc = wcsrchr(wzOutputFilename,L'.');
+ if(pc==NULL)
+ {
+ pc = &wzOutputFilename[wcslen(wzOutputFilename)];
+ *pc = L'.';
+ }
+ wcscpy_s(pc+1,4,W("PDB"));
+#undef DeleteFileW
+ DeleteFileW(wzOutputFilename);
+ }
+ if (exitval == 0)
+ {
+ if(bReportProgress) printf("Operation completed successfully\n");
+ if(bClock)
+ {
+ printf("Timing (msec): Total run %d\n",(cw.cEnd-cw.cBegin));
+ printf(" Startup %d\n",(cw.cParsBegin-cw.cBegin));
+ printf(" - MD initialization %d\n",(cw.cMDInitEnd - cw.cMDInitBegin));
+ printf(" Parsing %d\n",(cw.cParsEnd - cw.cParsBegin));
+ printf(" Emitting MD %d\n",(cw.cMDEmitEnd - cw.cRef2DefEnd)+(cw.cRef2DefBegin - cw.cMDEmitBegin));
+ //printf(" - global fixups %d\n",(cw.cMDEmit1 - cw.cMDEmitBegin));
+ printf(" - SN sig alloc %d\n",(cw.cMDEmit2 - cw.cMDEmitBegin));
+ printf(" - Classes,Methods,Fields %d\n",(cw.cRef2DefBegin - cw.cMDEmit2));
+ printf(" - Events,Properties %d\n",(cw.cMDEmit3 - cw.cRef2DefEnd));
+ printf(" - MethodImpls %d\n",(cw.cMDEmit4 - cw.cMDEmit3));
+ printf(" - Manifest,CAs %d\n",(cw.cMDEmitEnd - cw.cMDEmit4));
+ printf(" Ref to Def resolution %d\n",(cw.cRef2DefEnd - cw.cRef2DefBegin));
+ printf(" Fixup and linking %d\n",(cw.cFilegenBegin - cw.cMDEmitEnd));
+ printf(" CEE file generation %d\n",(cw.cFilegenEnd - cw.cFilegenBegin));
+ printf(" PE file writing %d\n",(cw.cEnd - cw.cFilegenEnd));
+ }
+ }
+ else
+ {
+ printf("\n***** FAILURE ***** \n");
+ }
+ exit(exitval);
+ return exitval;
+}
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+
+#ifndef FEATURE_CORECLR
+HINSTANCE GetModuleInst()
+{
+ return (NULL);
+}
+#endif // !FEATURE_CORECLR
+
+#ifdef FEATURE_PAL
+int main(int argc, char* str[])
+{
+ g_pszExeFile = str[0];
+ if (0 != PAL_Initialize(argc, str))
+ {
+ fprintf(stderr,"Error: Fail to PAL_Initialize\n");
+ exit(1);
+ }
+
+ WCHAR **argv = new WCHAR*[argc];
+ for (int i = 0; i < argc; i++) {
+ int length = MultiByteToWideChar(CP_ACP, 0, str[i], -1, NULL, 0);
+ ASSERTE_ALL_BUILDS(length != 0);
+
+ LPWSTR result = new (nothrow) WCHAR[length];
+ ASSERTE_ALL_BUILDS(result != NULL);
+
+ length = MultiByteToWideChar(CP_ACP, 0, str[i], -1, result, length);
+ ASSERTE_ALL_BUILDS (length != 0);
+
+ argv[i] = result;
+ }
+
+ int ret = wmain(argc, argv);
+
+ for (int i = 0 ; i < argc; i++) {
+ delete[] argv[i];
+ }
+ delete[] argv;
+
+ return ret;
+}
+#endif // FEATURE_PAL
+
diff --git a/src/ilasm/method.cpp b/src/ilasm/method.cpp
new file mode 100644
index 0000000000..18f6c47b00
--- /dev/null
+++ b/src/ilasm/method.cpp
@@ -0,0 +1,157 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// file: method.cpp
+//
+
+//
+#include "ilasmpch.h"
+#include "assembler.h"
+
+Method::Method(Assembler *pAssembler, Class *pClass, __in __nullterminated char *pszName, BinStr* pbsSig, DWORD Attr)
+{
+
+ // default values
+ m_pClass = pClass;
+ m_MaxStack = 8;
+ m_Flags = 0;
+ m_LocalsSig = 0;
+ m_dwNumExceptions = 0;
+ m_dwNumEndfilters = 0;
+ m_firstArgName = NULL;
+ m_firstVarName = NULL;
+ m_pMethodSig = NULL;
+ m_wImplAttr = miIL; //default, if native or optil are not specified
+ m_wVTEntry = 0;
+ m_wVTSlot = 0;
+ m_pAssembler = pAssembler;
+ m_pCurrScope = &m_MainScope;
+ m_pRetMarshal = NULL;
+ m_pRetValue = NULL;
+ m_szExportAlias = NULL;
+ m_dwExportOrdinal = 0xFFFFFFFF;
+ m_ulLines[0]=m_ulLines[1]=0;
+ m_ulColumns[0]=m_ulColumns[0]=0;
+ m_pbsBody = NULL;
+ m_fNewBody = TRUE;
+ m_fNew = TRUE;
+
+ // move the PInvoke descriptor (if any) from Assembler
+ // (Assembler gets the descriptor BEFORE it calls new Method)
+ m_pPInvoke = pAssembler->m_pPInvoke;
+ pAssembler->m_pPInvoke = NULL;
+
+ _ASSERTE(pszName);
+ if (!pszName) return;
+
+ m_szName = pszName;
+ m_dwName = (DWORD)strlen(pszName);
+
+ m_ExceptionList = new COR_ILMETHOD_SECT_EH_CLAUSE_FAT[MAX_EXCEPTIONS];
+ m_EndfilterOffsetList = new DWORD[MAX_EXCEPTIONS];
+ if((m_ExceptionList==NULL)||(m_EndfilterOffsetList==NULL))
+ {
+ fprintf(stderr,"\nOutOfMemory!\n");
+ return;
+ }
+ m_dwMaxNumExceptions = MAX_EXCEPTIONS;
+ m_dwMaxNumEndfilters = MAX_EXCEPTIONS;
+
+ m_Attr = Attr;
+ if((!strcmp(pszName,COR_CCTOR_METHOD_NAME))||(!strcmp(pszName,COR_CTOR_METHOD_NAME)))
+ m_Attr |= mdSpecialName;
+ m_fEntryPoint = FALSE;
+ m_fGlobalMethod = FALSE;
+
+ if(pbsSig)
+ {
+ m_dwMethodCSig = pbsSig->length();
+ m_pMethodSig = (COR_SIGNATURE*)(pbsSig->ptr());
+ m_pbsMethodSig = pbsSig;
+ }
+
+ m_firstArgName = pAssembler->getArgNameList();
+ if(pClass == NULL) pClass = pAssembler->m_pModuleClass; // fake "class" <Module>
+ pClass->m_MethodList.PUSH(this);
+ pClass->m_fNewMembers = TRUE;
+
+
+ m_pPermissions = NULL;
+ m_pPermissionSets = NULL;
+
+ m_TyPars = NULL;
+ m_NumTyPars = 0;
+}
+
+
+// lexical scope handling
+void Method::OpenScope()
+{
+ Scope* psc = new Scope;
+ if(psc)
+ {
+ psc->dwStart = m_pAssembler->m_CurPC;
+ psc->pSuperScope = m_pCurrScope;
+#if(0)
+ LinePC *pLPC = new LinePC;
+ if(pLPC)
+ {
+ pLPC->Line = m_pAssembler->m_ulCurLine;
+ pLPC->Column = m_pAssembler->m_ulCurColumn;
+ pLPC->PC = m_pAssembler->m_CurPC;
+ m_LinePCList.PUSH(pLPC);
+ }
+#endif
+ m_pCurrScope->SubScope.PUSH(psc);
+ m_pCurrScope = psc;
+ }
+}
+void Method::CloseScope()
+{
+ VarDescr* pVD;
+ ARG_NAME_LIST* pAN;
+ for(pAN=m_pCurrScope->pLocals; pAN; pAN = pAN->pNext)
+ {
+ if((pVD = m_Locals.PEEK(pAN->dwAttr))) pVD->bInScope = FALSE;
+ }
+ m_pCurrScope->dwEnd = m_pAssembler->m_CurPC;
+#if(0)
+ LinePC *pLPC = new LinePC;
+ if(pLPC)
+ {
+ pLPC->Line = m_pAssembler->m_ulCurLine;
+ pLPC->Column = m_pAssembler->m_ulCurColumn;
+ pLPC->PC = m_pAssembler->m_CurPC;
+ m_LinePCList.PUSH(pLPC);
+ }
+#endif
+ m_pCurrScope = m_pCurrScope->pSuperScope;
+}
+
+Label *Method::FindLabel(LPCUTF8 pszName)
+{
+ Label lSearch(pszName,0), *pL;
+ lSearch.m_szName = pszName;
+ //pL = m_lstLabel.FIND(&lSearch);
+ pL = m_pAssembler->m_lstLabel.FIND(&lSearch);
+ lSearch.m_szName = NULL;
+ return pL;
+ //return m_lstLabel.FIND(pszName);
+}
+
+
+Label *Method::FindLabel(DWORD PC)
+{
+ Label *pSearch;
+
+ //for (int i = 0; (pSearch = m_lstLabel.PEEK(i)); i++)
+ for (int i = 0; (pSearch = m_pAssembler->m_lstLabel.PEEK(i)); i++)
+ {
+ if (pSearch->m_PC == PC)
+ return pSearch;
+ }
+
+ return NULL;
+}
+
diff --git a/src/ilasm/method.hpp b/src/ilasm/method.hpp
new file mode 100644
index 0000000000..a70fab43a8
--- /dev/null
+++ b/src/ilasm/method.hpp
@@ -0,0 +1,380 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// method.hpp
+//
+#ifndef _METHOD_HPP
+#define _METHOD_HPP
+
+class Assembler;
+class PermissionDecl;
+class PermissionSetDecl;
+
+#define MAX_EXCEPTIONS 16 // init.number; increased by 16 when needed
+
+extern unsigned int g_uCodePage;
+extern WCHAR wzUniBuf[];
+
+/**************************************************************************/
+struct LinePC
+{
+ ULONG Line;
+ ULONG Column;
+ ULONG LineEnd;
+ ULONG ColumnEnd;
+ ULONG PC;
+ ISymUnmanagedDocumentWriter* pWriter;
+};
+typedef FIFO<LinePC> LinePCList;
+
+
+struct PInvokeDescriptor
+{
+ mdModuleRef mrDll;
+ char* szAlias;
+ DWORD dwAttrs;
+};
+
+struct TokenRelocDescr // for OBJ generation only!
+{
+ DWORD offset;
+ mdToken token;
+ TokenRelocDescr(DWORD off, mdToken tk) { offset = off; token = tk; };
+};
+typedef FIFO<TokenRelocDescr> TRDList;
+/* structure - element of [local] signature name list */
+
+struct ARG_NAME_LIST
+{
+ LPCUTF8 szName; //szName[1024];
+ DWORD dwName;
+ BinStr* pSig; // argument's signature ptr
+ BinStr* pMarshal;
+ BinStr* pValue;
+ int nNum;
+ DWORD dwAttr;
+ CustomDescrList CustDList;
+ ARG_NAME_LIST *pNext;
+ __forceinline ARG_NAME_LIST(int i, LPCUTF8 sz, BinStr *pbSig, BinStr *pbMarsh, DWORD attr)
+ {
+ nNum = i;
+ //dwName = (DWORD)strlen(sz);
+ //strcpy(szName,sz);
+ szName = sz;
+ dwName = (sz == NULL) ? 0 : (DWORD)strlen(sz);
+ pNext = NULL;
+ pSig=pbSig;
+ pMarshal = pbMarsh;
+ dwAttr = attr;
+ pValue=NULL;
+ };
+ inline ~ARG_NAME_LIST()
+ {
+ if(pSig) delete pSig;
+ if(pMarshal) delete pMarshal;
+ if(pValue) delete pValue;
+ if(szName) delete [] szName;
+ }
+};
+
+class Scope;
+typedef FIFO<Scope> ScopeList;
+class Scope
+{
+public:
+ DWORD dwStart;
+ DWORD dwEnd;
+ ARG_NAME_LIST* pLocals;
+ ScopeList SubScope;
+ Scope* pSuperScope;
+ Scope() { dwStart = dwEnd = 0; pLocals = NULL; pSuperScope = NULL; };
+ ~Scope() { Reset(); };
+ void Reset()
+ {
+ ARG_NAME_LIST* pNext;
+ while(pLocals) { pNext = pLocals->pNext; delete pLocals; pLocals = pNext; }
+ Scope* pS;
+ while((pS = SubScope.POP()) != NULL) delete pS;
+ pSuperScope = NULL;
+ dwStart = dwEnd = 0;
+ };
+};
+struct VarDescr
+{
+ DWORD dwSlot;
+ BinStr* pbsSig;
+ BOOL bInScope;
+ VarDescr() { dwSlot = (DWORD) -1; pbsSig = NULL; bInScope = FALSE; };
+};
+typedef FIFO<VarDescr> VarDescrList;
+
+
+struct Label
+{
+//public:
+ LPCUTF8 m_szName;
+ DWORD m_PC;
+
+ Label() :m_szName(NULL),m_PC(0){};
+ Label(LPCUTF8 pszName, DWORD PC):m_szName(pszName),m_PC(PC){};
+ ~Label(){ delete [] m_szName; };
+ int ComparedTo(Label* L) { return strcmp(m_szName,L->m_szName); };
+ //int Compare(char* L) { return strcmp(L,m_szName); };
+ LPCUTF8 NameOf() { return m_szName; };
+};
+//typedef SORTEDARRAY<Label> LabelList;
+typedef FIFO_INDEXED<Label> LabelList;
+
+class GlobalFixup
+{
+public:
+ LPCUTF8 m_szLabel;
+ BYTE * m_pReference; // The place to fix up
+
+ GlobalFixup(LPCUTF8 pszName, BYTE* pReference)
+ {
+ m_pReference = pReference;
+ m_szLabel = pszName;
+ }
+ ~GlobalFixup(){ delete [] m_szLabel; }
+};
+typedef FIFO<GlobalFixup> GlobalFixupList;
+
+
+class Fixup
+{
+public:
+ LPCUTF8 m_szLabel;
+ BYTE * m_pBytes; // where to make the fixup
+ DWORD m_RelativeToPC;
+ BYTE m_FixupSize;
+
+ Fixup(LPCUTF8 pszName, BYTE *pBytes, DWORD RelativeToPC, BYTE FixupSize)
+ {
+ m_pBytes = pBytes;
+ m_RelativeToPC = RelativeToPC;
+ m_FixupSize = FixupSize;
+ m_szLabel = pszName;
+ }
+ ~Fixup(){ delete [] m_szLabel; }
+};
+typedef FIFO<Fixup> FixupList;
+
+typedef enum { ilRVA, ilToken, ilGlobal} ILFixupType;
+
+class ILFixup
+{
+public:
+ ILFixupType m_Kind;
+ DWORD m_OffsetInMethod;
+ GlobalFixup * m_Fixup;
+
+ ILFixup(DWORD Offset, ILFixupType Kind, GlobalFixup *Fix)
+ {
+ m_Kind = Kind;
+ m_OffsetInMethod = Offset;
+ m_Fixup = Fix;
+ }
+};
+typedef FIFO<ILFixup> ILFixupList;
+
+class Method
+{
+public:
+ Class *m_pClass;
+ //BinStr **m_TyParBounds;
+ //LPCWSTR *m_TyParNames;
+ TyParDescr* m_TyPars;
+ DWORD m_NumTyPars;
+ DWORD m_SigInfoCount;
+ USHORT m_MaxStack;
+ mdSignature m_LocalsSig;
+ DWORD m_Flags;
+ char* m_szName;
+ DWORD m_dwName;
+ char* m_szExportAlias;
+ DWORD m_dwExportOrdinal;
+ COR_ILMETHOD_SECT_EH_CLAUSE_FAT *m_ExceptionList;
+ DWORD m_dwNumExceptions;
+ DWORD m_dwMaxNumExceptions;
+ DWORD* m_EndfilterOffsetList;
+ DWORD m_dwNumEndfilters;
+ DWORD m_dwMaxNumEndfilters;
+ DWORD m_Attr;
+ BOOL m_fEntryPoint;
+ BOOL m_fGlobalMethod;
+ BOOL m_fNewBody;
+ BOOL m_fNew;
+ DWORD m_methodOffset;
+ DWORD m_headerOffset;
+ BYTE * m_pCode;
+ DWORD m_CodeSize;
+ WORD m_wImplAttr;
+ ULONG m_ulLines[2];
+ ULONG m_ulColumns[2];
+ // PInvoke attributes
+ PInvokeDescriptor* m_pPInvoke;
+ // Security attributes
+ PermissionDecl* m_pPermissions;
+ PermissionSetDecl* m_pPermissionSets;
+ // VTable attributes
+ WORD m_wVTEntry;
+ WORD m_wVTSlot;
+ // Return marshaling
+ BinStr* m_pRetMarshal;
+ BinStr* m_pRetValue;
+ DWORD m_dwRetAttr;
+ CustomDescrList m_RetCustDList;
+ ILFixupList m_lstILFixup;
+ FixupList m_lstFixup;
+// LabelList m_lstLabel;
+ // Member ref fixups
+ LocalMemberRefFixupList m_LocalMemberRefFixupList;
+ // Method body (header+code+EH)
+ BinStr* m_pbsBody;
+ mdToken m_Tok;
+ Method(Assembler *pAssembler, Class *pClass, __in __nullterminated char *pszName, BinStr* pbsSig, DWORD Attr);
+ ~Method()
+ {
+ m_lstFixup.RESET(true);
+ //m_lstLabel.RESET(true);
+ delete [] m_szName;
+ if(m_szExportAlias) delete [] m_szExportAlias;
+ delArgNameList(m_firstArgName);
+ delArgNameList(m_firstVarName);
+ delete m_pbsMethodSig;
+ delete [] m_ExceptionList;
+ delete [] m_EndfilterOffsetList;
+ if(m_pRetMarshal) delete m_pRetMarshal;
+ if(m_pRetValue) delete m_pRetValue;
+ while(m_MethodImplDList.POP()); // ptrs in m_MethodImplDList are dups of those in Assembler
+ if(m_pbsBody) delete m_pbsBody;
+ if(m_TyPars) delete [] m_TyPars;
+ };
+
+ BOOL IsGlobalMethod()
+ {
+ return m_fGlobalMethod;
+ };
+
+ void SetIsGlobalMethod()
+ {
+ m_fGlobalMethod = TRUE;
+ };
+
+ void delArgNameList(ARG_NAME_LIST *pFirst)
+ {
+ ARG_NAME_LIST *pArgList=pFirst, *pArgListNext;
+ for(; pArgList; pArgListNext=pArgList->pNext,
+ delete pArgList,
+ pArgList=pArgListNext);
+ };
+
+ ARG_NAME_LIST *catArgNameList(ARG_NAME_LIST *pBase, ARG_NAME_LIST *pAdd)
+ {
+ if(pAdd) //even if nothing to concatenate, result == head
+ {
+ ARG_NAME_LIST *pAN = pBase;
+ if(pBase)
+ {
+ int i;
+ for(; pAN->pNext; pAN = pAN->pNext) ;
+ pAN->pNext = pAdd;
+ i = pAN->nNum;
+ for(pAN = pAdd; pAN; pAN->nNum = ++i, pAN = pAN->pNext);
+ }
+ else pBase = pAdd; //nothing to concatenate to, result == tail
+ }
+ return pBase;
+ };
+
+ int findArgNum(ARG_NAME_LIST *pFirst, LPCUTF8 szArgName, DWORD dwArgName)
+ {
+ int ret=-1;
+ if(dwArgName)
+ {
+ ARG_NAME_LIST *pAN;
+ for(pAN=pFirst; pAN; pAN = pAN->pNext)
+ {
+ if((pAN->dwName == dwArgName)&& ((dwArgName==0)||(!strcmp(pAN->szName,szArgName))))
+ {
+ ret = pAN->nNum;
+ break;
+ }
+ }
+ }
+ return ret;
+ };
+
+ int findLocSlot(ARG_NAME_LIST *pFirst, LPCUTF8 szArgName, DWORD dwArgName)
+ {
+ int ret=-1;
+ if(dwArgName)
+ {
+ ARG_NAME_LIST *pAN;
+ for(pAN=pFirst; pAN; pAN = pAN->pNext)
+ {
+ if((pAN->dwName == dwArgName)&& ((dwArgName==0)||(!strcmp(pAN->szName,szArgName))))
+ {
+ ret = (int)(pAN->dwAttr);
+ break;
+ }
+ }
+ }
+ return ret;
+ };
+
+ BinStr *m_pbsMethodSig;
+ COR_SIGNATURE* m_pMethodSig;
+ DWORD m_dwMethodCSig;
+ ARG_NAME_LIST *m_firstArgName;
+ ARG_NAME_LIST *m_firstVarName;
+ // to call error() from Method:
+ const char* m_FileName;
+ unsigned m_LineNum;
+ // debug info
+ LinePCList m_LinePCList;
+ // custom values
+ CustomDescrList m_CustomDescrList;
+ // token relocs (used for OBJ generation only)
+ TRDList m_TRDList;
+ // method's own list of method impls
+ MethodImplDList m_MethodImplDList;
+ // lexical scope handling
+ Assembler* m_pAssembler;
+ Scope m_MainScope;
+ Scope* m_pCurrScope;
+ VarDescrList m_Locals;
+ void OpenScope();
+ void CloseScope();
+
+ Label *FindLabel(LPCUTF8 pszName);
+ Label *FindLabel(DWORD PC);
+
+ int FindTyPar(__in __nullterminated WCHAR* wz)
+ {
+ int i,retval=-1;
+ for(i=0; i < (int)m_NumTyPars; i++)
+ {
+ if(!wcscmp(wz,m_TyPars[i].Name()))
+ {
+ retval = i;
+ }
+ }
+ return retval;
+ };
+ int FindTyPar(__in __nullterminated char* sz)
+ {
+ if(sz)
+ {
+ wzUniBuf[0] = 0;
+ WszMultiByteToWideChar(g_uCodePage,0,sz,-1,wzUniBuf,dwUniBuf);
+ return FindTyPar(wzUniBuf);
+ }
+ else return -1;
+ };
+};
+
+#endif /* _METHOD_HPP */
+
diff --git a/src/ilasm/nvpair.h b/src/ilasm/nvpair.h
new file mode 100644
index 0000000000..8e0f4bd4ac
--- /dev/null
+++ b/src/ilasm/nvpair.h
@@ -0,0 +1,46 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+/***************************************************************************/
+/* Name value pair (both strings) which can be linked into a list of pairs */
+
+#ifndef NVPAIR_H
+#define NVPAIR_H
+
+#include "binstr.h"
+
+class NVPair
+{
+public:
+
+ NVPair(BinStr *name, BinStr *value)
+ {
+ m_Name = name;
+ m_Value = value;
+ m_Tail = NULL;
+ }
+
+ ~NVPair()
+ {
+ delete m_Name;
+ delete m_Value;
+ delete m_Tail;
+ }
+
+ NVPair *Concat(NVPair *list)
+ {
+ m_Tail = list;
+ return this;
+ }
+
+ BinStr *Name() { return m_Name; }
+ BinStr *Value() { return m_Value; }
+ NVPair *Next() { return m_Tail; }
+
+private:
+ BinStr *m_Name;
+ BinStr *m_Value;
+ NVPair *m_Tail;
+};
+
+#endif
diff --git a/src/ilasm/prebuilt/asmparse.c b/src/ilasm/prebuilt/asmparse.c
new file mode 100644
index 0000000000..71b31a5ed6
--- /dev/null
+++ b/src/ilasm/prebuilt/asmparse.c
@@ -0,0 +1,4907 @@
+/*
+ * Created by Microsoft VCBU Internal YACC from "asmparse.y"
+ */
+
+#line 2 "asmparse.y"
+
+ // Licensed to the .NET Foundation under one or more agreements.
+ // The .NET Foundation licenses this file to you under the MIT license.
+ // See the LICENSE file in the project root for more information.
+//
+// File asmparse.y
+//
+#include "ilasmpch.h"
+
+#include "grammar_before.cpp"
+
+
+#line 16 "asmparse.y"
+
+#define UNION 1
+typedef union {
+ CorRegTypeAttr classAttr;
+ CorMethodAttr methAttr;
+ CorFieldAttr fieldAttr;
+ CorMethodImpl implAttr;
+ CorEventAttr eventAttr;
+ CorPropertyAttr propAttr;
+ CorPinvokeMap pinvAttr;
+ CorDeclSecurity secAct;
+ CorFileFlags fileAttr;
+ CorAssemblyFlags asmAttr;
+ CorAssemblyFlags asmRefAttr;
+ CorTypeAttr exptAttr;
+ CorManifestResourceFlags manresAttr;
+ double* float64;
+ __int64* int64;
+ __int32 int32;
+ char* string;
+ BinStr* binstr;
+ Labels* labels;
+ Instr* instr; // instruction opcode
+ NVPair* pair;
+ pTyParList typarlist;
+ mdToken token;
+ TypeDefDescr* tdd;
+ CustomDescr* cad;
+ unsigned short opcode;
+} YYSTYPE;
+# define ERROR_ 257
+# define BAD_COMMENT_ 258
+# define BAD_LITERAL_ 259
+# define ID 260
+# define DOTTEDNAME 261
+# define QSTRING 262
+# define SQSTRING 263
+# define INT32 264
+# define INT64 265
+# define FLOAT64 266
+# define HEXBYTE 267
+# define TYPEDEF_T 268
+# define TYPEDEF_M 269
+# define TYPEDEF_F 270
+# define TYPEDEF_TS 271
+# define TYPEDEF_MR 272
+# define TYPEDEF_CA 273
+# define DCOLON 274
+# define ELIPSIS 275
+# define VOID_ 276
+# define BOOL_ 277
+# define CHAR_ 278
+# define UNSIGNED_ 279
+# define INT_ 280
+# define INT8_ 281
+# define INT16_ 282
+# define INT32_ 283
+# define INT64_ 284
+# define FLOAT_ 285
+# define FLOAT32_ 286
+# define FLOAT64_ 287
+# define BYTEARRAY_ 288
+# define UINT_ 289
+# define UINT8_ 290
+# define UINT16_ 291
+# define UINT32_ 292
+# define UINT64_ 293
+# define FLAGS_ 294
+# define CALLCONV_ 295
+# define MDTOKEN_ 296
+# define OBJECT_ 297
+# define STRING_ 298
+# define NULLREF_ 299
+# define DEFAULT_ 300
+# define CDECL_ 301
+# define VARARG_ 302
+# define STDCALL_ 303
+# define THISCALL_ 304
+# define FASTCALL_ 305
+# define CLASS_ 306
+# define TYPEDREF_ 307
+# define UNMANAGED_ 308
+# define FINALLY_ 309
+# define HANDLER_ 310
+# define CATCH_ 311
+# define FILTER_ 312
+# define FAULT_ 313
+# define EXTENDS_ 314
+# define IMPLEMENTS_ 315
+# define TO_ 316
+# define AT_ 317
+# define TLS_ 318
+# define TRUE_ 319
+# define FALSE_ 320
+# define _INTERFACEIMPL 321
+# define VALUE_ 322
+# define VALUETYPE_ 323
+# define NATIVE_ 324
+# define INSTANCE_ 325
+# define SPECIALNAME_ 326
+# define FORWARDER_ 327
+# define STATIC_ 328
+# define PUBLIC_ 329
+# define PRIVATE_ 330
+# define FAMILY_ 331
+# define FINAL_ 332
+# define SYNCHRONIZED_ 333
+# define INTERFACE_ 334
+# define SEALED_ 335
+# define NESTED_ 336
+# define ABSTRACT_ 337
+# define AUTO_ 338
+# define SEQUENTIAL_ 339
+# define EXPLICIT_ 340
+# define ANSI_ 341
+# define UNICODE_ 342
+# define AUTOCHAR_ 343
+# define IMPORT_ 344
+# define ENUM_ 345
+# define VIRTUAL_ 346
+# define NOINLINING_ 347
+# define AGGRESSIVEINLINING_ 348
+# define NOOPTIMIZATION_ 349
+# define UNMANAGEDEXP_ 350
+# define BEFOREFIELDINIT_ 351
+# define STRICT_ 352
+# define RETARGETABLE_ 353
+# define WINDOWSRUNTIME_ 354
+# define NOPLATFORM_ 355
+# define METHOD_ 356
+# define FIELD_ 357
+# define PINNED_ 358
+# define MODREQ_ 359
+# define MODOPT_ 360
+# define SERIALIZABLE_ 361
+# define PROPERTY_ 362
+# define TYPE_ 363
+# define ASSEMBLY_ 364
+# define FAMANDASSEM_ 365
+# define FAMORASSEM_ 366
+# define PRIVATESCOPE_ 367
+# define HIDEBYSIG_ 368
+# define NEWSLOT_ 369
+# define RTSPECIALNAME_ 370
+# define PINVOKEIMPL_ 371
+# define _CTOR 372
+# define _CCTOR 373
+# define LITERAL_ 374
+# define NOTSERIALIZED_ 375
+# define INITONLY_ 376
+# define REQSECOBJ_ 377
+# define CIL_ 378
+# define OPTIL_ 379
+# define MANAGED_ 380
+# define FORWARDREF_ 381
+# define PRESERVESIG_ 382
+# define RUNTIME_ 383
+# define INTERNALCALL_ 384
+# define _IMPORT 385
+# define NOMANGLE_ 386
+# define LASTERR_ 387
+# define WINAPI_ 388
+# define AS_ 389
+# define BESTFIT_ 390
+# define ON_ 391
+# define OFF_ 392
+# define CHARMAPERROR_ 393
+# define INSTR_NONE 394
+# define INSTR_VAR 395
+# define INSTR_I 396
+# define INSTR_I8 397
+# define INSTR_R 398
+# define INSTR_BRTARGET 399
+# define INSTR_METHOD 400
+# define INSTR_FIELD 401
+# define INSTR_TYPE 402
+# define INSTR_STRING 403
+# define INSTR_SIG 404
+# define INSTR_TOK 405
+# define INSTR_SWITCH 406
+# define _CLASS 407
+# define _NAMESPACE 408
+# define _METHOD 409
+# define _FIELD 410
+# define _DATA 411
+# define _THIS 412
+# define _BASE 413
+# define _NESTER 414
+# define _EMITBYTE 415
+# define _TRY 416
+# define _MAXSTACK 417
+# define _LOCALS 418
+# define _ENTRYPOINT 419
+# define _ZEROINIT 420
+# define _EVENT 421
+# define _ADDON 422
+# define _REMOVEON 423
+# define _FIRE 424
+# define _OTHER 425
+# define _PROPERTY 426
+# define _SET 427
+# define _GET 428
+# define _PERMISSION 429
+# define _PERMISSIONSET 430
+# define REQUEST_ 431
+# define DEMAND_ 432
+# define ASSERT_ 433
+# define DENY_ 434
+# define PERMITONLY_ 435
+# define LINKCHECK_ 436
+# define INHERITCHECK_ 437
+# define REQMIN_ 438
+# define REQOPT_ 439
+# define REQREFUSE_ 440
+# define PREJITGRANT_ 441
+# define PREJITDENY_ 442
+# define NONCASDEMAND_ 443
+# define NONCASLINKDEMAND_ 444
+# define NONCASINHERITANCE_ 445
+# define _LINE 446
+# define P_LINE 447
+# define _LANGUAGE 448
+# define _CUSTOM 449
+# define INIT_ 450
+# define _SIZE 451
+# define _PACK 452
+# define _VTABLE 453
+# define _VTFIXUP 454
+# define FROMUNMANAGED_ 455
+# define CALLMOSTDERIVED_ 456
+# define _VTENTRY 457
+# define RETAINAPPDOMAIN_ 458
+# define _FILE 459
+# define NOMETADATA_ 460
+# define _HASH 461
+# define _ASSEMBLY 462
+# define _PUBLICKEY 463
+# define _PUBLICKEYTOKEN 464
+# define ALGORITHM_ 465
+# define _VER 466
+# define _LOCALE 467
+# define EXTERN_ 468
+# define _MRESOURCE 469
+# define _MODULE 470
+# define _EXPORT 471
+# define LEGACY_ 472
+# define LIBRARY_ 473
+# define X86_ 474
+# define IA64_ 475
+# define AMD64_ 476
+# define ARM_ 477
+# define MARSHAL_ 478
+# define CUSTOM_ 479
+# define SYSSTRING_ 480
+# define FIXED_ 481
+# define VARIANT_ 482
+# define CURRENCY_ 483
+# define SYSCHAR_ 484
+# define DECIMAL_ 485
+# define DATE_ 486
+# define BSTR_ 487
+# define TBSTR_ 488
+# define LPSTR_ 489
+# define LPWSTR_ 490
+# define LPTSTR_ 491
+# define OBJECTREF_ 492
+# define IUNKNOWN_ 493
+# define IDISPATCH_ 494
+# define STRUCT_ 495
+# define SAFEARRAY_ 496
+# define BYVALSTR_ 497
+# define LPVOID_ 498
+# define ANY_ 499
+# define ARRAY_ 500
+# define LPSTRUCT_ 501
+# define IIDPARAM_ 502
+# define IN_ 503
+# define OUT_ 504
+# define OPT_ 505
+# define PARAM_ 506
+# define _OVERRIDE 507
+# define WITH_ 508
+# define NULL_ 509
+# define HRESULT_ 510
+# define CARRAY_ 511
+# define USERDEFINED_ 512
+# define RECORD_ 513
+# define FILETIME_ 514
+# define BLOB_ 515
+# define STREAM_ 516
+# define STORAGE_ 517
+# define STREAMED_OBJECT_ 518
+# define STORED_OBJECT_ 519
+# define BLOB_OBJECT_ 520
+# define CF_ 521
+# define CLSID_ 522
+# define VECTOR_ 523
+# define _SUBSYSTEM 524
+# define _CORFLAGS 525
+# define ALIGNMENT_ 526
+# define _IMAGEBASE 527
+# define _STACKRESERVE 528
+# define _TYPEDEF 529
+# define _TEMPLATE 530
+# define _TYPELIST 531
+# define _MSCORLIB 532
+# define P_DEFINE 533
+# define P_UNDEF 534
+# define P_IFDEF 535
+# define P_IFNDEF 536
+# define P_ELSE 537
+# define P_ENDIF 538
+# define P_INCLUDE 539
+#define yyclearin yychar = -1
+#define yyerrok yyerrflag = 0
+#ifndef YYMAXDEPTH
+#define YYMAXDEPTH 150
+#endif
+YYSTYPE yylval, yyval;
+#ifndef YYFARDATA
+#define YYFARDATA /*nothing*/
+#endif
+#if ! defined YYSTATIC
+#define YYSTATIC /*nothing*/
+#endif
+#if ! defined YYCONST
+#define YYCONST /*nothing*/
+#endif
+#ifndef YYACT
+#define YYACT yyact
+#endif
+#ifndef YYPACT
+#define YYPACT yypact
+#endif
+#ifndef YYPGO
+#define YYPGO yypgo
+#endif
+#ifndef YYR1
+#define YYR1 yyr1
+#endif
+#ifndef YYR2
+#define YYR2 yyr2
+#endif
+#ifndef YYCHK
+#define YYCHK yychk
+#endif
+#ifndef YYDEF
+#define YYDEF yydef
+#endif
+#ifndef YYV
+#define YYV yyv
+#endif
+#ifndef YYS
+#define YYS yys
+#endif
+#ifndef YYLOCAL
+#define YYLOCAL
+#endif
+#ifndef YYR_T
+#define YYR_T int
+#endif
+typedef YYR_T yyr_t;
+#ifndef YYEXIND_T
+#define YYEXIND_T unsigned int
+#endif
+typedef YYEXIND_T yyexind_t;
+#ifndef YYOPTTIME
+#define YYOPTTIME 0
+#endif
+# define YYERRCODE 256
+
+#line 2051 "asmparse.y"
+
+
+#include "grammar_after.cpp"
+YYSTATIC YYCONST short yyexca[] = {
+#if !(YYOPTTIME)
+-1, 1,
+#endif
+ 0, -1,
+ -2, 0,
+#if !(YYOPTTIME)
+-1, 452,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 621,
+#endif
+ 274, 549,
+ 47, 549,
+ -2, 227,
+#if !(YYOPTTIME)
+-1, 642,
+#endif
+ 40, 307,
+ 60, 307,
+ -2, 549,
+#if !(YYOPTTIME)
+-1, 663,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 686,
+#endif
+ 274, 549,
+ 47, 549,
+ -2, 510,
+#if !(YYOPTTIME)
+-1, 803,
+#endif
+ 123, 232,
+ -2, 549,
+#if !(YYOPTTIME)
+-1, 828,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 953,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 986,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 987,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 1308,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 1309,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 1315,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 1322,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 1447,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 1479,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 1545,
+#endif
+ 41, 532,
+ -2, 308,
+#if !(YYOPTTIME)
+-1, 1562,
+#endif
+ 41, 532,
+ -2, 308,
+
+};
+
+# define YYNPROD 838
+#if YYOPTTIME
+YYSTATIC YYCONST yyexind_t yyexcaind[] = {
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 4, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 8, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 14, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 20, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 24, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 30, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 34, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 38, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 42, 46, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 50, 54,
+ 0, 0, 0, 0, 0, 58, 0, 0, 0, 0,
+ 0, 0, 62, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 66, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 70,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 74, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 78
+};
+#endif
+# define YYLAST 3904
+
+YYSTATIC YYCONST short YYFARDATA YYACT[] = {
+ 699, 1398, 1121, 1466, 658, 1467, 639, 1024, 1465, 878,
+ 1464, 963, 784, 753, 964, 221, 775, 26, 698, 725,
+ 73, 75, 275, 414, 624, 877, 966, 1399, 535, 191,
+ 477, 1503, 150, 788, 751, 756, 1134, 110, 1065, 107,
+ 690, 852, 273, 153, 219, 660, 24, 44, 776, 218,
+ 307, 10, 190, 176, 78, 81, 6, 86, 5, 598,
+ 673, 262, 204, 515, 3, 188, 217, 983, 17, 301,
+ 603, 136, 76, 1550, 1194, 1242, 214, 264, 7, 1238,
+ 1057, 1239, 1113, 1111, 85, 1112, 580, 74, 715, 88,
+ 87, 137, 89, 300, 115, 56, 139, 712, 672, 113,
+ 1058, 98, 112, 178, 179, 180, 181, 74, 272, 696,
+ 322, 519, 1015, 461, 220, 56, 18, 452, 536, 338,
+ 278, 88, 87, 1021, 89, 268, 216, 269, 1240, 225,
+ 56, 265, 277, 277, 1228, 1229, 106, 1226, 1227, 590,
+ 277, 343, 361, 360, 359, 358, 654, 368, 345, 653,
+ 68, 310, 312, 314, 316, 318, 185, 1554, 460, 1126,
+ 1127, 1414, 98, 931, 932, 327, 277, 348, 339, 1027,
+ 342, 778, 1026, 779, 373, 366, 154, 277, 695, 133,
+ 694, 991, 379, 271, 362, 84, 258, 364, 363, 376,
+ 614, 192, 387, 105, 1519, 662, 513, 930, 365, 1059,
+ 369, 202, 203, 371, 370, 1487, 374, 1264, 596, 450,
+ 661, 451, 763, 372, 416, 469, 186, 467, 471, 470,
+ 442, 26, 74, 376, 456, 417, 418, 346, 376, 1559,
+ 352, 472, 474, 599, 353, 305, 483, 388, 88, 87,
+ 596, 89, 410, 1263, 1478, 500, 492, 1314, 457, 441,
+ 24, 1200, 357, 491, 435, 10, 825, 797, 787, 56,
+ 486, 432, 490, 428, 475, 478, 479, 773, 476, 429,
+ 494, 434, 17, 192, 108, 666, 511, 511, 528, 534,
+ 375, 433, 7, 351, 267, 321, 480, 481, 473, 485,
+ 152, 710, 74, 484, 1234, 540, 1345, 116, 1496, 1391,
+ 56, 1540, 499, 80, 79, 498, 543, 493, 1417, 571,
+ 959, 268, 1351, 1544, 574, 348, 575, 154, 576, 436,
+ 18, 266, 548, 1335, 1116, 578, 579, 504, 541, 46,
+ 420, 544, 421, 422, 423, 933, 934, 570, 935, 88,
+ 572, 947, 89, 573, 46, 594, 854, 855, 856, 1128,
+ 640, 641, 600, 135, 198, 88, 87, 962, 89, 199,
+ 1541, 200, 568, 1510, 192, 487, 1341, 201, 612, 154,
+ 755, 482, 277, 674, 1543, 510, 510, 527, 533, 74,
+ 605, 744, 745, 746, 195, 808, 182, 623, 943, 611,
+ 599, 581, 582, 1141, 497, 1233, 700, 1252, 1142, 196,
+ 565, 367, 375, 620, 595, 258, 610, 88, 87, 518,
+ 89, 74, 606, 607, 608, 609, 747, 748, 749, 1542,
+ 643, 613, 599, 537, 340, 341, 634, 1489, 348, 807,
+ 459, 618, 619, 621, 780, 1130, 321, 876, 648, 649,
+ 638, 88, 87, 177, 89, 1231, 88, 87, 847, 89,
+ 152, 781, 702, 754, 347, 650, 664, 1502, 413, 88,
+ 87, 670, 946, 1488, 651, 88, 87, 155, 89, 681,
+ 642, 1518, 1126, 1127, 545, 743, 1118, 177, 993, 994,
+ 995, 996, 177, 587, 505, 859, 352, 1513, 667, 988,
+ 353, 678, 80, 79, 479, 177, 647, 692, 646, 1512,
+ 782, 1511, 61, 62, 47, 63, 536, 1508, 357, 645,
+ 685, 198, 741, 669, 480, 481, 199, 689, 200, 82,
+ 63, 74, 701, 479, 201, 711, 680, 453, 72, 679,
+ 88, 87, 519, 89, 512, 520, 74, 507, 508, 351,
+ 686, 195, 88, 480, 481, 89, 74, 723, 71, 70,
+ 354, 355, 356, 538, 691, 216, 196, 1141, 225, 1506,
+ 1241, 724, 1142, 675, 676, 677, 720, 657, 721, 49,
+ 50, 51, 52, 53, 54, 55, 671, 709, 74, 644,
+ 479, 730, 1504, 80, 79, 714, 80, 79, 348, 49,
+ 50, 51, 52, 53, 54, 55, 719, 74, 1141, 716,
+ 480, 481, 726, 1142, 49, 50, 51, 52, 53, 54,
+ 55, 156, 157, 158, 69, 758, 74, 542, 74, 88,
+ 87, 592, 89, 600, 67, 764, 765, 155, 88, 87,
+ 688, 89, 74, 783, 98, 638, 729, 1320, 1319, 1318,
+ 1317, 750, 74, 697, 325, 74, 703, 1172, 1171, 1170,
+ 1169, 542, 705, 348, 706, 177, 377, 1499, 324, 769,
+ 770, 771, 1337, 1338, 1339, 642, 815, 789, 813, 819,
+ 853, 88, 87, 816, 89, 822, 541, 1180, 801, 802,
+ 80, 79, 798, 823, 88, 812, 806, 89, 74, 66,
+ 818, 626, 627, 628, 74, 1117, 833, 834, 762, 1450,
+ 495, 826, 216, 786, 591, 225, 1439, 800, 793, 803,
+ 74, 809, 796, 636, 846, 824, 382, 383, 384, 385,
+ 817, 152, 74, 857, 74, 56, 629, 630, 631, 922,
+ 74, 740, 821, 49, 50, 51, 52, 53, 54, 55,
+ 1437, 850, 936, 937, 860, 1490, 516, 761, 88, 87,
+ 375, 89, 832, 1327, 844, 1247, 1243, 1244, 1245, 1246,
+ 1179, 1435, 769, 600, 949, 192, 845, 942, 1433, 848,
+ 276, 156, 157, 158, 49, 50, 51, 52, 53, 54,
+ 55, 97, 74, 924, 111, 925, 926, 927, 928, 929,
+ 952, 1001, 1416, 1407, 985, 152, 635, 938, 1406, 277,
+ 1013, 965, 362, 1326, 1011, 74, 354, 355, 356, 442,
+ 1000, 1009, 528, 605, 1404, 585, 954, 584, 583, 145,
+ 1390, 1012, 948, 1388, 586, 799, 960, 955, 277, 1017,
+ 958, 692, 692, 1032, 1378, 1376, 1237, 350, 441, 999,
+ 1008, 817, 1022, 435, 997, 1007, 851, 1374, 1037, 1014,
+ 432, 817, 428, 849, 1019, 1035, 1016, 1018, 429, 1039,
+ 434, 989, 326, 323, 88, 87, 94, 89, 74, 1372,
+ 433, 1033, 1034, 1045, 352, 772, 828, 277, 353, 1030,
+ 80, 79, 479, 1050, 277, 56, 1370, 1368, 691, 691,
+ 88, 87, 348, 89, 74, 954, 357, 337, 155, 348,
+ 1366, 1364, 480, 481, 668, 1362, 817, 1359, 436, 998,
+ 1006, 527, 1356, 1123, 1354, 1350, 56, 1334, 1312, 1055,
+ 152, 1196, 88, 87, 718, 89, 177, 351, 1044, 1053,
+ 193, 615, 1043, 194, 1051, 348, 1042, 352, 1041, 46,
+ 352, 353, 1122, 1023, 768, 820, 1067, 814, 1068, 1126,
+ 1127, 501, 733, 617, 616, 1124, 198, 177, 1132, 357,
+ 145, 199, 357, 200, 88, 87, 577, 89, 758, 201,
+ 564, 1300, 155, 1236, 308, 1119, 455, 109, 1054, 1140,
+ 1129, 92, 529, 1138, 1125, 1394, 195, 1298, 1115, 1185,
+ 351, 1183, 1184, 351, 88, 87, 1186, 89, 1178, 277,
+ 177, 196, 1296, 1491, 1064, 1060, 1061, 1062, 1063, 1025,
+ 1492, 1133, 145, 1182, 1415, 328, 329, 330, 1294, 1181,
+ 956, 96, 1301, 590, 104, 103, 102, 101, 1219, 99,
+ 100, 105, 56, 1, 1175, 1332, 1195, 1173, 1299, 1203,
+ 332, 941, 156, 157, 158, 1167, 1187, 1188, 1189, 1190,
+ 1230, 766, 1202, 1297, 1165, 1232, 1191, 1192, 1193, 80,
+ 79, 479, 588, 1131, 1223, 1225, 1224, 1222, 984, 1295,
+ 1235, 1197, 1400, 88, 87, 1163, 89, 1198, 1161, 1199,
+ 945, 480, 481, 589, 1218, 1176, 189, 708, 1174, 88,
+ 87, 1005, 89, 1003, 1004, 1159, 1168, 155, 1010, 46,
+ 707, 205, 152, 1157, 704, 1166, 633, 1412, 412, 187,
+ 625, 790, 61, 62, 47, 63, 156, 157, 158, 1248,
+ 1177, 192, 192, 192, 192, 177, 1164, 277, 1268, 1162,
+ 46, 192, 192, 192, 331, 1266, 333, 334, 335, 336,
+ 1155, 625, 1251, 192, 1411, 1265, 1160, 1269, 1410, 1271,
+ 1273, 1274, 1255, 1277, 1158, 1279, 1280, 1281, 1282, 1283,
+ 1284, 1285, 1270, 1287, 1288, 1289, 1290, 1291, 1292, 1293,
+ 1254, 1401, 1259, 56, 1302, 1303, 1153, 1305, 1304, 1151,
+ 1272, 1149, 1275, 1276, 1147, 1278, 1221, 1048, 1267, 1047,
+ 836, 1156, 1307, 1286, 354, 355, 356, 1145, 1143, 49,
+ 50, 51, 52, 53, 54, 55, 742, 1316, 118, 119,
+ 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
+ 130, 131, 132, 665, 1313, 352, 317, 1154, 454, 353,
+ 1152, 315, 1150, 313, 1328, 1148, 378, 1330, 1331, 521,
+ 1321, 156, 157, 158, 311, 45, 46, 357, 1146, 1144,
+ 1336, 1340, 309, 1333, 817, 41, 43, 354, 355, 356,
+ 354, 355, 356, 1135, 1342, 277, 277, 1140, 1552, 526,
+ 590, 88, 87, 306, 89, 63, 415, 308, 351, 155,
+ 1315, 1343, 308, 1257, 308, 56, 277, 503, 1452, 512,
+ 590, 1451, 507, 508, 140, 308, 1380, 1381, 1382, 1383,
+ 1384, 1385, 1386, 308, 944, 1347, 63, 177, 590, 1539,
+ 590, 1329, 1344, 1392, 1393, 193, 531, 1346, 194, 532,
+ 1397, 1396, 940, 831, 308, 138, 1379, 1402, 1403, 1031,
+ 1524, 590, 923, 1408, 590, 590, 1395, 830, 811, 767,
+ 760, 198, 177, 1405, 717, 566, 199, 349, 200, 258,
+ 303, 792, 1564, 117, 201, 97, 1555, 1553, 1140, 49,
+ 50, 51, 52, 53, 54, 55, 1546, 1523, 817, 1486,
+ 1485, 195, 1484, 1454, 1449, 1446, 1443, 1442, 1438, 56,
+ 524, 1436, 1434, 1432, 1419, 1413, 196, 46, 1409, 1389,
+ 49, 50, 51, 52, 53, 54, 55, 134, 1445, 1387,
+ 1377, 1375, 1373, 1371, 1369, 1367, 1365, 1363, 1361, 1360,
+ 526, 1455, 1456, 1457, 1358, 1357, 1355, 1453, 1353, 1444,
+ 1448, 1352, 63, 156, 157, 158, 1349, 1324, 1348, 1325,
+ 1458, 1323, 523, 1311, 1470, 525, 1310, 1471, 1469, 1468,
+ 1306, 1256, 1253, 258, 1476, 693, 1220, 88, 87, 1114,
+ 89, 1052, 1481, 1038, 1480, 1036, 1029, 1028, 1020, 961,
+ 951, 950, 56, 1498, 939, 1483, 1505, 1507, 1509, 858,
+ 1505, 1507, 1509, 530, 841, 840, 1495, 1507, 1516, 838,
+ 1520, 1517, 1515, 1514, 1522, 1521, 88, 835, 829, 89,
+ 827, 56, 810, 1497, 1500, 1501, 791, 774, 738, 46,
+ 737, 1538, 736, 1493, 735, 734, 49, 50, 51, 52,
+ 53, 54, 55, 732, 731, 1529, 1505, 1507, 1509, 684,
+ 637, 524, 569, 425, 424, 344, 258, 320, 206, 1562,
+ 1547, 1525, 817, 1545, 1479, 1475, 1474, 1473, 1472, 1447,
+ 1534, 1441, 1440, 1431, 1430, 354, 355, 356, 1551, 1429,
+ 1549, 1428, 1427, 1548, 1535, 1536, 1537, 449, 1426, 1425,
+ 1424, 1423, 1561, 63, 1422, 1421, 1560, 1563, 1420, 1418,
+ 1300, 1298, 1296, 523, 1294, 1322, 525, 1175, 1173, 1557,
+ 88, 1558, 1167, 89, 1556, 1526, 1527, 1528, 1530, 1531,
+ 1532, 1533, 1165, 46, 1163, 96, 1161, 1159, 104, 103,
+ 102, 101, 56, 99, 100, 105, 1157, 1155, 1153, 1151,
+ 1149, 1309, 1308, 817, 1250, 1249, 1066, 1056, 1049, 1040,
+ 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
+ 255, 256, 257, 987, 986, 953, 843, 59, 842, 839,
+ 837, 208, 259, 210, 228, 212, 213, 49, 50, 51,
+ 52, 53, 54, 55, 728, 41, 43, 727, 713, 687,
+ 683, 682, 663, 88, 632, 602, 89, 601, 593, 567,
+ 547, 546, 61, 62, 47, 63, 46, 496, 419, 411,
+ 874, 386, 319, 223, 304, 522, 514, 868, 517, 869,
+ 870, 871, 509, 506, 56, 502, 302, 222, 36, 184,
+ 93, 33, 468, 466, 465, 46, 464, 463, 244, 462,
+ 227, 243, 215, 209, 245, 246, 247, 248, 249, 250,
+ 251, 252, 253, 254, 255, 256, 257, 863, 864, 865,
+ 95, 59, 226, 224, 207, 208, 259, 210, 228, 212,
+ 213, 211, 879, 31, 56, 1002, 992, 439, 795, 41,
+ 43, 431, 794, 430, 427, 539, 1046, 270, 83, 49,
+ 50, 51, 52, 53, 54, 55, 61, 62, 47, 63,
+ 29, 57, 862, 866, 867, 34, 872, 223, 25, 873,
+ 16, 263, 15, 14, 261, 13, 260, 12, 11, 9,
+ 8, 222, 1086, 4, 2, 234, 242, 245, 246, 247,
+ 248, 249, 250, 251, 252, 253, 254, 255, 256, 257,
+ 990, 241, 240, 239, 59, 238, 46, 237, 208, 259,
+ 210, 228, 212, 213, 236, 235, 226, 224, 233, 232,
+ 231, 230, 41, 43, 229, 114, 77, 42, 56, 38,
+ 30, 58, 32, 59, 752, 656, 655, 1482, 299, 61,
+ 62, 47, 63, 49, 50, 51, 52, 53, 54, 55,
+ 223, 41, 43, 90, 183, 861, 1139, 757, 785, 1258,
+ 957, 1137, 1136, 604, 222, 1461, 1460, 1459, 61, 62,
+ 47, 63, 1477, 1463, 1462, 60, 35, 1201, 1120, 597,
+ 659, 21, 777, 91, 37, 1069, 739, 65, 64, 197,
+ 875, 39, 40, 0, 426, 0, 0, 0, 0, 226,
+ 224, 0, 982, 981, 980, 0, 975, 974, 973, 972,
+ 0, 970, 971, 105, 0, 979, 978, 977, 976, 0,
+ 0, 0, 969, 967, 0, 0, 49, 50, 51, 52,
+ 53, 54, 55, 0, 0, 0, 0, 0, 0, 0,
+ 38, 30, 58, 32, 59, 0, 19, 20, 46, 22,
+ 23, 48, 0, 27, 28, 49, 50, 51, 52, 53,
+ 54, 55, 41, 43, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 61,
+ 62, 47, 63, 0, 0, 0, 60, 35, 968, 0,
+ 0, 0, 21, 0, 0, 37, 444, 1097, 0, 874,
+ 0, 0, 39, 40, 0, 0, 868, 0, 869, 870,
+ 871, 0, 0, 0, 0, 0, 1073, 1074, 0, 1081,
+ 1095, 1075, 1076, 1077, 1078, 0, 1079, 1080, 0, 1096,
+ 1082, 1083, 1084, 1085, 0, 0, 0, 0, 0, 0,
+ 0, 0, 46, 0, 0, 0, 863, 864, 865, 0,
+ 0, 0, 0, 0, 0, 0, 0, 19, 20, 0,
+ 22, 23, 48, 0, 27, 28, 49, 50, 51, 52,
+ 53, 54, 55, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 448, 0, 58, 32, 59, 0, 0, 0,
+ 444, 862, 866, 867, 0, 872, 445, 0, 873, 0,
+ 0, 446, 0, 0, 41, 43, 0, 146, 874, 0,
+ 0, 0, 0, 0, 0, 868, 0, 869, 870, 871,
+ 0, 61, 62, 47, 63, 0, 437, 438, 0, 921,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 447, 0, 0, 0,
+ 0, 0, 0, 0, 0, 863, 864, 865, 49, 50,
+ 51, 52, 53, 54, 55, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 448, 0, 58, 32,
+ 59, 443, 440, 0, 0, 0, 0, 0, 0, 0,
+ 445, 0, 0, 0, 0, 446, 0, 0, 41, 43,
+ 862, 866, 867, 0, 872, 0, 0, 873, 49, 50,
+ 51, 52, 53, 54, 55, 61, 62, 47, 63, 1494,
+ 437, 438, 1071, 1072, 0, 1087, 1088, 1089, 0, 1090,
+ 1091, 0, 0, 1092, 1093, 0, 1094, 0, 0, 0,
+ 447, 0, 0, 0, 0, 0, 0, 0, 0, 1070,
+ 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107,
+ 1108, 1109, 1110, 893, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 443, 440, 920, 0, 0,
+ 0, 0, 885, 886, 0, 894, 911, 887, 888, 889,
+ 890, 0, 891, 892, 0, 912, 895, 896, 897, 898,
+ 893, 0, 49, 50, 51, 52, 53, 54, 55, 0,
+ 0, 0, 0, 0, 920, 146, 0, 0, 0, 885,
+ 886, 0, 894, 911, 887, 888, 889, 890, 0, 891,
+ 892, 0, 912, 895, 896, 897, 898, 0, 0, 0,
+ 909, 0, 913, 0, 0, 175, 0, 915, 0, 151,
+ 148, 163, 161, 170, 0, 164, 165, 166, 167, 0,
+ 168, 169, 917, 0, 171, 172, 173, 174, 563, 0,
+ 0, 142, 162, 152, 0, 0, 0, 909, 0, 913,
+ 141, 147, 0, 0, 915, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 918, 143, 144, 149, 917,
+ 555, 0, 549, 550, 551, 552, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 146, 0, 0, 0, 0,
+ 352, 0, 0, 0, 768, 0, 0, 0, 0, 0,
+ 160, 0, 918, 0, 0, 0, 0, 0, 557, 558,
+ 559, 560, 357, 0, 554, 0, 0, 0, 561, 562,
+ 553, 0, 0, 0, 0, 982, 981, 980, 0, 975,
+ 974, 973, 972, 0, 970, 971, 105, 0, 979, 978,
+ 977, 976, 0, 622, 0, 969, 967, 0, 0, 0,
+ 0, 0, 0, 0, 0, 880, 0, 881, 882, 883,
+ 884, 899, 900, 901, 916, 902, 903, 904, 905, 906,
+ 907, 908, 910, 914, 0, 0, 0, 919, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 880, 0, 881, 882, 883, 884, 899, 900,
+ 901, 916, 902, 903, 904, 905, 906, 907, 908, 910,
+ 914, 968, 88, 87, 919, 89, 0, 0, 0, 0,
+ 155, 0, 556, 175, 0, 0, 0, 151, 148, 163,
+ 161, 170, 0, 164, 165, 166, 167, 0, 168, 169,
+ 0, 0, 171, 172, 173, 174, 146, 0, 177, 142,
+ 162, 352, 0, 0, 0, 353, 0, 0, 141, 147,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 357, 143, 144, 149, 0, 0, 175,
+ 0, 0, 0, 0, 0, 163, 161, 170, 0, 164,
+ 165, 166, 167, 0, 168, 169, 0, 0, 171, 172,
+ 173, 174, 0, 0, 622, 1261, 162, 0, 160, 159,
+ 0, 0, 88, 87, 0, 89, 0, 0, 0, 0,
+ 155, 0, 0, 175, 0, 0, 0, 151, 148, 163,
+ 161, 170, 0, 164, 165, 166, 167, 0, 168, 169,
+ 0, 0, 171, 172, 173, 174, 0, 0, 177, 142,
+ 162, 0, 0, 1262, 0, 0, 0, 0, 141, 147,
+ 0, 0, 0, 0, 156, 157, 158, 0, 0, 0,
+ 0, 1260, 0, 0, 143, 144, 149, 0, 0, 0,
+ 0, 0, 0, 0, 297, 198, 146, 0, 0, 0,
+ 199, 352, 200, 0, 0, 353, 0, 0, 201, 0,
+ 0, 63, 0, 0, 0, 0, 0, 0, 160, 0,
+ 354, 355, 356, 357, 0, 195, 284, 0, 279, 280,
+ 281, 282, 283, 0, 640, 641, 0, 287, 0, 0,
+ 196, 0, 0, 0, 0, 0, 285, 0, 0, 0,
+ 295, 0, 286, 0, 622, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 288, 289, 290, 291, 292, 293,
+ 294, 298, 0, 0, 156, 157, 158, 296, 0, 0,
+ 0, 0, 0, 88, 87, 0, 89, 0, 0, 0,
+ 146, 155, 0, 0, 175, 0, 0, 0, 151, 148,
+ 163, 161, 170, 0, 164, 165, 166, 167, 0, 168,
+ 169, 0, 0, 171, 172, 173, 174, 0, 0, 177,
+ 142, 162, 0, 0, 0, 0, 0, 0, 0, 141,
+ 147, 0, 0, 0, 348, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 143, 144, 149, 274, 1217,
+ 1216, 1211, 0, 1210, 1209, 1208, 1207, 146, 1205, 1206,
+ 105, 0, 1215, 1214, 1213, 1212, 0, 0, 0, 0,
+ 0, 1204, 0, 0, 0, 0, 0, 0, 0, 160,
+ 0, 354, 355, 356, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 640, 641, 982, 981, 980,
+ 0, 975, 974, 973, 972, 0, 970, 971, 105, 0,
+ 979, 978, 977, 976, 0, 274, 0, 969, 967, 0,
+ 0, 0, 0, 88, 87, 0, 89, 0, 0, 0,
+ 0, 155, 0, 0, 175, 156, 157, 158, 151, 148,
+ 163, 161, 170, 0, 164, 165, 166, 167, 0, 168,
+ 169, 0, 0, 171, 172, 173, 174, 146, 0, 177,
+ 142, 162, 0, 0, 0, 0, 0, 0, 0, 141,
+ 147, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 968, 0, 143, 144, 149, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 274, 0, 88, 87, 160,
+ 89, 354, 355, 356, 146, 155, 0, 0, 175, 0,
+ 0, 0, 151, 148, 163, 161, 170, 0, 164, 165,
+ 166, 167, 0, 168, 169, 0, 0, 171, 172, 173,
+ 174, 0, 0, 177, 142, 162, 0, 0, 0, 0,
+ 0, 0, 0, 141, 147, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 156, 157, 158, 0, 143,
+ 144, 149, 274, 805, 88, 87, 0, 89, 0, 0,
+ 0, 0, 155, 0, 0, 175, 0, 0, 0, 151,
+ 148, 163, 161, 170, 0, 164, 165, 166, 167, 0,
+ 168, 169, 0, 160, 171, 172, 173, 174, 146, 0,
+ 177, 142, 162, 0, 0, 0, 0, 804, 0, 0,
+ 141, 147, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 143, 144, 149, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 156,
+ 157, 158, 0, 0, 0, 0, 274, 0, 0, 0,
+ 160, 159, 0, 0, 88, 87, 146, 89, 0, 0,
+ 0, 0, 155, 0, 0, 175, 0, 0, 0, 151,
+ 148, 163, 161, 170, 0, 164, 165, 166, 167, 0,
+ 168, 169, 0, 0, 171, 172, 173, 174, 0, 0,
+ 177, 142, 162, 0, 0, 0, 0, 0, 0, 0,
+ 141, 147, 0, 0, 0, 0, 156, 157, 158, 0,
+ 0, 0, 0, 0, 274, 0, 143, 144, 149, 0,
+ 0, 88, 87, 0, 89, 0, 0, 0, 0, 155,
+ 0, 0, 175, 0, 0, 0, 151, 148, 163, 161,
+ 170, 0, 164, 165, 166, 167, 0, 168, 169, 0,
+ 160, 171, 172, 173, 174, 0, 0, 177, 142, 162,
+ 0, 0, 0, 0, 0, 0, 0, 759, 147, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 143, 144, 149, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 146, 0, 0, 0, 0, 156, 157, 158, 0,
+ 0, 0, 0, 0, 0, 88, 87, 160, 89, 0,
+ 0, 0, 0, 155, 0, 0, 175, 0, 0, 0,
+ 151, 148, 163, 161, 170, 0, 164, 165, 166, 167,
+ 0, 168, 169, 0, 0, 171, 172, 173, 174, 0,
+ 0, 177, 142, 162, 0, 0, 146, 0, 0, 0,
+ 0, 141, 147, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 156, 157, 158, 0, 143, 144, 149,
+ 0, 0, 0, 88, 87, 0, 89, 0, 0, 0,
+ 0, 155, 0, 0, 175, 0, 0, 0, 151, 148,
+ 163, 161, 170, 0, 164, 165, 166, 167, 0, 168,
+ 169, 652, 146, 171, 172, 173, 174, 0, 0, 177,
+ 142, 162, 88, 87, 0, 89, 0, 0, 0, 141,
+ 147, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 143, 144, 149, 0, 0,
+ 0, 0, 0, 0, 0, 0, 409, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 146, 156, 157, 158,
+ 988, 0, 0, 0, 0, 0, 0, 0, 0, 458,
+ 0, 0, 0, 0, 391, 0, 0, 0, 407, 0,
+ 0, 389, 390, 0, 0, 0, 393, 394, 405, 395,
+ 396, 397, 398, 399, 400, 401, 402, 392, 0, 0,
+ 0, 0, 0, 406, 0, 0, 404, 0, 0, 0,
+ 146, 0, 0, 403, 722, 0, 0, 0, 0, 0,
+ 0, 0, 408, 0, 0, 156, 157, 158, 488, 175,
+ 489, 0, 0, 151, 148, 163, 161, 170, 0, 164,
+ 165, 166, 167, 0, 168, 169, 0, 0, 171, 172,
+ 173, 174, 0, 0, 177, 142, 162, 0, 0, 0,
+ 0, 0, 0, 0, 141, 147, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 143, 144, 149, 380, 175, 381, 0, 0, 151, 148,
+ 163, 161, 170, 0, 164, 165, 166, 167, 0, 168,
+ 169, 0, 0, 171, 172, 173, 174, 0, 0, 0,
+ 142, 162, 0, 0, 160, 0, 0, 0, 0, 141,
+ 147, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 143, 144, 149, 0, 0,
+ 175, 0, 0, 0, 151, 148, 163, 161, 170, 0,
+ 164, 165, 166, 167, 0, 168, 169, 0, 0, 171,
+ 172, 173, 174, 0, 0, 0, 142, 162, 0, 160,
+ 0, 0, 0, 0, 0, 141, 147, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 143, 144, 149, 175, 0, 0, 0, 151, 148,
+ 163, 161, 170, 0, 164, 165, 166, 167, 0, 168,
+ 169, 0, 0, 171, 172, 173, 174, 0, 0, 0,
+ 142, 162, 0, 0, 0, 160, 0, 0, 0, 141,
+ 147, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 143, 144, 149, 175, 0,
+ 0, 0, 151, 148, 163, 161, 170, 0, 164, 165,
+ 166, 167, 0, 168, 169, 0, 0, 171, 172, 173,
+ 174, 0, 0, 0, 142, 162, 0, 0, 0, 160,
+ 0, 0, 0, 141, 147, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 143,
+ 144, 149, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 160
+};
+
+YYSTATIC YYCONST short YYFARDATA YYPACT[] = {
+-1000, 1543,-1000, 566, 501,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000, 491, 426, 425, 405,-1000,-1000,-1000, 28,
+ 28, -454, 39, 39,-1000,-1000,-1000, 396,-1000, -129,
+ 411,-1000, 890, 743, 7, 886, 28, -366, -369,-1000,
+ -171, 777, 7, 777,-1000,-1000,-1000, 90, 2292, 411,
+ 411, 411, 411,-1000,-1000, 124,-1000,-1000,-1000, -162,
+ 1048,-1000,-1000, 1046, 7, 7,-1000,-1000, 1403,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000, 28, -139,-1000,-1000,
+-1000,-1000, 359, -132, 2954, 1220,-1000,-1000,-1000,-1000,
+ 2430,-1000, 28,-1000, 1317,-1000, 1308, 1644, 7, 1233,
+ 1212, 1204, 1193, 1191, 1186, 1642, 1486, 18,-1000, 28,
+ 600, 662,-1000,-1000, 95, 1220, 411, 2954,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000, 1484, 166, 1303, 448, -244, -245, -246,
+ -247, 359,-1000, -118, 359, 661, 368,-1000,-1000, -76,
+-1000, 3547, 186, 1189,-1000,-1000,-1000,-1000,-1000, 3383,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+ 435,-1000,-1000,-1000,-1000,-1000, 1220, 1641, 326, 1220,
+ 1220, 1220,-1000, 3222, 79,-1000,-1000, 1639, 1047, 2854,
+-1000, 3547,-1000,-1000,-1000, 216, 216,-1000, 1638,-1000,
+-1000, 29, 1483, 1482, 1779, 1432,-1000,-1000, 28,-1000,
+ 28, 77,-1000,-1000,-1000,-1000, 1170,-1000,-1000,-1000,
+-1000,-1000, 885, 28, 3183,-1000, 67, -94,-1000,-1000,
+ 424, 28, 39, 228, 7, 424, 661, 3328, 2954, -95,
+ 216, 2854, 1637,-1000, 282,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+ 826, 71, 1114, 857,-1000, 87,-1000, 298, 359,-1000,
+-1000, 2954,-1000,-1000, 181, 899, 216, 411,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000, 1631, 1630, 2084,
+ 877, 275, 1301, 1629, 79, 1481, 0,-1000, 28, 0,
+-1000, 39,-1000, 28,-1000, 28,-1000, 28,-1000,-1000,
+-1000,-1000, 873,-1000, 28, 28,-1000, 1220,-1000,-1000,
+-1000, -387,-1000,-1000,-1000,-1000,-1000, 662, 488, 94,
+-1000,-1000, 1220, 1022,-1000, 1292, 581, 1628,-1000, 82,
+ 411, 115,-1000,-1000,-1000, 1627, 1625, 3547, 411, 411,
+ 411, 411,-1000, 359,-1000,-1000, 3547, 604,-1000, 1220,
+-1000, -90,-1000, 899, 838, 861, 860, 411, 411, 2693,
+-1000,-1000,-1000,-1000,-1000,-1000, 28, 1292, 1081,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000, 362,-1000,-1000,-1000, 1624,
+ 1045,-1000, 673, 1479,-1000,-1000, 2553,-1000,-1000, 28,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000, 386,
+ 375, 373,-1000,-1000,-1000,-1000,-1000, 28, 28, 332,
+ 3115,-1000,-1000, -214, -217,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000, -65, 1622,-1000, 28, 1165, 1, 216, 813,
+ 28,-1000, -94, 63, 63, 63, 63, 2954, 282,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+ 1621, 1620, 1478,-1000,-1000,-1000, 2693,-1000,-1000,-1000,
+-1000, 1292, 1619, 7, 3547,-1000, 424, 1320,-1000, -136,
+ -138,-1000,-1000, -356,-1000,-1000, 7, 354, 391, 7,
+-1000,-1000, 1043,-1000,-1000, 7,-1000, 7,-1000, 1039,
+ 1026,-1000,-1000, 411, -177, -371, 1618,-1000,-1000,-1000,
+-1000, 411, -380,-1000,-1000, -350,-1000,-1000,-1000, 1300,
+-1000, 831, 411, 3547, 1220, 3493, 28, 53, 1187,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000, 1617,-1000,-1000,-1000,
+-1000,-1000,-1000, 1614,-1000,-1000, 1317, 53, 1473,-1000,
+ 1472, 859, 1464, 1463, 1461, 1459, 1457,-1000, 468, 1148,
+-1000, 86, 1220,-1000,-1000,-1000, 52, 411, 53, 330,
+ 108, 3021,-1000,-1000, 1296, 1220,-1000, 654,-1000,-1000,
+ -63, 2954, 2954, 989, 1295, 899, 1220, 1220, 1220, 1220,
+-1000, 2392,-1000, 1220,-1000, 411, 411, 411, 782, 1220,
+ -7, 1220, 147, 1456,-1000, 128,-1000,-1000,-1000,-1000,
+-1000,-1000, 28,-1000, 1292,-1000,-1000, 661, -16, 1051,
+-1000,-1000, 1220, 1455, 1226,-1000,-1000,-1000,-1000,-1000,
+-1000, -17, 216, 734, 2954, 2787, 59, 488, 1451, 1294,
+-1000,-1000, 3493, -65, 854, 28, -22, 3547, 28, 1220,
+ 852,-1000,-1000,-1000, 424,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000, 28, 39,-1000, -18, 1220, 53, 1449, 836,
+ 1447, 1293, 1279,-1000, 79, 28, 28, 1446, 1132,-1000,
+-1000, 1292, 1600, 1438, 1599, 1434, 1433, 1598, 1596, 1220,
+ 411,-1000, 411, 28, 131, 411, 7, 2954, 411, 753,
+ 902, 192, -157, 1428, 96, 1824, 120, 2016, 28,-1000,
+ 1291,-1000, 883,-1000, 883, 883, 883, 883, 883, -120,
+-1000, 28, 28, 411,-1000,-1000,-1000,-1000,-1000,-1000,
+ 1220, 1423, 1278, 980,-1000,-1000, 263, 1260, 1019, 199,
+ 78,-1000, -42, 28, 1420, 1419,-1000, 3547, 1595, 1189,
+ 1189, 1189, 411, 411,-1000, 958, 270, 128,-1000,-1000,
+-1000,-1000,-1000, 1418, 232, 1635, 1007, -22, 1594, 1593,
+ 3439,-1000,-1000, 1685, 56, 666, 973, -22, 3547, 28,
+ 1220, -337, 411, 1220,-1000,-1000, 3547,-1000,-1000, 1220,
+-1000, -65, 192, 1417, -266,-1000,-1000, 1220, 2693, 850,
+ 948, -144, -147, 1416, 1415, 411, 1288,-1000, -65,-1000,
+ 424, 424,-1000,-1000,-1000,-1000, 354,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000, 1189, 1220, 1414, 28, 1220, 1412,
+-1000, 411, -22, 1579, 845, 843, 839, 835,-1000, 53,
+ 1715,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000, 1131, 1129, 1578, 948, 79, 1410, 887, 7,
+ 1577, -400, -78,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000, 724,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000, 1576, 1576,-1000, 1576,
+ 1750,-1000,-1000, -412,-1000, -402,-1000,-1000, -417,-1000,
+-1000,-1000, 1408,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+ 79,-1000,-1000,-1000,-1000,-1000, 61, 432, 1220,-1000,
+ 53, 630, 224,-1000, 3021, 312, 1002,-1000,-1000,-1000,
+-1000,-1000, 899, -65, 1189, 1220,-1000, 411, 1219, 2954,
+-1000,-1000,-1000, 200,-1000,-1000,-1000, 1158, 1157, 1144,
+ 1141, 1139, 1136, 1100, 1063, 1055, 1038, 1035, 1014, 1005,
+ 366, 997, 994, 7, 637, 1051, -65, -65, 28, 934,
+-1000,-1000,-1000, 661, 661, 661, 661,-1000,-1000,-1000,
+-1000,-1000,-1000, 661, 661, 661,-1000,-1000,-1000,-1000,
+-1000, -434, 2693, 828,-1000, 661, 1220, 1187,-1000, 79,
+-1000, 79, -23,-1000,-1000, 2602, 79, 28,-1000,-1000,
+ 1220,-1000, 1405,-1000,-1000, 1128,-1000,-1000, -301, 1050,
+ 2016,-1000,-1000,-1000,-1000, 1292,-1000, -254, -257, 28,
+-1000,-1000,-1000,-1000, 352, 169, 53, 882, 745,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000, -423,-1000,-1000, 37,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000, 475,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000, 28,-1000,
+-1000,-1000,-1000, 1575, 1292, 1574,-1000,-1000,-1000,-1000,
+-1000, 274, 1401, 1219,-1000, 128, 1400, 1239,-1000, 2348,
+-1000,-1000,-1000, -56, 28, 829, 28, 2650, 28, 314,
+ 28, 795, 28, 39, 28, 28, 28, 28, 28, 28,
+ 28, 39, 28, 28, 28, 28, 28, 28, 28, 978,
+ 962, 947, 931, 28, 28, -160, 28, 1399, 1292,-1000,
+-1000, 1572, 1571, 1395, 1392, 825,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000, 216, -27,-1000, 1240,-1000,-1000,
+ -22,-1000,-1000, 1292,-1000, 1570, 1569, 1568, 1567, 1566,
+ 1557, 356, 1556, 1554, 1552, 1542, 1538, 1537,-1000,-1000,
+-1000, 354,-1000, 1535, 1390, 1386,-1000,-1000,-1000,-1000,
+ 1388,-1000, 710, 28,-1000, 1267, 28, 28, 974, 53,
+ 824,-1000,-1000,-1000,-1000,-1000,-1000,-1000, 60, 28,
+ 381, 241,-1000,-1000,-1000,-1000,-1000, 2954, 205,-1000,
+-1000,-1000, 1011, 1387, 1385, 822, 49, 1380, 1377, 821,
+ 1375, 819, 1374, 1373, 814, 1368, 1367, 812, 1366, 808,
+ 1365, 807, 1364, 794, 1363, 793, 1362, 776, 1361, 754,
+ 1360, 742, 1359, 741, 39, 28, 28, 28, 28, 28,
+ 28, 28, 1358, 730, 1348, 727,-1000, 174, -65, -65,
+-1000,-1000, 923, 3547, -22, -65, 1012, 1534, 1532, 1531,
+ 1530, 1113, -65,-1000,-1000,-1000,-1000, 28, 721, 53,
+ 705, 700, 28, 1292,-1000,-1000, 1347, 1090, 1086, 1049,
+ 1344,-1000, 36,-1000, 953, 699, 45,-1000,-1000,-1000,
+ 1529, 1343,-1000,-1000, 1528,-1000, 1525,-1000,-1000, 1524,
+-1000,-1000, 1521,-1000, 1520,-1000, 1519,-1000, 1518,-1000,
+ 1512,-1000, 1511,-1000, 1509,-1000, 1504,-1000, 1503, 1342,
+ 675, 1341, 668, 1340, 647, 1337, 613,-1000, 1502,-1000,
+ 1501,-1000, 1336, 1335,-1000, 2693, 1012, 1334, 1499,-1000,
+ 398, 354, 1333, 606,-1000, 1247,-1000, 2053, 1332,-1000,
+ 28, 28, 28,-1000,-1000, 2650,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000, 1498,-1000, 1497,-1000, 1496,-1000, 1495,
+-1000,-1000,-1000,-1000, -30, 1494, 948, -65,-1000,-1000,
+-1000, 53,-1000, 887,-1000, 1331, 1329, 1328,-1000, 164,
+ 704, 2188, 257, 616, 416, 541, 518, 466, 322, 460,
+ 458, 446,-1000,-1000,-1000,-1000, 430, 153, -22, -65,
+-1000, 1326, 1207, 1265,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000, 38,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000, 319, 378, 333, 272,-1000,-1000,
+-1000, 1493, 1325,-1000,-1000,-1000,-1000,-1000,-1000,-1000,
+-1000,-1000,-1000,-1000,-1000,-1000,-1000,-1000, 1490, 53,
+-1000,-1000,-1000,-1000,-1000, -65, -435, 28, 1227, 1316,
+ -199, 1315,-1000,-1000, 216,-1000, 3547, 2693, -45, -22,
+ 1012, 1489, -65, 1311,-1000
+};
+
+YYSTATIC YYCONST short YYFARDATA YYPGO[] = {
+ 0, 53, 57, 6, 1900, 43, 40, 29, 1899, 0,
+ 1898, 1897, 1896, 195, 50, 1895, 1893, 2, 1892, 48,
+ 38, 1, 27, 30, 31, 4, 1890, 45, 22, 59,
+ 1889, 136, 39, 9, 25, 7, 13, 1888, 41, 1887,
+ 14, 26, 1884, 1883, 5, 3, 8, 10, 1882, 1877,
+ 1876, 1875, 32, 33, 70, 1873, 1872, 1871, 1870, 12,
+ 1869, 1868, 11, 1867, 35, 1866, 18, 36, 16, 24,
+ 42, 23, 458, 65, 1276, 52, 127, 1864, 1863, 1848,
+ 1847, 1846, 1845, 19, 34, 1844, 1353, 1837, 1836, 28,
+ 784, 119, 1835, 47, 1245, 1834, 1831, 1830, 1829, 1828,
+ 1825, 1824, 1817, 1815, 1813, 1812, 1811, 1796, 1795, 1033,
+ 1794, 64, 62, 1793, 58, 150, 56, 76, 1790, 1789,
+ 49, 1788, 1787, 1786, 1785, 1784, 1783, 61, 1782, 1781,
+ 1780, 66, 114, 44, 1778, 15, 284, 1775, 1771, 1770,
+ 1758, 1757, 1755, 1754, 1753, 1752, 1751, 1748, 1747, 770,
+ 1746, 1745, 1743, 1742, 1741, 1734, 1713, 1712, 60, 1711,
+ 1710, 113, 1709, 1708, 1707, 98, 1706, 1704, 1703, 1702,
+ 1701, 1700, 1699, 69, 1696, 67, 1698, 63, 1695, 484,
+ 1693, 1692, 1688, 1686, 1685, 1473
+};
+YYSTATIC YYCONST yyr_t YYFARDATA YYR1[]={
+
+ 0, 109, 109, 110, 110, 110, 110, 110, 110, 110,
+ 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
+ 110, 110, 110, 110, 110, 110, 110, 110, 110, 136,
+ 136, 36, 36, 133, 133, 133, 2, 2, 1, 1,
+ 1, 9, 24, 24, 23, 23, 23, 134, 134, 134,
+ 134, 134, 135, 135, 135, 135, 135, 135, 135, 135,
+ 135, 93, 93, 93, 93, 94, 94, 94, 94, 10,
+ 11, 73, 72, 72, 59, 61, 61, 61, 62, 62,
+ 62, 65, 65, 132, 132, 132, 60, 60, 60, 60,
+ 60, 60, 130, 130, 130, 119, 12, 12, 12, 12,
+ 12, 12, 118, 137, 113, 138, 139, 111, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
+ 77, 77, 77, 77, 77, 140, 140, 141, 141, 112,
+ 112, 142, 142, 56, 56, 57, 57, 69, 69, 18,
+ 18, 18, 18, 18, 19, 19, 68, 68, 67, 67,
+ 58, 21, 21, 22, 143, 143, 143, 143, 143, 143,
+ 143, 143, 143, 143, 143, 143, 143, 143, 143, 143,
+ 143, 143, 143, 116, 79, 79, 79, 79, 79, 79,
+ 79, 79, 79, 79, 79, 79, 79, 79, 79, 79,
+ 4, 4, 35, 35, 16, 16, 75, 75, 75, 75,
+ 75, 75, 75, 7, 7, 7, 7, 8, 8, 8,
+ 8, 8, 8, 8, 76, 74, 74, 74, 74, 74,
+ 74, 144, 144, 81, 81, 81, 145, 145, 150, 150,
+ 150, 150, 150, 150, 150, 150, 146, 82, 82, 82,
+ 147, 147, 151, 151, 151, 151, 151, 151, 151, 152,
+ 38, 38, 34, 34, 153, 114, 78, 78, 78, 78,
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 78,
+ 78, 78, 78, 78, 78, 78, 78, 78, 78, 83,
+ 83, 83, 83, 83, 83, 83, 83, 83, 83, 83,
+ 83, 83, 83, 83, 83, 3, 3, 3, 13, 13,
+ 13, 13, 13, 80, 80, 80, 80, 80, 80, 80,
+ 80, 80, 80, 80, 80, 80, 80, 80, 154, 115,
+ 115, 155, 155, 155, 155, 155, 155, 155, 155, 155,
+ 155, 155, 155, 155, 155, 155, 155, 155, 155, 155,
+ 155, 155, 155, 155, 155, 158, 159, 156, 161, 161,
+ 160, 160, 160, 163, 162, 162, 162, 162, 166, 166,
+ 166, 169, 164, 167, 168, 165, 165, 165, 117, 170,
+ 170, 172, 172, 172, 171, 171, 173, 173, 14, 14,
+ 174, 174, 174, 174, 174, 174, 174, 174, 174, 174,
+ 174, 174, 174, 174, 174, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
+ 41, 41, 41, 41, 175, 31, 31, 32, 32, 39,
+ 39, 39, 40, 40, 40, 40, 40, 40, 40, 40,
+ 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
+ 40, 40, 40, 40, 40, 40, 40, 40, 42, 42,
+ 42, 43, 43, 43, 47, 47, 46, 46, 45, 45,
+ 44, 44, 48, 48, 49, 49, 49, 50, 50, 50,
+ 50, 51, 51, 149, 95, 96, 97, 98, 99, 100,
+ 101, 102, 103, 104, 105, 106, 107, 108, 157, 157,
+ 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+ 157, 157, 157, 157, 157, 157, 157, 157, 157, 157,
+ 157, 6, 6, 6, 6, 6, 53, 53, 54, 54,
+ 55, 55, 25, 25, 26, 26, 27, 27, 27, 70,
+ 70, 70, 70, 70, 70, 70, 70, 70, 70, 5,
+ 5, 71, 71, 71, 71, 33, 33, 33, 33, 33,
+ 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
+ 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
+ 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
+ 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
+ 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
+ 20, 20, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+ 15, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+ 28, 28, 28, 28, 28, 52, 52, 52, 52, 52,
+ 52, 52, 52, 52, 52, 52, 52, 52, 52, 52,
+ 52, 52, 52, 30, 30, 29, 29, 29, 29, 29,
+ 131, 131, 131, 131, 131, 131, 64, 64, 64, 63,
+ 63, 87, 87, 84, 84, 85, 17, 17, 37, 37,
+ 37, 37, 37, 37, 37, 37, 86, 86, 86, 86,
+ 86, 86, 86, 86, 86, 86, 86, 86, 86, 86,
+ 86, 176, 176, 120, 120, 120, 120, 120, 120, 120,
+ 120, 120, 120, 120, 121, 121, 88, 88, 89, 89,
+ 177, 122, 90, 90, 90, 90, 90, 90, 90, 90,
+ 90, 90, 123, 123, 178, 178, 178, 66, 66, 179,
+ 179, 179, 179, 179, 179, 180, 182, 181, 124, 124,
+ 125, 125, 183, 183, 183, 183, 126, 148, 91, 91,
+ 91, 91, 91, 91, 91, 91, 91, 91, 127, 127,
+ 184, 184, 184, 184, 184, 184, 184, 128, 128, 92,
+ 92, 92, 129, 129, 185, 185, 185, 185 };
+YYSTATIC YYCONST yyr_t YYFARDATA YYR2[]={
+
+ 0, 0, 2, 4, 4, 3, 1, 1, 1, 1,
+ 1, 1, 4, 4, 4, 4, 1, 1, 1, 2,
+ 2, 3, 2, 2, 1, 1, 1, 4, 1, 0,
+ 2, 1, 3, 2, 4, 6, 1, 1, 1, 1,
+ 3, 1, 1, 1, 1, 4, 4, 4, 4, 4,
+ 4, 4, 2, 3, 2, 2, 2, 1, 1, 2,
+ 1, 2, 4, 6, 3, 5, 7, 9, 3, 4,
+ 7, 1, 1, 1, 2, 0, 2, 2, 0, 6,
+ 2, 1, 1, 1, 1, 1, 1, 1, 1, 3,
+ 2, 3, 1, 2, 3, 7, 0, 2, 2, 2,
+ 2, 2, 3, 3, 2, 1, 4, 3, 0, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 3, 3, 3, 3, 3,
+ 3, 2, 2, 2, 5, 0, 2, 0, 2, 0,
+ 2, 3, 1, 0, 1, 1, 3, 0, 3, 1,
+ 1, 1, 1, 1, 0, 2, 4, 3, 0, 2,
+ 3, 0, 1, 5, 3, 4, 4, 4, 1, 1,
+ 1, 1, 1, 2, 2, 4, 13, 22, 1, 1,
+ 5, 3, 4, 7, 0, 2, 2, 2, 2, 2,
+ 2, 2, 5, 2, 2, 2, 2, 2, 2, 5,
+ 0, 2, 0, 2, 0, 3, 9, 9, 7, 7,
+ 1, 1, 1, 2, 2, 1, 4, 0, 1, 1,
+ 2, 2, 2, 2, 4, 2, 5, 3, 2, 2,
+ 1, 4, 3, 0, 2, 2, 0, 2, 2, 2,
+ 2, 2, 1, 1, 1, 1, 9, 0, 2, 2,
+ 0, 2, 2, 2, 2, 1, 1, 1, 1, 1,
+ 0, 4, 1, 3, 1, 13, 0, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 5, 8, 6, 5, 0,
+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ 4, 4, 4, 4, 5, 1, 1, 1, 0, 4,
+ 4, 4, 4, 0, 2, 2, 2, 2, 2, 2,
+ 2, 2, 2, 2, 2, 2, 2, 5, 1, 0,
+ 2, 2, 1, 2, 4, 5, 1, 1, 1, 1,
+ 2, 1, 1, 1, 1, 1, 4, 6, 4, 4,
+ 11, 1, 5, 3, 5, 3, 1, 2, 2, 1,
+ 2, 4, 4, 1, 2, 2, 2, 2, 2, 2,
+ 2, 1, 2, 1, 1, 1, 4, 4, 2, 4,
+ 2, 0, 1, 1, 3, 1, 3, 1, 0, 3,
+ 5, 4, 3, 5, 5, 5, 5, 5, 5, 2,
+ 2, 2, 2, 2, 2, 4, 4, 4, 4, 4,
+ 4, 4, 4, 5, 5, 5, 5, 4, 4, 4,
+ 4, 4, 4, 3, 2, 0, 1, 1, 2, 1,
+ 1, 1, 1, 4, 4, 5, 4, 4, 4, 7,
+ 7, 7, 7, 7, 7, 7, 7, 7, 7, 8,
+ 8, 8, 8, 7, 7, 7, 7, 7, 0, 2,
+ 2, 0, 2, 2, 0, 2, 0, 2, 0, 2,
+ 0, 2, 0, 2, 0, 2, 2, 0, 2, 3,
+ 2, 0, 2, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 2, 1, 2,
+ 2, 2, 2, 2, 2, 3, 2, 2, 2, 5,
+ 3, 2, 2, 2, 2, 2, 5, 4, 6, 2,
+ 4, 0, 3, 3, 1, 1, 0, 3, 0, 1,
+ 1, 3, 0, 1, 1, 3, 1, 3, 4, 4,
+ 4, 4, 5, 1, 1, 1, 1, 1, 1, 1,
+ 3, 1, 3, 4, 1, 0, 10, 6, 5, 6,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 2, 2, 2, 2, 1, 1, 1, 1,
+ 2, 3, 4, 6, 5, 1, 1, 1, 1, 1,
+ 1, 1, 2, 2, 1, 2, 2, 4, 1, 2,
+ 1, 2, 1, 2, 1, 2, 1, 2, 1, 1,
+ 0, 5, 0, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 2, 2, 2, 2, 1, 1,
+ 1, 1, 1, 3, 2, 2, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 2, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 2, 1, 3, 2, 3, 4, 2, 2, 2,
+ 5, 5, 7, 4, 3, 2, 3, 2, 1, 1,
+ 2, 3, 2, 1, 2, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 2, 2, 2, 2, 1, 1,
+ 1, 1, 1, 1, 3, 0, 1, 1, 3, 2,
+ 6, 7, 3, 3, 3, 6, 0, 1, 3, 5,
+ 6, 4, 4, 1, 3, 3, 1, 1, 1, 1,
+ 4, 1, 6, 6, 6, 4, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 3, 2, 5, 4, 7, 6, 7,
+ 6, 9, 8, 3, 8, 4, 0, 2, 0, 1,
+ 3, 3, 0, 2, 2, 2, 3, 2, 2, 2,
+ 2, 2, 0, 2, 3, 1, 1, 1, 1, 3,
+ 8, 2, 3, 1, 1, 3, 3, 3, 4, 6,
+ 0, 2, 3, 1, 3, 1, 4, 3, 0, 2,
+ 2, 2, 3, 3, 3, 3, 3, 3, 0, 2,
+ 2, 3, 3, 4, 2, 1, 1, 3, 5, 0,
+ 2, 2, 0, 2, 4, 3, 1, 1 };
+YYSTATIC YYCONST short YYFARDATA YYCHK[]={
+
+-1000,-109,-110,-111,-113,-114,-116,-117,-118,-119,
+-120,-121,-122,-124,-126,-128,-130,-131,-132, 524,
+ 525, 459, 527, 528,-133,-134,-135, 531, 532,-139,
+ 408,-152, 410,-170,-137, 454,-176, 462, 407, 469,
+ 470, 429, -87, 430, -93, -94, 273, 448, 529, 533,
+ 534, 535, 536, 537, 538, 539, 59,-138, 409, 411,
+ 453, 446, 447, 449, -10, -11, 123, 123,-115, 123,
+ 123, 123, 123, -9, 264, -9, 526, -88, -24, 265,
+ 264, -24, 123,-140, 314, -1, -2, 261, 260, 263,
+ -78, -16, 91,-171, 123,-174, 278, 38,-175, 286,
+ 287, 284, 283, 282, 281, 288, -31, -32, 267, 91,
+ -9, -90, 468, 468, -92, -1, 468, -86, 431, 432,
+ 433, 434, 435, 436, 437, 438, 439, 440, 441, 442,
+ 443, 444, 445, -31, -86, 263, -28, -70, -74, -93,
+ -94, 306, 297, 322, 323,-149, 33, 307, 276, 324,
+ -52, 275, 91, -5, -76, 268, 412, 413, 414, 357,
+ 356, 278, 298, 277, 281, 282, 283, 284, 286, 287,
+ 279, 290, 291, 292, 293, 271, -1, 296, -1, -1,
+ -1, -1, 262, -77,-172, 318, 378, 61, -73, 40,
+ -75, -7, -76, 269, 272, 325, 340, -8, 295, 300,
+ 302, 308, -31, -31,-112,-109, 125,-155, 415,-156,
+ 417,-154, 419, 420,-117,-157, -2,-131,-120,-133,
+-132,-135, 471, 457, 507,-158, 506,-160, 418, -95,
+ -96, -97, -98, -99,-108,-100,-101,-102,-103,-104,
+-105,-106,-107,-159,-163, 394, 395, 396, 397, 398,
+ 399, 400, 401, 402, 403, 404, 405, 406, 123, 416,
+-123,-125,-127,-129, -9, -1, 460,-136, -70, -76,
+-141, 315, -71, -70, 91, -28,-149, 46, -7, 328,
+ 329, 330, 331, 332, 326, 346, 352, 337, 364, 365,
+ 366, 367, 368, 369, 370, 350, 377, 294, 371, -79,
+ -9,-173,-174, 42, 40, -31, 40, -14, 91, 40,
+ -14, 40, -14, 40, -14, 40, -14, 40, -14, 40,
+ 41, 267, -9, 263, 58, 44, 262, -1, 353, 354,
+ 355, 472, 378, 474, 475, 476, 477, -90, -91, -1,
+ 329, 330, -1, -71, 41, -36, 61, 288, 262, 44,
+ 389, 91, 38, 42, 358, 359, 360, 60, 389, 389,
+ 389, 389, -70, 306, -70, -75, -7, 33, -9, -1,
+ 280, 279, 289, -28, -1, -76, 42, 470, 47, -28,
+ 270, 272, 281, 282, 283, 284, 40, -36, -1, 329,
+ 330, 322, 345, 334, 335, 337, 338, 339, 340, 341,
+ 342, 343, 344, 361, 354, 336, 351, 326, 370, 294,
+ -2, 40, 61, -72, -71, -74, -28, -7, -7, 40,
+ 301, 303, 304, 305, 41, 41, 125,-143,-114,-111,
+-144,-146,-116,-117,-131,-120,-132, 451, 452,-148,
+ 507,-133,-135, 506, 321, 421, 426, 471, 407, 125,
+ -9, -9, 40, 450, 58, 91, -9, -71, 356, 363,
+ 91,-161,-162,-164,-166,-167,-168, 311,-169, 309,
+ 313, 312, -9, -2, -9, -24, 40, -23, -24, 266,
+ 286, 287, -31, -9, -2, -75, -28, -76, 270, 272,
+ -71, -36, 341,-175, -7, -72, 40,-115,-158, -2,
+ -9, 125,-178, 461,-131,-179,-180, 466, 467,-181,
+-132,-135, 463, 125,-183,-177,-179,-182, 338, 461,
+ 464, 125,-184, 459, 407, 462, 296,-132,-135, 125,
+-185, 459, 462,-132,-135, -89, 419, 125,-136,-142,
+ -71, -1, 470, -7, -1, -13, 40, 40, -28, 328,
+ 329, 330, 331, 376, 370, 326, 478, 364, 365, 366,
+ 367, 374, 375, 294, 93, 125, 44, 40, -2, 41,
+ -23, -9, -23, -24, -9, -9, -9, 93, -9, -9,
+ 473, -1, -1, 330, 329, 327, 336, 389, 40, 61,
+ 43, 123, 40, 40, 263, -1, 93, -30, -29, 275,
+ -9, 40, 40, -54, -55, -28, -1, -1, -1, -1,
+ -70, -28, -9, -1, 280, 93, 93, 93, -1, -1,
+ -71, -1, 91, -9, -69, 60, 329, 330, 331, 364,
+ 365, 366, 40, 61, -36, 123, 40, 41, -71, -3,
+ 372, 373, -1, -9,-115, 123, 123, 123, -9, -9,
+ 123, -71, 356, 363, 363, -81, -82, -91, -25, -26,
+ -27, 275, -13, 40, -9, 58, 274, -7, 91, -1,
+ -9,-161,-165,-158, 310,-165,-165,-165, -71,-158,
+ -2, -9, 40, 40, 41, -71, -1, 40, -31, -28,
+ -6, -2, -9, 125, 316, 316, 465, -31, -66, -9,
+ 42, -36, 61, -31, 61, -31, -31, 61, 61, -1,
+ 468, -9, 468, 40, -1, 468,-177, 44, 93, -1,
+ -28, -28, 91, -9, -36, -83, -1, 40, 40,-173,
+ -36, 41, 41, 93, 41, 41, 41, 41, 41, -12,
+ 263, 44, 58, 389, 329, 330, 331, 364, 365, 366,
+ -1, -84, -85, -36, 123, 262, -64, -63, -71, 306,
+ 44, 93, 44, 275, -71, -71, 62, 44, 42, -5,
+ -5, -5, 93, 274, 41, -68, -19, -18, 43, 45,
+ 306, 323, 372, -9, -59, -61, -73, 274, -53, -22,
+ 60, 41, 125,-112,-145,-147,-127, 274, -7, 91,
+ -1, -71, -71, -1, 370, 326, -7, 370, 326, -1,
+ 41, 44, -28, -25, 93, -9, -3, -1, -28, -9,
+ 93, -2, -9, -9, -24, 274, -36, 41, 40, 41,
+ 44, 44, -2, -9, -9, 41, 58, 40, 41, 40,
+ 41, 41, 40, 40, -5, -1, -9, 317, -1, -31,
+ -71, 93, -38, 478, 503, 504, 505, -9, 41, 389,
+ -83, 41, 386, 341, 342, 343, 387, 388, 301, 303,
+ 304, 305, 390, 393, 294, -4, 317, -34, -33,-153,
+ 479, 481, 482, 483, 484, 276, 277, 281, 282, 283,
+ 284, 286, 287, 257, 279, 290, 291, 292, 293, 485,
+ 486, 487, 489, 490, 491, 492, 493, 494, 495, 334,
+ 496, 280, 289, 336, 497, 341, 488, 356, 389, 501,
+ 271, 123, -9, 41, -14, -14, -14, -14, -14, -14,
+ 317, 283, 284, 455, 456, 458, -9, -9, -1, 41,
+ 44, 61, -59, 125, 44, 61, 263, 263, -29, -9,
+ 41, 41, -28, 40, -5, -1, 62, -58, -1, 40,
+ -19, 41, 125, -62, -40,-135, -41, 298, 363, 297,
+ 286, 287, 284, 283, 282, 281, 293, 292, 291, 290,
+ 279, 278, 277,-175, 61, -3, 40, 40, 91, -54,
+ 125, 125,-150, 422, 423, 424, 425,-120,-132,-133,
+-135, 125,-151, 427, 428, 425,-132,-120,-133,-135,
+ 125, -3, -28, -9, -93, 449, -1, -28, -27, -38,
+ 41, 389, -71, 93, -35, 61, 316, 316, 41, 41,
+ -1, 41, -25, -6, -6, -66, 41, -9, 41, -3,
+ 40, 93, 93, 93, 93, -36, 41, 58, 58, 40,
+ -35, -2, 41, 42, 91, -32, 40, 480, 500, 277,
+ 281, 282, 283, 284, 280, -20, 40, -20, -20, -15,
+ 509, 482, 483, 276, 277, 281, 282, 283, 284, 286,
+ 287, 279, 290, 291, 292, 293, 42, 485, 486, 487,
+ 489, 490, 493, 494, 496, 280, 289, 257, 510, 511,
+ 512, 513, 514, 515, 516, 517, 518, 519, 520, 521,
+ 522, 495, 487, 499, 41, -2, 263, 263, 44, -84,
+ -37, -17, -9, 283, -36, -70, 319, 320, 125, -64,
+ 123, 61, -25, -1, -67, 44, -56, -57, -71, -65,
+-135, 357, 362, 40, 91, 40, 91, 40, 91, 40,
+ 91, 40, 91, 40, 91, 40, 91, 40, 91, 40,
+ 91, 40, 91, 40, 91, 40, 91, 40, 91, 284,
+ 283, 282, 281, 40, 91, 40, 91, -31, -36, 123,
+ 40, -53, -22, -25, -25, -9, 62, -75, -75, -75,
+ -75, -75, -75, -75, 508, -71, 93, -1, -2, -2,
+ 274, -39, -41, -36, 299, 286, 287, 284, 283, 282,
+ 281, 279, 293, 292, 291, 290, 278, 277, -2, -9,
+ 41, 58, -89, -69, -34, -83, 391, 392, 391, 392,
+ -9, 93, -9, 43, 125, -36, 91, 91, 502, 44,
+ 91, 523, 38, 281, 282, 283, 284, 280, -9, 40,
+ 40, -62, 123, 41, -67, -68, 41, 44, -60, -52,
+ 363, 297, 345, 299, 263, -9, 306, -70, 299, -9,
+ -40, -9, -23, -9, -9, -23, -24, -9, -24, -9,
+ -9, -9, -9, -9, -9, -9, -24, -9, -9, -9,
+ -9, -9, -9, -9, 40, 91, 40, 91, 40, 91,
+ 40, 91, -9, -9, -17, -9, 41, -59, 40, 40,
+ 41, 41, 93, -7, 274, 40, -3, 284, 283, 282,
+ 281, -66, 40, 41, 41, 41, 93, 43, -9, 44,
+ -9, -9, 61, -36, 93, 263, -9, 281, 282, 283,
+ -9, 125, -62, -71, -1, 91, 306, -70, 41, 41,
+ 93, 263, 41, 41, 93, 41, 93, 41, 41, 93,
+ 41, 41, 93, 41, 93, 41, 93, 41, 93, 41,
+ 93, 41, 93, 41, 93, 41, 93, 41, 93, -24,
+ -9, -9, -9, -9, -9, -9, -9, 41, 93, 41,
+ 93, 125, -25, -25, 62, -28, -3, -25, -21, -22,
+ 60, 58, -25, -9, 93, -36, 93, 93, -9, 41,
+ 58, 58, 58, 41, 125, 61, 93, 263, 40, 41,
+ 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
+ 40, 40, 41, 93, 41, 93, 41, 93, 41, 93,
+ 40, 40, 41, 41, -71, -21, 41, 40, -66, 41,
+ 93, 44, 41, -33, 41, -9, -9, -9, -40, -49,
+ -50, -51, -42, -43, -47, -46, -45, -44, -47, -46,
+ -45, -44, 40, 40, 40, 40, -45, -48, 274, 40,
+ -35, -25, -80, -36, 41, 41, 41, 41, 299, 263,
+ 41, 299, 306, -70, 41, -40, 41, -23, -9, 41,
+ -23, -24, 41, -24, 41, -9, 41, -9, 41, -9,
+ 41, 41, 41, 41, -47, -46, -45, -44, 41, 41,
+ -17, -3, -25, 41, 123, 324, 378, 379, 380, 308,
+ 381, 382, 383, 384, 333, 347, 348, 349, 294, 44,
+ 263, 41, 41, 41, 41, 40, 41, 40, -36, -25,
+ 508, -9, 41, 41, 356, 41, -7, -28, -71, 274,
+ -3, -21, 40, -25, 41 };
+YYSTATIC YYCONST short YYFARDATA YYDEF[]={
+
+ 1, -2, 2, 0, 0, 329, 6, 7, 8, 9,
+ 10, 11, 0, 0, 0, 0, 16, 17, 18, 0,
+ 0, 766, 0, 0, 24, 25, 26, 0, 28, 135,
+ 0, 266, 204, 0, 425, 0, 0, 772, 105, 829,
+ 92, 0, 425, 0, 83, 84, 85, 0, 0, 0,
+ 0, 0, 0, 57, 58, 0, 60, 108, 259, 381,
+ 0, 751, 752, 217, 425, 425, 139, 1, 0, 782,
+ 800, 818, 832, 19, 41, 20, 0, 0, 22, 42,
+ 43, 23, 29, 137, 0, 104, 38, 39, 36, 37,
+ 217, 184, 0, 378, 0, 385, 0, 0, 425, 388,
+ 388, 388, 388, 388, 388, 0, 0, 426, 427, 0,
+ 754, 0, 772, 808, 0, 93, 0, 0, 736, 737,
+ 738, 739, 740, 741, 742, 743, 744, 745, 746, 747,
+ 748, 749, 750, 0, 0, 33, 0, 0, 0, 0,
+ 0, 0, 662, 0, 0, 217, 0, 678, 679, 0,
+ 683, 0, 0, 543, 230, 545, 546, 547, 548, 0,
+ 483, 685, 686, 687, 688, 689, 690, 691, 692, 693,
+ 0, 698, 699, 700, 701, 702, 549, 0, 52, 54,
+ 55, 56, 59, 0, 380, 382, 383, 0, 61, 0,
+ 71, 0, 210, 211, 212, 217, 217, 215, 0, 218,
+ 219, 0, 0, 0, 0, 0, 5, 330, 0, 332,
+ 0, 0, 336, 337, 338, 339, 0, 341, 342, 343,
+ 344, 345, 0, 0, 0, 351, 0, 0, 328, 498,
+ 0, 0, 0, 0, 425, 0, 217, 0, 0, 0,
+ 217, 0, 0, 329, 0, 484, 485, 486, 487, 488,
+ 489, 490, 491, 492, 493, 494, 495, 496, 356, 363,
+ 0, 0, 0, 0, 21, 768, 767, 0, 29, 544,
+ 107, 0, 136, 551, 0, 554, 217, 0, 308, 267,
+ 268, 269, 270, 271, 272, 273, 274, 275, 276, 277,
+ 278, 279, 280, 281, 282, 283, 284, 0, 0, 0,
+ 0, 0, 387, 0, 0, 0, 0, 399, 0, 0,
+ 400, 0, 401, 0, 402, 0, 403, 0, 404, 424,
+ 102, 428, 0, 753, 0, 0, 763, 771, 773, 774,
+ 775, 0, 777, 778, 779, 780, 781, 0, 0, 827,
+ 830, 831, 94, 712, 713, 714, 0, 0, 31, 0,
+ 0, 705, 667, 668, 669, 0, 0, 528, 0, 0,
+ 0, 0, 661, 0, 664, 225, 0, 0, 675, 677,
+ 680, 0, 682, 684, 0, 0, 0, 0, 0, 0,
+ 228, 229, 694, 695, 696, 697, 0, 53, 147, 109,
+ 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
+ 120, 121, 122, 123, 124, 0, 131, 132, 133, 0,
+ 0, 103, 0, 0, 72, 73, 0, 213, 214, 0,
+ 220, 221, 222, 223, 64, 68, 3, 140, 329, 0,
+ 0, 0, 168, 169, 170, 171, 172, 0, 0, 0,
+ 0, 178, 179, 0, 0, 233, 247, 808, 105, 4,
+ 331, 333, -2, 0, 340, 0, 0, 0, 217, 0,
+ 0, 357, 359, 0, 0, 0, 0, 0, 0, 373,
+ 374, 371, 499, 500, 501, 502, 497, 503, 504, 44,
+ 0, 0, 0, 506, 507, 508, 0, 511, 512, 513,
+ 514, 515, 0, 425, 0, 519, 521, 0, 360, 0,
+ 0, 12, 783, 0, 785, 786, 425, 0, 0, 425,
+ 793, 794, 0, 13, 801, 425, 803, 425, 805, 0,
+ 0, 14, 819, 0, 0, 0, 0, 825, 826, 15,
+ 833, 0, 0, 836, 837, 765, 769, 27, 30, 138,
+ 142, 0, 0, 0, 40, 0, 0, 289, 0, 185,
+ 186, 187, 188, 189, 190, 191, 0, 193, 194, 195,
+ 196, 197, 198, 0, 205, 384, 0, 0, 0, 392,
+ 0, 0, 0, 0, 0, 0, 0, 96, 756, 0,
+ 776, 798, 806, 809, 810, 811, 0, 0, 0, 0,
+ 0, 716, 721, 722, 34, 47, 665, 0, 703, 706,
+ 707, 0, 0, 0, 529, 530, 48, 49, 50, 51,
+ 663, 0, 674, 676, 681, 0, 0, 0, 0, 550,
+ 0, -2, 705, 0, 106, 154, 125, 126, 127, 128,
+ 129, 130, 0, 379, 62, 75, 69, 217, 0, 526,
+ 305, 306, -2, 0, 0, 139, 236, 250, 173, 174,
+ 818, 0, 217, 0, 0, 0, 217, 0, 0, 533,
+ 534, 536, 0, -2, 0, 0, 0, 0, 0, 353,
+ 0, 358, 364, 375, 0, 365, 366, 367, 372, 368,
+ 369, 370, 0, 0, 505, 0, -2, 0, 0, 0,
+ 0, 524, 525, 355, 0, 0, 0, 0, 0, 787,
+ 788, 791, 0, 0, 0, 0, 0, 0, 0, 820,
+ 0, 824, 0, 0, 0, 0, 425, 0, 552, 0,
+ 0, 260, 0, 0, 289, 0, 200, 555, 0, 386,
+ 0, 391, 388, 389, 388, 388, 388, 388, 388, 0,
+ 755, 0, 0, 0, 812, 813, 814, 815, 816, 817,
+ 828, 0, 723, 0, 75, 32, 0, 717, 0, 0,
+ 0, 666, 705, 709, 0, 0, 673, 0, 668, 539,
+ 540, 541, 0, 0, 224, 0, 0, 154, 149, 150,
+ 151, 152, 153, 0, 0, 78, 65, 0, 0, 0,
+ 528, 216, 164, 0, 0, 0, 0, 0, 0, 0,
+ 181, 0, 0, -2, 234, 235, 0, 248, 249, 807,
+ 334, 308, 260, 0, 346, 348, 349, 307, 0, 0,
+ 202, 0, 0, 0, 0, 0, 0, 517, -2, 520,
+ 521, 521, 361, 362, 784, 789, 0, 797, 792, 795,
+ 802, 804, 770, 796, 821, 822, 0, 0, 835, 0,
+ 141, 553, 0, 0, 0, 0, 0, 0, 285, 0,
+ 0, 288, 290, 291, 292, 293, 294, 295, 296, 297,
+ 298, 299, 0, 0, 0, 202, 0, 0, 262, 0,
+ 0, 0, 560, 561, 562, 563, 564, 565, 566, 567,
+ 568, 569, 570, 571, 0, 576, 577, 578, 579, 585,
+ 586, 587, 588, 589, 590, 591, 610, 610, 594, 610,
+ 612, 598, 600, 0, 602, 0, 604, 606, 0, 608,
+ 609, 264, 0, 390, 393, 394, 395, 396, 397, 398,
+ 0, 97, 98, 99, 100, 101, 758, 760, 799, 710,
+ 0, 0, 0, 715, 716, 0, 37, 35, 704, 708,
+ 670, 671, 531, -2, 542, 226, 148, 0, 158, 143,
+ 155, 134, 63, 74, 76, 77, 432, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 425, 0, 526, -2, -2, 0, 0,
+ 165, 166, 237, 217, 217, 217, 217, 242, 243, 244,
+ 245, 167, 251, 217, 217, 217, 255, 256, 257, 258,
+ 175, 0, 0, 0, 182, 217, 231, 0, 535, 537,
+ 335, 0, 0, 352, 354, 0, 0, 0, 45, 46,
+ 509, 516, 0, 522, 523, 0, 823, 834, 768, 147,
+ 555, 309, 310, 311, 312, 289, 287, 0, 0, 0,
+ 183, 201, 192, 580, 0, 0, 0, 0, 0, 605,
+ 572, 573, 574, 575, 599, 592, 0, 593, 595, 596,
+ 613, 614, 615, 616, 617, 618, 619, 620, 621, 622,
+ 623, 0, 628, 629, 630, 631, 632, 636, 637, 638,
+ 639, 640, 641, 642, 643, 644, 646, 647, 648, 649,
+ 650, 651, 652, 653, 654, 655, 656, 657, 658, 659,
+ 660, 601, 603, 607, 199, 95, 757, 759, 0, 724,
+ 725, 728, 729, 0, 731, 0, 726, 727, 711, 718,
+ 78, 0, 0, 158, 157, 154, 0, 144, 145, 0,
+ 80, 81, 82, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 66, 75,
+ 70, 0, 0, 0, 0, 0, 527, 238, 239, 240,
+ 241, 252, 253, 254, 217, 0, 180, 0, 538, 347,
+ 0, 203, 429, 430, 431, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 376, 377,
+ 518, 0, 764, 0, 0, 0, 300, 301, 302, 303,
+ 0, 581, 0, 0, 263, 0, 0, 0, 0, 0,
+ 0, 634, 635, 624, 625, 626, 627, 645, 762, 0,
+ 0, 0, 78, 672, 156, 159, 160, 0, 0, 86,
+ 87, 88, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 423, 0, -2, -2,
+ 208, 209, 0, 0, 0, -2, 161, 0, 0, 0,
+ 0, 0, -2, 261, 286, 304, 582, 0, 0, 0,
+ 0, 0, 0, 597, 633, 761, 0, 0, 0, 0,
+ 0, 719, 0, 146, 0, 0, 0, 90, 433, 434,
+ 0, 0, 436, 437, 0, 438, 0, 405, 407, 0,
+ 406, 408, 0, 409, 0, 410, 0, 411, 0, 412,
+ 0, 417, 0, 418, 0, 419, 0, 420, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 421, 0, 422,
+ 0, 67, 0, 0, 163, 0, 161, 0, 0, 162,
+ 0, 0, 0, 0, 584, 0, 558, 555, 0, 730,
+ 0, 0, 0, 735, 720, 0, 91, 89, 474, 435,
+ 477, 481, 458, 461, 464, 466, 468, 470, 464, 466,
+ 468, 470, 413, 0, 414, 0, 415, 0, 416, 0,
+ 468, 472, 206, 207, 0, 0, 202, -2, 790, 313,
+ 583, 0, 557, 559, 611, 0, 0, 0, 79, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 464, 466, 468, 470, 0, 0, 0, -2,
+ 246, 0, 0, 0, 732, 733, 734, 455, 475, 476,
+ 456, 478, 0, 480, 457, 482, 439, 459, 460, 440,
+ 462, 463, 441, 465, 442, 467, 443, 469, 444, 471,
+ 445, 446, 447, 448, 0, 0, 0, 0, 453, 454,
+ 473, 0, 0, 350, 265, 314, 315, 316, 317, 318,
+ 319, 320, 321, 322, 323, 324, 325, 326, 0, 0,
+ 479, 449, 450, 451, 452, -2, 0, 0, 0, 0,
+ 0, 0, 556, 176, 217, 327, 0, 0, 0, 0,
+ 161, 0, -2, 0, 177 };
+#ifdef YYRECOVER
+YYSTATIC YYCONST short yyrecover[] = {
+-1000
+};
+#endif
+
+/* SCCSWHAT( "@(#)yypars.c 3.1 88/11/16 22:00:49 " ) */
+#line 3 "D:\\ProjectK3\\src\\tools\\devdiv\\x86\\yypars.c"
+#if ! defined(YYAPI_PACKAGE)
+/*
+** YYAPI_TOKENNAME : name used for return value of yylex
+** YYAPI_TOKENTYPE : type of the token
+** YYAPI_TOKENEME(t) : the value of the token that the parser should see
+** YYAPI_TOKENNONE : the representation when there is no token
+** YYAPI_VALUENAME : the name of the value of the token
+** YYAPI_VALUETYPE : the type of the value of the token (if null, then the value is derivable from the token itself)
+** YYAPI_VALUEOF(v) : how to get the value of the token.
+*/
+#define YYAPI_TOKENNAME yychar
+#define YYAPI_TOKENTYPE int
+#define YYAPI_TOKENEME(t) (t)
+#define YYAPI_TOKENNONE -1
+#define YYAPI_TOKENSTR(t) (sprintf(yytokbuf, "%d", t), yytokbuf)
+#define YYAPI_VALUENAME yylval
+#define YYAPI_VALUETYPE YYSTYPE
+#define YYAPI_VALUEOF(v) (v)
+#endif
+#if ! defined(YYAPI_CALLAFTERYYLEX)
+#define YYAPI_CALLAFTERYYLEX
+#endif
+
+# define YYFLAG -1000
+# define YYERROR goto yyerrlab
+# define YYACCEPT return(0)
+# define YYABORT return(1)
+
+#ifdef YYDEBUG /* RRR - 10/9/85 */
+char yytokbuf[20];
+# ifndef YYDBFLG
+# define YYDBFLG (yydebug)
+# endif
+# define yyprintf(a, b, c, d) if (YYDBFLG) YYPRINT(a, b, c, d)
+#else
+# define yyprintf(a, b, c, d)
+#endif
+
+#ifndef YYPRINT
+#define YYPRINT printf
+#endif
+
+/* parser for yacc output */
+
+#ifdef YYDUMP
+int yydump = 1; /* 1 for dumping */
+void yydumpinfo(void);
+#endif
+#ifdef YYDEBUG
+YYSTATIC int yydebug = 0; /* 1 for debugging */
+#endif
+YYSTATIC YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
+YYSTATIC short yys[YYMAXDEPTH]; /* the parse stack */
+
+#if ! defined(YYRECURSIVE)
+YYSTATIC YYAPI_TOKENTYPE YYAPI_TOKENNAME = YYAPI_TOKENNONE;
+#if defined(YYAPI_VALUETYPE)
+// YYSTATIC YYAPI_VALUETYPE YYAPI_VALUENAME; FIX
+#endif
+YYSTATIC int yynerrs = 0; /* number of errors */
+YYSTATIC short yyerrflag = 0; /* error recovery flag */
+#endif
+
+#ifdef YYRECOVER
+/*
+** yyscpy : copy f onto t and return a ptr to the null terminator at the
+** end of t.
+*/
+YYSTATIC char *yyscpy(register char*t, register char*f)
+ {
+ while(*t = *f++)
+ t++;
+ return(t); /* ptr to the null char */
+ }
+#endif
+
+#ifndef YYNEAR
+#define YYNEAR
+#endif
+#ifndef YYPASCAL
+#define YYPASCAL
+#endif
+#ifndef YYLOCAL
+#define YYLOCAL
+#endif
+#if ! defined YYPARSER
+#define YYPARSER yyparse
+#endif
+#if ! defined YYLEX
+#define YYLEX yylex
+#endif
+
+#if defined(YYRECURSIVE)
+
+ YYSTATIC YYAPI_TOKENTYPE YYAPI_TOKENNAME = YYAPI_TOKENNONE;
+ #if defined(YYAPI_VALUETYPE)
+ YYSTATIC YYAPI_VALUETYPE YYAPI_VALUENAME;
+ #endif
+ YYSTATIC int yynerrs = 0; /* number of errors */
+ YYSTATIC short yyerrflag = 0; /* error recovery flag */
+
+ YYSTATIC short yyn;
+ YYSTATIC short yystate = 0;
+ YYSTATIC short *yyps= &yys[-1];
+ YYSTATIC YYSTYPE *yypv= &yyv[-1];
+ YYSTATIC short yyj;
+ YYSTATIC short yym;
+
+#endif
+
+#pragma warning(disable:102)
+YYLOCAL YYNEAR YYPASCAL YYPARSER()
+{
+#if ! defined(YYRECURSIVE)
+
+ register short yyn;
+ short yystate, *yyps;
+ YYSTYPE *yypv;
+ short yyj, yym;
+
+ YYAPI_TOKENNAME = YYAPI_TOKENNONE;
+ yystate = 0;
+ yyps= &yys[-1];
+ yypv= &yyv[-1];
+#endif
+
+#ifdef YYDUMP
+ yydumpinfo();
+#endif
+ yystack: /* put a state and value onto the stack */
+
+#ifdef YYDEBUG
+ if(YYAPI_TOKENNAME == YYAPI_TOKENNONE) {
+ yyprintf( "state %d, token # '%d'\n", yystate, -1, 0 );
+ }
+ else {
+ yyprintf( "state %d, token # '%s'\n", yystate, YYAPI_TOKENSTR(YYAPI_TOKENNAME), 0 );
+ }
+#endif
+ if( ++yyps > &yys[YYMAXDEPTH] ) {
+ yyerror( "yacc stack overflow" );
+ return(1);
+ }
+ *yyps = yystate;
+ ++yypv;
+
+ *yypv = yyval;
+
+yynewstate:
+
+ yyn = YYPACT[yystate];
+
+ if( yyn <= YYFLAG ) { /* simple state, no lookahead */
+ goto yydefault;
+ }
+ if( YYAPI_TOKENNAME == YYAPI_TOKENNONE ) { /* need a lookahead */
+ YYAPI_TOKENNAME = YYLEX();
+ YYAPI_CALLAFTERYYLEX(YYAPI_TOKENNAME);
+ }
+ if( ((yyn += YYAPI_TOKENEME(YYAPI_TOKENNAME)) < 0) || (yyn >= YYLAST) ) {
+ goto yydefault;
+ }
+ if( YYCHK[ yyn = YYACT[ yyn ] ] == YYAPI_TOKENEME(YYAPI_TOKENNAME) ) { /* valid shift */
+ yyval = YYAPI_VALUEOF(YYAPI_VALUENAME);
+ yystate = yyn;
+ yyprintf( "SHIFT: saw token '%s', now in state %4d\n", YYAPI_TOKENSTR(YYAPI_TOKENNAME), yystate, 0 );
+ YYAPI_TOKENNAME = YYAPI_TOKENNONE;
+ if( yyerrflag > 0 ) {
+ --yyerrflag;
+ }
+ goto yystack;
+ }
+
+ yydefault:
+ /* default state action */
+
+ if( (yyn = YYDEF[yystate]) == -2 ) {
+ register YYCONST short *yyxi;
+
+ if( YYAPI_TOKENNAME == YYAPI_TOKENNONE ) {
+ YYAPI_TOKENNAME = YYLEX();
+ YYAPI_CALLAFTERYYLEX(YYAPI_TOKENNAME);
+ yyprintf("LOOKAHEAD: token '%s'\n", YYAPI_TOKENSTR(YYAPI_TOKENNAME), 0, 0);
+ }
+/*
+** search exception table, we find a -1 followed by the current state.
+** if we find one, we'll look through terminal,state pairs. if we find
+** a terminal which matches the current one, we have a match.
+** the exception table is when we have a reduce on a terminal.
+*/
+
+#if YYOPTTIME
+ yyxi = yyexca + yyexcaind[yystate];
+ while(( *yyxi != YYAPI_TOKENEME(YYAPI_TOKENNAME) ) && ( *yyxi >= 0 )){
+ yyxi += 2;
+ }
+#else
+ for(yyxi = yyexca;
+ (*yyxi != (-1)) || (yyxi[1] != yystate);
+ yyxi += 2
+ ) {
+ ; /* VOID */
+ }
+
+ while( *(yyxi += 2) >= 0 ){
+ if( *yyxi == YYAPI_TOKENEME(YYAPI_TOKENNAME) ) {
+ break;
+ }
+ }
+#endif
+ if( (yyn = yyxi[1]) < 0 ) {
+ return(0); /* accept */
+ }
+ }
+
+ if( yyn == 0 ){ /* error */
+ /* error ... attempt to resume parsing */
+
+ switch( yyerrflag ){
+
+ case 0: /* brand new error */
+#ifdef YYRECOVER
+ {
+ register int i,j;
+
+ for(i = 0;
+ (yyrecover[i] != -1000) && (yystate > yyrecover[i]);
+ i += 3
+ ) {
+ ;
+ }
+ if(yystate == yyrecover[i]) {
+ yyprintf("recovered, from state %d to state %d on token # %d\n",
+ yystate,yyrecover[i+2],yyrecover[i+1]
+ );
+ j = yyrecover[i + 1];
+ if(j < 0) {
+ /*
+ ** here we have one of the injection set, so we're not quite
+ ** sure that the next valid thing will be a shift. so we'll
+ ** count it as an error and continue.
+ ** actually we're not absolutely sure that the next token
+ ** we were supposed to get is the one when j > 0. for example,
+ ** for(+) {;} error recovery with yyerrflag always set, stops
+ ** after inserting one ; before the +. at the point of the +,
+ ** we're pretty sure the guy wants a 'for' loop. without
+ ** setting the flag, when we're almost absolutely sure, we'll
+ ** give him one, since the only thing we can shift on this
+ ** error is after finding an expression followed by a +
+ */
+ yyerrflag++;
+ j = -j;
+ }
+ if(yyerrflag <= 1) { /* only on first insertion */
+ yyrecerr(YYAPI_TOKENNAME, j); /* what was, what should be first */
+ }
+ yyval = yyeval(j);
+ yystate = yyrecover[i + 2];
+ goto yystack;
+ }
+ }
+#endif
+ yyerror("syntax error");
+
+ yyerrlab:
+ ++yynerrs;
+
+ case 1:
+ case 2: /* incompletely recovered error ... try again */
+
+ yyerrflag = 3;
+
+ /* find a state where "error" is a legal shift action */
+
+ while ( yyps >= yys ) {
+ yyn = YYPACT[*yyps] + YYERRCODE;
+ if( yyn>= 0 && yyn < YYLAST && YYCHK[YYACT[yyn]] == YYERRCODE ){
+ yystate = YYACT[yyn]; /* simulate a shift of "error" */
+ yyprintf( "SHIFT 'error': now in state %4d\n", yystate, 0, 0 );
+ goto yystack;
+ }
+ yyn = YYPACT[*yyps];
+
+ /* the current yyps has no shift onn "error", pop stack */
+
+ yyprintf( "error recovery pops state %4d, uncovers %4d\n", *yyps, yyps[-1], 0 );
+ --yyps;
+ --yypv;
+ }
+
+ /* there is no state on the stack with an error shift ... abort */
+
+ yyabort:
+ return(1);
+
+
+ case 3: /* no shift yet; clobber input char */
+
+ yyprintf( "error recovery discards token '%s'\n", YYAPI_TOKENSTR(YYAPI_TOKENNAME), 0, 0 );
+
+ if( YYAPI_TOKENEME(YYAPI_TOKENNAME) == 0 ) goto yyabort; /* don't discard EOF, quit */
+ YYAPI_TOKENNAME = YYAPI_TOKENNONE;
+ goto yynewstate; /* try again in the same state */
+ }
+ }
+
+ /* reduction by production yyn */
+yyreduce:
+ {
+ register YYSTYPE *yypvt;
+ yypvt = yypv;
+ yyps -= YYR2[yyn];
+ yypv -= YYR2[yyn];
+ yyval = yypv[1];
+ yyprintf("REDUCE: rule %4d, popped %2d tokens, uncovered state %4d, ",yyn, YYR2[yyn], *yyps);
+ yym = yyn;
+ yyn = YYR1[yyn]; /* consult goto table to find next state */
+ yyj = YYPGO[yyn] + *yyps + 1;
+ if( (yyj >= YYLAST) || (YYCHK[ yystate = YYACT[yyj] ] != -yyn) ) {
+ yystate = YYACT[YYPGO[yyn]];
+ }
+ yyprintf("goto state %4d\n", yystate, 0, 0);
+#ifdef YYDUMP
+ yydumpinfo();
+#endif
+ switch(yym){
+
+case 3:
+#line 189 "asmparse.y"
+{ PASM->EndClass(); } break;
+case 4:
+#line 190 "asmparse.y"
+{ PASM->EndNameSpace(); } break;
+case 5:
+#line 191 "asmparse.y"
+{ if(PASM->m_pCurMethod->m_ulLines[1] ==0)
+ { PASM->m_pCurMethod->m_ulLines[1] = PASM->m_ulCurLine;
+ PASM->m_pCurMethod->m_ulColumns[1]=PASM->m_ulCurColumn;}
+ PASM->EndMethod(); } break;
+case 12:
+#line 201 "asmparse.y"
+{ PASMM->EndAssembly(); } break;
+case 13:
+#line 202 "asmparse.y"
+{ PASMM->EndAssembly(); } break;
+case 14:
+#line 203 "asmparse.y"
+{ PASMM->EndComType(); } break;
+case 15:
+#line 204 "asmparse.y"
+{ PASMM->EndManifestRes(); } break;
+case 19:
+#line 208 "asmparse.y"
+{
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:22011) // Suppress PREFast warning about integer overflow/underflow
+#endif
+ PASM->m_dwSubsystem = yypvt[-0].int32;
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+ } break;
+case 20:
+#line 218 "asmparse.y"
+{ PASM->m_dwComImageFlags = yypvt[-0].int32; } break;
+case 21:
+#line 219 "asmparse.y"
+{ PASM->m_dwFileAlignment = yypvt[-0].int32;
+ if((yypvt[-0].int32 & (yypvt[-0].int32 - 1))||(yypvt[-0].int32 < 0x200)||(yypvt[-0].int32 > 0x10000))
+ PASM->report->error("Invalid file alignment, must be power of 2 from 0x200 to 0x10000\n");} break;
+case 22:
+#line 222 "asmparse.y"
+{ PASM->m_stBaseAddress = (ULONGLONG)(*(yypvt[-0].int64)); delete yypvt[-0].int64;
+ if(PASM->m_stBaseAddress & 0xFFFF)
+ PASM->report->error("Invalid image base, must be 0x10000-aligned\n");} break;
+case 23:
+#line 225 "asmparse.y"
+{ PASM->m_stSizeOfStackReserve = (size_t)(*(yypvt[-0].int64)); delete yypvt[-0].int64; } break;
+case 28:
+#line 230 "asmparse.y"
+{ PASM->m_fIsMscorlib = TRUE; } break;
+case 31:
+#line 237 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 32:
+#line 238 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; yyval.binstr->append(yypvt[-0].binstr); delete yypvt[-0].binstr; } break;
+case 33:
+#line 241 "asmparse.y"
+{ LPCSTRToGuid(yypvt[-0].string,&(PASM->m_guidLang)); } break;
+case 34:
+#line 242 "asmparse.y"
+{ LPCSTRToGuid(yypvt[-2].string,&(PASM->m_guidLang));
+ LPCSTRToGuid(yypvt[-0].string,&(PASM->m_guidLangVendor));} break;
+case 35:
+#line 244 "asmparse.y"
+{ LPCSTRToGuid(yypvt[-4].string,&(PASM->m_guidLang));
+ LPCSTRToGuid(yypvt[-2].string,&(PASM->m_guidLangVendor));
+ LPCSTRToGuid(yypvt[-2].string,&(PASM->m_guidDoc));} break;
+case 36:
+#line 249 "asmparse.y"
+{ yyval.string = yypvt[-0].string; } break;
+case 37:
+#line 250 "asmparse.y"
+{ yyval.string = yypvt[-0].string; } break;
+case 38:
+#line 253 "asmparse.y"
+{ yyval.string = yypvt[-0].string; } break;
+case 39:
+#line 254 "asmparse.y"
+{ yyval.string = yypvt[-0].string; } break;
+case 40:
+#line 255 "asmparse.y"
+{ yyval.string = newStringWDel(yypvt[-2].string, '.', yypvt[-0].string); } break;
+case 41:
+#line 258 "asmparse.y"
+{ yyval.int32 = yypvt[-0].int32; } break;
+case 42:
+#line 261 "asmparse.y"
+{ yyval.int64 = yypvt[-0].int64; } break;
+case 43:
+#line 262 "asmparse.y"
+{ yyval.int64 = neg ? new __int64(yypvt[-0].int32) : new __int64((unsigned)yypvt[-0].int32); } break;
+case 44:
+#line 265 "asmparse.y"
+{ yyval.float64 = yypvt[-0].float64; } break;
+case 45:
+#line 266 "asmparse.y"
+{ float f; *((__int32*) (&f)) = yypvt[-1].int32; yyval.float64 = new double(f); } break;
+case 46:
+#line 267 "asmparse.y"
+{ yyval.float64 = (double*) yypvt[-1].int64; } break;
+case 47:
+#line 271 "asmparse.y"
+{ PASM->AddTypeDef(yypvt[-2].binstr,yypvt[-0].string); } break;
+case 48:
+#line 272 "asmparse.y"
+{ PASM->AddTypeDef(yypvt[-2].token,yypvt[-0].string); } break;
+case 49:
+#line 273 "asmparse.y"
+{ PASM->AddTypeDef(yypvt[-2].token,yypvt[-0].string); } break;
+case 50:
+#line 274 "asmparse.y"
+{ yypvt[-2].cad->tkOwner = 0; PASM->AddTypeDef(yypvt[-2].cad,yypvt[-0].string); } break;
+case 51:
+#line 275 "asmparse.y"
+{ PASM->AddTypeDef(yypvt[-2].cad,yypvt[-0].string); } break;
+case 52:
+#line 280 "asmparse.y"
+{ DefineVar(yypvt[-0].string, NULL); } break;
+case 53:
+#line 281 "asmparse.y"
+{ DefineVar(yypvt[-1].string, yypvt[-0].binstr); } break;
+case 54:
+#line 282 "asmparse.y"
+{ UndefVar(yypvt[-0].string); } break;
+case 55:
+#line 283 "asmparse.y"
+{ SkipToken = !IsVarDefined(yypvt[-0].string);
+ IfEndif++;
+ } break;
+case 56:
+#line 286 "asmparse.y"
+{ SkipToken = IsVarDefined(yypvt[-0].string);
+ IfEndif++;
+ } break;
+case 57:
+#line 289 "asmparse.y"
+{ if(IfEndif == 1) SkipToken = !SkipToken;} break;
+case 58:
+#line 290 "asmparse.y"
+{ if(IfEndif == 0)
+ PASM->report->error("Unmatched #endif\n");
+ else IfEndif--;
+ } break;
+case 59:
+#line 294 "asmparse.y"
+{ _ASSERTE(!"yylex should have dealt with this"); } break;
+case 60:
+#line 295 "asmparse.y"
+{ } break;
+case 61:
+#line 299 "asmparse.y"
+{ yyval.cad = new CustomDescr(PASM->m_tkCurrentCVOwner, yypvt[-0].token, NULL); } break;
+case 62:
+#line 300 "asmparse.y"
+{ yyval.cad = new CustomDescr(PASM->m_tkCurrentCVOwner, yypvt[-2].token, yypvt[-0].binstr); } break;
+case 63:
+#line 301 "asmparse.y"
+{ yyval.cad = new CustomDescr(PASM->m_tkCurrentCVOwner, yypvt[-4].token, yypvt[-1].binstr); } break;
+case 64:
+#line 302 "asmparse.y"
+{ yyval.cad = new CustomDescr(PASM->m_tkCurrentCVOwner, yypvt[-2].int32, yypvt[-1].binstr); } break;
+case 65:
+#line 305 "asmparse.y"
+{ yyval.cad = new CustomDescr(yypvt[-2].token, yypvt[-0].token, NULL); } break;
+case 66:
+#line 306 "asmparse.y"
+{ yyval.cad = new CustomDescr(yypvt[-4].token, yypvt[-2].token, yypvt[-0].binstr); } break;
+case 67:
+#line 308 "asmparse.y"
+{ yyval.cad = new CustomDescr(yypvt[-6].token, yypvt[-4].token, yypvt[-1].binstr); } break;
+case 68:
+#line 309 "asmparse.y"
+{ yyval.cad = new CustomDescr(PASM->m_tkCurrentCVOwner, yypvt[-2].int32, yypvt[-1].binstr); } break;
+case 69:
+#line 312 "asmparse.y"
+{ yyval.int32 = yypvt[-2].token; bParsingByteArray = TRUE; } break;
+case 70:
+#line 316 "asmparse.y"
+{ PASM->m_pCustomDescrList = NULL;
+ PASM->m_tkCurrentCVOwner = yypvt[-4].token;
+ yyval.int32 = yypvt[-2].token; bParsingByteArray = TRUE; } break;
+case 71:
+#line 321 "asmparse.y"
+{ yyval.token = yypvt[-0].token; } break;
+case 72:
+#line 324 "asmparse.y"
+{ yyval.token = yypvt[-0].token; } break;
+case 73:
+#line 325 "asmparse.y"
+{ yyval.token = yypvt[-0].token; } break;
+case 74:
+#line 329 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ yyval.binstr->appendInt16(nCustomBlobNVPairs);
+ yyval.binstr->append(yypvt[-0].binstr);
+ nCustomBlobNVPairs = 0; } break;
+case 75:
+#line 335 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt16(VAL16(0x0001)); } break;
+case 76:
+#line 336 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ yyval.binstr->appendFrom(yypvt[-0].binstr, (*(yypvt[-0].binstr->ptr()) == ELEMENT_TYPE_SZARRAY) ? 2 : 1); } break;
+case 77:
+#line 338 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; } break;
+case 78:
+#line 341 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 79:
+#line 343 "asmparse.y"
+{ yyval.binstr = yypvt[-5].binstr; yyval.binstr->appendInt8(yypvt[-4].int32);
+ yyval.binstr->append(yypvt[-3].binstr);
+ AppendStringWithLength(yyval.binstr,yypvt[-2].string);
+ yyval.binstr->appendFrom(yypvt[-0].binstr, (*(yypvt[-0].binstr->ptr()) == ELEMENT_TYPE_SZARRAY) ? 2 : 1);
+ nCustomBlobNVPairs++; } break;
+case 80:
+#line 348 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; } break;
+case 81:
+#line 351 "asmparse.y"
+{ yyval.int32 = SERIALIZATION_TYPE_FIELD; } break;
+case 82:
+#line 352 "asmparse.y"
+{ yyval.int32 = SERIALIZATION_TYPE_PROPERTY; } break;
+case 83:
+#line 355 "asmparse.y"
+{ if(yypvt[-0].cad->tkOwner && !yypvt[-0].cad->tkInterfacePair)
+ PASM->DefineCV(yypvt[-0].cad);
+ else if(PASM->m_pCustomDescrList)
+ PASM->m_pCustomDescrList->PUSH(yypvt[-0].cad); } break;
+case 84:
+#line 359 "asmparse.y"
+{ PASM->DefineCV(yypvt[-0].cad); } break;
+case 85:
+#line 360 "asmparse.y"
+{ CustomDescr* pNew = new CustomDescr(yypvt[-0].tdd->m_pCA);
+ if(pNew->tkOwner == 0) pNew->tkOwner = PASM->m_tkCurrentCVOwner;
+ if(pNew->tkOwner)
+ PASM->DefineCV(pNew);
+ else if(PASM->m_pCustomDescrList)
+ PASM->m_pCustomDescrList->PUSH(pNew); } break;
+case 86:
+#line 368 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 87:
+#line 369 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(SERIALIZATION_TYPE_TYPE); } break;
+case 88:
+#line 370 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(SERIALIZATION_TYPE_TAGGED_OBJECT); } break;
+case 89:
+#line 371 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(SERIALIZATION_TYPE_ENUM);
+ AppendStringWithLength(yyval.binstr,yypvt[-0].string); } break;
+case 90:
+#line 373 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(SERIALIZATION_TYPE_ENUM);
+ AppendStringWithLength(yyval.binstr,PASM->ReflectionNotation(yypvt[-0].token)); } break;
+case 91:
+#line 375 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 92:
+#line 380 "asmparse.y"
+{ PASMM->SetModuleName(NULL); PASM->m_tkCurrentCVOwner=1; } break;
+case 93:
+#line 381 "asmparse.y"
+{ PASMM->SetModuleName(yypvt[-0].string); PASM->m_tkCurrentCVOwner=1; } break;
+case 94:
+#line 382 "asmparse.y"
+{ BinStr* pbs = new BinStr();
+ unsigned L = (unsigned)strlen(yypvt[-0].string);
+ memcpy((char*)(pbs->getBuff(L)),yypvt[-0].string,L);
+ PASM->EmitImport(pbs); delete pbs;} break;
+case 95:
+#line 389 "asmparse.y"
+{ /*PASM->SetDataSection(); PASM->EmitDataLabel($7);*/
+ PASM->m_VTFList.PUSH(new VTFEntry((USHORT)yypvt[-4].int32, (USHORT)yypvt[-2].int32, yypvt[-0].string)); } break;
+case 96:
+#line 393 "asmparse.y"
+{ yyval.int32 = 0; } break;
+case 97:
+#line 394 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 | COR_VTABLE_32BIT; } break;
+case 98:
+#line 395 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 | COR_VTABLE_64BIT; } break;
+case 99:
+#line 396 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 | COR_VTABLE_FROM_UNMANAGED; } break;
+case 100:
+#line 397 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 | COR_VTABLE_CALL_MOST_DERIVED; } break;
+case 101:
+#line 398 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 | COR_VTABLE_FROM_UNMANAGED_RETAIN_APPDOMAIN; } break;
+case 102:
+#line 401 "asmparse.y"
+{ PASM->m_pVTable = yypvt[-1].binstr; } break;
+case 103:
+#line 404 "asmparse.y"
+{ bParsingByteArray = TRUE; } break;
+case 104:
+#line 408 "asmparse.y"
+{ PASM->StartNameSpace(yypvt[-0].string); } break;
+case 105:
+#line 411 "asmparse.y"
+{ newclass = TRUE; } break;
+case 106:
+#line 414 "asmparse.y"
+{ if(yypvt[-0].typarlist) FixupConstraints();
+ PASM->StartClass(yypvt[-1].string, yypvt[-2].classAttr, yypvt[-0].typarlist);
+ TyParFixupList.RESET(false);
+ newclass = FALSE;
+ } break;
+case 107:
+#line 420 "asmparse.y"
+{ PASM->AddClass(); } break;
+case 108:
+#line 423 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) 0; } break;
+case 109:
+#line 424 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-1].classAttr & ~tdVisibilityMask) | tdPublic); } break;
+case 110:
+#line 425 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-1].classAttr & ~tdVisibilityMask) | tdNotPublic); } break;
+case 111:
+#line 426 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | 0x80000000 | tdSealed); } break;
+case 112:
+#line 427 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | 0x40000000); } break;
+case 113:
+#line 428 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | tdInterface | tdAbstract); } break;
+case 114:
+#line 429 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | tdSealed); } break;
+case 115:
+#line 430 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | tdAbstract); } break;
+case 116:
+#line 431 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-1].classAttr & ~tdLayoutMask) | tdAutoLayout); } break;
+case 117:
+#line 432 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-1].classAttr & ~tdLayoutMask) | tdSequentialLayout); } break;
+case 118:
+#line 433 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-1].classAttr & ~tdLayoutMask) | tdExplicitLayout); } break;
+case 119:
+#line 434 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-1].classAttr & ~tdStringFormatMask) | tdAnsiClass); } break;
+case 120:
+#line 435 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-1].classAttr & ~tdStringFormatMask) | tdUnicodeClass); } break;
+case 121:
+#line 436 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-1].classAttr & ~tdStringFormatMask) | tdAutoClass); } break;
+case 122:
+#line 437 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | tdImport); } break;
+case 123:
+#line 438 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | tdSerializable); } break;
+case 124:
+#line 439 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | tdWindowsRuntime); } break;
+case 125:
+#line 440 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-2].classAttr & ~tdVisibilityMask) | tdNestedPublic); } break;
+case 126:
+#line 441 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-2].classAttr & ~tdVisibilityMask) | tdNestedPrivate); } break;
+case 127:
+#line 442 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-2].classAttr & ~tdVisibilityMask) | tdNestedFamily); } break;
+case 128:
+#line 443 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-2].classAttr & ~tdVisibilityMask) | tdNestedAssembly); } break;
+case 129:
+#line 444 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-2].classAttr & ~tdVisibilityMask) | tdNestedFamANDAssem); } break;
+case 130:
+#line 445 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) ((yypvt[-2].classAttr & ~tdVisibilityMask) | tdNestedFamORAssem); } break;
+case 131:
+#line 446 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | tdBeforeFieldInit); } break;
+case 132:
+#line 447 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr | tdSpecialName); } break;
+case 133:
+#line 448 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].classAttr); } break;
+case 134:
+#line 449 "asmparse.y"
+{ yyval.classAttr = (CorRegTypeAttr) (yypvt[-1].int32); } break;
+case 136:
+#line 453 "asmparse.y"
+{ PASM->m_crExtends = yypvt[-0].token; } break;
+case 141:
+#line 464 "asmparse.y"
+{ PASM->AddToImplList(yypvt[-0].token); } break;
+case 142:
+#line 465 "asmparse.y"
+{ PASM->AddToImplList(yypvt[-0].token); } break;
+case 143:
+#line 469 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 144:
+#line 470 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 145:
+#line 473 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt32(yypvt[-0].token); } break;
+case 146:
+#line 474 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; yyval.binstr->appendInt32(yypvt[-0].token); } break;
+case 147:
+#line 477 "asmparse.y"
+{ yyval.typarlist = NULL; PASM->m_TyParList = NULL;} break;
+case 148:
+#line 478 "asmparse.y"
+{ yyval.typarlist = yypvt[-1].typarlist; PASM->m_TyParList = yypvt[-1].typarlist;} break;
+case 149:
+#line 481 "asmparse.y"
+{ yyval.int32 = gpCovariant; } break;
+case 150:
+#line 482 "asmparse.y"
+{ yyval.int32 = gpContravariant; } break;
+case 151:
+#line 483 "asmparse.y"
+{ yyval.int32 = gpReferenceTypeConstraint; } break;
+case 152:
+#line 484 "asmparse.y"
+{ yyval.int32 = gpNotNullableValueTypeConstraint; } break;
+case 153:
+#line 485 "asmparse.y"
+{ yyval.int32 = gpDefaultConstructorConstraint; } break;
+case 154:
+#line 488 "asmparse.y"
+{ yyval.int32 = 0; } break;
+case 155:
+#line 489 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 | yypvt[-0].int32; } break;
+case 156:
+#line 492 "asmparse.y"
+{yyval.typarlist = new TyParList(yypvt[-3].int32, yypvt[-2].binstr, yypvt[-1].string, yypvt[-0].typarlist);} break;
+case 157:
+#line 493 "asmparse.y"
+{yyval.typarlist = new TyParList(yypvt[-2].int32, NULL, yypvt[-1].string, yypvt[-0].typarlist);} break;
+case 158:
+#line 496 "asmparse.y"
+{ yyval.typarlist = NULL; } break;
+case 159:
+#line 497 "asmparse.y"
+{ yyval.typarlist = yypvt[-0].typarlist; } break;
+case 160:
+#line 500 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; } break;
+case 161:
+#line 503 "asmparse.y"
+{ yyval.int32= 0; } break;
+case 162:
+#line 504 "asmparse.y"
+{ yyval.int32 = yypvt[-0].int32; } break;
+case 163:
+#line 507 "asmparse.y"
+{ yyval.int32 = yypvt[-2].int32; } break;
+case 164:
+#line 511 "asmparse.y"
+{ if(PASM->m_pCurMethod->m_ulLines[1] ==0)
+ { PASM->m_pCurMethod->m_ulLines[1] = PASM->m_ulCurLine;
+ PASM->m_pCurMethod->m_ulColumns[1]=PASM->m_ulCurColumn;}
+ PASM->EndMethod(); } break;
+case 165:
+#line 515 "asmparse.y"
+{ PASM->EndClass(); } break;
+case 166:
+#line 516 "asmparse.y"
+{ PASM->EndEvent(); } break;
+case 167:
+#line 517 "asmparse.y"
+{ PASM->EndProp(); } break;
+case 173:
+#line 523 "asmparse.y"
+{ PASM->m_pCurClass->m_ulSize = yypvt[-0].int32; } break;
+case 174:
+#line 524 "asmparse.y"
+{ PASM->m_pCurClass->m_ulPack = yypvt[-0].int32; } break;
+case 175:
+#line 525 "asmparse.y"
+{ PASMM->EndComType(); } break;
+case 176:
+#line 527 "asmparse.y"
+{ BinStr *sig1 = parser->MakeSig(yypvt[-7].int32, yypvt[-6].binstr, yypvt[-1].binstr);
+ BinStr *sig2 = new BinStr(); sig2->append(sig1);
+ PASM->AddMethodImpl(yypvt[-11].token,yypvt[-9].string,sig1,yypvt[-5].token,yypvt[-3].string,sig2);
+ PASM->ResetArgNameList();
+ } break;
+case 177:
+#line 533 "asmparse.y"
+{ PASM->AddMethodImpl(yypvt[-17].token,yypvt[-15].string,
+ (yypvt[-14].int32==0 ? parser->MakeSig(yypvt[-19].int32,yypvt[-18].binstr,yypvt[-12].binstr) :
+ parser->MakeSig(yypvt[-19].int32| IMAGE_CEE_CS_CALLCONV_GENERIC,yypvt[-18].binstr,yypvt[-12].binstr,yypvt[-14].int32)),
+ yypvt[-6].token,yypvt[-4].string,
+ (yypvt[-3].int32==0 ? parser->MakeSig(yypvt[-8].int32,yypvt[-7].binstr,yypvt[-1].binstr) :
+ parser->MakeSig(yypvt[-8].int32| IMAGE_CEE_CS_CALLCONV_GENERIC,yypvt[-7].binstr,yypvt[-1].binstr,yypvt[-3].int32)));
+ PASM->ResetArgNameList();
+ } break;
+case 180:
+#line 543 "asmparse.y"
+{ if((yypvt[-1].int32 > 0) && (yypvt[-1].int32 <= (int)PASM->m_pCurClass->m_NumTyPars))
+ PASM->m_pCustomDescrList = PASM->m_pCurClass->m_TyPars[yypvt[-1].int32-1].CAList();
+ else
+ PASM->report->error("Type parameter index out of range\n");
+ } break;
+case 181:
+#line 548 "asmparse.y"
+{ int n = PASM->m_pCurClass->FindTyPar(yypvt[-0].string);
+ if(n >= 0)
+ PASM->m_pCustomDescrList = PASM->m_pCurClass->m_TyPars[n].CAList();
+ else
+ PASM->report->error("Type parameter '%s' undefined\n",yypvt[-0].string);
+ } break;
+case 182:
+#line 554 "asmparse.y"
+{ yypvt[-0].cad->tkInterfacePair = yypvt[-1].token;
+ if(PASM->m_pCustomDescrList)
+ PASM->m_pCustomDescrList->PUSH(yypvt[-0].cad);
+ } break;
+case 183:
+#line 562 "asmparse.y"
+{ yypvt[-3].binstr->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ PASM->AddField(yypvt[-2].string, yypvt[-3].binstr, yypvt[-4].fieldAttr, yypvt[-1].string, yypvt[-0].binstr, yypvt[-5].int32); } break;
+case 184:
+#line 566 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) 0; } break;
+case 185:
+#line 567 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) (yypvt[-1].fieldAttr | fdStatic); } break;
+case 186:
+#line 568 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) ((yypvt[-1].fieldAttr & ~mdMemberAccessMask) | fdPublic); } break;
+case 187:
+#line 569 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) ((yypvt[-1].fieldAttr & ~mdMemberAccessMask) | fdPrivate); } break;
+case 188:
+#line 570 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) ((yypvt[-1].fieldAttr & ~mdMemberAccessMask) | fdFamily); } break;
+case 189:
+#line 571 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) (yypvt[-1].fieldAttr | fdInitOnly); } break;
+case 190:
+#line 572 "asmparse.y"
+{ yyval.fieldAttr = yypvt[-1].fieldAttr; } break;
+case 191:
+#line 573 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) (yypvt[-1].fieldAttr | fdSpecialName); } break;
+case 192:
+#line 586 "asmparse.y"
+{ PASM->m_pMarshal = yypvt[-1].binstr; } break;
+case 193:
+#line 587 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) ((yypvt[-1].fieldAttr & ~mdMemberAccessMask) | fdAssembly); } break;
+case 194:
+#line 588 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) ((yypvt[-1].fieldAttr & ~mdMemberAccessMask) | fdFamANDAssem); } break;
+case 195:
+#line 589 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) ((yypvt[-1].fieldAttr & ~mdMemberAccessMask) | fdFamORAssem); } break;
+case 196:
+#line 590 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) ((yypvt[-1].fieldAttr & ~mdMemberAccessMask) | fdPrivateScope); } break;
+case 197:
+#line 591 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) (yypvt[-1].fieldAttr | fdLiteral); } break;
+case 198:
+#line 592 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) (yypvt[-1].fieldAttr | fdNotSerialized); } break;
+case 199:
+#line 593 "asmparse.y"
+{ yyval.fieldAttr = (CorFieldAttr) (yypvt[-1].int32); } break;
+case 200:
+#line 596 "asmparse.y"
+{ yyval.string = 0; } break;
+case 201:
+#line 597 "asmparse.y"
+{ yyval.string = yypvt[-0].string; } break;
+case 202:
+#line 600 "asmparse.y"
+{ yyval.binstr = NULL; } break;
+case 203:
+#line 601 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 204:
+#line 604 "asmparse.y"
+{ yyval.int32 = 0xFFFFFFFF; } break;
+case 205:
+#line 605 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32; } break;
+case 206:
+#line 610 "asmparse.y"
+{ PASM->ResetArgNameList();
+ if (yypvt[-3].binstr == NULL)
+ {
+ if((iCallConv)&&((yypvt[-8].int32 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ yyval.token = PASM->MakeMemberRef(yypvt[-6].token, yypvt[-4].string, parser->MakeSig(yypvt[-8].int32|iCallConv, yypvt[-7].binstr, yypvt[-1].binstr));
+ }
+ else
+ {
+ mdToken mr;
+ if((iCallConv)&&((yypvt[-8].int32 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ mr = PASM->MakeMemberRef(yypvt[-6].token, yypvt[-4].string,
+ parser->MakeSig(yypvt[-8].int32 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, yypvt[-7].binstr, yypvt[-1].binstr, corCountArgs(yypvt[-3].binstr)));
+ yyval.token = PASM->MakeMethodSpec(mr,
+ parser->MakeSig(IMAGE_CEE_CS_CALLCONV_INSTANTIATION, 0, yypvt[-3].binstr));
+ }
+ } break;
+case 207:
+#line 627 "asmparse.y"
+{ PASM->ResetArgNameList();
+ if((iCallConv)&&((yypvt[-8].int32 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ yyval.token = PASM->MakeMemberRef(yypvt[-6].token, yypvt[-4].string,
+ parser->MakeSig(yypvt[-8].int32 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, yypvt[-7].binstr, yypvt[-1].binstr, yypvt[-3].int32));
+ } break;
+case 208:
+#line 633 "asmparse.y"
+{ PASM->ResetArgNameList();
+ if (yypvt[-3].binstr == NULL)
+ {
+ if((iCallConv)&&((yypvt[-6].int32 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ yyval.token = PASM->MakeMemberRef(mdTokenNil, yypvt[-4].string, parser->MakeSig(yypvt[-6].int32|iCallConv, yypvt[-5].binstr, yypvt[-1].binstr));
+ }
+ else
+ {
+ mdToken mr;
+ if((iCallConv)&&((yypvt[-6].int32 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ mr = PASM->MakeMemberRef(mdTokenNil, yypvt[-4].string, parser->MakeSig(yypvt[-6].int32 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, yypvt[-5].binstr, yypvt[-1].binstr, corCountArgs(yypvt[-3].binstr)));
+ yyval.token = PASM->MakeMethodSpec(mr,
+ parser->MakeSig(IMAGE_CEE_CS_CALLCONV_INSTANTIATION, 0, yypvt[-3].binstr));
+ }
+ } break;
+case 209:
+#line 649 "asmparse.y"
+{ PASM->ResetArgNameList();
+ if((iCallConv)&&((yypvt[-6].int32 & iCallConv) != iCallConv)) parser->warn("'instance' added to method's calling convention\n");
+ yyval.token = PASM->MakeMemberRef(mdTokenNil, yypvt[-4].string, parser->MakeSig(yypvt[-6].int32 | IMAGE_CEE_CS_CALLCONV_GENERIC|iCallConv, yypvt[-5].binstr, yypvt[-1].binstr, yypvt[-3].int32));
+ } break;
+case 210:
+#line 653 "asmparse.y"
+{ yyval.token = yypvt[-0].token; } break;
+case 211:
+#line 654 "asmparse.y"
+{ yyval.token = yypvt[-0].tdd->m_tkTypeSpec; } break;
+case 212:
+#line 655 "asmparse.y"
+{ yyval.token = yypvt[-0].tdd->m_tkTypeSpec; } break;
+case 213:
+#line 658 "asmparse.y"
+{ yyval.int32 = (yypvt[-0].int32 | IMAGE_CEE_CS_CALLCONV_HASTHIS); } break;
+case 214:
+#line 659 "asmparse.y"
+{ yyval.int32 = (yypvt[-0].int32 | IMAGE_CEE_CS_CALLCONV_EXPLICITTHIS); } break;
+case 215:
+#line 660 "asmparse.y"
+{ yyval.int32 = yypvt[-0].int32; } break;
+case 216:
+#line 661 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32; } break;
+case 217:
+#line 664 "asmparse.y"
+{ yyval.int32 = IMAGE_CEE_CS_CALLCONV_DEFAULT; } break;
+case 218:
+#line 665 "asmparse.y"
+{ yyval.int32 = IMAGE_CEE_CS_CALLCONV_DEFAULT; } break;
+case 219:
+#line 666 "asmparse.y"
+{ yyval.int32 = IMAGE_CEE_CS_CALLCONV_VARARG; } break;
+case 220:
+#line 667 "asmparse.y"
+{ yyval.int32 = IMAGE_CEE_CS_CALLCONV_C; } break;
+case 221:
+#line 668 "asmparse.y"
+{ yyval.int32 = IMAGE_CEE_CS_CALLCONV_STDCALL; } break;
+case 222:
+#line 669 "asmparse.y"
+{ yyval.int32 = IMAGE_CEE_CS_CALLCONV_THISCALL; } break;
+case 223:
+#line 670 "asmparse.y"
+{ yyval.int32 = IMAGE_CEE_CS_CALLCONV_FASTCALL; } break;
+case 224:
+#line 673 "asmparse.y"
+{ yyval.token = yypvt[-1].int32; } break;
+case 225:
+#line 676 "asmparse.y"
+{ yyval.token = yypvt[-0].token;
+ PASM->delArgNameList(PASM->m_firstArgName);
+ PASM->m_firstArgName = parser->m_ANSFirst.POP();
+ PASM->m_lastArgName = parser->m_ANSLast.POP();
+ PASM->SetMemberRefFixup(yypvt[-0].token,iOpcodeLen); } break;
+case 226:
+#line 682 "asmparse.y"
+{ yypvt[-3].binstr->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ yyval.token = PASM->MakeMemberRef(yypvt[-2].token, yypvt[-0].string, yypvt[-3].binstr);
+ PASM->SetMemberRefFixup(yyval.token,iOpcodeLen); } break;
+case 227:
+#line 686 "asmparse.y"
+{ yypvt[-1].binstr->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ yyval.token = PASM->MakeMemberRef(NULL, yypvt[-0].string, yypvt[-1].binstr);
+ PASM->SetMemberRefFixup(yyval.token,iOpcodeLen); } break;
+case 228:
+#line 689 "asmparse.y"
+{ yyval.token = yypvt[-0].tdd->m_tkTypeSpec;
+ PASM->SetMemberRefFixup(yyval.token,iOpcodeLen); } break;
+case 229:
+#line 691 "asmparse.y"
+{ yyval.token = yypvt[-0].tdd->m_tkTypeSpec;
+ PASM->SetMemberRefFixup(yyval.token,iOpcodeLen); } break;
+case 230:
+#line 693 "asmparse.y"
+{ yyval.token = yypvt[-0].token;
+ PASM->SetMemberRefFixup(yyval.token,iOpcodeLen); } break;
+case 231:
+#line 698 "asmparse.y"
+{ PASM->ResetEvent(yypvt[-0].string, yypvt[-1].token, yypvt[-2].eventAttr); } break;
+case 232:
+#line 699 "asmparse.y"
+{ PASM->ResetEvent(yypvt[-0].string, mdTypeRefNil, yypvt[-1].eventAttr); } break;
+case 233:
+#line 703 "asmparse.y"
+{ yyval.eventAttr = (CorEventAttr) 0; } break;
+case 234:
+#line 704 "asmparse.y"
+{ yyval.eventAttr = yypvt[-1].eventAttr; } break;
+case 235:
+#line 705 "asmparse.y"
+{ yyval.eventAttr = (CorEventAttr) (yypvt[-1].eventAttr | evSpecialName); } break;
+case 238:
+#line 712 "asmparse.y"
+{ PASM->SetEventMethod(0, yypvt[-0].token); } break;
+case 239:
+#line 713 "asmparse.y"
+{ PASM->SetEventMethod(1, yypvt[-0].token); } break;
+case 240:
+#line 714 "asmparse.y"
+{ PASM->SetEventMethod(2, yypvt[-0].token); } break;
+case 241:
+#line 715 "asmparse.y"
+{ PASM->SetEventMethod(3, yypvt[-0].token); } break;
+case 246:
+#line 724 "asmparse.y"
+{ PASM->ResetProp(yypvt[-4].string,
+ parser->MakeSig((IMAGE_CEE_CS_CALLCONV_PROPERTY |
+ (yypvt[-6].int32 & IMAGE_CEE_CS_CALLCONV_HASTHIS)),yypvt[-5].binstr,yypvt[-2].binstr), yypvt[-7].propAttr, yypvt[-0].binstr);} break;
+case 247:
+#line 729 "asmparse.y"
+{ yyval.propAttr = (CorPropertyAttr) 0; } break;
+case 248:
+#line 730 "asmparse.y"
+{ yyval.propAttr = yypvt[-1].propAttr; } break;
+case 249:
+#line 731 "asmparse.y"
+{ yyval.propAttr = (CorPropertyAttr) (yypvt[-1].propAttr | prSpecialName); } break;
+case 252:
+#line 739 "asmparse.y"
+{ PASM->SetPropMethod(0, yypvt[-0].token); } break;
+case 253:
+#line 740 "asmparse.y"
+{ PASM->SetPropMethod(1, yypvt[-0].token); } break;
+case 254:
+#line 741 "asmparse.y"
+{ PASM->SetPropMethod(2, yypvt[-0].token); } break;
+case 259:
+#line 749 "asmparse.y"
+{ PASM->ResetForNextMethod();
+ uMethodBeginLine = PASM->m_ulCurLine;
+ uMethodBeginColumn=PASM->m_ulCurColumn;
+ } break;
+case 260:
+#line 755 "asmparse.y"
+{ yyval.binstr = NULL; } break;
+case 261:
+#line 756 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; } break;
+case 262:
+#line 759 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 263:
+#line 760 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; } break;
+case 264:
+#line 763 "asmparse.y"
+{ bParsingByteArray = TRUE; } break;
+case 265:
+#line 767 "asmparse.y"
+{ BinStr* sig;
+ if (yypvt[-5].typarlist == NULL) sig = parser->MakeSig(yypvt[-10].int32, yypvt[-8].binstr, yypvt[-3].binstr);
+ else {
+ FixupTyPars(yypvt[-8].binstr);
+ sig = parser->MakeSig(yypvt[-10].int32 | IMAGE_CEE_CS_CALLCONV_GENERIC, yypvt[-8].binstr, yypvt[-3].binstr, yypvt[-5].typarlist->Count());
+ FixupConstraints();
+ }
+ PASM->StartMethod(yypvt[-6].string, sig, yypvt[-11].methAttr, yypvt[-7].binstr, yypvt[-9].int32, yypvt[-5].typarlist);
+ TyParFixupList.RESET(false);
+ PASM->SetImplAttr((USHORT)yypvt[-1].implAttr);
+ PASM->m_pCurMethod->m_ulLines[0] = uMethodBeginLine;
+ PASM->m_pCurMethod->m_ulColumns[0]=uMethodBeginColumn;
+ } break;
+case 266:
+#line 782 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) 0; } break;
+case 267:
+#line 783 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdStatic); } break;
+case 268:
+#line 784 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) ((yypvt[-1].methAttr & ~mdMemberAccessMask) | mdPublic); } break;
+case 269:
+#line 785 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) ((yypvt[-1].methAttr & ~mdMemberAccessMask) | mdPrivate); } break;
+case 270:
+#line 786 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) ((yypvt[-1].methAttr & ~mdMemberAccessMask) | mdFamily); } break;
+case 271:
+#line 787 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdFinal); } break;
+case 272:
+#line 788 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdSpecialName); } break;
+case 273:
+#line 789 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdVirtual); } break;
+case 274:
+#line 790 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdCheckAccessOnOverride); } break;
+case 275:
+#line 791 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdAbstract); } break;
+case 276:
+#line 792 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) ((yypvt[-1].methAttr & ~mdMemberAccessMask) | mdAssem); } break;
+case 277:
+#line 793 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) ((yypvt[-1].methAttr & ~mdMemberAccessMask) | mdFamANDAssem); } break;
+case 278:
+#line 794 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) ((yypvt[-1].methAttr & ~mdMemberAccessMask) | mdFamORAssem); } break;
+case 279:
+#line 795 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) ((yypvt[-1].methAttr & ~mdMemberAccessMask) | mdPrivateScope); } break;
+case 280:
+#line 796 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdHideBySig); } break;
+case 281:
+#line 797 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdNewSlot); } break;
+case 282:
+#line 798 "asmparse.y"
+{ yyval.methAttr = yypvt[-1].methAttr; } break;
+case 283:
+#line 799 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdUnmanagedExport); } break;
+case 284:
+#line 800 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].methAttr | mdRequireSecObject); } break;
+case 285:
+#line 801 "asmparse.y"
+{ yyval.methAttr = (CorMethodAttr) (yypvt[-1].int32); } break;
+case 286:
+#line 803 "asmparse.y"
+{ PASM->SetPinvoke(yypvt[-4].binstr,0,yypvt[-2].binstr,yypvt[-1].pinvAttr);
+ yyval.methAttr = (CorMethodAttr) (yypvt[-7].methAttr | mdPinvokeImpl); } break;
+case 287:
+#line 806 "asmparse.y"
+{ PASM->SetPinvoke(yypvt[-2].binstr,0,NULL,yypvt[-1].pinvAttr);
+ yyval.methAttr = (CorMethodAttr) (yypvt[-5].methAttr | mdPinvokeImpl); } break;
+case 288:
+#line 809 "asmparse.y"
+{ PASM->SetPinvoke(new BinStr(),0,NULL,yypvt[-1].pinvAttr);
+ yyval.methAttr = (CorMethodAttr) (yypvt[-4].methAttr | mdPinvokeImpl); } break;
+case 289:
+#line 813 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) 0; } break;
+case 290:
+#line 814 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmNoMangle); } break;
+case 291:
+#line 815 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmCharSetAnsi); } break;
+case 292:
+#line 816 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmCharSetUnicode); } break;
+case 293:
+#line 817 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmCharSetAuto); } break;
+case 294:
+#line 818 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmSupportsLastError); } break;
+case 295:
+#line 819 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmCallConvWinapi); } break;
+case 296:
+#line 820 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmCallConvCdecl); } break;
+case 297:
+#line 821 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmCallConvStdcall); } break;
+case 298:
+#line 822 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmCallConvThiscall); } break;
+case 299:
+#line 823 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].pinvAttr | pmCallConvFastcall); } break;
+case 300:
+#line 824 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-3].pinvAttr | pmBestFitEnabled); } break;
+case 301:
+#line 825 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-3].pinvAttr | pmBestFitDisabled); } break;
+case 302:
+#line 826 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-3].pinvAttr | pmThrowOnUnmappableCharEnabled); } break;
+case 303:
+#line 827 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-3].pinvAttr | pmThrowOnUnmappableCharDisabled); } break;
+case 304:
+#line 828 "asmparse.y"
+{ yyval.pinvAttr = (CorPinvokeMap) (yypvt[-1].int32); } break;
+case 305:
+#line 831 "asmparse.y"
+{ yyval.string = newString(COR_CTOR_METHOD_NAME); } break;
+case 306:
+#line 832 "asmparse.y"
+{ yyval.string = newString(COR_CCTOR_METHOD_NAME); } break;
+case 307:
+#line 833 "asmparse.y"
+{ yyval.string = yypvt[-0].string; } break;
+case 308:
+#line 836 "asmparse.y"
+{ yyval.int32 = 0; } break;
+case 309:
+#line 837 "asmparse.y"
+{ yyval.int32 = yypvt[-3].int32 | pdIn; } break;
+case 310:
+#line 838 "asmparse.y"
+{ yyval.int32 = yypvt[-3].int32 | pdOut; } break;
+case 311:
+#line 839 "asmparse.y"
+{ yyval.int32 = yypvt[-3].int32 | pdOptional; } break;
+case 312:
+#line 840 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 + 1; } break;
+case 313:
+#line 843 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (miIL | miManaged); } break;
+case 314:
+#line 844 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) ((yypvt[-1].implAttr & 0xFFF4) | miNative); } break;
+case 315:
+#line 845 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) ((yypvt[-1].implAttr & 0xFFF4) | miIL); } break;
+case 316:
+#line 846 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) ((yypvt[-1].implAttr & 0xFFF4) | miOPTIL); } break;
+case 317:
+#line 847 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) ((yypvt[-1].implAttr & 0xFFFB) | miManaged); } break;
+case 318:
+#line 848 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) ((yypvt[-1].implAttr & 0xFFFB) | miUnmanaged); } break;
+case 319:
+#line 849 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].implAttr | miForwardRef); } break;
+case 320:
+#line 850 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].implAttr | miPreserveSig); } break;
+case 321:
+#line 851 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].implAttr | miRuntime); } break;
+case 322:
+#line 852 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].implAttr | miInternalCall); } break;
+case 323:
+#line 853 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].implAttr | miSynchronized); } break;
+case 324:
+#line 854 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].implAttr | miNoInlining); } break;
+case 325:
+#line 855 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].implAttr | miAggressiveInlining); } break;
+case 326:
+#line 856 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].implAttr | miNoOptimization); } break;
+case 327:
+#line 857 "asmparse.y"
+{ yyval.implAttr = (CorMethodImpl) (yypvt[-1].int32); } break;
+case 328:
+#line 860 "asmparse.y"
+{ PASM->delArgNameList(PASM->m_firstArgName); PASM->m_firstArgName = NULL;PASM->m_lastArgName = NULL;
+ } break;
+case 331:
+#line 868 "asmparse.y"
+{ PASM->EmitByte(yypvt[-0].int32); } break;
+case 332:
+#line 869 "asmparse.y"
+{ delete PASM->m_SEHD; PASM->m_SEHD = PASM->m_SEHDstack.POP(); } break;
+case 333:
+#line 870 "asmparse.y"
+{ PASM->EmitMaxStack(yypvt[-0].int32); } break;
+case 334:
+#line 871 "asmparse.y"
+{ PASM->EmitLocals(parser->MakeSig(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG, 0, yypvt[-1].binstr));
+ } break;
+case 335:
+#line 873 "asmparse.y"
+{ PASM->EmitZeroInit();
+ PASM->EmitLocals(parser->MakeSig(IMAGE_CEE_CS_CALLCONV_LOCAL_SIG, 0, yypvt[-1].binstr));
+ } break;
+case 336:
+#line 876 "asmparse.y"
+{ PASM->EmitEntryPoint(); } break;
+case 337:
+#line 877 "asmparse.y"
+{ PASM->EmitZeroInit(); } break;
+case 340:
+#line 880 "asmparse.y"
+{ PASM->AddLabel(PASM->m_CurPC,yypvt[-1].string); /*PASM->EmitLabel($1);*/ } break;
+case 346:
+#line 886 "asmparse.y"
+{ if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
+ {
+ PASM->m_pCurMethod->m_dwExportOrdinal = yypvt[-1].int32;
+ PASM->m_pCurMethod->m_szExportAlias = NULL;
+ if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
+ if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = yypvt[-1].int32 + 0x8000;
+ }
+ else
+ PASM->report->warn("Duplicate .export directive, ignored\n");
+ } break;
+case 347:
+#line 896 "asmparse.y"
+{ if(PASM->m_pCurMethod->m_dwExportOrdinal == 0xFFFFFFFF)
+ {
+ PASM->m_pCurMethod->m_dwExportOrdinal = yypvt[-3].int32;
+ PASM->m_pCurMethod->m_szExportAlias = yypvt[-0].string;
+ if(PASM->m_pCurMethod->m_wVTEntry == 0) PASM->m_pCurMethod->m_wVTEntry = 1;
+ if(PASM->m_pCurMethod->m_wVTSlot == 0) PASM->m_pCurMethod->m_wVTSlot = yypvt[-3].int32 + 0x8000;
+ }
+ else
+ PASM->report->warn("Duplicate .export directive, ignored\n");
+ } break;
+case 348:
+#line 906 "asmparse.y"
+{ PASM->m_pCurMethod->m_wVTEntry = (WORD)yypvt[-2].int32;
+ PASM->m_pCurMethod->m_wVTSlot = (WORD)yypvt[-0].int32; } break;
+case 349:
+#line 909 "asmparse.y"
+{ PASM->AddMethodImpl(yypvt[-2].token,yypvt[-0].string,NULL,NULL,NULL,NULL); } break;
+case 350:
+#line 912 "asmparse.y"
+{ PASM->AddMethodImpl(yypvt[-6].token,yypvt[-4].string,
+ (yypvt[-3].int32==0 ? parser->MakeSig(yypvt[-8].int32,yypvt[-7].binstr,yypvt[-1].binstr) :
+ parser->MakeSig(yypvt[-8].int32| IMAGE_CEE_CS_CALLCONV_GENERIC,yypvt[-7].binstr,yypvt[-1].binstr,yypvt[-3].int32))
+ ,NULL,NULL,NULL);
+ PASM->ResetArgNameList();
+ } break;
+case 352:
+#line 919 "asmparse.y"
+{ if((yypvt[-1].int32 > 0) && (yypvt[-1].int32 <= (int)PASM->m_pCurMethod->m_NumTyPars))
+ PASM->m_pCustomDescrList = PASM->m_pCurMethod->m_TyPars[yypvt[-1].int32-1].CAList();
+ else
+ PASM->report->error("Type parameter index out of range\n");
+ } break;
+case 353:
+#line 924 "asmparse.y"
+{ int n = PASM->m_pCurMethod->FindTyPar(yypvt[-0].string);
+ if(n >= 0)
+ PASM->m_pCustomDescrList = PASM->m_pCurMethod->m_TyPars[n].CAList();
+ else
+ PASM->report->error("Type parameter '%s' undefined\n",yypvt[-0].string);
+ } break;
+case 354:
+#line 931 "asmparse.y"
+{ if( yypvt[-2].int32 ) {
+ ARG_NAME_LIST* pAN=PASM->findArg(PASM->m_pCurMethod->m_firstArgName, yypvt[-2].int32 - 1);
+ if(pAN)
+ {
+ PASM->m_pCustomDescrList = &(pAN->CustDList);
+ pAN->pValue = yypvt[-0].binstr;
+ }
+ else
+ {
+ PASM->m_pCustomDescrList = NULL;
+ if(yypvt[-0].binstr) delete yypvt[-0].binstr;
+ }
+ } else {
+ PASM->m_pCustomDescrList = &(PASM->m_pCurMethod->m_RetCustDList);
+ PASM->m_pCurMethod->m_pRetValue = yypvt[-0].binstr;
+ }
+ PASM->m_tkCurrentCVOwner = 0;
+ } break;
+case 355:
+#line 951 "asmparse.y"
+{ PASM->m_pCurMethod->CloseScope(); } break;
+case 356:
+#line 954 "asmparse.y"
+{ PASM->m_pCurMethod->OpenScope(); } break;
+case 360:
+#line 965 "asmparse.y"
+{ PASM->m_SEHD->tryTo = PASM->m_CurPC; } break;
+case 361:
+#line 966 "asmparse.y"
+{ PASM->SetTryLabels(yypvt[-2].string, yypvt[-0].string); } break;
+case 362:
+#line 967 "asmparse.y"
+{ if(PASM->m_SEHD) {PASM->m_SEHD->tryFrom = yypvt[-2].int32;
+ PASM->m_SEHD->tryTo = yypvt[-0].int32;} } break;
+case 363:
+#line 971 "asmparse.y"
+{ PASM->NewSEHDescriptor();
+ PASM->m_SEHD->tryFrom = PASM->m_CurPC; } break;
+case 364:
+#line 976 "asmparse.y"
+{ PASM->EmitTry(); } break;
+case 365:
+#line 977 "asmparse.y"
+{ PASM->EmitTry(); } break;
+case 366:
+#line 978 "asmparse.y"
+{ PASM->EmitTry(); } break;
+case 367:
+#line 979 "asmparse.y"
+{ PASM->EmitTry(); } break;
+case 368:
+#line 983 "asmparse.y"
+{ PASM->m_SEHD->sehHandler = PASM->m_CurPC; } break;
+case 369:
+#line 984 "asmparse.y"
+{ PASM->SetFilterLabel(yypvt[-0].string);
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; } break;
+case 370:
+#line 986 "asmparse.y"
+{ PASM->m_SEHD->sehFilter = yypvt[-0].int32;
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; } break;
+case 371:
+#line 990 "asmparse.y"
+{ PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FILTER;
+ PASM->m_SEHD->sehFilter = PASM->m_CurPC; } break;
+case 372:
+#line 994 "asmparse.y"
+{ PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_NONE;
+ PASM->SetCatchClass(yypvt[-0].token);
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; } break;
+case 373:
+#line 999 "asmparse.y"
+{ PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FINALLY;
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; } break;
+case 374:
+#line 1003 "asmparse.y"
+{ PASM->m_SEHD->sehClause = COR_ILEXCEPTION_CLAUSE_FAULT;
+ PASM->m_SEHD->sehHandler = PASM->m_CurPC; } break;
+case 375:
+#line 1007 "asmparse.y"
+{ PASM->m_SEHD->sehHandlerTo = PASM->m_CurPC; } break;
+case 376:
+#line 1008 "asmparse.y"
+{ PASM->SetHandlerLabels(yypvt[-2].string, yypvt[-0].string); } break;
+case 377:
+#line 1009 "asmparse.y"
+{ PASM->m_SEHD->sehHandler = yypvt[-2].int32;
+ PASM->m_SEHD->sehHandlerTo = yypvt[-0].int32; } break;
+case 379:
+#line 1017 "asmparse.y"
+{ PASM->EmitDataLabel(yypvt[-1].string); } break;
+case 381:
+#line 1021 "asmparse.y"
+{ PASM->SetDataSection(); } break;
+case 382:
+#line 1022 "asmparse.y"
+{ PASM->SetTLSSection(); } break;
+case 383:
+#line 1023 "asmparse.y"
+{ PASM->SetILSection(); } break;
+case 388:
+#line 1034 "asmparse.y"
+{ yyval.int32 = 1; } break;
+case 389:
+#line 1035 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32;
+ if(yypvt[-1].int32 <= 0) { PASM->report->error("Illegal item count: %d\n",yypvt[-1].int32);
+ if(!PASM->OnErrGo) yyval.int32 = 1; }} break;
+case 390:
+#line 1040 "asmparse.y"
+{ PASM->EmitDataString(yypvt[-1].binstr); } break;
+case 391:
+#line 1041 "asmparse.y"
+{ PASM->EmitDD(yypvt[-1].string); } break;
+case 392:
+#line 1042 "asmparse.y"
+{ PASM->EmitData(yypvt[-1].binstr->ptr(),yypvt[-1].binstr->length()); } break;
+case 393:
+#line 1044 "asmparse.y"
+{ float f = (float) (*yypvt[-2].float64); float* p = new (nothrow) float[yypvt[-0].int32];
+ if(p != NULL) {
+ for(int i=0; i < yypvt[-0].int32; i++) p[i] = f;
+ PASM->EmitData(p, sizeof(float)*yypvt[-0].int32); delete yypvt[-2].float64; delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(float)*yypvt[-0].int32); } break;
+case 394:
+#line 1051 "asmparse.y"
+{ double* p = new (nothrow) double[yypvt[-0].int32];
+ if(p != NULL) {
+ for(int i=0; i<yypvt[-0].int32; i++) p[i] = *(yypvt[-2].float64);
+ PASM->EmitData(p, sizeof(double)*yypvt[-0].int32); delete yypvt[-2].float64; delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(double)*yypvt[-0].int32); } break;
+case 395:
+#line 1058 "asmparse.y"
+{ __int64* p = new (nothrow) __int64[yypvt[-0].int32];
+ if(p != NULL) {
+ for(int i=0; i<yypvt[-0].int32; i++) p[i] = *(yypvt[-2].int64);
+ PASM->EmitData(p, sizeof(__int64)*yypvt[-0].int32); delete yypvt[-2].int64; delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(__int64)*yypvt[-0].int32); } break;
+case 396:
+#line 1065 "asmparse.y"
+{ __int32* p = new (nothrow) __int32[yypvt[-0].int32];
+ if(p != NULL) {
+ for(int i=0; i<yypvt[-0].int32; i++) p[i] = yypvt[-2].int32;
+ PASM->EmitData(p, sizeof(__int32)*yypvt[-0].int32); delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(__int32)*yypvt[-0].int32); } break;
+case 397:
+#line 1072 "asmparse.y"
+{ __int16 i = (__int16) yypvt[-2].int32; FAIL_UNLESS(i == yypvt[-2].int32, ("Value %d too big\n", yypvt[-2].int32));
+ __int16* p = new (nothrow) __int16[yypvt[-0].int32];
+ if(p != NULL) {
+ for(int j=0; j<yypvt[-0].int32; j++) p[j] = i;
+ PASM->EmitData(p, sizeof(__int16)*yypvt[-0].int32); delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(__int16)*yypvt[-0].int32); } break;
+case 398:
+#line 1080 "asmparse.y"
+{ __int8 i = (__int8) yypvt[-2].int32; FAIL_UNLESS(i == yypvt[-2].int32, ("Value %d too big\n", yypvt[-2].int32));
+ __int8* p = new (nothrow) __int8[yypvt[-0].int32];
+ if(p != NULL) {
+ for(int j=0; j<yypvt[-0].int32; j++) p[j] = i;
+ PASM->EmitData(p, sizeof(__int8)*yypvt[-0].int32); delete [] p;
+ } else PASM->report->error("Out of memory emitting data block %d bytes\n",
+ sizeof(__int8)*yypvt[-0].int32); } break;
+case 399:
+#line 1087 "asmparse.y"
+{ PASM->EmitData(NULL, sizeof(float)*yypvt[-0].int32); } break;
+case 400:
+#line 1088 "asmparse.y"
+{ PASM->EmitData(NULL, sizeof(double)*yypvt[-0].int32); } break;
+case 401:
+#line 1089 "asmparse.y"
+{ PASM->EmitData(NULL, sizeof(__int64)*yypvt[-0].int32); } break;
+case 402:
+#line 1090 "asmparse.y"
+{ PASM->EmitData(NULL, sizeof(__int32)*yypvt[-0].int32); } break;
+case 403:
+#line 1091 "asmparse.y"
+{ PASM->EmitData(NULL, sizeof(__int16)*yypvt[-0].int32); } break;
+case 404:
+#line 1092 "asmparse.y"
+{ PASM->EmitData(NULL, sizeof(__int8)*yypvt[-0].int32); } break;
+case 405:
+#line 1096 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_R4);
+ float f = (float)(*yypvt[-1].float64);
+ yyval.binstr->appendInt32(*((__int32*)&f)); delete yypvt[-1].float64; } break;
+case 406:
+#line 1099 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_R8);
+ yyval.binstr->appendInt64((__int64 *)yypvt[-1].float64); delete yypvt[-1].float64; } break;
+case 407:
+#line 1101 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_R4);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 408:
+#line 1103 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_R8);
+ yyval.binstr->appendInt64((__int64 *)yypvt[-1].int64); delete yypvt[-1].int64; } break;
+case 409:
+#line 1105 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I8);
+ yyval.binstr->appendInt64((__int64 *)yypvt[-1].int64); delete yypvt[-1].int64; } break;
+case 410:
+#line 1107 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I4);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 411:
+#line 1109 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I2);
+ yyval.binstr->appendInt16(yypvt[-1].int32); } break;
+case 412:
+#line 1111 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I1);
+ yyval.binstr->appendInt8(yypvt[-1].int32); } break;
+case 413:
+#line 1113 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U8);
+ yyval.binstr->appendInt64((__int64 *)yypvt[-1].int64); delete yypvt[-1].int64; } break;
+case 414:
+#line 1115 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U4);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 415:
+#line 1117 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U2);
+ yyval.binstr->appendInt16(yypvt[-1].int32); } break;
+case 416:
+#line 1119 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U1);
+ yyval.binstr->appendInt8(yypvt[-1].int32); } break;
+case 417:
+#line 1121 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U8);
+ yyval.binstr->appendInt64((__int64 *)yypvt[-1].int64); delete yypvt[-1].int64; } break;
+case 418:
+#line 1123 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U4);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 419:
+#line 1125 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U2);
+ yyval.binstr->appendInt16(yypvt[-1].int32); } break;
+case 420:
+#line 1127 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U1);
+ yyval.binstr->appendInt8(yypvt[-1].int32); } break;
+case 421:
+#line 1129 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_CHAR);
+ yyval.binstr->appendInt16(yypvt[-1].int32); } break;
+case 422:
+#line 1131 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_BOOLEAN);
+ yyval.binstr->appendInt8(yypvt[-1].int32);} break;
+case 423:
+#line 1133 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_STRING);
+ yyval.binstr->append(yypvt[-1].binstr); delete yypvt[-1].binstr;} break;
+case 424:
+#line 1137 "asmparse.y"
+{ bParsingByteArray = TRUE; } break;
+case 425:
+#line 1140 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 426:
+#line 1141 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 427:
+#line 1144 "asmparse.y"
+{ __int8 i = (__int8) yypvt[-0].int32; yyval.binstr = new BinStr(); yyval.binstr->appendInt8(i); } break;
+case 428:
+#line 1145 "asmparse.y"
+{ __int8 i = (__int8) yypvt[-0].int32; yyval.binstr = yypvt[-1].binstr; yyval.binstr->appendInt8(i); } break;
+case 429:
+#line 1149 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 430:
+#line 1150 "asmparse.y"
+{ yyval.binstr = BinStrToUnicode(yypvt[-0].binstr,true); yyval.binstr->insertInt8(ELEMENT_TYPE_STRING);} break;
+case 431:
+#line 1151 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_CLASS);
+ yyval.binstr->appendInt32(0); } break;
+case 432:
+#line 1156 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 433:
+#line 1157 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_STRING); yyval.binstr->appendInt8(0xFF); } break;
+case 434:
+#line 1158 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_STRING);
+ AppendStringWithLength(yyval.binstr,yypvt[-1].string); delete [] yypvt[-1].string;} break;
+case 435:
+#line 1160 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(SERIALIZATION_TYPE_TYPE);
+ AppendStringWithLength(yyval.binstr,yypvt[-1].string); delete [] yypvt[-1].string;} break;
+case 436:
+#line 1162 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(SERIALIZATION_TYPE_TYPE);
+ AppendStringWithLength(yyval.binstr,PASM->ReflectionNotation(yypvt[-1].token));} break;
+case 437:
+#line 1164 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(SERIALIZATION_TYPE_TYPE); yyval.binstr->appendInt8(0xFF); } break;
+case 438:
+#line 1165 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt8(SERIALIZATION_TYPE_TAGGED_OBJECT);} break;
+case 439:
+#line 1167 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_R4);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 440:
+#line 1171 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_R8);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 441:
+#line 1175 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_I8);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 442:
+#line 1179 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_I4);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 443:
+#line 1183 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_I2);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 444:
+#line 1187 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_I1);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 445:
+#line 1191 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_U8);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 446:
+#line 1195 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_U4);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 447:
+#line 1199 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_U2);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 448:
+#line 1203 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_U1);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 449:
+#line 1207 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_U8);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 450:
+#line 1211 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_U4);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 451:
+#line 1215 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_U2);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 452:
+#line 1219 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_U1);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 453:
+#line 1223 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_CHAR);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 454:
+#line 1227 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_BOOLEAN);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 455:
+#line 1231 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_STRING);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 456:
+#line 1235 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(SERIALIZATION_TYPE_TYPE);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 457:
+#line 1239 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt32(yypvt[-4].int32);
+ yyval.binstr->insertInt8(SERIALIZATION_TYPE_TAGGED_OBJECT);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 458:
+#line 1245 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 459:
+#line 1246 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ float f = (float) (*yypvt[-0].float64); yyval.binstr->appendInt32(*((__int32*)&f)); delete yypvt[-0].float64; } break;
+case 460:
+#line 1248 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ yyval.binstr->appendInt32(yypvt[-0].int32); } break;
+case 461:
+#line 1252 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 462:
+#line 1253 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ yyval.binstr->appendInt64((__int64 *)yypvt[-0].float64); delete yypvt[-0].float64; } break;
+case 463:
+#line 1255 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ yyval.binstr->appendInt64((__int64 *)yypvt[-0].int64); delete yypvt[-0].int64; } break;
+case 464:
+#line 1259 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 465:
+#line 1260 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ yyval.binstr->appendInt64((__int64 *)yypvt[-0].int64); delete yypvt[-0].int64; } break;
+case 466:
+#line 1264 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 467:
+#line 1265 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->appendInt32(yypvt[-0].int32);} break;
+case 468:
+#line 1268 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 469:
+#line 1269 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->appendInt16(yypvt[-0].int32);} break;
+case 470:
+#line 1272 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 471:
+#line 1273 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->appendInt8(yypvt[-0].int32); } break;
+case 472:
+#line 1276 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 473:
+#line 1277 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ yyval.binstr->appendInt8(yypvt[-0].int32);} break;
+case 474:
+#line 1281 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 475:
+#line 1282 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->appendInt8(0xFF); } break;
+case 476:
+#line 1283 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ AppendStringWithLength(yyval.binstr,yypvt[-0].string); delete [] yypvt[-0].string;} break;
+case 477:
+#line 1287 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 478:
+#line 1288 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->appendInt8(0xFF); } break;
+case 479:
+#line 1289 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr;
+ AppendStringWithLength(yyval.binstr,yypvt[-0].string); delete [] yypvt[-0].string;} break;
+case 480:
+#line 1291 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr;
+ AppendStringWithLength(yyval.binstr,PASM->ReflectionNotation(yypvt[-0].token));} break;
+case 481:
+#line 1295 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 482:
+#line 1296 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->append(yypvt[-0].binstr); delete yypvt[-0].binstr; } break;
+case 483:
+#line 1300 "asmparse.y"
+{ parser->m_ANSFirst.PUSH(PASM->m_firstArgName);
+ parser->m_ANSLast.PUSH(PASM->m_lastArgName);
+ PASM->m_firstArgName = NULL;
+ PASM->m_lastArgName = NULL; } break;
+case 484:
+#line 1306 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 485:
+#line 1309 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 486:
+#line 1312 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 487:
+#line 1315 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 488:
+#line 1318 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 489:
+#line 1321 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 490:
+#line 1324 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode);
+ if((!PASM->OnErrGo)&&
+ ((yypvt[-0].opcode == CEE_NEWOBJ)||
+ (yypvt[-0].opcode == CEE_CALLVIRT)))
+ iCallConv = IMAGE_CEE_CS_CALLCONV_HASTHIS;
+ } break;
+case 491:
+#line 1332 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 492:
+#line 1335 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 493:
+#line 1338 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 494:
+#line 1341 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 495:
+#line 1344 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); iOpcodeLen = PASM->OpcodeLen(yyval.instr); } break;
+case 496:
+#line 1347 "asmparse.y"
+{ yyval.instr = SetupInstr(yypvt[-0].opcode); } break;
+case 497:
+#line 1350 "asmparse.y"
+{ yyval.instr = yypvt[-1].instr; bParsingByteArray = TRUE; } break;
+case 498:
+#line 1354 "asmparse.y"
+{ PASM->EmitOpcode(yypvt[-0].instr); } break;
+case 499:
+#line 1355 "asmparse.y"
+{ PASM->EmitInstrVar(yypvt[-1].instr, yypvt[-0].int32); } break;
+case 500:
+#line 1356 "asmparse.y"
+{ PASM->EmitInstrVarByName(yypvt[-1].instr, yypvt[-0].string); } break;
+case 501:
+#line 1357 "asmparse.y"
+{ PASM->EmitInstrI(yypvt[-1].instr, yypvt[-0].int32); } break;
+case 502:
+#line 1358 "asmparse.y"
+{ PASM->EmitInstrI8(yypvt[-1].instr, yypvt[-0].int64); } break;
+case 503:
+#line 1359 "asmparse.y"
+{ PASM->EmitInstrR(yypvt[-1].instr, yypvt[-0].float64); delete (yypvt[-0].float64);} break;
+case 504:
+#line 1360 "asmparse.y"
+{ double f = (double) (*yypvt[-0].int64); PASM->EmitInstrR(yypvt[-1].instr, &f); } break;
+case 505:
+#line 1361 "asmparse.y"
+{ unsigned L = yypvt[-1].binstr->length();
+ FAIL_UNLESS(L >= sizeof(float), ("%d hexbytes, must be at least %d\n",
+ L,sizeof(float)));
+ if(L < sizeof(float)) {YYERROR; }
+ else {
+ double f = (L >= sizeof(double)) ? *((double *)(yypvt[-1].binstr->ptr()))
+ : (double)(*(float *)(yypvt[-1].binstr->ptr()));
+ PASM->EmitInstrR(yypvt[-2].instr,&f); }
+ delete yypvt[-1].binstr; } break;
+case 506:
+#line 1370 "asmparse.y"
+{ PASM->EmitInstrBrOffset(yypvt[-1].instr, yypvt[-0].int32); } break;
+case 507:
+#line 1371 "asmparse.y"
+{ PASM->EmitInstrBrTarget(yypvt[-1].instr, yypvt[-0].string); } break;
+case 508:
+#line 1373 "asmparse.y"
+{ PASM->SetMemberRefFixup(yypvt[-0].token,PASM->OpcodeLen(yypvt[-1].instr));
+ PASM->EmitInstrI(yypvt[-1].instr,yypvt[-0].token);
+ PASM->m_tkCurrentCVOwner = yypvt[-0].token;
+ PASM->m_pCustomDescrList = NULL;
+ iCallConv = 0;
+ } break;
+case 509:
+#line 1380 "asmparse.y"
+{ yypvt[-3].binstr->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ mdToken mr = PASM->MakeMemberRef(yypvt[-2].token, yypvt[-0].string, yypvt[-3].binstr);
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen(yypvt[-4].instr));
+ PASM->EmitInstrI(yypvt[-4].instr,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ } break;
+case 510:
+#line 1388 "asmparse.y"
+{ yypvt[-1].binstr->insertInt8(IMAGE_CEE_CS_CALLCONV_FIELD);
+ mdToken mr = PASM->MakeMemberRef(mdTokenNil, yypvt[-0].string, yypvt[-1].binstr);
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen(yypvt[-2].instr));
+ PASM->EmitInstrI(yypvt[-2].instr,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ } break;
+case 511:
+#line 1395 "asmparse.y"
+{ mdToken mr = yypvt[-0].token;
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen(yypvt[-1].instr));
+ PASM->EmitInstrI(yypvt[-1].instr,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ } break;
+case 512:
+#line 1401 "asmparse.y"
+{ mdToken mr = yypvt[-0].tdd->m_tkTypeSpec;
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen(yypvt[-1].instr));
+ PASM->EmitInstrI(yypvt[-1].instr,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ } break;
+case 513:
+#line 1407 "asmparse.y"
+{ mdToken mr = yypvt[-0].tdd->m_tkTypeSpec;
+ PASM->SetMemberRefFixup(mr, PASM->OpcodeLen(yypvt[-1].instr));
+ PASM->EmitInstrI(yypvt[-1].instr,mr);
+ PASM->m_tkCurrentCVOwner = mr;
+ PASM->m_pCustomDescrList = NULL;
+ } break;
+case 514:
+#line 1413 "asmparse.y"
+{ PASM->EmitInstrI(yypvt[-1].instr, yypvt[-0].token);
+ PASM->m_tkCurrentCVOwner = yypvt[-0].token;
+ PASM->m_pCustomDescrList = NULL;
+ } break;
+case 515:
+#line 1417 "asmparse.y"
+{ PASM->EmitInstrStringLiteral(yypvt[-1].instr, yypvt[-0].binstr,TRUE); } break;
+case 516:
+#line 1419 "asmparse.y"
+{ PASM->EmitInstrStringLiteral(yypvt[-4].instr, yypvt[-1].binstr,FALSE); } break;
+case 517:
+#line 1421 "asmparse.y"
+{ PASM->EmitInstrStringLiteral(yypvt[-3].instr, yypvt[-1].binstr,FALSE,TRUE); } break;
+case 518:
+#line 1423 "asmparse.y"
+{ PASM->EmitInstrSig(yypvt[-5].instr, parser->MakeSig(yypvt[-4].int32, yypvt[-3].binstr, yypvt[-1].binstr));
+ PASM->ResetArgNameList();
+ } break;
+case 519:
+#line 1427 "asmparse.y"
+{ PASM->EmitInstrI(yypvt[-1].instr,yypvt[-0].token);
+ PASM->m_tkCurrentCVOwner = yypvt[-0].token;
+ PASM->m_pCustomDescrList = NULL;
+ iOpcodeLen = 0;
+ } break;
+case 520:
+#line 1432 "asmparse.y"
+{ PASM->EmitInstrSwitch(yypvt[-3].instr, yypvt[-1].labels); } break;
+case 521:
+#line 1435 "asmparse.y"
+{ yyval.labels = 0; } break;
+case 522:
+#line 1436 "asmparse.y"
+{ yyval.labels = new Labels(yypvt[-2].string, yypvt[-0].labels, TRUE); } break;
+case 523:
+#line 1437 "asmparse.y"
+{ yyval.labels = new Labels((char *)(UINT_PTR)yypvt[-2].int32, yypvt[-0].labels, FALSE); } break;
+case 524:
+#line 1438 "asmparse.y"
+{ yyval.labels = new Labels(yypvt[-0].string, NULL, TRUE); } break;
+case 525:
+#line 1439 "asmparse.y"
+{ yyval.labels = new Labels((char *)(UINT_PTR)yypvt[-0].int32, NULL, FALSE); } break;
+case 526:
+#line 1443 "asmparse.y"
+{ yyval.binstr = NULL; } break;
+case 527:
+#line 1444 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; } break;
+case 528:
+#line 1447 "asmparse.y"
+{ yyval.binstr = NULL; } break;
+case 529:
+#line 1448 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 530:
+#line 1451 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 531:
+#line 1452 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; yyval.binstr->append(yypvt[-0].binstr); delete yypvt[-0].binstr; } break;
+case 532:
+#line 1456 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 533:
+#line 1457 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr;} break;
+case 534:
+#line 1460 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 535:
+#line 1461 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; yyval.binstr->append(yypvt[-0].binstr); delete yypvt[-0].binstr; } break;
+case 536:
+#line 1464 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_SENTINEL); } break;
+case 537:
+#line 1465 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->append(yypvt[-1].binstr); PASM->addArgName(NULL, yypvt[-1].binstr, yypvt[-0].binstr, yypvt[-2].int32); } break;
+case 538:
+#line 1466 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->append(yypvt[-2].binstr); PASM->addArgName(yypvt[-0].string, yypvt[-2].binstr, yypvt[-1].binstr, yypvt[-3].int32);} break;
+case 539:
+#line 1470 "asmparse.y"
+{ yyval.token = PASM->ResolveClassRef(PASM->GetAsmRef(yypvt[-2].string), yypvt[-0].string, NULL); delete[] yypvt[-2].string;} break;
+case 540:
+#line 1471 "asmparse.y"
+{ yyval.token = PASM->ResolveClassRef(yypvt[-2].token, yypvt[-0].string, NULL); } break;
+case 541:
+#line 1472 "asmparse.y"
+{ yyval.token = PASM->ResolveClassRef(mdTokenNil, yypvt[-0].string, NULL); } break;
+case 542:
+#line 1473 "asmparse.y"
+{ yyval.token = PASM->ResolveClassRef(PASM->GetModRef(yypvt[-2].string),yypvt[-0].string, NULL); delete[] yypvt[-2].string;} break;
+case 543:
+#line 1474 "asmparse.y"
+{ yyval.token = PASM->ResolveClassRef(1,yypvt[-0].string,NULL); } break;
+case 544:
+#line 1475 "asmparse.y"
+{ yyval.token = yypvt[-0].token; } break;
+case 545:
+#line 1476 "asmparse.y"
+{ yyval.token = yypvt[-0].tdd->m_tkTypeSpec; } break;
+case 546:
+#line 1477 "asmparse.y"
+{ if(PASM->m_pCurClass != NULL) yyval.token = PASM->m_pCurClass->m_cl;
+ else { yyval.token = 0; PASM->report->error(".this outside class scope\n"); }
+ } break;
+case 547:
+#line 1480 "asmparse.y"
+{ if(PASM->m_pCurClass != NULL) {
+ yyval.token = PASM->m_pCurClass->m_crExtends;
+ if(RidFromToken(yyval.token) == 0)
+ PASM->report->error(".base undefined\n");
+ } else { yyval.token = 0; PASM->report->error(".base outside class scope\n"); }
+ } break;
+case 548:
+#line 1486 "asmparse.y"
+{ if(PASM->m_pCurClass != NULL) {
+ if(PASM->m_pCurClass->m_pEncloser != NULL) yyval.token = PASM->m_pCurClass->m_pEncloser->m_cl;
+ else { yyval.token = 0; PASM->report->error(".nester undefined\n"); }
+ } else { yyval.token = 0; PASM->report->error(".nester outside class scope\n"); }
+ } break;
+case 549:
+#line 1493 "asmparse.y"
+{ yyval.string = yypvt[-0].string; } break;
+case 550:
+#line 1494 "asmparse.y"
+{ yyval.string = newStringWDel(yypvt[-2].string, NESTING_SEP, yypvt[-0].string); } break;
+case 551:
+#line 1497 "asmparse.y"
+{ yyval.token = yypvt[-0].token;} break;
+case 552:
+#line 1498 "asmparse.y"
+{ yyval.token = PASM->GetAsmRef(yypvt[-1].string); delete[] yypvt[-1].string;} break;
+case 553:
+#line 1499 "asmparse.y"
+{ yyval.token = PASM->GetModRef(yypvt[-1].string); delete[] yypvt[-1].string;} break;
+case 554:
+#line 1500 "asmparse.y"
+{ yyval.token = PASM->ResolveTypeSpec(yypvt[-0].binstr); } break;
+case 555:
+#line 1504 "asmparse.y"
+{ yyval.binstr = new BinStr(); } break;
+case 556:
+#line 1506 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_CUSTOMMARSHALER);
+ corEmitInt(yyval.binstr,yypvt[-7].binstr->length()); yyval.binstr->append(yypvt[-7].binstr);
+ corEmitInt(yyval.binstr,yypvt[-5].binstr->length()); yyval.binstr->append(yypvt[-5].binstr);
+ corEmitInt(yyval.binstr,yypvt[-3].binstr->length()); yyval.binstr->append(yypvt[-3].binstr);
+ corEmitInt(yyval.binstr,yypvt[-1].binstr->length()); yyval.binstr->append(yypvt[-1].binstr);
+ PASM->report->warn("Deprecated 4-string form of custom marshaler, first two strings ignored\n");} break;
+case 557:
+#line 1513 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_CUSTOMMARSHALER);
+ corEmitInt(yyval.binstr,0);
+ corEmitInt(yyval.binstr,0);
+ corEmitInt(yyval.binstr,yypvt[-3].binstr->length()); yyval.binstr->append(yypvt[-3].binstr);
+ corEmitInt(yyval.binstr,yypvt[-1].binstr->length()); yyval.binstr->append(yypvt[-1].binstr); } break;
+case 558:
+#line 1518 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_FIXEDSYSSTRING);
+ corEmitInt(yyval.binstr,yypvt[-1].int32); } break;
+case 559:
+#line 1521 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_FIXEDARRAY);
+ corEmitInt(yyval.binstr,yypvt[-2].int32); yyval.binstr->append(yypvt[-0].binstr); } break;
+case 560:
+#line 1523 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_VARIANT);
+ PASM->report->warn("Deprecated native type 'variant'\n"); } break;
+case 561:
+#line 1525 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_CURRENCY); } break;
+case 562:
+#line 1526 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_SYSCHAR);
+ PASM->report->warn("Deprecated native type 'syschar'\n"); } break;
+case 563:
+#line 1528 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_VOID);
+ PASM->report->warn("Deprecated native type 'void'\n"); } break;
+case 564:
+#line 1530 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_BOOLEAN); } break;
+case 565:
+#line 1531 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_I1); } break;
+case 566:
+#line 1532 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_I2); } break;
+case 567:
+#line 1533 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_I4); } break;
+case 568:
+#line 1534 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_I8); } break;
+case 569:
+#line 1535 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_R4); } break;
+case 570:
+#line 1536 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_R8); } break;
+case 571:
+#line 1537 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_ERROR); } break;
+case 572:
+#line 1538 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_U1); } break;
+case 573:
+#line 1539 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_U2); } break;
+case 574:
+#line 1540 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_U4); } break;
+case 575:
+#line 1541 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_U8); } break;
+case 576:
+#line 1542 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_U1); } break;
+case 577:
+#line 1543 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_U2); } break;
+case 578:
+#line 1544 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_U4); } break;
+case 579:
+#line 1545 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_U8); } break;
+case 580:
+#line 1546 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt8(NATIVE_TYPE_PTR);
+ PASM->report->warn("Deprecated native type '*'\n"); } break;
+case 581:
+#line 1548 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; if(yyval.binstr->length()==0) yyval.binstr->appendInt8(NATIVE_TYPE_MAX);
+ yyval.binstr->insertInt8(NATIVE_TYPE_ARRAY); } break;
+case 582:
+#line 1550 "asmparse.y"
+{ yyval.binstr = yypvt[-3].binstr; if(yyval.binstr->length()==0) yyval.binstr->appendInt8(NATIVE_TYPE_MAX);
+ yyval.binstr->insertInt8(NATIVE_TYPE_ARRAY);
+ corEmitInt(yyval.binstr,0);
+ corEmitInt(yyval.binstr,yypvt[-1].int32);
+ corEmitInt(yyval.binstr,0); } break;
+case 583:
+#line 1555 "asmparse.y"
+{ yyval.binstr = yypvt[-5].binstr; if(yyval.binstr->length()==0) yyval.binstr->appendInt8(NATIVE_TYPE_MAX);
+ yyval.binstr->insertInt8(NATIVE_TYPE_ARRAY);
+ corEmitInt(yyval.binstr,yypvt[-1].int32);
+ corEmitInt(yyval.binstr,yypvt[-3].int32);
+ corEmitInt(yyval.binstr,ntaSizeParamIndexSpecified); } break;
+case 584:
+#line 1560 "asmparse.y"
+{ yyval.binstr = yypvt[-4].binstr; if(yyval.binstr->length()==0) yyval.binstr->appendInt8(NATIVE_TYPE_MAX);
+ yyval.binstr->insertInt8(NATIVE_TYPE_ARRAY);
+ corEmitInt(yyval.binstr,yypvt[-1].int32); } break;
+case 585:
+#line 1563 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_DECIMAL);
+ PASM->report->warn("Deprecated native type 'decimal'\n"); } break;
+case 586:
+#line 1565 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_DATE);
+ PASM->report->warn("Deprecated native type 'date'\n"); } break;
+case 587:
+#line 1567 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_BSTR); } break;
+case 588:
+#line 1568 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_LPSTR); } break;
+case 589:
+#line 1569 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_LPWSTR); } break;
+case 590:
+#line 1570 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_LPTSTR); } break;
+case 591:
+#line 1571 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_OBJECTREF);
+ PASM->report->warn("Deprecated native type 'objectref'\n"); } break;
+case 592:
+#line 1573 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_IUNKNOWN);
+ if(yypvt[-0].int32 != -1) corEmitInt(yyval.binstr,yypvt[-0].int32); } break;
+case 593:
+#line 1575 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_IDISPATCH);
+ if(yypvt[-0].int32 != -1) corEmitInt(yyval.binstr,yypvt[-0].int32); } break;
+case 594:
+#line 1577 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_STRUCT); } break;
+case 595:
+#line 1578 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_INTF);
+ if(yypvt[-0].int32 != -1) corEmitInt(yyval.binstr,yypvt[-0].int32); } break;
+case 596:
+#line 1580 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_SAFEARRAY);
+ corEmitInt(yyval.binstr,yypvt[-0].int32);
+ corEmitInt(yyval.binstr,0);} break;
+case 597:
+#line 1583 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_SAFEARRAY);
+ corEmitInt(yyval.binstr,yypvt[-2].int32);
+ corEmitInt(yyval.binstr,yypvt[-0].binstr->length()); yyval.binstr->append(yypvt[-0].binstr); } break;
+case 598:
+#line 1587 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_INT); } break;
+case 599:
+#line 1588 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_UINT); } break;
+case 600:
+#line 1589 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_UINT); } break;
+case 601:
+#line 1590 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_NESTEDSTRUCT);
+ PASM->report->warn("Deprecated native type 'nested struct'\n"); } break;
+case 602:
+#line 1592 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_BYVALSTR); } break;
+case 603:
+#line 1593 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_ANSIBSTR); } break;
+case 604:
+#line 1594 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_TBSTR); } break;
+case 605:
+#line 1595 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_VARIANTBOOL); } break;
+case 606:
+#line 1596 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_FUNC); } break;
+case 607:
+#line 1597 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_ASANY); } break;
+case 608:
+#line 1598 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(NATIVE_TYPE_LPSTRUCT); } break;
+case 609:
+#line 1599 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->append(yypvt[-0].tdd->m_pbsTypeSpec); } break;
+case 610:
+#line 1602 "asmparse.y"
+{ yyval.int32 = -1; } break;
+case 611:
+#line 1603 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32; } break;
+case 612:
+#line 1606 "asmparse.y"
+{ yyval.int32 = VT_EMPTY; } break;
+case 613:
+#line 1607 "asmparse.y"
+{ yyval.int32 = VT_NULL; } break;
+case 614:
+#line 1608 "asmparse.y"
+{ yyval.int32 = VT_VARIANT; } break;
+case 615:
+#line 1609 "asmparse.y"
+{ yyval.int32 = VT_CY; } break;
+case 616:
+#line 1610 "asmparse.y"
+{ yyval.int32 = VT_VOID; } break;
+case 617:
+#line 1611 "asmparse.y"
+{ yyval.int32 = VT_BOOL; } break;
+case 618:
+#line 1612 "asmparse.y"
+{ yyval.int32 = VT_I1; } break;
+case 619:
+#line 1613 "asmparse.y"
+{ yyval.int32 = VT_I2; } break;
+case 620:
+#line 1614 "asmparse.y"
+{ yyval.int32 = VT_I4; } break;
+case 621:
+#line 1615 "asmparse.y"
+{ yyval.int32 = VT_I8; } break;
+case 622:
+#line 1616 "asmparse.y"
+{ yyval.int32 = VT_R4; } break;
+case 623:
+#line 1617 "asmparse.y"
+{ yyval.int32 = VT_R8; } break;
+case 624:
+#line 1618 "asmparse.y"
+{ yyval.int32 = VT_UI1; } break;
+case 625:
+#line 1619 "asmparse.y"
+{ yyval.int32 = VT_UI2; } break;
+case 626:
+#line 1620 "asmparse.y"
+{ yyval.int32 = VT_UI4; } break;
+case 627:
+#line 1621 "asmparse.y"
+{ yyval.int32 = VT_UI8; } break;
+case 628:
+#line 1622 "asmparse.y"
+{ yyval.int32 = VT_UI1; } break;
+case 629:
+#line 1623 "asmparse.y"
+{ yyval.int32 = VT_UI2; } break;
+case 630:
+#line 1624 "asmparse.y"
+{ yyval.int32 = VT_UI4; } break;
+case 631:
+#line 1625 "asmparse.y"
+{ yyval.int32 = VT_UI8; } break;
+case 632:
+#line 1626 "asmparse.y"
+{ yyval.int32 = VT_PTR; } break;
+case 633:
+#line 1627 "asmparse.y"
+{ yyval.int32 = yypvt[-2].int32 | VT_ARRAY; } break;
+case 634:
+#line 1628 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 | VT_VECTOR; } break;
+case 635:
+#line 1629 "asmparse.y"
+{ yyval.int32 = yypvt[-1].int32 | VT_BYREF; } break;
+case 636:
+#line 1630 "asmparse.y"
+{ yyval.int32 = VT_DECIMAL; } break;
+case 637:
+#line 1631 "asmparse.y"
+{ yyval.int32 = VT_DATE; } break;
+case 638:
+#line 1632 "asmparse.y"
+{ yyval.int32 = VT_BSTR; } break;
+case 639:
+#line 1633 "asmparse.y"
+{ yyval.int32 = VT_LPSTR; } break;
+case 640:
+#line 1634 "asmparse.y"
+{ yyval.int32 = VT_LPWSTR; } break;
+case 641:
+#line 1635 "asmparse.y"
+{ yyval.int32 = VT_UNKNOWN; } break;
+case 642:
+#line 1636 "asmparse.y"
+{ yyval.int32 = VT_DISPATCH; } break;
+case 643:
+#line 1637 "asmparse.y"
+{ yyval.int32 = VT_SAFEARRAY; } break;
+case 644:
+#line 1638 "asmparse.y"
+{ yyval.int32 = VT_INT; } break;
+case 645:
+#line 1639 "asmparse.y"
+{ yyval.int32 = VT_UINT; } break;
+case 646:
+#line 1640 "asmparse.y"
+{ yyval.int32 = VT_UINT; } break;
+case 647:
+#line 1641 "asmparse.y"
+{ yyval.int32 = VT_ERROR; } break;
+case 648:
+#line 1642 "asmparse.y"
+{ yyval.int32 = VT_HRESULT; } break;
+case 649:
+#line 1643 "asmparse.y"
+{ yyval.int32 = VT_CARRAY; } break;
+case 650:
+#line 1644 "asmparse.y"
+{ yyval.int32 = VT_USERDEFINED; } break;
+case 651:
+#line 1645 "asmparse.y"
+{ yyval.int32 = VT_RECORD; } break;
+case 652:
+#line 1646 "asmparse.y"
+{ yyval.int32 = VT_FILETIME; } break;
+case 653:
+#line 1647 "asmparse.y"
+{ yyval.int32 = VT_BLOB; } break;
+case 654:
+#line 1648 "asmparse.y"
+{ yyval.int32 = VT_STREAM; } break;
+case 655:
+#line 1649 "asmparse.y"
+{ yyval.int32 = VT_STORAGE; } break;
+case 656:
+#line 1650 "asmparse.y"
+{ yyval.int32 = VT_STREAMED_OBJECT; } break;
+case 657:
+#line 1651 "asmparse.y"
+{ yyval.int32 = VT_STORED_OBJECT; } break;
+case 658:
+#line 1652 "asmparse.y"
+{ yyval.int32 = VT_BLOB_OBJECT; } break;
+case 659:
+#line 1653 "asmparse.y"
+{ yyval.int32 = VT_CF; } break;
+case 660:
+#line 1654 "asmparse.y"
+{ yyval.int32 = VT_CLSID; } break;
+case 661:
+#line 1658 "asmparse.y"
+{ if(yypvt[-0].token == PASM->m_tkSysString)
+ { yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_STRING); }
+ else if(yypvt[-0].token == PASM->m_tkSysObject)
+ { yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_OBJECT); }
+ else
+ yyval.binstr = parser->MakeTypeClass(ELEMENT_TYPE_CLASS, yypvt[-0].token); } break;
+case 662:
+#line 1664 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_OBJECT); } break;
+case 663:
+#line 1665 "asmparse.y"
+{ yyval.binstr = parser->MakeTypeClass(ELEMENT_TYPE_VALUETYPE, yypvt[-0].token); } break;
+case 664:
+#line 1666 "asmparse.y"
+{ yyval.binstr = parser->MakeTypeClass(ELEMENT_TYPE_VALUETYPE, yypvt[-0].token); } break;
+case 665:
+#line 1667 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; yyval.binstr->insertInt8(ELEMENT_TYPE_SZARRAY); } break;
+case 666:
+#line 1668 "asmparse.y"
+{ yyval.binstr = parser->MakeTypeArray(ELEMENT_TYPE_ARRAY, yypvt[-3].binstr, yypvt[-1].binstr); } break;
+case 667:
+#line 1669 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt8(ELEMENT_TYPE_BYREF); } break;
+case 668:
+#line 1670 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt8(ELEMENT_TYPE_PTR); } break;
+case 669:
+#line 1671 "asmparse.y"
+{ yyval.binstr = yypvt[-1].binstr; yyval.binstr->insertInt8(ELEMENT_TYPE_PINNED); } break;
+case 670:
+#line 1672 "asmparse.y"
+{ yyval.binstr = parser->MakeTypeClass(ELEMENT_TYPE_CMOD_REQD, yypvt[-1].token);
+ yyval.binstr->append(yypvt[-4].binstr); } break;
+case 671:
+#line 1674 "asmparse.y"
+{ yyval.binstr = parser->MakeTypeClass(ELEMENT_TYPE_CMOD_OPT, yypvt[-1].token);
+ yyval.binstr->append(yypvt[-4].binstr); } break;
+case 672:
+#line 1677 "asmparse.y"
+{ yyval.binstr = parser->MakeSig(yypvt[-5].int32, yypvt[-4].binstr, yypvt[-1].binstr);
+ yyval.binstr->insertInt8(ELEMENT_TYPE_FNPTR);
+ PASM->delArgNameList(PASM->m_firstArgName);
+ PASM->m_firstArgName = parser->m_ANSFirst.POP();
+ PASM->m_lastArgName = parser->m_ANSLast.POP();
+ } break;
+case 673:
+#line 1683 "asmparse.y"
+{ if(yypvt[-1].binstr == NULL) yyval.binstr = yypvt[-3].binstr;
+ else {
+ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(ELEMENT_TYPE_GENERICINST);
+ yyval.binstr->append(yypvt[-3].binstr);
+ corEmitInt(yyval.binstr, corCountArgs(yypvt[-1].binstr));
+ yyval.binstr->append(yypvt[-1].binstr); delete yypvt[-3].binstr; delete yypvt[-1].binstr; }} break;
+case 674:
+#line 1690 "asmparse.y"
+{ //if(PASM->m_pCurMethod) {
+ // if(($3 < 0)||((DWORD)$3 >= PASM->m_pCurMethod->m_NumTyPars))
+ // PASM->report->error("Invalid method type parameter '%d'\n",$3);
+ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_MVAR); corEmitInt(yyval.binstr, yypvt[-0].int32);
+ //} else PASM->report->error("Method type parameter '%d' outside method scope\n",$3);
+ } break;
+case 675:
+#line 1696 "asmparse.y"
+{ //if(PASM->m_pCurClass) {
+ // if(($2 < 0)||((DWORD)$2 >= PASM->m_pCurClass->m_NumTyPars))
+ // PASM->report->error("Invalid type parameter '%d'\n",$2);
+ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_VAR); corEmitInt(yyval.binstr, yypvt[-0].int32);
+ //} else PASM->report->error("Type parameter '%d' outside class scope\n",$2);
+ } break;
+case 676:
+#line 1702 "asmparse.y"
+{ int eltype = ELEMENT_TYPE_MVAR;
+ int n=-1;
+ if(PASM->m_pCurMethod) n = PASM->m_pCurMethod->FindTyPar(yypvt[-0].string);
+ else {
+ if(PASM->m_TyParList) n = PASM->m_TyParList->IndexOf(yypvt[-0].string);
+ if(n == -1)
+ { n = TyParFixupList.COUNT();
+ TyParFixupList.PUSH(yypvt[-0].string);
+ eltype = ELEMENT_TYPE_MVARFIXUP;
+ }
+ }
+ if(n == -1) { PASM->report->error("Invalid method type parameter '%s'\n",yypvt[-0].string);
+ n = 0x1FFFFFFF; }
+ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(eltype); corEmitInt(yyval.binstr,n);
+ } break;
+case 677:
+#line 1717 "asmparse.y"
+{ int eltype = ELEMENT_TYPE_VAR;
+ int n=-1;
+ if(PASM->m_pCurClass && !newclass) n = PASM->m_pCurClass->FindTyPar(yypvt[-0].string);
+ else {
+ if(PASM->m_TyParList) n = PASM->m_TyParList->IndexOf(yypvt[-0].string);
+ if(n == -1)
+ { n = TyParFixupList.COUNT();
+ TyParFixupList.PUSH(yypvt[-0].string);
+ eltype = ELEMENT_TYPE_VARFIXUP;
+ }
+ }
+ if(n == -1) { PASM->report->error("Invalid type parameter '%s'\n",yypvt[-0].string);
+ n = 0x1FFFFFFF; }
+ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(eltype); corEmitInt(yyval.binstr,n);
+ } break;
+case 678:
+#line 1732 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_TYPEDBYREF); } break;
+case 679:
+#line 1733 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_VOID); } break;
+case 680:
+#line 1734 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I); } break;
+case 681:
+#line 1735 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U); } break;
+case 682:
+#line 1736 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U); } break;
+case 683:
+#line 1737 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 684:
+#line 1738 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; yyval.binstr->insertInt8(ELEMENT_TYPE_SENTINEL); } break;
+case 685:
+#line 1741 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_CHAR); } break;
+case 686:
+#line 1742 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_STRING); } break;
+case 687:
+#line 1743 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_BOOLEAN); } break;
+case 688:
+#line 1744 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I1); } break;
+case 689:
+#line 1745 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I2); } break;
+case 690:
+#line 1746 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I4); } break;
+case 691:
+#line 1747 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_I8); } break;
+case 692:
+#line 1748 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_R4); } break;
+case 693:
+#line 1749 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_R8); } break;
+case 694:
+#line 1750 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U1); } break;
+case 695:
+#line 1751 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U2); } break;
+case 696:
+#line 1752 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U4); } break;
+case 697:
+#line 1753 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U8); } break;
+case 698:
+#line 1754 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U1); } break;
+case 699:
+#line 1755 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U2); } break;
+case 700:
+#line 1756 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U4); } break;
+case 701:
+#line 1757 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt8(ELEMENT_TYPE_U8); } break;
+case 702:
+#line 1758 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->append(yypvt[-0].tdd->m_pbsTypeSpec); } break;
+case 703:
+#line 1761 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; } break;
+case 704:
+#line 1762 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; yypvt[-2].binstr->append(yypvt[-0].binstr); delete yypvt[-0].binstr; } break;
+case 705:
+#line 1765 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt32(0x7FFFFFFF); yyval.binstr->appendInt32(0x7FFFFFFF); } break;
+case 706:
+#line 1766 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt32(0x7FFFFFFF); yyval.binstr->appendInt32(0x7FFFFFFF); } break;
+case 707:
+#line 1767 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt32(0); yyval.binstr->appendInt32(yypvt[-0].int32); } break;
+case 708:
+#line 1768 "asmparse.y"
+{ FAIL_UNLESS(yypvt[-2].int32 <= yypvt[-0].int32, ("lower bound %d must be <= upper bound %d\n", yypvt[-2].int32, yypvt[-0].int32));
+ if (yypvt[-2].int32 > yypvt[-0].int32) { YYERROR; };
+ yyval.binstr = new BinStr(); yyval.binstr->appendInt32(yypvt[-2].int32); yyval.binstr->appendInt32(yypvt[-0].int32-yypvt[-2].int32+1); } break;
+case 709:
+#line 1771 "asmparse.y"
+{ yyval.binstr = new BinStr(); yyval.binstr->appendInt32(yypvt[-1].int32); yyval.binstr->appendInt32(0x7FFFFFFF); } break;
+case 710:
+#line 1776 "asmparse.y"
+{ PASM->AddPermissionDecl(yypvt[-4].secAct, yypvt[-3].token, yypvt[-1].pair); } break;
+case 711:
+#line 1778 "asmparse.y"
+{ PASM->AddPermissionDecl(yypvt[-5].secAct, yypvt[-4].token, yypvt[-1].binstr); } break;
+case 712:
+#line 1779 "asmparse.y"
+{ PASM->AddPermissionDecl(yypvt[-1].secAct, yypvt[-0].token, (NVPair *)NULL); } break;
+case 713:
+#line 1780 "asmparse.y"
+{ PASM->AddPermissionSetDecl(yypvt[-2].secAct, yypvt[-1].binstr); } break;
+case 714:
+#line 1782 "asmparse.y"
+{ PASM->AddPermissionSetDecl(yypvt[-1].secAct,BinStrToUnicode(yypvt[-0].binstr,true));} break;
+case 715:
+#line 1784 "asmparse.y"
+{ BinStr* ret = new BinStr();
+ ret->insertInt8('.');
+ corEmitInt(ret, nSecAttrBlobs);
+ ret->append(yypvt[-1].binstr);
+ PASM->AddPermissionSetDecl(yypvt[-4].secAct,ret);
+ nSecAttrBlobs = 0; } break;
+case 716:
+#line 1792 "asmparse.y"
+{ yyval.binstr = new BinStr(); nSecAttrBlobs = 0;} break;
+case 717:
+#line 1793 "asmparse.y"
+{ yyval.binstr = yypvt[-0].binstr; nSecAttrBlobs = 1; } break;
+case 718:
+#line 1794 "asmparse.y"
+{ yyval.binstr = yypvt[-2].binstr; yyval.binstr->append(yypvt[-0].binstr); nSecAttrBlobs++; } break;
+case 719:
+#line 1798 "asmparse.y"
+{ yyval.binstr = PASM->EncodeSecAttr(PASM->ReflectionNotation(yypvt[-4].token),yypvt[-1].binstr,nCustomBlobNVPairs);
+ nCustomBlobNVPairs = 0; } break;
+case 720:
+#line 1801 "asmparse.y"
+{ yyval.binstr = PASM->EncodeSecAttr(yypvt[-4].string,yypvt[-1].binstr,nCustomBlobNVPairs);
+ nCustomBlobNVPairs = 0; } break;
+case 721:
+#line 1805 "asmparse.y"
+{ yyval.secAct = yypvt[-2].secAct; bParsingByteArray = TRUE; } break;
+case 722:
+#line 1807 "asmparse.y"
+{ yyval.secAct = yypvt[-2].secAct; bParsingByteArray = TRUE; } break;
+case 723:
+#line 1810 "asmparse.y"
+{ yyval.pair = yypvt[-0].pair; } break;
+case 724:
+#line 1811 "asmparse.y"
+{ yyval.pair = yypvt[-2].pair->Concat(yypvt[-0].pair); } break;
+case 725:
+#line 1814 "asmparse.y"
+{ yypvt[-2].binstr->appendInt8(0); yyval.pair = new NVPair(yypvt[-2].binstr, yypvt[-0].binstr); } break;
+case 726:
+#line 1817 "asmparse.y"
+{ yyval.int32 = 1; } break;
+case 727:
+#line 1818 "asmparse.y"
+{ yyval.int32 = 0; } break;
+case 728:
+#line 1821 "asmparse.y"
+{ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(SERIALIZATION_TYPE_BOOLEAN);
+ yyval.binstr->appendInt8(yypvt[-0].int32); } break;
+case 729:
+#line 1824 "asmparse.y"
+{ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(SERIALIZATION_TYPE_I4);
+ yyval.binstr->appendInt32(yypvt[-0].int32); } break;
+case 730:
+#line 1827 "asmparse.y"
+{ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(SERIALIZATION_TYPE_I4);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 731:
+#line 1830 "asmparse.y"
+{ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(SERIALIZATION_TYPE_STRING);
+ yyval.binstr->append(yypvt[-0].binstr); delete yypvt[-0].binstr;
+ yyval.binstr->appendInt8(0); } break;
+case 732:
+#line 1834 "asmparse.y"
+{ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(SERIALIZATION_TYPE_ENUM);
+ char* sz = PASM->ReflectionNotation(yypvt[-5].token);
+ strcpy_s((char *)yyval.binstr->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
+ yyval.binstr->appendInt8(1);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 733:
+#line 1840 "asmparse.y"
+{ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(SERIALIZATION_TYPE_ENUM);
+ char* sz = PASM->ReflectionNotation(yypvt[-5].token);
+ strcpy_s((char *)yyval.binstr->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
+ yyval.binstr->appendInt8(2);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 734:
+#line 1846 "asmparse.y"
+{ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(SERIALIZATION_TYPE_ENUM);
+ char* sz = PASM->ReflectionNotation(yypvt[-5].token);
+ strcpy_s((char *)yyval.binstr->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
+ yyval.binstr->appendInt8(4);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 735:
+#line 1852 "asmparse.y"
+{ yyval.binstr = new BinStr();
+ yyval.binstr->appendInt8(SERIALIZATION_TYPE_ENUM);
+ char* sz = PASM->ReflectionNotation(yypvt[-3].token);
+ strcpy_s((char *)yyval.binstr->getBuff((unsigned)strlen(sz) + 1), strlen(sz) + 1,sz);
+ yyval.binstr->appendInt8(4);
+ yyval.binstr->appendInt32(yypvt[-1].int32); } break;
+case 736:
+#line 1860 "asmparse.y"
+{ yyval.secAct = dclRequest; } break;
+case 737:
+#line 1861 "asmparse.y"
+{ yyval.secAct = dclDemand; } break;
+case 738:
+#line 1862 "asmparse.y"
+{ yyval.secAct = dclAssert; } break;
+case 739:
+#line 1863 "asmparse.y"
+{ yyval.secAct = dclDeny; } break;
+case 740:
+#line 1864 "asmparse.y"
+{ yyval.secAct = dclPermitOnly; } break;
+case 741:
+#line 1865 "asmparse.y"
+{ yyval.secAct = dclLinktimeCheck; } break;
+case 742:
+#line 1866 "asmparse.y"
+{ yyval.secAct = dclInheritanceCheck; } break;
+case 743:
+#line 1867 "asmparse.y"
+{ yyval.secAct = dclRequestMinimum; } break;
+case 744:
+#line 1868 "asmparse.y"
+{ yyval.secAct = dclRequestOptional; } break;
+case 745:
+#line 1869 "asmparse.y"
+{ yyval.secAct = dclRequestRefuse; } break;
+case 746:
+#line 1870 "asmparse.y"
+{ yyval.secAct = dclPrejitGrant; } break;
+case 747:
+#line 1871 "asmparse.y"
+{ yyval.secAct = dclPrejitDenied; } break;
+case 748:
+#line 1872 "asmparse.y"
+{ yyval.secAct = dclNonCasDemand; } break;
+case 749:
+#line 1873 "asmparse.y"
+{ yyval.secAct = dclNonCasLinkDemand; } break;
+case 750:
+#line 1874 "asmparse.y"
+{ yyval.secAct = dclNonCasInheritance; } break;
+case 751:
+#line 1878 "asmparse.y"
+{ PASM->ResetLineNumbers(); nCurrPC = PASM->m_CurPC; PENV->bExternSource = TRUE; PENV->bExternSourceAutoincrement = FALSE; } break;
+case 752:
+#line 1879 "asmparse.y"
+{ PASM->ResetLineNumbers(); nCurrPC = PASM->m_CurPC; PENV->bExternSource = TRUE; PENV->bExternSourceAutoincrement = TRUE; } break;
+case 753:
+#line 1882 "asmparse.y"
+{ PENV->nExtLine = PENV->nExtLineEnd = yypvt[-1].int32;
+ PENV->nExtCol = 0; PENV->nExtColEnd = static_cast<unsigned>(-1);
+ PASM->SetSourceFileName(yypvt[-0].string);} break;
+case 754:
+#line 1885 "asmparse.y"
+{ PENV->nExtLine = PENV->nExtLineEnd = yypvt[-0].int32;
+ PENV->nExtCol = 0; PENV->nExtColEnd = static_cast<unsigned>(-1); } break;
+case 755:
+#line 1887 "asmparse.y"
+{ PENV->nExtLine = PENV->nExtLineEnd = yypvt[-3].int32;
+ PENV->nExtCol=yypvt[-1].int32; PENV->nExtColEnd = static_cast<unsigned>(-1);
+ PASM->SetSourceFileName(yypvt[-0].string);} break;
+case 756:
+#line 1890 "asmparse.y"
+{ PENV->nExtLine = PENV->nExtLineEnd = yypvt[-2].int32;
+ PENV->nExtCol=yypvt[-0].int32; PENV->nExtColEnd = static_cast<unsigned>(-1);} break;
+case 757:
+#line 1893 "asmparse.y"
+{ PENV->nExtLine = PENV->nExtLineEnd = yypvt[-5].int32;
+ PENV->nExtCol=yypvt[-3].int32; PENV->nExtColEnd = yypvt[-1].int32;
+ PASM->SetSourceFileName(yypvt[-0].string);} break;
+case 758:
+#line 1897 "asmparse.y"
+{ PENV->nExtLine = PENV->nExtLineEnd = yypvt[-4].int32;
+ PENV->nExtCol=yypvt[-2].int32; PENV->nExtColEnd = yypvt[-0].int32; } break;
+case 759:
+#line 1900 "asmparse.y"
+{ PENV->nExtLine = yypvt[-5].int32; PENV->nExtLineEnd = yypvt[-3].int32;
+ PENV->nExtCol=yypvt[-1].int32; PENV->nExtColEnd = static_cast<unsigned>(-1);
+ PASM->SetSourceFileName(yypvt[-0].string);} break;
+case 760:
+#line 1904 "asmparse.y"
+{ PENV->nExtLine = yypvt[-4].int32; PENV->nExtLineEnd = yypvt[-2].int32;
+ PENV->nExtCol=yypvt[-0].int32; PENV->nExtColEnd = static_cast<unsigned>(-1); } break;
+case 761:
+#line 1907 "asmparse.y"
+{ PENV->nExtLine = yypvt[-7].int32; PENV->nExtLineEnd = yypvt[-5].int32;
+ PENV->nExtCol=yypvt[-3].int32; PENV->nExtColEnd = yypvt[-1].int32;
+ PASM->SetSourceFileName(yypvt[-0].string);} break;
+case 762:
+#line 1911 "asmparse.y"
+{ PENV->nExtLine = yypvt[-6].int32; PENV->nExtLineEnd = yypvt[-4].int32;
+ PENV->nExtCol=yypvt[-2].int32; PENV->nExtColEnd = yypvt[-0].int32; } break;
+case 763:
+#line 1913 "asmparse.y"
+{ PENV->nExtLine = PENV->nExtLineEnd = yypvt[-1].int32 - 1;
+ PENV->nExtCol = 0; PENV->nExtColEnd = static_cast<unsigned>(-1);
+ PASM->SetSourceFileName(yypvt[-0].binstr);} break;
+case 764:
+#line 1920 "asmparse.y"
+{ PASMM->AddFile(yypvt[-5].string, yypvt[-6].fileAttr|yypvt[-4].fileAttr|yypvt[-0].fileAttr, yypvt[-2].binstr); } break;
+case 765:
+#line 1921 "asmparse.y"
+{ PASMM->AddFile(yypvt[-1].string, yypvt[-2].fileAttr|yypvt[-0].fileAttr, NULL); } break;
+case 766:
+#line 1924 "asmparse.y"
+{ yyval.fileAttr = (CorFileFlags) 0; } break;
+case 767:
+#line 1925 "asmparse.y"
+{ yyval.fileAttr = (CorFileFlags) (yypvt[-1].fileAttr | ffContainsNoMetaData); } break;
+case 768:
+#line 1928 "asmparse.y"
+{ yyval.fileAttr = (CorFileFlags) 0; } break;
+case 769:
+#line 1929 "asmparse.y"
+{ yyval.fileAttr = (CorFileFlags) 0x80000000; } break;
+case 770:
+#line 1932 "asmparse.y"
+{ bParsingByteArray = TRUE; } break;
+case 771:
+#line 1935 "asmparse.y"
+{ PASMM->StartAssembly(yypvt[-0].string, NULL, (DWORD)yypvt[-1].asmAttr, FALSE); } break;
+case 772:
+#line 1938 "asmparse.y"
+{ yyval.asmAttr = (CorAssemblyFlags) 0; } break;
+case 773:
+#line 1939 "asmparse.y"
+{ yyval.asmAttr = (CorAssemblyFlags) (yypvt[-1].asmAttr | afRetargetable); } break;
+case 774:
+#line 1940 "asmparse.y"
+{ yyval.asmAttr = (CorAssemblyFlags) (yypvt[-1].asmAttr | afContentType_WindowsRuntime); } break;
+case 775:
+#line 1941 "asmparse.y"
+{ yyval.asmAttr = (CorAssemblyFlags) (yypvt[-1].asmAttr | afPA_NoPlatform); } break;
+case 776:
+#line 1942 "asmparse.y"
+{ yyval.asmAttr = yypvt[-2].asmAttr; } break;
+case 777:
+#line 1943 "asmparse.y"
+{ SET_PA(yyval.asmAttr,yypvt[-1].asmAttr,afPA_MSIL); } break;
+case 778:
+#line 1944 "asmparse.y"
+{ SET_PA(yyval.asmAttr,yypvt[-1].asmAttr,afPA_x86); } break;
+case 779:
+#line 1945 "asmparse.y"
+{ SET_PA(yyval.asmAttr,yypvt[-1].asmAttr,afPA_IA64); } break;
+case 780:
+#line 1946 "asmparse.y"
+{ SET_PA(yyval.asmAttr,yypvt[-1].asmAttr,afPA_AMD64); } break;
+case 781:
+#line 1947 "asmparse.y"
+{ SET_PA(yyval.asmAttr,yypvt[-1].asmAttr,afPA_ARM); } break;
+case 784:
+#line 1954 "asmparse.y"
+{ PASMM->SetAssemblyHashAlg(yypvt[-0].int32); } break;
+case 787:
+#line 1959 "asmparse.y"
+{ yyval.int32 = yypvt[-0].int32; } break;
+case 788:
+#line 1960 "asmparse.y"
+{ yyval.int32 = 0xFFFF; } break;
+case 789:
+#line 1963 "asmparse.y"
+{ PASMM->SetAssemblyPublicKey(yypvt[-1].binstr); } break;
+case 790:
+#line 1965 "asmparse.y"
+{ PASMM->SetAssemblyVer((USHORT)yypvt[-6].int32, (USHORT)yypvt[-4].int32, (USHORT)yypvt[-2].int32, (USHORT)yypvt[-0].int32); } break;
+case 791:
+#line 1966 "asmparse.y"
+{ yypvt[-0].binstr->appendInt8(0); PASMM->SetAssemblyLocale(yypvt[-0].binstr,TRUE); } break;
+case 792:
+#line 1967 "asmparse.y"
+{ PASMM->SetAssemblyLocale(yypvt[-1].binstr,FALSE); } break;
+case 795:
+#line 1972 "asmparse.y"
+{ bParsingByteArray = TRUE; } break;
+case 796:
+#line 1975 "asmparse.y"
+{ bParsingByteArray = TRUE; } break;
+case 797:
+#line 1978 "asmparse.y"
+{ bParsingByteArray = TRUE; } break;
+case 798:
+#line 1982 "asmparse.y"
+{ PASMM->StartAssembly(yypvt[-0].string, NULL, yypvt[-1].asmAttr, TRUE); } break;
+case 799:
+#line 1984 "asmparse.y"
+{ PASMM->StartAssembly(yypvt[-2].string, yypvt[-0].string, yypvt[-3].asmAttr, TRUE); } break;
+case 802:
+#line 1991 "asmparse.y"
+{ PASMM->SetAssemblyHashBlob(yypvt[-1].binstr); } break;
+case 804:
+#line 1993 "asmparse.y"
+{ PASMM->SetAssemblyPublicKeyToken(yypvt[-1].binstr); } break;
+case 805:
+#line 1994 "asmparse.y"
+{ PASMM->SetAssemblyAutodetect(); } break;
+case 806:
+#line 1997 "asmparse.y"
+{ PASMM->StartComType(yypvt[-0].string, yypvt[-1].exptAttr);} break;
+case 807:
+#line 2000 "asmparse.y"
+{ PASMM->StartComType(yypvt[-0].string, yypvt[-1].exptAttr); } break;
+case 808:
+#line 2003 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) 0; } break;
+case 809:
+#line 2004 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-1].exptAttr | tdNotPublic); } break;
+case 810:
+#line 2005 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-1].exptAttr | tdPublic); } break;
+case 811:
+#line 2006 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-1].exptAttr | tdForwarder); } break;
+case 812:
+#line 2007 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-2].exptAttr | tdNestedPublic); } break;
+case 813:
+#line 2008 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-2].exptAttr | tdNestedPrivate); } break;
+case 814:
+#line 2009 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-2].exptAttr | tdNestedFamily); } break;
+case 815:
+#line 2010 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-2].exptAttr | tdNestedAssembly); } break;
+case 816:
+#line 2011 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-2].exptAttr | tdNestedFamANDAssem); } break;
+case 817:
+#line 2012 "asmparse.y"
+{ yyval.exptAttr = (CorTypeAttr) (yypvt[-2].exptAttr | tdNestedFamORAssem); } break;
+case 820:
+#line 2019 "asmparse.y"
+{ PASMM->SetComTypeFile(yypvt[-0].string); } break;
+case 821:
+#line 2020 "asmparse.y"
+{ PASMM->SetComTypeComType(yypvt[-0].string); } break;
+case 822:
+#line 2021 "asmparse.y"
+{ PASMM->SetComTypeAsmRef(yypvt[-0].string); } break;
+case 823:
+#line 2022 "asmparse.y"
+{ if(!PASMM->SetComTypeImplementationTok(yypvt[-1].int32))
+ PASM->report->error("Invalid implementation of exported type\n"); } break;
+case 824:
+#line 2024 "asmparse.y"
+{ if(!PASMM->SetComTypeClassTok(yypvt[-0].int32))
+ PASM->report->error("Invalid TypeDefID of exported type\n"); } break;
+case 827:
+#line 2030 "asmparse.y"
+{ PASMM->StartManifestRes(yypvt[-0].string, yypvt[-0].string, yypvt[-1].manresAttr); } break;
+case 828:
+#line 2032 "asmparse.y"
+{ PASMM->StartManifestRes(yypvt[-2].string, yypvt[-0].string, yypvt[-3].manresAttr); } break;
+case 829:
+#line 2035 "asmparse.y"
+{ yyval.manresAttr = (CorManifestResourceFlags) 0; } break;
+case 830:
+#line 2036 "asmparse.y"
+{ yyval.manresAttr = (CorManifestResourceFlags) (yypvt[-1].manresAttr | mrPublic); } break;
+case 831:
+#line 2037 "asmparse.y"
+{ yyval.manresAttr = (CorManifestResourceFlags) (yypvt[-1].manresAttr | mrPrivate); } break;
+case 834:
+#line 2044 "asmparse.y"
+{ PASMM->SetManifestResFile(yypvt[-2].string, (ULONG)yypvt[-0].int32); } break;
+case 835:
+#line 2045 "asmparse.y"
+{ PASMM->SetManifestResAsmRef(yypvt[-0].string); } break;/* End of actions */
+#line 329 "D:\\ProjectK3\\src\\tools\\devdiv\\x86\\yypars.c"
+ }
+ }
+ goto yystack; /* stack new state and value */
+ }
+#pragma warning(default:102)
+
+
+#ifdef YYDUMP
+YYLOCAL void YYNEAR YYPASCAL yydumpinfo(void)
+{
+ short stackindex;
+ short valindex;
+
+ //dump yys
+ printf("short yys[%d] {\n", YYMAXDEPTH);
+ for (stackindex = 0; stackindex < YYMAXDEPTH; stackindex++){
+ if (stackindex)
+ printf(", %s", stackindex % 10 ? "\0" : "\n");
+ printf("%6d", yys[stackindex]);
+ }
+ printf("\n};\n");
+
+ //dump yyv
+ printf("YYSTYPE yyv[%d] {\n", YYMAXDEPTH);
+ for (valindex = 0; valindex < YYMAXDEPTH; valindex++){
+ if (valindex)
+ printf(", %s", valindex % 5 ? "\0" : "\n");
+ printf("%#*x", 3+sizeof(YYSTYPE), yyv[valindex]);
+ }
+ printf("\n};\n");
+ }
+#endif
diff --git a/src/ilasm/typar.hpp b/src/ilasm/typar.hpp
new file mode 100644
index 0000000000..143a4a2da3
--- /dev/null
+++ b/src/ilasm/typar.hpp
@@ -0,0 +1,166 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+/**************************************************************************/
+/* a type parameter list */
+
+#ifndef TYPAR_H
+#define TYPAR_H
+#include "binstr.h"
+
+extern unsigned int g_uCodePage;
+
+class TyParDescr
+{
+public:
+ TyParDescr()
+ {
+ m_pbsBounds = NULL;
+ m_wzName = NULL;
+ m_dwAttrs = 0;
+ };
+ ~TyParDescr()
+ {
+ delete m_pbsBounds;
+ delete [] m_wzName;
+ m_lstCA.RESET(true);
+ };
+ void Init(BinStr* bounds, LPCUTF8 name, DWORD attrs)
+ {
+ m_pbsBounds = bounds;
+ ULONG cTemp = (ULONG)strlen(name)+1;
+ WCHAR *pwzName;
+ m_wzName = pwzName = new WCHAR[cTemp];
+ if(pwzName)
+ {
+ memset(pwzName,0,sizeof(WCHAR)*cTemp);
+ WszMultiByteToWideChar(g_uCodePage,0,name,-1,pwzName,cTemp);
+ }
+ m_dwAttrs = attrs;
+ };
+ BinStr* Bounds() { return m_pbsBounds; };
+ LPCWSTR Name() { return m_wzName; };
+ DWORD Attrs() { return m_dwAttrs; };
+ CustomDescrList* CAList() { return &m_lstCA; };
+private:
+ BinStr* m_pbsBounds;
+ LPCWSTR m_wzName;
+ DWORD m_dwAttrs;
+ CustomDescrList m_lstCA;
+};
+
+class TyParList {
+public:
+ TyParList(DWORD a, BinStr* b, LPCUTF8 n, TyParList* nx = NULL)
+ {
+ bound = (b == NULL) ? new BinStr() : b;
+ bound->appendInt32(0); // zero terminator
+ attrs = a; name = n; next = nx;
+ };
+ ~TyParList()
+ {
+ if(bound) delete bound;
+ if (next) delete next;
+ };
+ int Count()
+ {
+ TyParList* tp = this;
+ int n;
+ for(n = 1; (tp = tp->next) != NULL; n++);
+ return n;
+ };
+ int IndexOf(LPCUTF8 name)
+ {
+ TyParList* tp = this;
+ int n;
+ int ret = -1;
+ for(n=0; tp != NULL; n++, tp = tp->next)
+ {
+ if(tp->name == NULL)
+ {
+ if(name == NULL) ret = n;
+ }
+ else
+ {
+ if(name == NULL) continue;
+ if(0 == strcmp(name,tp->name)) ret = n;
+ }
+ }
+ return ret;
+ };
+
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:6211) // "Leaking memory 'b' due to an exception. Consider using a local catch block to clean up memory"
+#endif /*_PREFAST_ */
+
+ int ToArray(BinStr ***bounds, LPCWSTR** names, DWORD **attrs)
+ {
+ int n = Count();
+ BinStr **b = new BinStr* [n];
+ LPCWSTR *nam = new LPCWSTR [n];
+ DWORD *attr = attrs ? new DWORD [n] : NULL;
+ TyParList *tp = this;
+ int i = 0;
+ while (tp)
+ {
+ ULONG cTemp = (ULONG)strlen(tp->name)+1;
+ WCHAR* wzDllName = new WCHAR [cTemp];
+ // Convert name to UNICODE
+ memset(wzDllName,0,sizeof(WCHAR)*cTemp);
+ WszMultiByteToWideChar(g_uCodePage,0,tp->name,-1,wzDllName,cTemp);
+ nam[i] = (LPCWSTR)wzDllName;
+ b[i] = tp->bound;
+ if (attr)
+ attr[i] = tp->attrs;
+ tp->bound = 0; // to avoid deletion by destructor
+ i++;
+ tp = tp->next;
+ }
+ *bounds = b;
+ *names = nam;
+ if (attrs)
+ *attrs = attr;
+ return n;
+ };
+
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif /*_PREFAST_*/
+
+ int ToArray(TyParDescr **ppTPD)
+ {
+ int n = Count();
+ TyParDescr *pTPD = NULL;
+ if(n)
+ {
+ pTPD = new TyParDescr[n];
+ if(pTPD)
+ {
+ int i = 0;
+ TyParList *tp = this;
+ while (tp)
+ {
+ pTPD[i].Init(tp->bound,tp->name,tp->attrs);
+ tp->bound = 0; // to avoid deletion by destructor
+ i++;
+ tp = tp->next;
+ }
+ }
+ }
+ *ppTPD = pTPD;
+ return n;
+ };
+ TyParList* Next() { return next; };
+ BinStr* Bound() { return bound; };
+private:
+ BinStr* bound;
+ LPCUTF8 name;
+ TyParList* next;
+ DWORD attrs;
+};
+
+typedef TyParList* pTyParList;
+
+#endif
+
diff --git a/src/ilasm/writer.cpp b/src/ilasm/writer.cpp
new file mode 100644
index 0000000000..b5b87ce1ad
--- /dev/null
+++ b/src/ilasm/writer.cpp
@@ -0,0 +1,1814 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// writer.cpp
+//
+
+#include "ilasmpch.h"
+
+#include "assembler.h"
+
+#include "ceefilegenwriter.h"
+#ifndef FEATURE_CORECLR
+#include "strongname.h"
+#include "LegacyActivationShim.h"
+#endif
+
+#ifndef _MSC_VER
+//cloned definition from ntimage.h that is removed for non MSVC builds
+typedef VOID
+(NTAPI *PIMAGE_TLS_CALLBACK) (
+ PVOID DllHandle,
+ ULONG Reason,
+ PVOID Reserved
+ );
+#endif //_MSC_VER
+
+
+HRESULT Assembler::InitMetaData()
+{
+ HRESULT hr = E_FAIL;
+
+ if(m_fInitialisedMetaData) return S_OK;
+
+ if(bClock) bClock->cMDInitBegin = GetTickCount();
+
+#ifdef FEATURE_CORECLR
+ hr = metaDataGetDispenser(CLSID_CorMetaDataDispenser,
+ IID_IMetaDataDispenserEx, (void **)&m_pDisp);
+#else
+ hr = LegacyActivationShim::ClrCoCreateInstance(
+ CLSID_CorMetaDataDispenser,
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ IID_IMetaDataDispenserEx,
+ (void **)&m_pDisp);
+#endif
+ if (FAILED(hr))
+ goto exit;
+
+ if(m_wzMetadataVersion)
+ {
+ VARIANT encOption;
+ BSTR bstr;
+ V_VT(&encOption) = VT_BSTR;
+ V_BSTR(&encOption) = bstr = ::SysAllocString(m_wzMetadataVersion);
+ hr = m_pDisp->SetOption(MetaDataRuntimeVersion, &encOption);
+ ::SysFreeString(bstr);
+ }
+ hr = m_pDisp->DefineScope(CLSID_CorMetaDataRuntime, 0, IID_IMetaDataEmit2,
+ (IUnknown **)&m_pEmitter);
+ if (FAILED(hr))
+ goto exit;
+
+ m_pManifest->SetEmitter(m_pEmitter);
+ if(FAILED(hr = m_pEmitter->QueryInterface(IID_IMetaDataImport2, (void**)&m_pImporter)))
+ goto exit;
+
+#ifndef FEATURE_CORECLR
+ hr = CoCreateInstance(CLSID_CorSymWriter_SxS,
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ IID_ISymUnmanagedWriter,
+ (void **)&m_pSymWriter);
+ if(SUCCEEDED(hr))
+ {
+ if(m_pSymWriter) m_pSymWriter->Initialize((IUnknown*)m_pEmitter,
+ m_wzOutputFileName,
+ NULL,
+ TRUE);
+ }
+ else
+ {
+ fprintf(stderr, "Error: QueryInterface(IID_ISymUnmanagedWriter) returns %X\n",hr);
+ m_pSymWriter = NULL;
+ }
+#endif // !FEATURE_CORECLR
+
+ //m_Parser = new AsmParse(m_pEmitter);
+ m_fInitialisedMetaData = TRUE;
+
+ hr = S_OK;
+
+exit:
+ if(bClock) bClock->cMDInitEnd = GetTickCount();
+ return hr;
+}
+/*********************************************************************************/
+/* if we have any Thread local store data, make the TLS directory record for it */
+
+HRESULT Assembler::CreateTLSDirectory() {
+
+ ULONG tlsEnd;
+ HRESULT hr;
+ if (FAILED(hr=m_pCeeFileGen->GetSectionDataLen(m_pTLSSection, &tlsEnd))) return(hr);
+
+ if (tlsEnd == 0) // No TLS data, we are done
+ return(S_OK);
+
+ // place to put the TLS directory
+ HCEESECTION tlsDirSec = m_pGlobalDataSection;
+
+ if(m_dwCeeFileFlags & ICEE_CREATE_FILE_PE32)
+ {
+ DWORD sizeofptr = (DWORD)sizeof(DWORD);
+ DWORD sizeofdir = (DWORD)sizeof(IMAGE_TLS_DIRECTORY32);
+ DWORD offsetofStartAddressOfRawData = (DWORD)offsetof(IMAGE_TLS_DIRECTORY32, StartAddressOfRawData);
+ DWORD offsetofEndAddressOfRawData = (DWORD)offsetof(IMAGE_TLS_DIRECTORY32, EndAddressOfRawData);
+ DWORD offsetofAddressOfIndex = (DWORD)offsetof(IMAGE_TLS_DIRECTORY32, AddressOfIndex);
+ DWORD offsetofAddressOfCallBacks = (DWORD)offsetof(IMAGE_TLS_DIRECTORY32, AddressOfCallBacks);
+
+ // Get memory for for the TLS directory block,as well as a spot for callback chain
+ IMAGE_TLS_DIRECTORY32* tlsDir;
+ if(FAILED(hr=m_pCeeFileGen->GetSectionBlock(tlsDirSec, sizeofdir + sizeofptr, sizeofptr, (void**) &tlsDir))) return(hr);
+ DWORD* callBackChain = (DWORD*) &tlsDir[1];
+ *callBackChain = 0;
+
+ // Find out where the tls directory will end up
+ ULONG tlsDirOffset;
+ if(FAILED(hr=m_pCeeFileGen->GetSectionDataLen(tlsDirSec, &tlsDirOffset))) return(hr);
+ tlsDirOffset -= (sizeofdir + sizeofptr);
+
+ // Set the start of the TLS data (offset 0 of hte TLS section)
+ tlsDir->StartAddressOfRawData = 0;
+ if(FAILED(hr=m_pCeeFileGen->AddSectionReloc(tlsDirSec, tlsDirOffset + offsetofStartAddressOfRawData, m_pTLSSection, srRelocHighLow))) return(hr);
+
+ // Set the end of the TLS data
+ tlsDir->EndAddressOfRawData = VALPTR(tlsEnd);
+ if(FAILED(hr=m_pCeeFileGen->AddSectionReloc(tlsDirSec, tlsDirOffset + offsetofEndAddressOfRawData, m_pTLSSection, srRelocHighLow))) return(hr);
+
+ // Allocate space for the OS to put the TLS index for this PE file (needs to be Read/Write?)
+ DWORD* tlsIndex;
+ if(FAILED(hr=m_pCeeFileGen->GetSectionBlock(m_pGlobalDataSection, sizeof(DWORD), sizeof(DWORD), (void**) &tlsIndex))) return(hr);
+ *tlsIndex = 0xCCCCCCCC; // Does't really matter, the OS will fill it in
+
+ // Find out where tlsIndex index is
+ ULONG tlsIndexOffset;
+ if(FAILED(hr=m_pCeeFileGen->GetSectionDataLen(tlsDirSec, &tlsIndexOffset))) return(hr);
+ tlsIndexOffset -= sizeof(DWORD);
+
+ // Set the address of the TLS index
+ tlsDir->AddressOfIndex = VALPTR(tlsIndexOffset);
+ if(FAILED(hr=m_pCeeFileGen->AddSectionReloc(tlsDirSec, tlsDirOffset + offsetofAddressOfIndex, m_pGlobalDataSection, srRelocHighLow))) return(hr);
+
+ // Set addres of callbacks chain
+ tlsDir->AddressOfCallBacks = VALPTR((DWORD)(DWORD_PTR)(PIMAGE_TLS_CALLBACK*)(size_t)(tlsDirOffset + sizeofdir));
+ if(FAILED(hr=m_pCeeFileGen->AddSectionReloc(tlsDirSec, tlsDirOffset + offsetofAddressOfCallBacks, tlsDirSec, srRelocHighLow))) return(hr);
+
+ // Set the other fields.
+ tlsDir->SizeOfZeroFill = 0;
+ tlsDir->Characteristics = 0;
+
+ hr=m_pCeeFileGen->SetDirectoryEntry (m_pCeeFile, tlsDirSec, IMAGE_DIRECTORY_ENTRY_TLS,
+ sizeofdir, tlsDirOffset);
+
+ if (m_dwCeeFileFlags & ICEE_CREATE_MACHINE_I386)
+ COR_SET_32BIT_REQUIRED(m_dwComImageFlags);
+ }
+ else
+ {
+ DWORD sizeofptr = (DWORD)sizeof(__int64);
+ DWORD sizeofdir = (DWORD)sizeof(IMAGE_TLS_DIRECTORY64);
+ DWORD offsetofStartAddressOfRawData = (DWORD)offsetof(IMAGE_TLS_DIRECTORY64, StartAddressOfRawData);
+ DWORD offsetofEndAddressOfRawData = (DWORD)offsetof(IMAGE_TLS_DIRECTORY64, EndAddressOfRawData);
+ DWORD offsetofAddressOfIndex = (DWORD)offsetof(IMAGE_TLS_DIRECTORY64, AddressOfIndex);
+ DWORD offsetofAddressOfCallBacks = (DWORD)offsetof(IMAGE_TLS_DIRECTORY64, AddressOfCallBacks);
+
+ // Get memory for for the TLS directory block,as well as a spot for callback chain
+ IMAGE_TLS_DIRECTORY64* tlsDir;
+ if(FAILED(hr=m_pCeeFileGen->GetSectionBlock(tlsDirSec, sizeofdir + sizeofptr, sizeofptr, (void**) &tlsDir))) return(hr);
+ __int64* callBackChain = (__int64*) &tlsDir[1];
+ *callBackChain = 0;
+
+ // Find out where the tls directory will end up
+ ULONG tlsDirOffset;
+ if(FAILED(hr=m_pCeeFileGen->GetSectionDataLen(tlsDirSec, &tlsDirOffset))) return(hr);
+ tlsDirOffset -= (sizeofdir + sizeofptr);
+
+ // Set the start of the TLS data (offset 0 of hte TLS section)
+ tlsDir->StartAddressOfRawData = 0;
+ if(FAILED(hr=m_pCeeFileGen->AddSectionReloc(tlsDirSec, tlsDirOffset + offsetofStartAddressOfRawData, m_pTLSSection, srRelocHighLow))) return(hr);
+
+ // Set the end of the TLS data
+ tlsDir->EndAddressOfRawData = VALPTR(tlsEnd);
+ if(FAILED(hr=m_pCeeFileGen->AddSectionReloc(tlsDirSec, tlsDirOffset + offsetofEndAddressOfRawData, m_pTLSSection, srRelocHighLow))) return(hr);
+
+ // Allocate space for the OS to put the TLS index for this PE file (needs to be Read/Write?)
+ DWORD* tlsIndex;
+ if(FAILED(hr=m_pCeeFileGen->GetSectionBlock(m_pGlobalDataSection, sizeof(DWORD), sizeof(DWORD), (void**) &tlsIndex))) return(hr);
+ *tlsIndex = 0xCCCCCCCC; // Does't really matter, the OS will fill it in
+
+ // Find out where tlsIndex index is
+ ULONG tlsIndexOffset;
+ if(FAILED(hr=m_pCeeFileGen->GetSectionDataLen(tlsDirSec, &tlsIndexOffset))) return(hr);
+ tlsIndexOffset -= sizeof(DWORD);
+
+ // Set the address of the TLS index
+ tlsDir->AddressOfIndex = VALPTR(tlsIndexOffset);
+ if(FAILED(hr=m_pCeeFileGen->AddSectionReloc(tlsDirSec, tlsDirOffset + offsetofAddressOfIndex, m_pGlobalDataSection, srRelocHighLow))) return(hr);
+
+ // Set addres of callbacks chain
+ tlsDir->AddressOfCallBacks = VALPTR((DWORD)(DWORD_PTR)(PIMAGE_TLS_CALLBACK*)(size_t)(tlsDirOffset + sizeofdir));
+ if(FAILED(hr=m_pCeeFileGen->AddSectionReloc(tlsDirSec, tlsDirOffset + offsetofAddressOfCallBacks, tlsDirSec, srRelocHighLow))) return(hr);
+
+ // Set the other fields.
+ tlsDir->SizeOfZeroFill = 0;
+ tlsDir->Characteristics = 0;
+
+ hr=m_pCeeFileGen->SetDirectoryEntry (m_pCeeFile, tlsDirSec, IMAGE_DIRECTORY_ENTRY_TLS,
+ sizeofdir, tlsDirOffset);
+ }
+
+ if(m_dwCeeFileFlags & ICEE_CREATE_FILE_STRIP_RELOCS)
+ {
+ report->error("Base relocations are emitted, while /STRIPRELOC option has been specified");
+ }
+ m_dwComImageFlags &= ~COMIMAGE_FLAGS_ILONLY;
+
+ return(hr);
+}
+
+HRESULT Assembler::CreateDebugDirectory()
+{
+ HRESULT hr = S_OK;
+ HCEESECTION sec = m_pILSection;
+ BYTE *de;
+ ULONG deOffset;
+
+ // Only emit this if we're also emitting debug info.
+ if (!(m_fGeneratePDB && m_pSymWriter))
+ return S_OK;
+
+ IMAGE_DEBUG_DIRECTORY debugDirIDD;
+ struct Param
+ {
+ DWORD debugDirDataSize;
+ BYTE *debugDirData;
+ } param;
+ param.debugDirData = NULL;
+
+ // Get the debug info from the symbol writer.
+ if (FAILED(hr=m_pSymWriter->GetDebugInfo(NULL, 0, &param.debugDirDataSize, NULL)))
+ return hr;
+
+ // Will there even be any?
+ if (param.debugDirDataSize == 0)
+ return S_OK;
+
+ // Make some room for the data.
+ PAL_TRY(Param *, pParam, &param) {
+ pParam->debugDirData = new BYTE[pParam->debugDirDataSize];
+ } PAL_EXCEPT(EXCEPTION_EXECUTE_HANDLER) {
+ hr = E_FAIL;
+ } PAL_ENDTRY
+
+ if(FAILED(hr)) return hr;
+ // Actually get the data now.
+ if (FAILED(hr = m_pSymWriter->GetDebugInfo(&debugDirIDD,
+ param.debugDirDataSize,
+ NULL,
+ param.debugDirData)))
+ goto ErrExit;
+
+ // Grab the timestamp of the PE file.
+ DWORD fileTimeStamp;
+
+ if (FAILED(hr = m_pCeeFileGen->GetFileTimeStamp(m_pCeeFile,
+ &fileTimeStamp)))
+ goto ErrExit;
+
+ // Fill in the directory entry.
+ debugDirIDD.TimeDateStamp = VAL32(fileTimeStamp);
+
+ // Grab memory in the section for our stuff.
+ // Note that UpdateResource doesn't work correctly if the debug directory is
+ // in the data section. So instead we put it in the text section (same as
+ // cs compiler).
+ if (FAILED(hr = m_pCeeFileGen->GetSectionBlock(sec,
+ sizeof(debugDirIDD) +
+ param.debugDirDataSize,
+ 4,
+ (void**) &de)))
+ goto ErrExit;
+
+ // Where did we get that memory?
+ if (FAILED(hr = m_pCeeFileGen->GetSectionDataLen(sec,
+ &deOffset)))
+ goto ErrExit;
+
+ deOffset -= (sizeof(debugDirIDD) + param.debugDirDataSize);
+
+ // Setup a reloc so that the address of the raw
+ // data is setup correctly.
+ debugDirIDD.PointerToRawData = VAL32(deOffset + sizeof(debugDirIDD));
+
+ if (FAILED(hr = m_pCeeFileGen->AddSectionReloc(
+ sec,
+ deOffset +
+ offsetof(IMAGE_DEBUG_DIRECTORY,
+ PointerToRawData),
+ sec, srRelocFilePos)))
+ goto ErrExit;
+
+ debugDirIDD.AddressOfRawData = VAL32(deOffset + sizeof(debugDirIDD));
+
+ if (FAILED(hr = m_pCeeFileGen->AddSectionReloc(
+ sec,
+ deOffset +
+ offsetof(IMAGE_DEBUG_DIRECTORY,
+ AddressOfRawData),
+ sec, srRelocAbsolute)))
+ goto ErrExit;
+ // Emit the directory entry.
+ if (FAILED(hr = m_pCeeFileGen->SetDirectoryEntry(m_pCeeFile,
+ sec,
+ IMAGE_DIRECTORY_ENTRY_DEBUG,
+ sizeof(debugDirIDD),
+ deOffset)))
+ goto ErrExit;
+
+ // Copy the debug directory into the section.
+ memcpy(de, &debugDirIDD, sizeof(debugDirIDD));
+ memcpy(de + sizeof(debugDirIDD), param.debugDirData,
+ param.debugDirDataSize);
+
+ if (param.debugDirData)
+ {
+ delete [] param.debugDirData;
+ }
+ return S_OK;
+
+ErrExit:
+ if (param.debugDirData)
+ {
+ delete [] param.debugDirData;
+ }
+ return hr;
+}
+//#ifdef EXPORT_DIR_ENABLED
+HRESULT Assembler::CreateExportDirectory()
+{
+ HRESULT hr = S_OK;
+ DWORD Nentries = m_EATList.COUNT();
+ if(Nentries == 0) return S_OK;
+
+ IMAGE_EXPORT_DIRECTORY exportDirIDD;
+ DWORD exportDirDataSize;
+ BYTE *exportDirData;
+ EATEntry *pEATE;
+ unsigned i, L, ordBase = 0xFFFFFFFF, Ldllname;
+ // get the DLL name from output file name
+ char* pszDllName;
+ Ldllname = (unsigned)wcslen(m_wzOutputFileName)*3+3;
+ char* szOutputFileName = new char[Ldllname];
+ memset(szOutputFileName,0,wcslen(m_wzOutputFileName)*3+3);
+ WszWideCharToMultiByte(CP_ACP,0,m_wzOutputFileName,-1,szOutputFileName,Ldllname,NULL,NULL);
+ pszDllName = strrchr(szOutputFileName,'\\');
+ if(pszDllName == NULL) pszDllName = strrchr(szOutputFileName,':');
+ if(pszDllName == NULL) pszDllName = szOutputFileName;
+ Ldllname = (unsigned)strlen(pszDllName)+1;
+
+ // Allocate buffer for tables
+ for(i = 0, L=0; i < Nentries; i++) L += 1+(unsigned)strlen(m_EATList.PEEK(i)->szAlias);
+ exportDirDataSize = Nentries*5*sizeof(WORD) + L + Ldllname;
+ exportDirData = new BYTE[exportDirDataSize];
+ memset(exportDirData,0,exportDirDataSize);
+
+ // Export address table
+ DWORD* pEAT = (DWORD*)exportDirData;
+ // Name pointer table
+ DWORD* pNPT = pEAT + Nentries;
+ // Ordinal table
+ WORD* pOT = (WORD*)(pNPT + Nentries);
+ // Export name table
+ char* pENT = (char*)(pOT + Nentries);
+ // DLL name
+ char* pDLLName = pENT + L;
+
+ // sort the names/ordinals
+ char** pAlias = new char*[Nentries];
+ for(i = 0; i < Nentries; i++)
+ {
+ pEATE = m_EATList.PEEK(i);
+ pOT[i] = (WORD)pEATE->dwOrdinal;
+ if(pOT[i] < ordBase) ordBase = pOT[i];
+ pAlias[i] = pEATE->szAlias;
+ }
+ bool swapped = true;
+ unsigned j;
+ char* pch;
+ while(swapped)
+ {
+ swapped = false;
+ for(i=1; i < Nentries; i++)
+ {
+ if(strcmp(pAlias[i-1],pAlias[i]) > 0)
+ {
+ swapped = true;
+ pch = pAlias[i-1];
+ pAlias[i-1] = pAlias[i];
+ pAlias[i] = pch;
+ j = pOT[i-1];
+ pOT[i-1] = pOT[i];
+ pOT[i] = j;
+ }
+ }
+ }
+ // normalize ordinals
+ for(i = 0; i < Nentries; i++) pOT[i] -= ordBase;
+ // fill the export address table
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:22008) // "Suppress PREfast warnings about integer overflow"
+#endif
+ for(i = 0; i < Nentries; i++)
+ {
+ pEATE = m_EATList.PEEK(i);
+ pEAT[pEATE->dwOrdinal - ordBase] = pEATE->dwStubRVA;
+ }
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
+ // fill the export names table
+ unsigned l;
+ for(i = 0, j = 0; i < Nentries; i++)
+ {
+ pNPT[i] = j; // relative offset in the table
+ l = (unsigned)strlen(pAlias[i])+1;
+ memcpy(&pENT[j],pAlias[i],l);
+ j+=l;
+ }
+ _ASSERTE(j==L);
+ // fill the DLL name
+ memcpy(pDLLName,pszDllName,Ldllname);
+
+ // Data blob is ready pending Name Pointer Table values offsetting
+
+ memset(&exportDirIDD,0,sizeof(IMAGE_EXPORT_DIRECTORY));
+ // Grab the timestamp of the PE file.
+ DWORD fileTimeStamp;
+ if (FAILED(hr = m_pCeeFileGen->GetFileTimeStamp(m_pCeeFile,&fileTimeStamp))) return hr;
+ // Fill in the directory entry.
+ // Characteristics, MajorVersion and MinorVersion play no role and stay 0
+ exportDirIDD.TimeDateStamp = VAL32(fileTimeStamp);
+ exportDirIDD.Name = VAL32(exportDirDataSize - Ldllname); // to be offset later
+ exportDirIDD.Base = VAL32(ordBase);
+ exportDirIDD.NumberOfFunctions = VAL32(Nentries);
+ exportDirIDD.NumberOfNames = VAL32(Nentries);
+ exportDirIDD.AddressOfFunctions = 0; // to be offset later
+ exportDirIDD.AddressOfNames = VAL32(Nentries*sizeof(DWORD)); // to be offset later
+ exportDirIDD.AddressOfNameOrdinals = VAL32(Nentries*sizeof(DWORD)*2); // to be offset later
+
+ // Grab memory in the section for our stuff.
+ HCEESECTION sec = m_pGlobalDataSection;
+ BYTE *de;
+ if (FAILED(hr = m_pCeeFileGen->GetSectionBlock(sec,
+ sizeof(IMAGE_EXPORT_DIRECTORY) + exportDirDataSize,
+ 4,
+ (void**) &de))) return hr;
+ // Where did we get that memory?
+ ULONG deOffset, deDataOffset;
+ if (FAILED(hr = m_pCeeFileGen->GetSectionDataLen(sec, &deDataOffset))) return hr;
+
+ deDataOffset -= exportDirDataSize;
+ deOffset = deDataOffset - sizeof(IMAGE_EXPORT_DIRECTORY);
+
+ // Add offsets and set up relocs for header entries
+ exportDirIDD.Name = VAL32(VAL32(exportDirIDD.Name) + deDataOffset);
+ if (FAILED(hr = m_pCeeFileGen->AddSectionReloc(sec,deOffset + offsetof(IMAGE_EXPORT_DIRECTORY,Name),
+ sec, srRelocAbsolute))) return hr;
+ exportDirIDD.AddressOfFunctions = VAL32(VAL32(exportDirIDD.AddressOfFunctions) + deDataOffset);
+ if (FAILED(hr = m_pCeeFileGen->AddSectionReloc(sec,deOffset + offsetof(IMAGE_EXPORT_DIRECTORY,AddressOfFunctions),
+ sec, srRelocAbsolute))) return hr;
+ exportDirIDD.AddressOfNames = VAL32(VAL32(exportDirIDD.AddressOfNames) + deDataOffset);
+ if (FAILED(hr = m_pCeeFileGen->AddSectionReloc(sec,deOffset + offsetof(IMAGE_EXPORT_DIRECTORY,AddressOfNames),
+ sec, srRelocAbsolute))) return hr;
+ exportDirIDD.AddressOfNameOrdinals = VAL32(VAL32(exportDirIDD.AddressOfNameOrdinals) + deDataOffset);
+ if (FAILED(hr = m_pCeeFileGen->AddSectionReloc(sec,deOffset + offsetof(IMAGE_EXPORT_DIRECTORY,AddressOfNameOrdinals),
+ sec, srRelocAbsolute))) return hr;
+
+ // Add offsets and set up relocs for Name Pointer Table
+ j = deDataOffset + Nentries*5*sizeof(WORD); // EA, NP and O Tables come first
+ for(i = 0; i < Nentries; i++)
+ {
+ pNPT[i] += j;
+ if (FAILED(hr = m_pCeeFileGen->AddSectionReloc(sec,exportDirIDD.AddressOfNames+i*sizeof(DWORD),
+ sec, srRelocAbsolute))) return hr;
+ }
+
+
+ // Emit the directory entry.
+ if (FAILED(hr = m_pCeeFileGen->SetDirectoryEntry(m_pCeeFile, sec, IMAGE_DIRECTORY_ENTRY_EXPORT,
+ sizeof(IMAGE_EXPORT_DIRECTORY), deOffset))) return hr;
+
+ // Copy the debug directory into the section.
+ memcpy(de, &exportDirIDD, sizeof(IMAGE_EXPORT_DIRECTORY));
+ memcpy(de + sizeof(IMAGE_EXPORT_DIRECTORY), exportDirData, exportDirDataSize);
+ delete [] pAlias;
+ delete [] exportDirData;
+ return S_OK;
+}
+
+static const BYTE ExportStubAMD64Template[] =
+{
+ // Jump through VTFixup table
+ 0x48, 0xA1, // rex.w rex.b mov rax,[following address]
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//address of VTFixup slot
+ 0xFF, 0xE0 // jmp [rax]
+};
+static const BYTE ExportStubX86Template[] =
+{
+ // Jump through VTFixup table
+ 0xFF, 0x25, // jmp [following address]
+ 0x00, 0x00, 0x00, 0x00 //address of VTFixup slot
+};
+static const WORD ExportStubARMTemplate[] =
+{
+ // Jump through VTFixup table
+ 0xf8df, 0xf000, // ldr pc, [pc, #0]
+ 0x0000, 0x0000 //address of VTFixup slot
+};
+
+static const BYTE ExportStubIA64Template[] =
+{
+ // ld8 r9 = [gp] ;;
+ // ld8 r10 = [r9],8
+ // nop.i ;;
+ // ld8 gp = [r9]
+ // mov b6 = r10
+ // br.cond.sptk.few b6
+ //
+ 0x0B, 0x48, 0x00, 0x02, 0x18, 0x10, 0xA0, 0x40,
+ 0x24, 0x30, 0x28, 0x00, 0x00, 0x00, 0x04, 0x00,
+ 0x10, 0x08, 0x00, 0x12, 0x18, 0x10, 0x60, 0x50,
+ 0x04, 0x80, 0x03, 0x00, 0x60, 0x00, 0x80, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//address of the template
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 //address of VTFixup slot
+};
+DWORD Assembler::EmitExportStub(DWORD dwVTFSlotRVA)
+{
+ DWORD EXPORT_STUB_SIZE = (DWORD)(sizeof(WORD)+sizeof(DWORD));
+ DWORD OFFSET_OF_ADDR = (DWORD)sizeof(WORD);
+ DWORD STUB_ALIGNMENT = 16;
+ BYTE* STUB_TEMPLATE = NULL;
+ DWORD PEFileOffset;
+ BYTE* outBuff;
+ DWORD* pdwVTFSlotRVA;
+ if(m_dwCeeFileFlags & ICEE_CREATE_MACHINE_IA64)
+ {
+ STUB_TEMPLATE = (BYTE*)&ExportStubIA64Template[0];
+ EXPORT_STUB_SIZE = sizeof(ExportStubIA64Template);
+ OFFSET_OF_ADDR = 40;
+ if (FAILED(m_pCeeFileGen->GetSectionBlock (m_pILSection, EXPORT_STUB_SIZE, STUB_ALIGNMENT, (void **) &outBuff))) return 0;
+ memcpy(outBuff,STUB_TEMPLATE,EXPORT_STUB_SIZE);
+ pdwVTFSlotRVA = (DWORD*)(&outBuff[OFFSET_OF_ADDR]);
+ *pdwVTFSlotRVA = VAL32(dwVTFSlotRVA);
+
+ // The offset where we start, (not where the alignment bytes start!)
+ if (FAILED(m_pCeeFileGen->GetSectionDataLen (m_pILSection, &PEFileOffset))) return 0;
+
+ PEFileOffset -= EXPORT_STUB_SIZE;
+ *((DWORD*)(&outBuff[OFFSET_OF_ADDR - 8])) = PEFileOffset; // set PLabel
+ m_pCeeFileGen->AddSectionReloc(m_pILSection, PEFileOffset+OFFSET_OF_ADDR-8,m_pILSection, srRelocHighLow);
+ m_pCeeFileGen->AddSectionReloc(m_pILSection, PEFileOffset+OFFSET_OF_ADDR,m_pGlobalDataSection, srRelocHighLow);
+ PEFileOffset += OFFSET_OF_ADDR - 8; // entry point is PLabel, which points at the template
+ }
+ else
+ {
+ if(m_dwCeeFileFlags & ICEE_CREATE_MACHINE_AMD64)
+ {
+ STUB_TEMPLATE = (BYTE*)&ExportStubAMD64Template[0];
+ EXPORT_STUB_SIZE = sizeof(ExportStubAMD64Template);
+ OFFSET_OF_ADDR = 2;
+ STUB_ALIGNMENT = 4;
+ }
+ else if(m_dwCeeFileFlags & ICEE_CREATE_MACHINE_I386)
+ {
+ STUB_TEMPLATE = (BYTE*)&ExportStubX86Template[0];
+ EXPORT_STUB_SIZE = sizeof(ExportStubX86Template);
+ OFFSET_OF_ADDR = 2;
+ }
+ else if(m_dwCeeFileFlags & ICEE_CREATE_MACHINE_ARM)
+ {
+ STUB_TEMPLATE = (BYTE*)&ExportStubARMTemplate[0];
+ EXPORT_STUB_SIZE = sizeof(ExportStubARMTemplate);
+ OFFSET_OF_ADDR = 4;
+ STUB_ALIGNMENT = 4;
+ }
+ else
+ {
+ report->error("Unmanaged exports are not implemented for unknown platform");
+ return NULL;
+ }
+ // Addr must be aligned, not the stub!
+ if (FAILED(m_pCeeFileGen->GetSectionDataLen (m_pILSection, &PEFileOffset))) return 0;
+ if((PEFileOffset + OFFSET_OF_ADDR)&(STUB_ALIGNMENT-1))
+ {
+ ULONG L = STUB_ALIGNMENT - ((PEFileOffset + OFFSET_OF_ADDR)&(STUB_ALIGNMENT-1));
+ if (FAILED(m_pCeeFileGen->GetSectionBlock (m_pILSection, L, 1, (void **) &outBuff))) return 0;
+ memset(outBuff,0,L);
+ }
+
+ if (FAILED(m_pCeeFileGen->GetSectionBlock (m_pILSection, EXPORT_STUB_SIZE, 1, (void **) &outBuff))) return 0;
+ memcpy(outBuff,STUB_TEMPLATE,EXPORT_STUB_SIZE);
+ pdwVTFSlotRVA = (DWORD*)(&outBuff[OFFSET_OF_ADDR]);
+ *pdwVTFSlotRVA = VAL32(dwVTFSlotRVA);
+
+ // The offset where we start, (not where the alignment bytes start!)
+ if (FAILED(m_pCeeFileGen->GetSectionDataLen (m_pILSection, &PEFileOffset))) return 0;
+
+ PEFileOffset -= EXPORT_STUB_SIZE;
+ _ASSERTE(((PEFileOffset + OFFSET_OF_ADDR)&(STUB_ALIGNMENT-1))==0);
+ m_pCeeFileGen->AddSectionReloc(m_pILSection, PEFileOffset+OFFSET_OF_ADDR,m_pGlobalDataSection, srRelocHighLow);
+ }
+ if(m_dwCeeFileFlags & ICEE_CREATE_FILE_STRIP_RELOCS)
+ {
+ report->error("Base relocations are emitted, while /STRIPRELOC option has been specified");
+ }
+ m_pCeeFileGen->GetMethodRVA(m_pCeeFile, PEFileOffset,&PEFileOffset);
+ return PEFileOffset;
+}
+//#endif
+
+HRESULT Assembler::GetCAName(mdToken tkCA, __out LPWSTR *ppszName)
+{
+ HRESULT hr = S_OK;
+ DWORD cchName;
+ LPWSTR name;
+
+ *ppszName = NULL;
+
+ if (TypeFromToken(tkCA) == mdtMemberRef)
+ {
+ mdToken parent;
+ if (FAILED(hr = m_pImporter->GetMemberRefProps( tkCA, &parent, NULL, 0, NULL, NULL, NULL)))
+ return hr;
+ tkCA = parent;
+ }
+ else if (TypeFromToken(tkCA) == mdtMethodDef)
+ {
+ mdToken parent;
+ if (FAILED(hr = m_pImporter->GetMemberProps( tkCA, &parent, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)))
+ return hr;
+ tkCA = parent;
+ }
+
+ if (TypeFromToken(tkCA) == mdtTypeRef)
+ {
+ // A TypeRef
+ if (FAILED(hr = m_pImporter->GetTypeRefProps(tkCA, NULL, NULL, 0, &cchName)))
+ return hr;
+ if ((name = new WCHAR[cchName + 1]) == NULL)
+ return E_OUTOFMEMORY;
+ hr = m_pImporter->GetTypeRefProps(tkCA, NULL, name, cchName, &cchName);
+ }
+ else
+ {
+ hr = m_pImporter->GetTypeDefProps(tkCA, NULL, 0, &cchName, NULL, NULL);
+ if (hr != S_OK)
+ return hr;
+ if ((name = new WCHAR[cchName + 1]) == NULL)
+ return E_OUTOFMEMORY;
+ hr = m_pImporter->GetTypeDefProps(tkCA, name, cchName, &cchName, NULL, NULL);
+ }
+ if (SUCCEEDED(hr))
+ *ppszName = name;
+ else
+ delete [] name;
+ return hr;
+}
+
+BYTE HexToByte (CHAR wc)
+{
+ if (!iswxdigit(wc)) return (BYTE) 0xff;
+ if (iswdigit(wc)) return (BYTE) (wc - L'0');
+ if (iswupper(wc)) return (BYTE) (wc - L'A' + 10);
+ return (BYTE) (wc - L'a' + 10);
+}
+
+#ifndef FEATURE_CORECLR
+bool GetBytesFromHex (LPCSTR szPublicKeyHexString, ULONG cchPublicKeyHexString, BYTE** buffer, ULONG *cbBufferSize)
+{
+ ULONG cchHex = cchPublicKeyHexString;
+ if (cchHex % 2 != 0)
+ return false;
+ *cbBufferSize = cchHex / 2;
+
+ *buffer = new BYTE[*cbBufferSize];
+ if (!*buffer)
+ return false;
+
+ for (ULONG i = 0; i < *cbBufferSize; i++)
+ {
+ BYTE msn = HexToByte(*szPublicKeyHexString);
+ BYTE lsn = HexToByte(*(szPublicKeyHexString + 1));
+ if (msn == 0xFF || lsn == 0xFF)
+ {
+ delete[] *buffer;
+ return false;
+ }
+
+ (*buffer)[i] = (BYTE) ( (msn << 4) | lsn );
+ szPublicKeyHexString += 2;
+ }
+
+ return true;
+}
+
+HRESULT Assembler::GetSignatureKey()
+{
+ HRESULT hr = S_OK;
+ ULONG cbSize = 0;
+ void * pvData = NULL;
+ LPWSTR pName = NULL;
+
+ CustomDescrList* pCDList = &m_pManifest->m_pAssembly->m_CustomDescrList;
+
+ for (ULONG i = 0;i < pCDList->COUNT(); i++)
+ {
+ CustomDescr* pCD = pCDList->PEEK(i);
+
+ if(pCD->pBlob)
+ {
+ pvData = (void *)(pCD->pBlob->ptr());
+ cbSize = pCD->pBlob->length();
+ pCD->tkOwner = m_pManifest->m_pAssembly->tkTok;
+ mdToken tkOwnerType, tkTypeType = TypeFromToken(pCD->tkType);
+
+ if (GetCAName(pCD->tkType, &pName) != S_OK)
+ continue;
+
+ if (wcscmp(pName, L"System.Reflection.AssemblySignatureKeyAttribute") == 0)
+ {
+ if (cbSize < sizeof(WORD) || GET_UNALIGNED_VAL16(pvData) != 1)
+ {
+ hr = E_FAIL;
+ break;;
+ }
+ pvData = (unsigned char *)pvData + sizeof(WORD);
+ cbSize -= sizeof(WORD);
+
+ // String is stored as compressed length, UTF8.
+ if (*(const BYTE*)pvData != 0xFF)
+ {
+ PCCOR_SIGNATURE sig = (PCCOR_SIGNATURE)pvData;
+ cbSize -= CorSigUncompressedDataSize(sig);
+ DWORD len = CorSigUncompressData(sig);
+ pvData = (void *)sig;
+ if (cbSize < len)
+ {
+ hr = E_FAIL;
+ break;
+ }
+
+ AsmManStrongName *pSN = &m_pManifest->m_sStrongName;
+ GetBytesFromHex((LPCSTR)pvData, len, &pSN->m_pbSignatureKey, &pSN->m_cbSignatureKey);
+ }
+
+ break;
+ }
+
+ if (pName)
+ {
+ delete pName;
+ pName = NULL;
+ }
+ }
+ }
+
+ if (pName)
+ delete pName;
+ return hr;
+}
+
+HRESULT Assembler::AllocateStrongNameSignature()
+{
+ HRESULT hr = S_OK;
+ HCEESECTION hSection;
+ DWORD dwDataLength;
+ DWORD dwDataOffset;
+ DWORD dwDataRVA;
+ VOID *pvBuffer;
+ AsmManStrongName *pSN = &m_pManifest->m_sStrongName;
+
+ // Pulls the AssemblySignatureKey attribute from m_CustomDescrList
+ // If present, populate the pSN->m_pbSignatureKey from the AssemblySignatureKeyAttribute blob
+ if (FAILED(hr = GetSignatureKey()))
+ {
+ return hr;
+ }
+
+ // Determine size of signature blob.
+ if (pSN->m_pbSignatureKey != NULL)
+ {
+ // If m_pbSignatureKey present use it, else fall back to using identity key.
+ if (FAILED(hr = LegacyActivationShim::StrongNameSignatureSize_HRESULT(
+ pSN->m_pbSignatureKey,
+ pSN->m_cbSignatureKey,
+ &dwDataLength)))
+ {
+ return hr;
+ }
+ }
+ else if (FAILED(hr = LegacyActivationShim::StrongNameSignatureSize_HRESULT(
+ pSN->m_pbPublicKey,
+ pSN->m_cbPublicKey,
+ &dwDataLength)))
+ {
+ return hr;
+ }
+
+ // Grab memory in the section for our stuff.
+ if (FAILED(hr = m_pCeeFileGen->GetIlSection(m_pCeeFile,
+ &hSection)))
+ return hr;
+
+ if (FAILED(hr = m_pCeeFileGen->GetSectionBlock(hSection,
+ dwDataLength,
+ 4,
+ &pvBuffer)))
+ return hr;
+
+ // Where did we get that memory?
+ if (FAILED(hr = m_pCeeFileGen->GetSectionDataLen(hSection,
+ &dwDataOffset)))
+ return hr;
+
+ dwDataOffset -= dwDataLength;
+
+ // Convert to an RVA.
+ if (FAILED(hr = m_pCeeFileGen->GetMethodRVA(m_pCeeFile,
+ dwDataOffset,
+ &dwDataRVA)))
+ return hr;
+
+ // Emit the directory entry.
+ if (FAILED(hr = m_pCeeFileGen->SetStrongNameEntry(m_pCeeFile,
+ dwDataLength,
+ dwDataRVA)))
+ return hr;
+
+ return S_OK;
+}
+
+HRESULT Assembler::StrongNameSign()
+{
+ LPWSTR wszOutputFile;
+ HRESULT hr = S_OK;
+ AsmManStrongName *pSN = &m_pManifest->m_sStrongName;
+
+ // Determine what the ouput PE was called.
+ if (FAILED(hr = m_pCeeFileGen->GetOutputFileName(m_pCeeFile,
+ &wszOutputFile)))
+ return hr;
+
+ // Update the output PE image with a strong name signature.
+ if (FAILED(hr = LegacyActivationShim::StrongNameSignatureGeneration_HRESULT(
+ wszOutputFile,
+ pSN->m_wzKeyContainer,
+ pSN->m_pbPrivateKey,
+ pSN->m_cbPrivateKey,
+ NULL,
+ NULL)))
+ {
+ return hr;
+ }
+
+ return S_OK;
+}
+#endif // !FEATURE_CORECLR
+
+BOOL Assembler::EmitFieldsMethods(Class* pClass)
+{
+ unsigned n;
+ BOOL ret = TRUE;
+ // emit all field definition metadata tokens
+ if((n = pClass->m_FieldDList.COUNT()))
+ {
+ FieldDescriptor* pFD;
+ if(m_fReportProgress) printf("Fields: %d;\t",n);
+ for(int j=0; (pFD = pClass->m_FieldDList.PEEK(j)); j++) // can't use POP here: we'll need field list for props
+ {
+ if(!EmitField(pFD))
+ {
+ if(!OnErrGo) return FALSE;
+ ret = FALSE;
+ }
+ pFD->m_fNew = FALSE;
+ }
+ }
+ // Fields are emitted; emit the class layout
+ {
+ COR_FIELD_OFFSET *pOffsets = NULL;
+ ULONG ul = pClass->m_ulPack;
+ ULONG N = pClass->m_dwNumFieldsWithOffset;
+
+ EmitSecurityInfo(pClass->m_cl,
+ pClass->m_pPermissions,
+ pClass->m_pPermissionSets);
+ pClass->m_pPermissions = NULL;
+ pClass->m_pPermissionSets = NULL;
+ if((pClass->m_ulSize != 0xFFFFFFFF)||(ul != 0)||(N != 0))
+ {
+ if(IsTdAutoLayout(pClass->m_Attr)) report->warn("Layout specified for auto-layout class\n");
+ if((ul > 128)||((ul & (ul-1)) !=0 ))
+ report->error("Invalid packing parameter (%d), must be 1,2,4,8...128\n",pClass->m_ulPack);
+ if(N)
+ {
+ pOffsets = new COR_FIELD_OFFSET[N+1];
+ ULONG i,j=0;
+ FieldDescriptor *pFD;
+ for(i=0; (pFD = pClass->m_FieldDList.PEEK(i)); i++)
+ {
+ if(pFD->m_ulOffset != 0xFFFFFFFF)
+ {
+ pOffsets[j].ridOfField = RidFromToken(pFD->m_fdFieldTok);
+ pOffsets[j].ulOffset = pFD->m_ulOffset;
+ j++;
+ }
+ }
+ _ASSERTE(j == N);
+ pOffsets[j].ridOfField = mdFieldDefNil;
+ }
+ m_pEmitter->SetClassLayout (
+ pClass->m_cl, // [IN] typedef
+ ul, // [IN] packing size specified as 1, 2, 4, 8, or 16
+ pOffsets, // [IN] array of layout specification
+ pClass->m_ulSize); // [IN] size of the class
+ if(pOffsets) delete [] pOffsets;
+ }
+ }
+ // emit all method definition metadata tokens
+ if((n = pClass->m_MethodList.COUNT()))
+ {
+ Method* pMethod;
+
+ if(m_fReportProgress) printf("Methods: %d;\t",n);
+ for(int i=0; (pMethod = pClass->m_MethodList.PEEK(i));i++)
+ {
+ if(!EmitMethod(pMethod))
+ {
+ if(!OnErrGo) return FALSE;
+ ret = FALSE;
+ }
+ pMethod->m_fNew = FALSE;
+ }
+ }
+ if(m_fReportProgress) printf("\n");
+ return ret;
+}
+
+HRESULT Assembler::ResolveLocalMemberRefs()
+{
+ unsigned ulTotal=0, ulDefs=0, ulRefs=0, ulUnres=0;
+ MemberRefDList* pList[2] = {&m_LocalMethodRefDList,&m_LocalFieldRefDList};
+
+ if(pList[0]->COUNT() + pList[1]->COUNT())
+ {
+ MemberRefDescriptor* pMRD;
+ mdToken tkMemberDef = 0;
+ int i,j,k;
+ Class *pSearch;
+
+ if(m_fReportProgress) printf("Resolving local member refs: ");
+ for(k=0; k<2; k++)
+ {
+ for(i=0; (pMRD = pList[k]->PEEK(i)) != NULL; i++)
+ {
+ if(pMRD->m_tkResolved) continue;
+
+ tkMemberDef = 0;
+ Method* pListMD;
+ char* pMRD_szName = pMRD->m_szName;
+ DWORD pMRD_dwName = pMRD->m_dwName;
+ ULONG pMRD_dwCSig = (pMRD->m_pSigBinStr ? pMRD->m_pSigBinStr->length() : 0);
+ PCOR_SIGNATURE pMRD_pSig = (PCOR_SIGNATURE)(pMRD->m_pSigBinStr ? pMRD->m_pSigBinStr->ptr() : NULL);
+ CQuickBytes qbSig;
+
+ ulTotal++;
+
+ pSearch = NULL;
+ if(pMRD->m_tdClass == mdTokenNil)
+ pSearch = m_lstClass.PEEK(0);
+ else if((TypeFromToken(pMRD->m_tdClass) != mdtTypeDef)
+ ||((pSearch = m_lstClass.PEEK(RidFromToken(pMRD->m_tdClass)-1)) == NULL))
+ {
+ report->msg("Error: bad parent 0x%08X of local member ref '%s'\n",
+ pMRD->m_tdClass,pMRD->m_szName);
+ }
+ if(pSearch)
+ {
+ // MemberRef may reference a method or a field
+ if(k==0) //methods
+ {
+ if((*pMRD_pSig & IMAGE_CEE_CS_CALLCONV_MASK)==IMAGE_CEE_CS_CALLCONV_VARARG)
+ {
+ ULONG L;
+ qbSig.Shrink(0);
+ _GetFixedSigOfVarArg(pMRD_pSig,pMRD_dwCSig,&qbSig,&L);
+ pMRD_pSig = (PCOR_SIGNATURE)(qbSig.Ptr());
+ pMRD_dwCSig = L;
+ }
+ for(j=0; (pListMD = pSearch->m_MethodList.PEEK(j)) != NULL; j++)
+ {
+ if(pListMD->m_dwName != pMRD_dwName) continue;
+ if(strcmp(pListMD->m_szName,pMRD_szName)) continue;
+ if(pListMD->m_dwMethodCSig != pMRD_dwCSig) continue;
+ if(memcmp(pListMD->m_pMethodSig,pMRD_pSig,pMRD_dwCSig)) continue;
+ tkMemberDef = pListMD->m_Tok;
+ ulDefs++;
+ break;
+ }
+ if(tkMemberDef && ((*pMRD_pSig & IMAGE_CEE_CS_CALLCONV_MASK)==IMAGE_CEE_CS_CALLCONV_VARARG))
+ {
+ WszMultiByteToWideChar(g_uCodePage,0,pMRD_szName,-1,wzUniBuf,dwUniBuf);
+
+ if(IsMdPrivateScope(pListMD->m_Attr))
+ {
+ WCHAR* p = wcsstr(wzUniBuf,W("$PST06"));
+ if(p) *p = 0;
+ }
+
+ m_pEmitter->DefineMemberRef(tkMemberDef, wzUniBuf,
+ pMRD->m_pSigBinStr->ptr(),
+ pMRD->m_pSigBinStr->length(),
+ &tkMemberDef);
+ ulDefs--;
+ ulRefs++;
+ }
+ }
+ else // fields
+ {
+ FieldDescriptor* pListFD;
+ for(j=0; (pListFD = pSearch->m_FieldDList.PEEK(j)) != NULL; j++)
+ {
+ if(pListFD->m_dwName != pMRD_dwName) continue;
+ if(strcmp(pListFD->m_szName,pMRD_szName)) continue;
+ if(pListFD->m_pbsSig)
+ {
+ if(pListFD->m_pbsSig->length() != pMRD_dwCSig) continue;
+ if(memcmp(pListFD->m_pbsSig->ptr(),pMRD_pSig,pMRD_dwCSig)) continue;
+ }
+ else if(pMRD_dwCSig) continue;
+ tkMemberDef = pListFD->m_fdFieldTok;
+ ulDefs++;
+ break;
+ }
+ }
+ }
+ if(tkMemberDef==0)
+ { // could not resolve ref to def, make new ref and leave it this way
+ if((pSearch = pMRD->m_pClass) != NULL)
+ {
+ mdToken tkRef = MakeTypeRef(1,pSearch->m_szFQN);
+
+ if(RidFromToken(tkRef))
+ {
+ WszMultiByteToWideChar(g_uCodePage,0,pMRD_szName,-1,wzUniBuf,dwUniBuf);
+
+ m_pEmitter->DefineMemberRef(tkRef, wzUniBuf, pMRD_pSig,
+ pMRD_dwCSig, &tkMemberDef);
+ ulRefs++;
+ }
+ else
+ {
+ report->msg("Error: unresolved member ref '%s' of class 0x%08X\n",pMRD->m_szName,pMRD->m_tdClass);
+ ulUnres++;
+ }
+ }
+ else
+ {
+ report->msg("Error: unresolved global member ref '%s'\n",pMRD->m_szName);
+ ulUnres++;
+ }
+ }
+ pMRD->m_tkResolved = tkMemberDef;
+ }
+ }
+ for(i=0; (pMRD = m_MethodSpecList.PEEK(i)) != NULL; i++)
+ {
+ if(pMRD->m_tkResolved) continue;
+ tkMemberDef = pMRD->m_tdClass;
+ if(TypeFromToken(tkMemberDef)==0x99000000)
+ {
+ tkMemberDef = m_LocalMethodRefDList.PEEK(RidFromToken(tkMemberDef)-1)->m_tkResolved;
+ if((TypeFromToken(tkMemberDef)==mdtMethodDef)||(TypeFromToken(tkMemberDef)==mdtMemberRef))
+ {
+ ULONG pMRD_dwCSig = (pMRD->m_pSigBinStr ? pMRD->m_pSigBinStr->length() : 0);
+ PCOR_SIGNATURE pMRD_pSig = (PCOR_SIGNATURE)(pMRD->m_pSigBinStr ? pMRD->m_pSigBinStr->ptr() : NULL);
+ HRESULT hr = m_pEmitter->DefineMethodSpec(tkMemberDef, pMRD_pSig, pMRD_dwCSig, &(pMRD->m_tkResolved));
+ if(FAILED(hr))
+ report->error("Unable to define method instantiation");
+ }
+ }
+ if(RidFromToken(pMRD->m_tkResolved)) ulDefs++;
+ else ulUnres++;
+ }
+ if(m_fReportProgress) printf("%d -> %d defs, %d refs, %d unresolved\n",ulTotal,ulDefs,ulRefs,ulUnres);
+ }
+ return (ulUnres ? E_FAIL : S_OK);
+}
+
+HRESULT Assembler::DoLocalMemberRefFixups()
+{
+ MemberRefDList* pList;
+ unsigned Nlmr = m_LocalMethodRefDList.COUNT() + m_LocalFieldRefDList.COUNT(),
+ Nlmrf = m_LocalMemberRefFixupList.COUNT();
+ HRESULT hr = S_OK;
+ if(Nlmr)
+ {
+ MemberRefDescriptor* pMRD;
+ LocalMemberRefFixup* pMRF;
+ int i;
+ for(i = 0; (pMRF = m_LocalMemberRefFixupList.PEEK(i)) != NULL; i++)
+ {
+ if(m_fENCMode && (!pMRF->m_fNew)) continue;
+
+ switch(TypeFromToken(pMRF->tk))
+ {
+ case 0x99000000: pList = &m_LocalMethodRefDList; break;
+ case 0x98000000: pList = &m_LocalFieldRefDList; break;
+ case 0x9A000000: pList = &m_MethodSpecList; break;
+ default: pList = NULL; break;
+ }
+ if(pList)
+ {
+ if((pMRD = pList->PEEK(RidFromToken(pMRF->tk)-1)) != NULL)
+ SET_UNALIGNED_VAL32((void *)(pMRF->offset), pMRD->m_tkResolved);
+ else
+ {
+ report->msg("Error: bad local member ref token 0x%08X in LMR fixup\n",pMRF->tk);
+ hr = E_FAIL;
+ }
+ }
+ pMRF->m_fNew = FALSE;
+ }
+ }
+ else if(Nlmrf)
+ {
+ report->msg("Error: %d local member ref fixups, no local member refs\n",Nlmrf);
+ hr = E_FAIL;
+ }
+ return hr;
+}
+void Assembler::EmitUnresolvedCustomAttributes()
+{
+ CustomDescr *pCD;
+ while((pCD = m_CustomDescrList.POP()) != NULL)
+ {
+ pCD->tkType = ResolveLocalMemberRef(pCD->tkType);
+ pCD->tkOwner = ResolveLocalMemberRef(pCD->tkOwner);
+ // Look for the class'es interfaceimpl if this CA is one of those
+ if (pCD->tkInterfacePair)
+ pCD->tkOwner = GetInterfaceImpl(pCD->tkOwner, pCD->tkInterfacePair);
+ DefineCV(new CustomDescr(pCD->tkOwner,pCD->tkType,pCD->pBlob));
+ }
+}
+
+BOOL Assembler::EmitEventsProps(Class* pClass)
+{
+ unsigned n;
+ BOOL ret = TRUE;
+ // emit all event definition metadata tokens
+ if((n = pClass->m_EventDList.COUNT()))
+ {
+ if(m_fReportProgress) printf("Events: %d;\t",n);
+ EventDescriptor* pED;
+ for(int j=0; (pED = pClass->m_EventDList.PEEK(j)); j++) // can't use POP here: we'll need event list for props
+ {
+ if(!EmitEvent(pED))
+ {
+ if(!OnErrGo) return FALSE;
+ ret = FALSE;
+ }
+ pED->m_fNew = FALSE;
+ }
+ }
+ // emit all property definition metadata tokens
+ if((n = pClass->m_PropDList.COUNT()))
+ {
+ if(m_fReportProgress) printf("Props: %d;\t",n);
+ PropDescriptor* pPD;
+
+ for(int j=0; (pPD = pClass->m_PropDList.PEEK(j)); j++)
+ {
+ if(!EmitProp(pPD))
+ {
+ if(!OnErrGo) return FALSE;
+ ret = FALSE;
+ }
+ pPD->m_fNew = FALSE;
+ }
+ }
+ if(m_fReportProgress) printf("\n");
+ return ret;
+}
+
+#ifdef _PREFAST_
+#pragma warning(push)
+#pragma warning(disable:21000) // Suppress PREFast warning about overly large function
+#endif
+HRESULT Assembler::CreatePEFile(__in __nullterminated WCHAR *pwzOutputFilename)
+{
+ HRESULT hr;
+ DWORD mresourceSize = 0;
+ BYTE* mresourceData = NULL;
+ WCHAR* wzScopeName = NULL;
+
+ if(bClock) bClock->cMDEmitBegin = GetTickCount();
+ if(m_fReportProgress) printf("Creating PE file\n");
+ if (!m_pEmitter)
+ {
+ printf("Error: Cannot create a PE file with no metadata\n");
+ return E_FAIL;
+ }
+ if(!(m_fDLL || m_fEntryPointPresent))
+ {
+ printf("Error: No entry point declared for executable\n");
+ if(!OnErrGo) return E_FAIL;
+ }
+
+ if(bClock) bClock->cMDEmit1 = GetTickCount();
+
+#ifndef FEATURE_CORECLR
+ // Allocate space for a strong name signature if we're delay or full
+ // signing the assembly.
+ if (m_pManifest->m_sStrongName.m_pbPublicKey)
+ if (FAILED(hr = AllocateStrongNameSignature()))
+ goto exit;
+#endif
+
+ if(bClock) bClock->cMDEmit2 = GetTickCount();
+
+ if(m_VTFList.COUNT()==0)
+ {
+ Method* pMD;
+ Class* pClass;
+ unsigned N=0, OrdBase=0xFFFFFFFF, i, j;
+ for(i=0; (pClass = m_lstClass.PEEK(i)) != NULL; i++)
+ {
+ for(j = 0; (pMD = pClass->m_MethodList.PEEK(j)) != NULL; j++)
+ {
+ if(pMD->m_dwExportOrdinal != 0xFFFFFFFF)
+ {
+ N++;
+ if(pMD->m_dwExportOrdinal < OrdBase) OrdBase = pMD->m_dwExportOrdinal;
+ }
+ }
+ }
+ if(N)
+ {
+ for(i=0; (pClass = m_lstClass.PEEK(i)) != NULL; i++)
+ {
+ for(j = 0; (pMD = pClass->m_MethodList.PEEK(j)) != NULL; j++)
+ {
+ if(pMD->m_wVTSlot >= 0x8000)
+ {
+ pMD->m_wVTSlot -= 0x8000 + OrdBase - 1;
+ }
+ }
+ }
+ SetDataSection();
+ char* sz = new char[20];
+ strcpy_s(sz,20,"VTF_EAT_internal");
+ EmitDataLabel(sz);
+ sz = new char[20];
+ strcpy_s(sz,20,"VTF_EAT_internal");
+ if(m_dwCeeFileFlags & ICEE_CREATE_FILE_PE64)
+ {
+ ULONGLONG *pdw = new ULONGLONG[N];
+ for(i=0; i<N; i++) pdw[i] = UI64(0xdeadbeefdeadbeef);
+ EmitData(pdw,sizeof(ULONGLONG)*N);
+ m_VTFList.PUSH(new VTFEntry((USHORT)N,COR_VTABLE_64BIT|COR_VTABLE_FROM_UNMANAGED,sz));
+ delete [] pdw;
+ }
+ else
+ {
+ unsigned *pdw = new unsigned[N];
+ for(i=0; i<N; i++) pdw[i] = 0xdeadbeef;
+ EmitData(pdw,sizeof(unsigned)*N);
+ m_VTFList.PUSH(new VTFEntry((USHORT)N,COR_VTABLE_32BIT|COR_VTABLE_FROM_UNMANAGED,sz));
+ delete [] pdw;
+ }
+ }
+ }
+ wzScopeName=&wzUniBuf[0];
+ if(m_szScopeName[0]) // default: scope name = output file name
+ {
+ WszMultiByteToWideChar(g_uCodePage,0,m_szScopeName,-1,wzScopeName,MAX_SCOPE_LENGTH);
+ }
+ else
+ {
+ WCHAR* pwc;
+ if ((pwc = wcsrchr(m_wzOutputFileName, '\\')) != NULL) pwc++;
+ else if ((pwc = wcsrchr(m_wzOutputFileName, ':')) != NULL) pwc++;
+ else pwc = m_wzOutputFileName;
+
+ wcsncpy_s(wzScopeName, MAX_SCOPE_LENGTH, pwc, _TRUNCATE);
+ }
+ hr = m_pEmitter->SetModuleProps(wzScopeName);
+
+ if (FAILED(hr))
+ goto exit;
+
+ EmitImports();
+ if(m_pManifest)
+ {
+ hr = S_OK;
+ if(m_pManifest->m_pAsmEmitter==NULL)
+ hr=m_pEmitter->QueryInterface(IID_IMetaDataAssemblyEmit, (void**) &(m_pManifest->m_pAsmEmitter));
+
+ if(SUCCEEDED(hr))
+ {
+ m_pManifest->EmitAssemblyRefs();
+ }
+ }
+ // Emit classes, class members and globals:
+ {
+ Class *pSearch;
+ int i;
+ BOOL bIsUndefClass = FALSE;
+ if(m_fReportProgress) printf("\nEmitting classes:\n");
+ for (i=1; (pSearch = m_lstClass.PEEK(i)); i++) // 0 is <Module>
+ {
+ if(m_fReportProgress)
+ printf("Class %d:\t%s\n",i,pSearch->m_szFQN);
+
+ if(pSearch->m_bIsMaster)
+ {
+ report->msg("Error: Reference to undefined class '%s'\n",pSearch->m_szFQN);
+ bIsUndefClass = TRUE;
+ }
+ if(!EmitClass(pSearch))
+ {
+ if(!OnErrGo) return E_FAIL;
+ }
+ pSearch->m_fNew = FALSE;
+ }
+ if(bIsUndefClass && !OnErrGo) return E_FAIL;
+
+ if(m_fReportProgress) printf("\nEmitting fields and methods:\n");
+ for (i=0; (pSearch = m_lstClass.PEEK(i)) != NULL; i++)
+ {
+ if(m_fReportProgress)
+ {
+ if(i == 0) printf("Global \t");
+ else printf("Class %d\t",i);
+ }
+ if(!EmitFieldsMethods(pSearch))
+ {
+ if(!OnErrGo) return E_FAIL;
+ }
+ }
+ }
+
+ // All ref'ed items def'ed in this file are emitted, resolve member refs to member defs:
+ if(bClock) bClock->cRef2DefBegin = GetTickCount();
+ hr = ResolveLocalMemberRefs();
+ if(bClock) bClock->cRef2DefEnd = GetTickCount();
+ if(FAILED(hr) &&(!OnErrGo)) goto exit;
+
+ // Local member refs resolved, emit events, props and method impls
+ {
+ Class *pSearch;
+ int i;
+
+ if(m_fReportProgress) printf("\nEmitting events and properties:\n");
+ for (i=0; (pSearch = m_lstClass.PEEK(i)); i++)
+ {
+ if(m_fReportProgress)
+ {
+ if(i == 0) printf("Global \t");
+ else printf("Class %d\t",i);
+ }
+ if(!EmitEventsProps(pSearch))
+ {
+ if(!OnErrGo) return E_FAIL;
+ }
+ pSearch->m_fNewMembers = FALSE;
+ }
+ }
+ if(bClock) bClock->cMDEmit3 = GetTickCount();
+ if(m_MethodImplDList.COUNT())
+ {
+ if(m_fReportProgress) report->msg("Method Implementations (total): %d\n",m_MethodImplDList.COUNT());
+ if(!EmitMethodImpls())
+ {
+ if(!OnErrGo) return E_FAIL;
+ }
+ }
+ // Emit the rest of the metadata
+ if(bClock) bClock->cMDEmit4 = GetTickCount();
+ hr = S_OK;
+ if(m_pManifest)
+ {
+ if (FAILED(hr = m_pManifest->EmitManifest())) goto exit;
+ }
+ ResolveLocalMemberRefs(); // in case CAs added some
+ EmitUnresolvedCustomAttributes();
+ // Emit typedefs as special TypeSpecs
+ {
+#define ELEMENT_TYPE_TYPEDEF ELEMENT_TYPE_MAX+1
+ TypeDefDescr* pTDD;
+ unsigned __int8* pb;
+ unsigned namesize;
+ while((pTDD = m_TypeDefDList.POP()))
+ {
+ BinStr* pbs = new BinStr();
+ if(pbs)
+ {
+ namesize = 1 + (unsigned)strlen(pTDD->m_szName);
+ pb = pbs->getBuff(namesize + 1 + sizeof(mdToken));
+ *pb = ELEMENT_TYPE_TYPEDEF;
+ memcpy(++pb,pTDD->m_szName,namesize);
+ pTDD->m_tkTypeSpec = ResolveLocalMemberRef(pTDD->m_tkTypeSpec);
+ memcpy(pb+namesize,&(pTDD->m_tkTypeSpec),sizeof(mdToken));
+ if(TypeFromToken(pTDD->m_tkTypeSpec)==mdtCustomAttribute)
+ {
+ CustomDescr* pCA = pTDD->m_pCA;
+ pbs->appendInt32(pCA->tkType);
+ pbs->appendInt32(pCA->tkOwner);
+ if(pCA->pBlob) pbs->append(pCA->pBlob);
+ }
+ ResolveTypeSpec(pbs);
+ delete pbs;
+ }
+ delete pTDD;
+ }
+ }
+ if(bClock) bClock->cMDEmitEnd = GetTickCount();
+
+ hr = DoLocalMemberRefFixups();
+ if(FAILED(hr) &&(!OnErrGo)) goto exit;
+ // Local member refs resolved and fixed up in BinStr method bodies. Emit the bodies.
+ {
+ Class* pClass;
+ Method* pMethod;
+ for (int i=0; (pClass = m_lstClass.PEEK(i)); i++)
+ {
+ for(int j=0; (pMethod = pClass->m_MethodList.PEEK(j)); j++)
+ {
+ if(!EmitMethodBody(pMethod,NULL))
+ {
+ report->msg("Error: failed to emit body of '%s'\n",pMethod->m_szName);
+ hr = E_FAIL;
+ if(!OnErrGo) goto exit;
+ }
+ pMethod->m_fNewBody = FALSE;
+ }
+ }
+ //while(MethodBody* pMB = m_MethodBodyList.POP()) delete pMB;
+ }
+
+ if (DoGlobalFixups() == FALSE)
+ return E_FAIL;
+
+ if(m_wzResourceFile)
+ {
+#ifdef FEATURE_PAL
+ report->msg("Warning: The Win32 resource file '%S' is ignored and not emitted on xPlatform.\n", m_wzResourceFile);
+#else
+ if (FAILED(hr=m_pCeeFileGen->SetResourceFileName(m_pCeeFile, m_wzResourceFile)))
+ {
+ report->msg("Warning: failed to set Win32 resource file name '%S', hr=0x%8.8X\n The Win32 resource is not emitted.\n",
+ m_wzResourceFile, hr);
+ }
+#endif
+ }
+
+ if (FAILED(hr=CreateTLSDirectory())) goto exit;
+
+ if (FAILED(hr=CreateDebugDirectory())) goto exit;
+
+ if (FAILED(hr=m_pCeeFileGen->SetOutputFileName(m_pCeeFile, pwzOutputFilename))) goto exit;
+
+ // Reserve a buffer for the meta-data
+ DWORD metaDataSize;
+ if (FAILED(hr=m_pEmitter->GetSaveSize(cssAccurate, &metaDataSize))) goto exit;
+ BYTE* metaData;
+ if (FAILED(hr=m_pCeeFileGen->GetSectionBlock(m_pILSection, metaDataSize, sizeof(DWORD), (void**) &metaData))) goto exit;
+ ULONG metaDataOffset;
+ if (FAILED(hr=m_pCeeFileGen->GetSectionDataLen(m_pILSection, &metaDataOffset))) goto exit;
+ metaDataOffset -= metaDataSize;
+ // set managed resource entry, if any
+ if(m_pManifest && m_pManifest->m_dwMResSizeTotal)
+ {
+ mresourceSize = m_pManifest->m_dwMResSizeTotal;
+
+ if (FAILED(hr=m_pCeeFileGen->GetSectionBlock(m_pILSection, mresourceSize,
+ sizeof(DWORD), (void**) &mresourceData))) goto exit;
+ if (FAILED(hr=m_pCeeFileGen->SetManifestEntry(m_pCeeFile, mresourceSize, 0))) goto exit;
+ }
+ if(m_VTFList.COUNT())
+ {
+ GlobalLabel *pGlobalLabel;
+ VTFEntry* pVTFEntry;
+
+ if(m_pVTable) delete m_pVTable; // can't have both; list takes precedence
+ m_pVTable = new BinStr();
+ hr = S_OK;
+ for(WORD k=0; (pVTFEntry = m_VTFList.POP()); k++)
+ {
+ if((pGlobalLabel = FindGlobalLabel(pVTFEntry->m_szLabel)))
+ {
+ Method* pMD;
+ Class* pClass;
+ m_pVTable->appendInt32(pGlobalLabel->m_GlobalOffset);
+ m_pVTable->appendInt16(pVTFEntry->m_wCount);
+ m_pVTable->appendInt16(pVTFEntry->m_wType);
+ for(int i=0; (pClass = m_lstClass.PEEK(i)); i++)
+ {
+ for(WORD j = 0; (pMD = pClass->m_MethodList.PEEK(j)); j++)
+ {
+ if(pMD->m_wVTEntry == k+1)
+ {
+ char* ptr;
+ if(SUCCEEDED(hr = m_pCeeFileGen->ComputeSectionPointer(m_pGlobalDataSection,pGlobalLabel->m_GlobalOffset,&ptr)))
+ {
+ DWORD dwDelta;
+ if((pVTFEntry->m_wType & COR_VTABLE_32BIT))
+ {
+ dwDelta = (pMD->m_wVTSlot-1)*(DWORD)sizeof(DWORD);
+ ptr += dwDelta;
+ DWORD* mptr = (DWORD*)ptr;
+ *mptr = (DWORD)(pMD->m_Tok);
+ }
+ else
+ {
+ dwDelta = (pMD->m_wVTSlot-1)*(DWORD)sizeof(ULONGLONG);
+ ptr += dwDelta;
+ ULONGLONG* mptr = (ULONGLONG*)ptr;
+ *mptr = (ULONGLONG)(pMD->m_Tok);
+ }
+ if(pMD->m_dwExportOrdinal != 0xFFFFFFFF)
+ {
+ EATEntry* pEATE = new EATEntry;
+ pEATE->dwOrdinal = pMD->m_dwExportOrdinal;
+ pEATE->szAlias = pMD->m_szExportAlias ? pMD->m_szExportAlias : pMD->m_szName;
+ pEATE->dwStubRVA = EmitExportStub(pGlobalLabel->m_GlobalOffset+dwDelta);
+ m_EATList.PUSH(pEATE);
+ }
+ }
+ else
+ report->msg("Error: Failed to get pointer to label '%s' inVTable fixup\n",pVTFEntry->m_szLabel);
+ }
+ }
+ }
+ }
+ else
+ {
+ report->msg("Error: Unresolved label '%s' in VTable fixup\n",pVTFEntry->m_szLabel);
+ hr = E_FAIL;
+ }
+ delete pVTFEntry;
+ }
+ if(FAILED(hr)) goto exit;
+ }
+ if(m_pVTable)
+ {
+ ULONG i, N = m_pVTable->length()/sizeof(DWORD);
+ ULONG ulVTableOffset;
+ m_pCeeFileGen->GetSectionDataLen (m_pILSection, &ulVTableOffset);
+ // SetVTableEntry will align VTable on DWORD
+ ulVTableOffset = (ulVTableOffset + (ULONG)sizeof(DWORD) - 1) & ~((ULONG)sizeof(DWORD) - 1);
+ if (FAILED(hr=m_pCeeFileGen->SetVTableEntry64(m_pCeeFile, m_pVTable->length(),(void*)(m_pVTable->ptr())))) goto exit; // @WARNING: casting down from pointer-size to DWORD
+ for(i = 0; i < N; i+=2)
+ {
+ m_pCeeFileGen->AddSectionReloc(m_pILSection,
+ ulVTableOffset+(i*sizeof(DWORD)),
+ m_pGlobalDataSection,
+ srRelocAbsolute);
+ }
+ }
+ if(m_EATList.COUNT())
+ {
+ if(FAILED(CreateExportDirectory())) goto exit;
+ m_dwComImageFlags &= ~COMIMAGE_FLAGS_ILONLY;
+ if (m_dwCeeFileFlags & ICEE_CREATE_MACHINE_I386)
+ COR_SET_32BIT_REQUIRED(m_dwComImageFlags);
+ }
+ if (m_fWindowsCE)
+ {
+ if (FAILED(hr=m_pCeeFileGen->SetSubsystem(m_pCeeFile, IMAGE_SUBSYSTEM_WINDOWS_CE_GUI, 2, 10))) goto exit;
+
+ if (FAILED(hr=m_pCeeFileGen->SetImageBase(m_pCeeFile, 0x10000))) goto exit;
+ }
+ else
+ {
+ if (m_dwCeeFileFlags & ICEE_CREATE_MACHINE_ARM || m_fAppContainer)
+ {
+ // For AppContainer and ARM, you must have a minimum subsystem version of 6.02
+ m_wSSVersionMajor = (m_wSSVersionMajor < 6) ? 6 : m_wSSVersionMajor;
+ m_wSSVersionMinor = (m_wSSVersionMinor < 2 && m_wSSVersionMajor <= 6) ? 2 : m_wSSVersionMinor;
+
+ }
+
+ // Default the subsystem, instead the user doesn't set it to GUI or CUI
+ if (m_dwSubsystem == (DWORD)-1)
+ // The default for ILAsm previously was CUI, so that should be the default behavior...
+ m_dwSubsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
+
+ if (FAILED(hr=m_pCeeFileGen->SetSubsystem(m_pCeeFile, m_dwSubsystem, m_wSSVersionMajor, m_wSSVersionMinor))) goto exit;
+ }
+
+ if (FAILED(hr=m_pCeeFileGen->ClearComImageFlags(m_pCeeFile, COMIMAGE_FLAGS_ILONLY))) goto exit;
+ if (FAILED(hr=m_pCeeFileGen->SetComImageFlags(m_pCeeFile, m_dwComImageFlags & ~COMIMAGE_FLAGS_STRONGNAMESIGNED))) goto exit;
+
+ if(m_dwFileAlignment)
+ {
+ if(FAILED(hr=m_pCeeFileGen->SetFileAlignment(m_pCeeFile, m_dwFileAlignment))) goto exit;
+ }
+ if(m_stBaseAddress)
+ {
+
+ if(m_dwCeeFileFlags & ICEE_CREATE_FILE_PE64)
+ {
+ if(FAILED(hr=m_pCeeFileGen->SetImageBase64(m_pCeeFile, m_stBaseAddress))) goto exit;
+ }
+ else
+ {
+ if(FAILED(hr=m_pCeeFileGen->SetImageBase(m_pCeeFile, (size_t)m_stBaseAddress))) goto exit;
+ }
+ }
+ if(m_stSizeOfStackReserve || m_fAppContainer || m_fHighEntropyVA)
+ {
+ PIMAGE_NT_HEADERS pNT;
+ PIMAGE_SECTION_HEADER pSect;
+ ULONG ulNumSect;
+ if(FAILED(hr=m_pCeeFileGen->GetHeaderInfo(m_pCeeFile,&pNT,&pSect,&ulNumSect))) goto exit;
+ if(m_dwCeeFileFlags & ICEE_CREATE_FILE_PE64)
+ {
+ PIMAGE_OPTIONAL_HEADER64 pOpt = (PIMAGE_OPTIONAL_HEADER64)(&pNT->OptionalHeader);
+ if (m_stSizeOfStackReserve)
+ pOpt->SizeOfStackReserve = VAL64(m_stSizeOfStackReserve);
+ if (m_fAppContainer)
+ pOpt->DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_APPCONTAINER;
+ if (m_fHighEntropyVA)
+ pOpt->DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA;
+ }
+ else
+ {
+ PIMAGE_OPTIONAL_HEADER32 pOpt = (PIMAGE_OPTIONAL_HEADER32)(&pNT->OptionalHeader);
+ if (m_stSizeOfStackReserve)
+ pOpt->SizeOfStackReserve = (DWORD)VAL32(m_stSizeOfStackReserve);
+ if (m_fAppContainer)
+ pOpt->DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_APPCONTAINER;
+ if (m_fHighEntropyVA)
+ pOpt->DllCharacteristics |= IMAGE_DLLCHARACTERISTICS_HIGH_ENTROPY_VA;
+ }
+ }
+ //Compute all the RVAs
+ if (FAILED(hr=m_pCeeFileGen->LinkCeeFile(m_pCeeFile))) goto exit;
+
+ // Fix up any fields that have RVA associated with them
+ if (m_fHaveFieldsWithRvas) {
+ hr = S_OK;
+ ULONG dataSectionRVA;
+ if (FAILED(hr=m_pCeeFileGen->GetSectionRVA(m_pGlobalDataSection, &dataSectionRVA))) goto exit;
+
+ ULONG tlsSectionRVA;
+ if (FAILED(hr=m_pCeeFileGen->GetSectionRVA(m_pTLSSection, &tlsSectionRVA))) goto exit;
+
+ ULONG ilSectionRVA;
+ if (FAILED(hr=m_pCeeFileGen->GetSectionRVA(m_pILSection, &ilSectionRVA))) goto exit;
+
+ FieldDescriptor* pListFD;
+ Class* pClass;
+ for(int i=0; (pClass = m_lstClass.PEEK(i)); i++)
+ {
+ for(int j=0; (pListFD = pClass->m_FieldDList.PEEK(j)); j++)
+ {
+ if (pListFD->m_rvaLabel != 0)
+ {
+ DWORD rva;
+ if(*(pListFD->m_rvaLabel)=='@')
+ {
+ rva = (DWORD)atoi(pListFD->m_rvaLabel + 1);
+ }
+ else
+ {
+ GlobalLabel *pLabel = FindGlobalLabel(pListFD->m_rvaLabel);
+ if (pLabel == 0)
+ {
+ report->msg("Error:Could not find label '%s' for the field '%s'\n", pListFD->m_rvaLabel, pListFD->m_szName);
+ hr = E_FAIL;
+ continue;
+ }
+
+ rva = pLabel->m_GlobalOffset;
+ if (pLabel->m_Section == m_pTLSSection)
+ rva += tlsSectionRVA;
+ else if (pLabel->m_Section == m_pILSection)
+ rva += ilSectionRVA;
+ else {
+ _ASSERTE(pLabel->m_Section == m_pGlobalDataSection);
+ rva += dataSectionRVA;
+ }
+ }
+ if (FAILED(m_pEmitter->SetFieldRVA(pListFD->m_fdFieldTok, rva))) goto exit;
+ }
+ }
+ }
+ if (FAILED(hr)) goto exit;
+ }
+
+ if(bClock) bClock->cFilegenBegin = GetTickCount();
+ // actually output the meta-data
+ if (FAILED(hr=m_pCeeFileGen->EmitMetaDataAt(m_pCeeFile, m_pEmitter, m_pILSection, metaDataOffset, metaData, metaDataSize))) goto exit;
+
+ if((m_wMSVmajor < 0xFF)&&(m_wMSVminor < 0xFF))
+ {
+ STORAGESIGNATURE *pSSig = (STORAGESIGNATURE *)metaData;
+ BYTE* pb = metaData;
+ pb += 3*sizeof(DWORD)+2*sizeof(WORD)+VAL32(pSSig->iVersionString);
+ pb = (BYTE*)(((size_t)pb + 3) & ~3);
+ PSTORAGEHEADER pSHdr = (PSTORAGEHEADER)pb;
+ PSTORAGESTREAM pStr = (PSTORAGESTREAM)(pSHdr+1);
+ for(short iStr = 1; iStr <= VAL16(pSHdr->iStreams); iStr++)
+ {
+ if((strcmp(pStr->rcName,"#-")==0)||(strcmp(pStr->rcName,"#~")==0))
+ {
+ pb = metaData + VAL32(pStr->iOffset); // start of the stream header
+ pb += sizeof(DWORD); // skip Reserved
+ *pb = VAL16(m_wMSVmajor)&0xFF;
+ *(pb+1) = VAL16(m_wMSVminor)&0xFF;
+ break;
+ }
+ pb = (BYTE*)pStr;
+ pb += 2*sizeof(DWORD)+strlen(pStr->rcName)+1;
+ pb = (BYTE*)(((size_t)pb + 3) & ~3);
+ pStr = (PSTORAGESTREAM)pb;
+ }
+ }
+
+ if(m_fTolerateDupMethods) // means that there are /ENC files
+ {
+ if(m_pbsMD) delete m_pbsMD;
+ m_pbsMD = new BinStr();
+ memcpy(m_pbsMD->getBuff(metaDataSize),metaData,metaDataSize);
+ }
+ // actually output the resources
+ if(mresourceSize && mresourceData)
+ {
+ size_t i, N = m_pManifest->m_dwMResNum, sizeread, L;
+ BYTE *ptr = (BYTE*)mresourceData;
+ BOOL mrfail = FALSE;
+ FILE* pFile = NULL;
+ char sz[2048];
+ for(i=0; i < N; i++)
+ {
+ m_pManifest->m_fMResNew[i] = FALSE;
+ memset(sz,0,2048);
+ WszWideCharToMultiByte(CP_ACP,0,m_pManifest->m_wzMResName[i],-1,sz,2047,NULL,NULL);
+ L = m_pManifest->m_dwMResSize[i];
+ sizeread = 0;
+ memcpy(ptr,&L,sizeof(DWORD));
+ ptr += sizeof(DWORD);
+ if(fopen_s(&pFile,sz,"rb") == 0)
+ {
+ sizeread = fread((void *)ptr,1,L,pFile);
+ fclose(pFile);
+ ptr += sizeread;
+ }
+ else
+ {
+ report->msg("Error: failed to open mgd resource file '%ls'\n",m_pManifest->m_wzMResName[i]);
+ mrfail = TRUE;
+ }
+ if(sizeread < L)
+ {
+ report->msg("Error: failed to read expected %d bytes from mgd resource file '%ls'\n",L,m_pManifest->m_wzMResName[i]);
+ mrfail = TRUE;
+ L -= sizeread;
+ memset(ptr,0,L);
+ ptr += L;
+ }
+ }
+ if(mrfail)
+ {
+ hr = E_FAIL;
+ goto exit;
+ }
+ }
+ /*
+ if((m_wRTVmajor < 0xFFFF)&&(m_wRTVminor < 0xFFFF))
+ {
+ IMAGE_COR20_HEADER* pCorH;
+ if(FAILED(hr=m_pCeeFileGen->GetCorHeader(m_pCeeFile,&pCorH))) goto exit;
+ pCorH->MajorRuntimeVersion = VAL16(m_wRTVmajor);
+ pCorH->MinorRuntimeVersion = VAL16(m_wRTVminor);
+ }
+ */
+ // Generate the file -- moved to main
+ //if (FAILED(hr=m_pCeeFileGen->GenerateCeeFile(m_pCeeFile))) goto exit;
+
+
+ hr = S_OK;
+
+exit:
+ return hr;
+}
+#ifdef _PREFAST_
+#pragma warning(pop)
+#endif
diff --git a/src/ilasm/writer_enc.cpp b/src/ilasm/writer_enc.cpp
new file mode 100644
index 0000000000..055b2edca9
--- /dev/null
+++ b/src/ilasm/writer_enc.cpp
@@ -0,0 +1,661 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+//
+// writer_ENC.cpp
+//
+
+//
+#include "ilasmpch.h"
+
+#include "assembler.h"
+
+//#include "ceefilegenwriter.h"
+#include "strongname.h"
+
+int ist=0;
+#define REPT_STEP //printf("Step %d\n",++ist);
+
+HRESULT Assembler::InitMetaDataForENC(__in __nullterminated WCHAR* wzOrigFileName)
+{
+ HRESULT hr = E_FAIL;
+
+ if((wzOrigFileName==NULL)||(*wzOrigFileName == 0)||(m_pDisp==NULL)) return hr;
+ if (m_pSymWriter != NULL)
+ {
+ m_pSymWriter->Close();
+ m_pSymWriter->Release();
+ m_pSymWriter = NULL;
+ }
+ if (m_pImporter != NULL)
+ {
+ m_pImporter->Release();
+ m_pImporter = NULL;
+ }
+ if (m_pEmitter != NULL)
+ {
+ m_pEmitter->Release();
+ m_pEmitter = NULL;
+ }
+ //WszSetEnvironmentVariable(L"COMP_ENC_OPENSCOPE", wzOrigFileName);
+ //hr = m_pDisp->DefineScope(CLSID_CorMetaDataRuntime, 0, IID_IMetaDataEmit2,
+ // (IUnknown **)&m_pEmitter);
+
+ if((m_pbsMD==NULL)||(m_pbsMD->length()==0))
+ {
+ _ASSERTE(!"NO BASE METADATA!");
+ return E_FAIL;
+ }
+
+ VARIANT encOption;
+ V_VT(&encOption) = VT_UI4;
+ V_UI4(&encOption) = MDUpdateENC;
+ m_pDisp->SetOption(MetaDataSetENC, &encOption);
+ V_UI4(&encOption) = MDErrorOutOfOrderDefault;
+ m_pDisp->SetOption(MetaDataErrorIfEmitOutOfOrder, &encOption);
+ hr = m_pDisp->OpenScopeOnMemory( m_pbsMD->ptr(),
+ m_pbsMD->length(),
+ ofWrite,
+ IID_IMetaDataEmit2,
+ (IUnknown **)&m_pEmitter);
+ _ASSERTE(SUCCEEDED(hr));
+ if (FAILED(hr))
+ goto exit;
+
+ m_pManifest->SetEmitter(m_pEmitter);
+ if(FAILED(hr = m_pEmitter->QueryInterface(IID_IMetaDataImport2, (void**)&m_pImporter)))
+ goto exit;
+
+ //WszSetEnvironmentVariable(L"COMP_ENC_EMIT", wzOrigFileName);
+ if(!Init()) goto exit; // close and re-open CeeFileGen and CeeFile
+ hr = S_OK;
+
+#ifndef FEATURE_CORECLR
+ hr = CoCreateInstance(CLSID_CorSymWriter_SxS,
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ IID_ISymUnmanagedWriter,
+ (void **)&m_pSymWriter);
+ if(SUCCEEDED(hr))
+ {
+ WCHAR* pwc = &wzOrigFileName[wcslen(wzOrigFileName)];
+ wcscat_s(wzOrigFileName,MAX_SCOPE_LENGTH,W(".pdb"));
+ if(m_pSymWriter) m_pSymWriter->Initialize((IUnknown*)m_pEmitter,
+ wzOrigFileName,
+ NULL,
+ TRUE);
+ *pwc = 0;
+ }
+ else
+ {
+ fprintf(stderr, "Error: CoCreateInstance(IID_ISymUnmanagedWriter) returns %X\n",hr);
+ m_pSymWriter = NULL;
+ }
+#endif
+
+exit:
+ return hr;
+}
+/*********************************************************************************/
+
+BOOL Assembler::EmitFieldsMethodsENC(Class* pClass)
+{
+ unsigned n;
+ BOOL ret = TRUE;
+ // emit all field definition metadata tokens
+ if((pClass->m_FieldDList.COUNT()))
+ {
+ FieldDescriptor* pFD;
+ int j;
+ for(j=0, n=0; (pFD = pClass->m_FieldDList.PEEK(j)); j++) // can't use POP here: we'll need field list for props
+ {
+ if(pFD->m_fNew)
+ {
+ if(!EmitField(pFD))
+ {
+ if(!OnErrGo) return FALSE;
+ ret = FALSE;
+ }
+ pFD->m_fNew = FALSE;
+ n++;
+ }
+ }
+ if(m_fReportProgress) printf("Fields: %d;\t",n);
+ }
+ // Fields are emitted; emit the class layout
+ {
+ COR_FIELD_OFFSET *pOffsets = NULL;
+ ULONG ul = pClass->m_ulPack;
+ ULONG N = pClass->m_dwNumFieldsWithOffset;
+
+ EmitSecurityInfo(pClass->m_cl,
+ pClass->m_pPermissions,
+ pClass->m_pPermissionSets);
+ pClass->m_pPermissions = NULL;
+ pClass->m_pPermissionSets = NULL;
+ if((pClass->m_ulSize != 0xFFFFFFFF)||(ul != 0)||(N != 0))
+ {
+ if(IsTdAutoLayout(pClass->m_Attr)) report->warn("Layout specified for auto-layout class\n");
+ if((ul > 128)||((ul & (ul-1)) !=0 ))
+ report->error("Invalid packing parameter (%d), must be 1,2,4,8...128\n",pClass->m_ulPack);
+ if(N)
+ {
+ pOffsets = new COR_FIELD_OFFSET[N+1];
+ ULONG i,j=0;
+ FieldDescriptor *pFD;
+ for(i=0; (pFD = pClass->m_FieldDList.PEEK(i)); i++)
+ {
+ if(pFD->m_ulOffset != 0xFFFFFFFF)
+ {
+ pOffsets[j].ridOfField = RidFromToken(pFD->m_fdFieldTok);
+ pOffsets[j].ulOffset = pFD->m_ulOffset;
+ j++;
+ }
+ }
+ _ASSERTE(j == N);
+ pOffsets[j].ridOfField = mdFieldDefNil;
+ }
+ m_pEmitter->SetClassLayout (
+ pClass->m_cl, // [IN] typedef
+ ul, // [IN] packing size specified as 1, 2, 4, 8, or 16
+ pOffsets, // [IN] array of layout specification
+ pClass->m_ulSize); // [IN] size of the class
+ if(pOffsets) delete [] pOffsets;
+ }
+ }
+ // emit all method definition metadata tokens
+ if((pClass->m_MethodList.COUNT()))
+ {
+ Method* pMethod;
+ int i;
+
+ for(i=0, n=0; (pMethod = pClass->m_MethodList.PEEK(i));i++)
+ {
+ if(pMethod->m_fNew)
+ {
+ if(!EmitMethod(pMethod))
+ {
+ if(!OnErrGo) return FALSE;
+ ret = FALSE;
+ }
+ pMethod->m_fNew = FALSE;
+ n++;
+ }
+ }
+ if(m_fReportProgress) printf("Methods: %d;\t",n);
+ }
+ if(m_fReportProgress) printf("\n");
+ return ret;
+}
+
+BOOL Assembler::EmitEventsPropsENC(Class* pClass)
+{
+ unsigned n;
+ BOOL ret = TRUE;
+ // emit all event definition metadata tokens
+ if((pClass->m_EventDList.COUNT()))
+ {
+ EventDescriptor* pED;
+ int j;
+ for(j=0,n=0; (pED = pClass->m_EventDList.PEEK(j)); j++) // can't use POP here: we'll need event list for props
+ {
+ if(pED->m_fNew)
+ {
+ if(!EmitEvent(pED))
+ {
+ if(!OnErrGo) return FALSE;
+ ret = FALSE;
+ }
+ pED->m_fNew = FALSE;
+ n++;
+ }
+ }
+ if(m_fReportProgress) printf("Events: %d;\t",n);
+ }
+ // emit all property definition metadata tokens
+ if((pClass->m_PropDList.COUNT()))
+ {
+ PropDescriptor* pPD;
+ int j;
+
+ for(j=0,n=0; (pPD = pClass->m_PropDList.PEEK(j)); j++)
+ {
+ if(pPD->m_fNew)
+ {
+ if(!EmitProp(pPD))
+ {
+ if(!OnErrGo) return FALSE;
+ ret = FALSE;
+ }
+ pPD->m_fNew = FALSE;
+ n++;
+ }
+ }
+ if(m_fReportProgress) printf("Props: %d;\t",n);
+ }
+ if(m_fReportProgress) printf("\n");
+ return ret;
+}
+
+HRESULT Assembler::CreateDeltaFiles(__in __nullterminated WCHAR *pwzOutputFilename)
+{
+ HRESULT hr;
+ DWORD mresourceSize = 0;
+ BYTE* mresourceData = NULL;
+ WCHAR* pEnd = NULL;
+
+ if(m_fReportProgress) printf("Creating DMETA,DIL files\n");
+ if (!m_pEmitter)
+ {
+ printf("Error: Cannot create a PE file with no metadata\n");
+ return E_FAIL;
+ }
+REPT_STEP
+ if(m_pManifest)
+ {
+ hr = S_OK;
+ if(m_pManifest->m_pAsmEmitter==NULL)
+ hr=m_pEmitter->QueryInterface(IID_IMetaDataAssemblyEmit, (void**) &(m_pManifest->m_pAsmEmitter));
+
+ if(SUCCEEDED(hr))
+ {
+ m_pManifest->EmitAssemblyRefs();
+ }
+ }
+ // Emit classes, class members and globals:
+ {
+ Class *pSearch;
+ int i;
+ BOOL bIsUndefClass = FALSE;
+ if(m_fReportProgress) printf("\nEmitting classes:\n");
+ for (i=1; (pSearch = m_lstClass.PEEK(i)); i++) // 0 is <Module>
+ {
+ if(pSearch->m_fNew)
+ {
+ if(m_fReportProgress)
+ printf("Class %d:\t%s\n",i,pSearch->m_szFQN);
+
+ if(pSearch->m_bIsMaster)
+ {
+ report->msg("Error: Reference to undefined class '%s'\n",pSearch->m_szFQN);
+ bIsUndefClass = TRUE;
+ }
+ if(!EmitClass(pSearch))
+ {
+ if(!OnErrGo) return E_FAIL;
+ }
+ pSearch->m_fNew = FALSE;
+ }
+ }
+ if(bIsUndefClass && !OnErrGo) return E_FAIL;
+
+ if(m_fReportProgress) printf("\nEmitting fields and methods:\n");
+ for (i=0; (pSearch = m_lstClass.PEEK(i)) != NULL; i++)
+ {
+ if(pSearch->m_fNewMembers)
+ {
+ if(m_fReportProgress)
+ {
+ if(i == 0) printf("Global \t");
+ else printf("Class %d\t",i);
+ }
+ if(!EmitFieldsMethodsENC(pSearch))
+ {
+ if(!OnErrGo) return E_FAIL;
+ }
+ }
+ }
+ }
+REPT_STEP
+
+ // All ref'ed items def'ed in this file are emitted, resolve member refs to member defs:
+ hr = ResolveLocalMemberRefs();
+ if(FAILED(hr) &&(!OnErrGo)) goto exit;
+
+ // Local member refs resolved, emit events, props and method impls
+ {
+ Class *pSearch;
+ int i;
+
+ if(m_fReportProgress) printf("\nEmitting events and properties:\n");
+ for (i=0; (pSearch = m_lstClass.PEEK(i)); i++)
+ {
+ if(pSearch->m_fNewMembers)
+ {
+ if(m_fReportProgress)
+ {
+ if(i == 0) printf("Global \t");
+ else printf("Class %d\t",i);
+ }
+ if(!EmitEventsPropsENC(pSearch))
+ {
+ if(!OnErrGo) return E_FAIL;
+ }
+ pSearch->m_fNewMembers = FALSE;
+ }
+ }
+ }
+ if(m_MethodImplDList.COUNT())
+ {
+ if(m_fReportProgress) report->msg("Method Implementations (total): %d\n",m_MethodImplDList.COUNT());
+ if(!EmitMethodImpls())
+ {
+ if(!OnErrGo) return E_FAIL;
+ }
+ }
+REPT_STEP
+ // Emit the rest of the metadata
+ hr = S_OK;
+ if(m_pManifest)
+ {
+ if (FAILED(hr = m_pManifest->EmitManifest())) goto exit;
+ }
+ ResolveLocalMemberRefs(); // in case CAs added some
+ EmitUnresolvedCustomAttributes();
+REPT_STEP
+
+ hr = DoLocalMemberRefFixups();
+ if(FAILED(hr) &&(!OnErrGo)) goto exit;
+
+ // Local member refs resolved and fixed up in BinStr method bodies. Emit the bodies to a separate file.
+ pEnd = &pwzOutputFilename[wcslen(pwzOutputFilename)];
+ {
+ Class* pClass;
+ Method* pMethod;
+ FILE* pF = NULL;
+ wcscat_s(pwzOutputFilename,MAX_SCOPE_LENGTH,W(".dil"));
+ if(_wfopen_s(&pF,pwzOutputFilename,W("wb"))==0)
+ {
+ int i,j,L=0,M=0;
+ BinStr bsOut;
+ for (i=0; (pClass = m_lstClass.PEEK(i)); i++)
+ {
+ for(j=0; (pMethod = pClass->m_MethodList.PEEK(j)); j++)
+ {
+ if(pMethod->m_fNewBody)
+ {
+ L+= pMethod->m_pbsBody->length()+3;
+ M++;
+ }
+ }
+ }
+ bsOut.getBuff(L+sizeof(DWORD)); // to avoid reallocs
+ bsOut.remove(L);
+ for (i=0; (pClass = m_lstClass.PEEK(i)); i++)
+ {
+ for(j=0; (pMethod = pClass->m_MethodList.PEEK(j)); j++)
+ {
+ if(pMethod->m_fNewBody)
+ {
+ if(!EmitMethodBody(pMethod,&bsOut))
+ {
+ report->msg("Error: failed to emit body of '%s'\n",pMethod->m_szName);
+ hr = E_FAIL;
+ if(!OnErrGo)
+ {
+ fclose(pF);
+ *pEnd = 0;
+ goto exit;
+ }
+ }
+ pMethod->m_fNewBody = FALSE;
+ }
+ }
+ }
+ *((DWORD*)(bsOut.ptr())) = bsOut.length() - sizeof(DWORD);
+ fwrite(bsOut.ptr(),bsOut.length(),1,pF);
+ fclose(pF);
+ }
+ else
+ report->msg("Error: failed to open file '%S'\n",pwzOutputFilename);
+
+ *pEnd = 0;
+ }
+REPT_STEP
+
+ //if (DoGlobalFixups() == FALSE)
+ // return E_FAIL;
+
+ //if (FAILED(hr=m_pCeeFileGen->SetOutputFileName(m_pCeeFile, pwzOutputFilename))) goto exit;
+
+ // Emit the meta-data to a separate file
+ IMetaDataEmit2* pENCEmitter;
+ if(FAILED(hr = m_pEmitter->QueryInterface(IID_IMetaDataEmit2, (void**)&pENCEmitter)))
+ goto exit;
+
+ DWORD metaDataSize;
+ if (FAILED(hr=pENCEmitter->GetDeltaSaveSize(cssAccurate, &metaDataSize))) goto exit;
+
+ wcscat_s(pwzOutputFilename,MAX_SCOPE_LENGTH,W(".dmeta"));
+ pENCEmitter->SaveDelta(pwzOutputFilename,0); // second arg (dwFlags) is not used
+ *pEnd = 0;
+ pENCEmitter->Release();
+
+ // apply delta to create basis for the next ENC iteration
+ if(m_pbsMD)
+ {
+ IMetaDataEmit2* pBaseMDEmit = NULL;
+ if(FAILED(hr = m_pDisp->OpenScopeOnMemory(m_pbsMD->ptr(),
+ m_pbsMD->length(),
+ ofWrite,
+ IID_IMetaDataEmit2,
+ (IUnknown **)&pBaseMDEmit))) goto exit;
+
+ if(FAILED(hr = pBaseMDEmit->ApplyEditAndContinue((IUnknown*)m_pImporter))) goto exit;
+ delete m_pbsMD;
+ if((m_pbsMD = new BinStr()) != NULL)
+ {
+ DWORD cb;
+ hr = pBaseMDEmit->GetSaveSize(cssAccurate,&cb);
+ BYTE* pb = m_pbsMD->getBuff(cb);
+ hr = pBaseMDEmit->SaveToMemory(pb,cb);
+ }
+ pBaseMDEmit->Release();
+ }
+
+#if(0)
+//===================================================================================
+ // release SymWriter interfaces
+ if (m_pSymWriter != NULL)
+ {
+ m_pSymWriter->Close();
+ m_pSymWriter->Release();
+ m_pSymWriter = NULL;
+ }
+
+ hr = CoCreateInstance(CLSID_CorSymWriter_SxS,
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ IID_ISymUnmanagedWriter,
+ (void **)&m_pSymWriter);
+ if(SUCCEEDED(hr))
+ {
+ WCHAR* pwc = &pwzOutputFilename[wcslen(pwzOutputFilename)];
+ wcscat(pwzOutputFilename,L".pdb");
+ if(m_pSymWriter) m_pSymWriter->Initialize((IUnknown*)m_pEmitter,
+ pwzOutputFilename,
+ NULL,
+ TRUE);
+ *pwc = 0;
+ }
+ else
+ {
+ fprintf(stderr, "Error: CoCreateInstance(IID_ISymUnmanagedWriter) returns %X\n",hr);
+ m_pSymWriter = NULL;
+ }
+
+ m_fENCMode = FALSE;
+ if(FAILED(hr=CreatePEFile(pwzOutputFilename)))
+ report->msg("Could not create output file, error code=0x%08X\n",hr);
+ m_fENCMode = TRUE;
+//=====================================================================================
+#endif
+
+ // release all interfaces
+ if (m_pSymWriter != NULL)
+ {
+ m_pSymWriter->Close();
+ m_pSymWriter->Release();
+ m_pSymWriter = NULL;
+ }
+ if (m_pImporter != NULL)
+ {
+ m_pImporter->Release();
+ m_pImporter = NULL;
+ }
+ if (m_pEmitter != NULL)
+ {
+ m_pEmitter->Release();
+ m_pEmitter = NULL;
+ }
+
+ return S_OK;
+
+REPT_STEP
+
+ // set managed resource entry, if any
+ if(m_pManifest && m_pManifest->m_dwMResSizeTotal)
+ {
+ mresourceSize = m_pManifest->m_dwMResSizeTotal;
+
+ if (FAILED(hr=m_pCeeFileGen->GetSectionBlock(m_pILSection, mresourceSize,
+ sizeof(DWORD), (void**) &mresourceData))) goto exit;
+ if (FAILED(hr=m_pCeeFileGen->SetManifestEntry(m_pCeeFile, mresourceSize, 0))) goto exit;
+ }
+REPT_STEP
+ /*
+ if (m_fWindowsCE)
+ {
+ if (FAILED(hr=m_pCeeFileGen->SetSubsystem(m_pCeeFile, IMAGE_SUBSYSTEM_WINDOWS_CE_GUI, 2, 10))) goto exit;
+
+ if (FAILED(hr=m_pCeeFileGen->SetImageBase(m_pCeeFile, 0x10000))) goto exit;
+ }
+ else if(m_dwSubsystem != (DWORD)-1)
+ {
+ if (FAILED(hr=m_pCeeFileGen->SetSubsystem(m_pCeeFile, m_dwSubsystem, 4, 0))) goto exit;
+ }
+
+ if (FAILED(hr=m_pCeeFileGen->ClearComImageFlags(m_pCeeFile, COMIMAGE_FLAGS_ILONLY))) goto exit;
+ if (FAILED(hr=m_pCeeFileGen->SetComImageFlags(m_pCeeFile, m_dwComImageFlags & ~COMIMAGE_FLAGS_STRONGNAMESIGNED))) goto exit;
+
+ if(m_dwFileAlignment)
+ {
+ if(FAILED(hr=m_pCeeFileGen->SetFileAlignment(m_pCeeFile, m_dwFileAlignment))) goto exit;
+ }
+ if(m_stBaseAddress)
+ {
+ if(FAILED(hr=m_pCeeFileGen->SetImageBase(m_pCeeFile, m_stBaseAddress))) goto exit;
+ }
+ */
+REPT_STEP
+ //Compute all the RVAs
+ if (FAILED(hr=m_pCeeFileGen->LinkCeeFile(m_pCeeFile))) goto exit;
+
+REPT_STEP
+ // Fix up any fields that have RVA associated with them
+/*
+ if (m_fHaveFieldsWithRvas) {
+ hr = S_OK;
+ ULONG dataSectionRVA;
+ if (FAILED(hr=m_pCeeFileGen->GetSectionRVA(m_pGlobalDataSection, &dataSectionRVA))) goto exit;
+
+ ULONG tlsSectionRVA;
+ if (FAILED(hr=m_pCeeFileGen->GetSectionRVA(m_pTLSSection, &tlsSectionRVA))) goto exit;
+
+ FieldDescriptor* pListFD;
+ Class* pClass;
+ for(int i=0; (pClass = m_lstClass.PEEK(i)); i++)
+ {
+ for(int j=0; (pListFD = pClass->m_FieldDList.PEEK(j)); j++)
+ {
+ if (pListFD->m_rvaLabel != 0)
+ {
+ DWORD rva;
+ if(*(pListFD->m_rvaLabel)=='@')
+ {
+ rva = (DWORD)atoi(pListFD->m_rvaLabel + 1);
+ }
+ else
+ {
+ GlobalLabel *pLabel = FindGlobalLabel(pListFD->m_rvaLabel);
+ if (pLabel == 0)
+ {
+ report->msg("Error:Could not find label '%s' for the field '%s'\n", pListFD->m_rvaLabel, pListFD->m_szName);
+ hr = E_FAIL;
+ continue;
+ }
+
+ rva = pLabel->m_GlobalOffset;
+ if (pLabel->m_Section == m_pTLSSection)
+ rva += tlsSectionRVA;
+ else {
+ _ASSERTE(pLabel->m_Section == m_pGlobalDataSection);
+ rva += dataSectionRVA;
+ }
+ }
+ if (FAILED(m_pEmitter->SetFieldRVA(pListFD->m_fdFieldTok, rva))) goto exit;
+ }
+ }
+ }
+ if (FAILED(hr)) goto exit;
+ }
+REPT_STEP
+*/
+
+REPT_STEP
+ // actually output the resources
+ if(mresourceSize && mresourceData)
+ {
+ size_t i, N = m_pManifest->m_dwMResNum, sizeread, L;
+ BYTE *ptr = (BYTE*)mresourceData;
+ BOOL mrfail = FALSE;
+ FILE* pFile = NULL;
+ char sz[2048];
+ for(i=0; i < N; i++)
+ {
+ if(!m_pManifest->m_fMResNew[i]) continue;
+ m_pManifest->m_fMResNew[i] = FALSE;
+ memset(sz,0,2048);
+ WszWideCharToMultiByte(CP_ACP,0,m_pManifest->m_wzMResName[i],-1,sz,2047,NULL,NULL);
+ L = m_pManifest->m_dwMResSize[i];
+ sizeread = 0;
+ memcpy(ptr,&L,sizeof(DWORD));
+ ptr += sizeof(DWORD);
+ pFile = NULL;
+ if(fopen_s(&pFile,sz,"rb")==0)
+ {
+ sizeread = fread((void *)ptr,1,L,pFile);
+ fclose(pFile);
+ ptr += sizeread;
+ }
+ else
+ {
+ report->msg("Error: failed to open mgd resource file '%ls'\n",m_pManifest->m_wzMResName[i]);
+ mrfail = TRUE;
+ }
+ if(sizeread < L)
+ {
+ report->msg("Error: failed to read expected %d bytes from mgd resource file '%ls'\n",L,m_pManifest->m_wzMResName[i]);
+ mrfail = TRUE;
+ L -= sizeread;
+ memset(ptr,0,L);
+ ptr += L;
+ }
+ }
+ if(mrfail)
+ {
+ hr = E_FAIL;
+ goto exit;
+ }
+ }
+REPT_STEP
+
+ // Generate the file -- moved to main
+ //if (FAILED(hr=m_pCeeFileGen->GenerateCeeFile(m_pCeeFile))) goto exit;
+
+
+ hr = S_OK;
+
+exit:
+ return hr;
+}