Author: akhaldi
Date: Wed Jul 13 12:00:42 2011
New Revision: 52671
URL:
http://svn.reactos.org/svn/reactos?rev=52671&view=rev
Log:
* Update spec2def.
Modified:
branches/GSoC_2011/ThemesSupport/tools/spec2def/spec2def.c
Modified: branches/GSoC_2011/ThemesSupport/tools/spec2def/spec2def.c
URL:
http://svn.reactos.org/svn/reactos/branches/GSoC_2011/ThemesSupport/tools/s…
==============================================================================
--- branches/GSoC_2011/ThemesSupport/tools/spec2def/spec2def.c [iso-8859-1] (original)
+++ branches/GSoC_2011/ThemesSupport/tools/spec2def/spec2def.c [iso-8859-1] Wed Jul 13
12:00:42 2011
@@ -10,7 +10,7 @@
typedef struct
{
char *pcName;
- int nNameLength;
+ size_t nNameLength;
char *pcRedirection;
int nRedirectionLength;
int nCallingConvention;
@@ -21,14 +21,25 @@
unsigned int uFlags;
} EXPORT;
+enum _ARCH
+{
+ ARCH_X86,
+ ARCH_AMD64,
+ ARCH_IA64,
+ ARCH_ARM,
+ ARCH_PPC
+};
+
typedef int (*PFNOUTLINE)(FILE *, EXPORT *);
int gbKillAt = 0;
-int gbUseDeco = 0;
int gbMSComp = 0;
+int gbImportLib = 0;
int no_redirections = 0;
+int giArch = ARCH_X86;
char *pszArchString = "i386";
char *pszArchString2;
char *pszDllName = 0;
+char *gpszUnderscore = "";
enum
{
@@ -151,7 +162,7 @@
(pexp->uFlags & FL_STUB) == 0) return 0;
fprintf(file, "int ");
- if (strcmp(pszArchString, "i386") == 0 &&
+ if ((giArch == ARCH_X86) &&
pexp->nCallingConvention == CC_STDCALL)
{
fprintf(file, "__stdcall ");
@@ -218,8 +229,12 @@
void
OutputHeader_asmstub(FILE *file, char *libname)
{
- fprintf(file, "; File generated automatically, do not edit! \n\n"
- ".586\n.model flat\n.code\n");
+ fprintf(file, "; File generated automatically, do not edit! \n\n");
+
+ if (giArch == ARCH_X86)
+ fprintf(file, ".586\n.model flat\n");
+
+ fprintf(file, ".code\n");
}
int
@@ -228,31 +243,37 @@
/* Handle autoname */
if (pexp->nNameLength == 1 && pexp->pcName[0] == '@')
{
- fprintf(fileDest, "PUBLIC ordinal%d\nordinal%d: nop\n",
- pexp->nOrdinal, pexp->nOrdinal);
+ fprintf(fileDest, "PUBLIC %sordinal%d\n%sordinal%d: nop\n",
+ gpszUnderscore, pexp->nOrdinal, gpszUnderscore, pexp->nOrdinal);
+ }
+ else if (giArch != ARCH_X86)
+ {
+ fprintf(fileDest, "PUBLIC _stub_%.*s\n_stub_%.*s: nop\n",
+ pexp->nNameLength, pexp->pcName,
+ pexp->nNameLength, pexp->pcName);
}
else if (pexp->nCallingConvention == CC_STDCALL)
{
- fprintf(fileDest, "PUBLIC _%.*s@%d\n_%.*s@%d: nop\n",
+ fprintf(fileDest, "PUBLIC __stub_%.*s@%d\n__stub_%.*s@%d: nop\n",
pexp->nNameLength, pexp->pcName, pexp->nStackBytes,
pexp->nNameLength, pexp->pcName, pexp->nStackBytes);
}
else if (pexp->nCallingConvention == CC_FASTCALL)
{
- fprintf(fileDest, "PUBLIC @%.*s@%d\n@%.*s@%d: nop\n",
+ fprintf(fileDest, "PUBLIC @_stub_%.*s@%d\n@_stub_%.*s@%d: nop\n",
pexp->nNameLength, pexp->pcName, pexp->nStackBytes,
pexp->nNameLength, pexp->pcName, pexp->nStackBytes);
}
else if (pexp->nCallingConvention == CC_CDECL ||
pexp->nCallingConvention == CC_STUB)
{
- fprintf(fileDest, "PUBLIC _%.*s\n_%.*s: nop\n",
+ fprintf(fileDest, "PUBLIC __stub_%.*s\n__stub_%.*s: nop\n",
pexp->nNameLength, pexp->pcName,
pexp->nNameLength, pexp->pcName);
}
else if (pexp->nCallingConvention == CC_EXTERN)
{
- fprintf(fileDest, "PUBLIC _%.*s\n_%.*s:\n",
+ fprintf(fileDest, "PUBLIC __stub_%.*s\n__stub_%.*s:\n",
pexp->nNameLength, pexp->pcName,
pexp->nNameLength, pexp->pcName);
}
@@ -271,18 +292,26 @@
}
void
-PrintName(FILE *fileDest, EXPORT *pexp, int fRedir, int fDeco)
+PrintName(FILE *fileDest, EXPORT *pexp, char *pszPrefix, int fRedir, int fDeco)
{
char *pcName = fRedir ? pexp->pcRedirection : pexp->pcName;
- int nNameLength = fRedir ? pexp->nRedirectionLength : pexp->nNameLength;
-
- if (fDeco && pexp->nCallingConvention == CC_FASTCALL)
- fprintf(fileDest, "@");
- fprintf(fileDest, "%.*s", nNameLength, pcName);
- if ((pexp->nCallingConvention == CC_STDCALL ||
- pexp->nCallingConvention == CC_FASTCALL) && fDeco)
- {
- fprintf(fileDest, "@%d", pexp->nStackBytes);
+ size_t nNameLength = fRedir ? pexp->nRedirectionLength : pexp->nNameLength;
+
+ /* Handle autoname */
+ if (nNameLength == 1 && pcName[0] == '@')
+ {
+ fprintf(fileDest, "ordinal%d", pexp->nOrdinal);
+ }
+ else
+ {
+ if (fDeco && pexp->nCallingConvention == CC_FASTCALL)
+ fprintf(fileDest, "@");
+ fprintf(fileDest, "%s%.*s", pszPrefix, nNameLength, pcName);
+ if ((pexp->nCallingConvention == CC_STDCALL ||
+ pexp->nCallingConvention == CC_FASTCALL) && fDeco)
+ {
+ fprintf(fileDest, "@%d", pexp->nStackBytes);
+ }
}
}
@@ -291,29 +320,26 @@
{
fprintf(fileDest, " ");
- /* Handle autoname */
- if (pexp->nNameLength == 1 && pexp->pcName[0] == '@')
- {
- fprintf(fileDest, "ordinal%d", pexp->nOrdinal);
- }
- else
- {
- PrintName(fileDest, pexp, 0, gbUseDeco && !gbKillAt);
- }
-
- if (pexp->pcRedirection && !no_redirections)
- {
- int fDeco = (gbUseDeco && !ScanToken(pexp->pcRedirection,
'.'));
-
+ PrintName(fileDest, pexp, "", 0, (giArch == ARCH_X86) &&
!gbKillAt);
+
+ if (gbImportLib)
+ {
fprintf(fileDest, "=");
- PrintName(fileDest, pexp, 1, fDeco && !gbMSComp);
- }
- else if (gbUseDeco && gbKillAt && !gbMSComp &&
+ PrintName(fileDest, pexp, "_stub_", 0, 0);
+ }
+ else if (pexp->pcRedirection)
+ {
+ int fDeco = ((giArch == ARCH_X86) && !ScanToken(pexp->pcRedirection,
'.'));
+
+ fprintf(fileDest, "=");
+ PrintName(fileDest, pexp, "", 1, fDeco && !gbMSComp);
+ }
+ else if ((giArch == ARCH_X86) && gbKillAt && !gbMSComp &&
(pexp->nCallingConvention == CC_STDCALL ||
pexp->nCallingConvention == CC_FASTCALL))
{
fprintf(fileDest, "=");
- PrintName(fileDest, pexp, 0, 1);
+ PrintName(fileDest, pexp, "", 0, 1);
}
if (pexp->nOrdinal != -1)
@@ -450,7 +476,7 @@
}
else if (CompareToken(pc, "-i386"))
{
- if (strcasecmp(pszArchString, "i386") != 0) included = 0;
+ if (giArch != ARCH_X86) included = 0;
}
else if (CompareToken(pc, "-private"))
{
@@ -530,7 +556,7 @@
CompareToken(pc, "str") ||
CompareToken(pc, "wstr"))
{
- exp.nStackBytes += sizeof(void*);
+ exp.nStackBytes += 4; // sizeof(void*) on x86
exp.anArgs[exp.nArgCount] = ARG_PTR; // FIXME: handle strings
}
else if (CompareToken(pc, "int64"))
@@ -572,7 +598,7 @@
{
/* Check for stdcall name */
char *p = strchr(pc, '@');
- if (p && (p - pc < exp.nNameLength))
+ if (p && ((size_t)(p - pc) < exp.nNameLength))
{
int i;
exp.nNameLength = p - pc;
@@ -671,6 +697,11 @@
{
pszDllName = argv[i] + 3;
}
+ else if ((strcasecmp(argv[i], "--implib") == 0))
+ {
+ no_redirections = 1;
+ gbImportLib = 1;
+ }
else if ((strcasecmp(argv[i], "--kill-at") == 0))
{
gbKillAt = 1;
@@ -694,24 +725,28 @@
}
}
- if ((strcasecmp(pszArchString, "x86_64") == 0) ||
- (strcasecmp(pszArchString, "ia64") == 0))
+ if (strcasecmp(pszArchString, "i386") == 0)
+ {
+ giArch = ARCH_X86;
+ gpszUnderscore = "_";
+ }
+ else if (strcasecmp(pszArchString, "x86_64") == 0) giArch = ARCH_AMD64;
+ else if (strcasecmp(pszArchString, "ia64") == 0) giArch = ARCH_IA64;
+ else if (strcasecmp(pszArchString, "arm") == 0) giArch = ARCH_ARM;
+ else if (strcasecmp(pszArchString, "ppc") == 0) giArch = ARCH_PPC;
+
+ if ((giArch == ARCH_AMD64) || (giArch == ARCH_IA64))
{
pszArchString2 = "win64";
}
else
pszArchString2 = "win32";
- if (strcasecmp(pszArchString, "i386") == 0)
- {
- gbUseDeco = 1;
- }
-
/* Set a default dll name */
if (!pszDllName)
{
char *p1, *p2;
- int len;
+ size_t len;
p1 = strrchr(argv[i], '\\');
if (!p1) p1 = strrchr(argv[i], '/');