Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
6.3 KiB

  1. /*++
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. Module Name:
  4. gennt32t.cpp
  5. Abstract:
  6. Generates NT32 headers for use in the NT64 build.
  7. Author:
  8. mzoran 5-8-98
  9. Revision History:
  10. --*/
  11. #pragma warning( disable : 4786) //disable identifier is too long for debugging error
  12. #pragma warning( disable : 4503) //disable decorated name is too long
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <imagehlp.h>
  18. #include <ctype.h>
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <assert.h>
  23. #include <iostream>
  24. #include <fstream>
  25. #include <iomanip>
  26. #include <string>
  27. #include <sstream>
  28. #include <set>
  29. #include <map>
  30. extern "C" {
  31. #include "gen.h"
  32. // string to put in front of all error messages so that BUILD can find them.
  33. const char *ErrMsgPrefix = "NMAKE : U8603: 'GENNT32T' ";
  34. void
  35. HandlePreprocessorDirective(
  36. char *p
  37. )
  38. {
  39. ExitErrMsg(FALSE, "Preprocessor directives not allowed by gennt32t.\n");
  40. }
  41. }
  42. using namespace std;
  43. typedef string String;
  44. PRBTREE pFunctions = NULL;
  45. PRBTREE pStructures = NULL;
  46. PRBTREE pTypedefs = NULL;
  47. PKNOWNTYPES NIL = NULL;
  48. void ExtractCVMHeader(PCVMHEAPHEADER pHeader) {
  49. pFunctions = &pHeader->FuncsList;
  50. pTypedefs = &pHeader->TypeDefsList;
  51. pStructures =&pHeader->StructsList;
  52. NIL =&pHeader->NIL;
  53. }
  54. void GetType(PKNOWNTYPES pTypes, char *pPrepend, ostream & oType, ostream & oName, BOOL bAddTypeName) {
  55. while(1) {
  56. PKNOWNTYPES pBasicType = NULL;
  57. assert(pTypes->TypeName != NULL);
  58. oType << "/* " << pTypes->TypeName << " */";
  59. if(pTypes->Flags & BTI_ISARRAY)
  60. oName << '[' << pTypes->dwArrayElements << ']';
  61. if (pTypes->IndLevel > 0) {
  62. oType << GetHostPointerName(pTypes->Flags & BTI_PTR64);
  63. return;
  64. }
  65. if(!(BTI_NOTDERIVED & pTypes->Flags)) {
  66. if (strcmp(pTypes->BaseName, "enum") == 0) {
  67. if (bAddTypeName)
  68. oType << "enum " << pPrepend << pTypes->TypeName << " {} \n";
  69. else
  70. oType << "_int32 \n";
  71. return;
  72. }
  73. else if (strcmp(pTypes->BaseName, "union") == 0 ||
  74. strcmp(pTypes->BaseName, "struct") == 0) {
  75. oType << "\n#pragma pack(" << pTypes->dwCurrentPacking
  76. << ")\n";
  77. if (bAddTypeName)
  78. oType << pTypes->BaseName << " " << pPrepend << pTypes->TypeName;
  79. else
  80. oType << pTypes->BaseName << " ";
  81. if (NULL != pTypes->pmeminfo) {
  82. oType << "{\n";
  83. PMEMBERINFO pmeminfo = pTypes->pmeminfo;
  84. do {
  85. ostringstream oMemberType("");
  86. ostringstream oMemberName("");
  87. PKNOWNTYPES pMemberType = pmeminfo->pkt;
  88. if(pmeminfo->sName != NULL)
  89. (ostream)oMemberName << pmeminfo->sName;
  90. if (pmeminfo->bIsArray)
  91. (ostream)oMemberName << '[' << pmeminfo->ArrayElements << ']';
  92. if (pmeminfo->IndLevel > 0) {
  93. (ostream)oMemberType << GetHostPointerName(pmeminfo->bIsPtr64);
  94. }
  95. else {
  96. GetType(pMemberType, pPrepend, oMemberType, oMemberName, FALSE);
  97. if (pmeminfo->bIsBitfield)
  98. (ostream)oMemberName << " : " << pmeminfo->BitsRequired;
  99. }
  100. oType << oMemberType.str() << " " << oMemberName.str() << ";\n";
  101. pmeminfo = pmeminfo->pmeminfoNext;
  102. } while(NULL != pmeminfo);
  103. oType << "}\n";
  104. }
  105. return;
  106. }
  107. else {
  108. pBasicType = pTypes->pTypedefBase;
  109. if (NULL == pBasicType) {
  110. oType << GetHostPointerName(pTypes->Flags & BTI_PTR64);
  111. return;
  112. }
  113. pTypes = pBasicType;
  114. }
  115. }
  116. else {
  117. char Buffer[MAX_PATH];
  118. oType << GetHostTypeName(pTypes, Buffer);
  119. return;
  120. }
  121. }
  122. }
  123. void DumpTypesHeader(void) {
  124. PKNOWNTYPES pTypes;
  125. cout << "///////////////////////////////////////////\n";
  126. cout << "// This file is autogenerated by gennt32t. \n";
  127. cout << "// Do not edit \n";
  128. cout << "///////////////////////////////////////////\n";
  129. cout << '\n' << '\n';
  130. cout << "#include <guiddef.h>\n\n";
  131. cout << "#pragma pack(push, gennt32t)\n\n";
  132. cout << "///////////////////////////////////////////\n";
  133. cout << "// Structures \n";
  134. cout << "///////////////////////////////////////////\n";
  135. for(pTypes = pStructures->pLastNodeInserted; pTypes != NULL; pTypes = pTypes->Next) {
  136. if (pTypes->TypeName != NULL && !(pTypes->Flags & BTI_NOTDERIVED)) {
  137. ostringstream oType;
  138. ostringstream oName;
  139. GetType(pTypes, "NT32", oType, oName, TRUE);
  140. cout << "/* " << pTypes->TypeName << " */";
  141. cout << oType.str() << "\n";
  142. cout << oName.str() << ";" << "\n";
  143. cout << "/* End of definition for " << pTypes->TypeName << " */\n";
  144. cout << '\n';
  145. } }
  146. cout << '\n' << '\n';
  147. cout << "///////////////////////////////////////////\n";
  148. cout << "// TypeDefs \n";
  149. cout << "///////////////////////////////////////////\n";
  150. for(pTypes = pTypedefs->pLastNodeInserted; pTypes != NULL; pTypes = pTypes->Next) {
  151. if (pTypes->TypeName != NULL && !(pTypes->Flags & BTI_NOTDERIVED)) {
  152. ostringstream oType;
  153. ostringstream oName;
  154. oName << "NT32" << pTypes->TypeName << " ";
  155. GetType(pTypes, "NT32", oType, oName, FALSE);
  156. cout << "/* " << pTypes->TypeName << " */" << " typedef \n";
  157. cout << oType.str() << "\n";
  158. cout << oName.str() << "\n";
  159. cout << ";" << "\n";
  160. cout << "/* End of definition for " << pTypes->TypeName << " */\n";
  161. cout << '\n';
  162. }
  163. }
  164. cout << '\n' << '\n';
  165. cout << "#pragma pack(pop, gennt32t)\n\n";
  166. }
  167. int _cdecl main(int argc, char*argv[]) {
  168. ExtractCVMHeader(MapPpmFile(argv[1], TRUE));
  169. DumpTypesHeader();
  170. return 0;
  171. }