Windows NT 4.0 source code leak
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.

526 lines
11 KiB

4 years ago
  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ilctxt.cxx
  5. Abstract:
  6. Intermediate Language translator context management routines
  7. Notes:
  8. Author:
  9. GregJen Jun-11-1993 Created.
  10. Notes:
  11. ----------------------------------------------------------------------------*/
  12. /****************************************************************************
  13. * include files
  14. ***************************************************************************/
  15. #include "becls.hxx"
  16. #pragma hdrstop
  17. #include "nodeskl.hxx"
  18. #include "ilxlat.hxx"
  19. #include "cmdana.hxx"
  20. #include "optprop.hxx"
  21. #include "ilreg.hxx"
  22. #include "ndrcls.hxx"
  23. /****************************************************************************
  24. * externs
  25. ***************************************************************************/
  26. extern CMD_ARG * pCommand;
  27. /****************************************************************************
  28. * definitions
  29. ***************************************************************************/
  30. // #define trace_cg
  31. //--------------------------------------------------------------------
  32. //
  33. // XLAT_SIZE_INFO::XLAT_SIZE_INFO
  34. //
  35. // Notes:
  36. //
  37. //
  38. //
  39. //--------------------------------------------------------------------
  40. XLAT_SIZE_INFO::XLAT_SIZE_INFO(
  41. CG_NDR * pCG )
  42. {
  43. ZeePee = 8;
  44. MemAlign = pCG->GetMemoryAlignment();
  45. WireAlign = CvtAlignPropertyToAlign(pCG->GetWireAlignment());
  46. MemSize = pCG->GetMemorySize();
  47. WireSize = pCG->GetWireSize();
  48. MemOffset = 0;
  49. WireOffset = 0;
  50. }
  51. //--------------------------------------------------------------------
  52. //
  53. // ::RoundToAlignment
  54. //
  55. // Helper round-up routine
  56. //
  57. // Notes:
  58. //
  59. //
  60. //
  61. //--------------------------------------------------------------------
  62. inline unsigned long
  63. RoundToAlignment( unsigned long & Offset, unsigned short Alignment )
  64. {
  65. unsigned long AlignFactor = Alignment - 1;
  66. return (Offset = (Offset + AlignFactor) & ~AlignFactor );
  67. }
  68. //--------------------------------------------------------------------
  69. //
  70. // XLAT_SIZE_INFO::BaseTypeSizes
  71. //
  72. // Notes:
  73. //
  74. //
  75. //
  76. //--------------------------------------------------------------------
  77. void
  78. XLAT_SIZE_INFO::BaseTypeSizes( node_skl * pNode )
  79. {
  80. unsigned short MS, WS;
  81. switch( pNode->NodeKind() )
  82. {
  83. case NODE_DOUBLE:
  84. case NODE_HYPER:
  85. case NODE_INT64:
  86. case NODE_LONGLONG:
  87. {
  88. MS=8; WS=8;
  89. break;
  90. };
  91. case NODE_FLOAT:
  92. case NODE_LONG:
  93. case NODE_INT:
  94. case NODE_POINTER:
  95. case NODE_HANDLE_T:
  96. case NODE_E_STATUS_T:
  97. {
  98. MS=4; WS=4;
  99. break;
  100. };
  101. case NODE_SHORT:
  102. case NODE_WCHAR_T:
  103. {
  104. MS=2; WS=2;
  105. break;
  106. };
  107. case NODE_SMALL:
  108. case NODE_CHAR:
  109. case NODE_BOOLEAN:
  110. case NODE_BYTE:
  111. {
  112. MS=1; WS=1;
  113. break;
  114. };
  115. default:
  116. {
  117. MS=0; WS=0;
  118. break;
  119. }
  120. }
  121. GetMemSize() = MS;
  122. GetMemAlign() = MS;
  123. GetWireSize() = WS;
  124. GetWireAlign() = WS;
  125. };
  126. //--------------------------------------------------------------------
  127. //
  128. // XLAT_SIZE_INFO::EnumTypeSizes
  129. //
  130. // Notes:
  131. //
  132. //
  133. //
  134. //--------------------------------------------------------------------
  135. void
  136. XLAT_SIZE_INFO::EnumTypeSizes( node_skl * pNode, BOOL Enum32 )
  137. {
  138. unsigned short MS, WS;
  139. // note - this needs to check environment
  140. WS = ( Enum32 ) ? 4 : 2;
  141. MS = ( ( pCommand->GetEnv() == ENV_DOS ) ||
  142. ( pCommand->GetEnv() == ENV_WIN16) ) ? 2 : 4;
  143. GetMemSize() = MS;
  144. GetMemAlign() = MS;
  145. GetWireSize() = WS;
  146. GetWireAlign() = WS;
  147. };
  148. //--------------------------------------------------------------------
  149. //
  150. // XLAT_SIZE_INFO::ContextHandleSizes
  151. //
  152. // Notes:
  153. //
  154. //
  155. //
  156. //--------------------------------------------------------------------
  157. void
  158. XLAT_SIZE_INFO::ContextHandleSizes( node_skl * pNode )
  159. {
  160. FixMemSizes( pNode );
  161. GetWireSize() = 20;
  162. GetWireAlign() = 4;
  163. };
  164. //--------------------------------------------------------------------
  165. //
  166. // XLAT_SIZE_INFO::ArraySize
  167. //
  168. // Notes:
  169. //
  170. //
  171. //
  172. //--------------------------------------------------------------------
  173. void
  174. XLAT_SIZE_INFO::ArraySize( node_skl * pNode, FIELD_ATTR_INFO * pFA )
  175. {
  176. // if conformant, set sizes to 0 and return
  177. if ( pFA->Kind & FA_CONFORMANT )
  178. {
  179. MemSize =
  180. WireSize = 0;
  181. return;
  182. }
  183. // round up element size to alignment boundary
  184. RoundToAlignment( MemSize, MemAlign );
  185. RoundToAlignment( WireSize, WireAlign );
  186. // compute number of elements and multiply...
  187. unsigned long ElementCount;
  188. ElementCount = pFA->pSizeIsExpr->GetValue();
  189. MemSize *= ElementCount;
  190. WireSize *= ElementCount;
  191. }
  192. //--------------------------------------------------------------------
  193. //
  194. // XLAT_SIZE_INFO::GetOffset
  195. //
  196. // Notes:
  197. // For use only by field nodes !!
  198. //
  199. // Fetch the offsets from another size info block
  200. //
  201. //--------------------------------------------------------------------
  202. void
  203. XLAT_SIZE_INFO::GetOffset( XLAT_SIZE_INFO & pInfo )
  204. {
  205. MemOffset = pInfo.MemOffset;
  206. WireOffset = pInfo.WireOffset;
  207. }
  208. //--------------------------------------------------------------------
  209. //
  210. // XLAT_SIZE_INFO::AlignOffset
  211. //
  212. // Notes:
  213. // For use only by field and struct/union nodes!!
  214. //
  215. // Round the offsets up to the corresponding alignments.
  216. //
  217. //--------------------------------------------------------------------
  218. void
  219. XLAT_SIZE_INFO::AlignOffset()
  220. {
  221. RoundToAlignment( MemOffset, MemAlign );
  222. RoundToAlignment( WireOffset, WireAlign );
  223. }
  224. //--------------------------------------------------------------------
  225. //
  226. // XLAT_SIZE_INFO::AlignEmbeddedUnion
  227. //
  228. // Notes:
  229. // For use only by field and struct/union nodes!!
  230. //
  231. // Round the offsets up to the corresponding alignments.
  232. // don't round up the wire offset
  233. //
  234. //--------------------------------------------------------------------
  235. void
  236. XLAT_SIZE_INFO::AlignEmbeddedUnion()
  237. {
  238. RoundToAlignment( MemOffset, MemAlign );
  239. RoundToAlignment( MemSize, MemAlign );
  240. // RoundToAlignment( WireOffset, WireAlign );
  241. }
  242. //--------------------------------------------------------------------
  243. //
  244. // XLAT_SIZE_INFO::AlignConfOffset
  245. //
  246. // Notes:
  247. // For use only by field and struct/union nodes!!
  248. //
  249. // Round the offsets up to the corresponding alignments.
  250. //
  251. // the Mem offset passed down from the parent
  252. // of the conformant field is aligned
  253. // the Wire offset passed down from the parent is advanced by
  254. // the wire size and then aligned
  255. //
  256. //--------------------------------------------------------------------
  257. void
  258. XLAT_SIZE_INFO::AlignConfOffset()
  259. {
  260. RoundToAlignment( MemOffset, MemAlign );
  261. //WireSize += WireOffset;
  262. WireOffset += WireSize;
  263. RoundToAlignment( WireOffset, WireAlign );
  264. }
  265. //--------------------------------------------------------------------
  266. //
  267. // XLAT_SIZE_INFO::AdjustForZP
  268. //
  269. // Notes:
  270. // For use only by field and struct/union nodes!!
  271. //
  272. // Round the offsets up to the corresponding alignments.
  273. //
  274. //--------------------------------------------------------------------
  275. void
  276. XLAT_SIZE_INFO::AdjustForZP()
  277. {
  278. if ( MemAlign > ZeePee ) MemAlign = ZeePee;
  279. }
  280. //--------------------------------------------------------------------
  281. //
  282. // XLAT_SIZE_INFO::AdjustSize
  283. //
  284. // Notes:
  285. // For use only by field and struct nodes!!
  286. //
  287. // Add current offsets to current sizes
  288. // pad MemSize out to ZeePee
  289. //
  290. //--------------------------------------------------------------------
  291. void
  292. XLAT_SIZE_INFO::AdjustSize()
  293. {
  294. MemSize += MemOffset;
  295. MemOffset = MemSize;
  296. WireSize += WireOffset;
  297. WireOffset = WireSize;
  298. }
  299. //--------------------------------------------------------------------
  300. //
  301. // XLAT_SIZE_INFO::AdjustConfSize
  302. //
  303. // Notes:
  304. // For use only by field and struct nodes!!
  305. //
  306. // Add current offsets to current sizes
  307. // pad MemSize out to ZeePee
  308. //
  309. //--------------------------------------------------------------------
  310. void
  311. XLAT_SIZE_INFO::AdjustConfSize()
  312. {
  313. MemSize += MemOffset;
  314. MemOffset = MemSize;
  315. // don't count padding before the conformance (in case it has size 0)
  316. /*****
  317. WireSize += WireOffset;
  318. WireOffset = WireSize;
  319. ******/
  320. }
  321. //--------------------------------------------------------------------
  322. //
  323. // XLAT_SIZE_INFO::AdjustTotalSize
  324. //
  325. // Notes:
  326. // For use only by field and struct/union nodes!!
  327. //
  328. // Add current offsets to current sizes
  329. // pad MemSize out to ZeePee
  330. //
  331. //--------------------------------------------------------------------
  332. void
  333. XLAT_SIZE_INFO::AdjustTotalSize()
  334. {
  335. RoundToAlignment( MemSize, MemAlign );
  336. }
  337. //--------------------------------------------------------------------
  338. //
  339. // XLAT_SIZE_INFO::FixMemSizes
  340. //
  341. // Notes:
  342. //
  343. // This routine fixes up mem sizes when they are different from what
  344. // the IL translate of children generated
  345. //
  346. //--------------------------------------------------------------------
  347. void
  348. XLAT_SIZE_INFO::FixMemSizes( node_skl * pNode )
  349. {
  350. MemSize = pNode->GetSize( 0, ZeePee );
  351. MemAlign = pNode->GetMscAlign( ZeePee );
  352. RoundToAlignment( MemSize, MemAlign );
  353. }
  354. //--------------------------------------------------------------------
  355. //
  356. // XLAT_SIZE_INFO::IgnoredPointerSizes
  357. //
  358. // Notes:
  359. //
  360. // This routine fixes up sizes for an ignored pointer
  361. //
  362. //--------------------------------------------------------------------
  363. void
  364. XLAT_SIZE_INFO::IgnoredPtrSizes()
  365. {
  366. MemSize = 4;
  367. MemAlign = 4;
  368. }
  369. //--------------------------------------------------------------------
  370. //
  371. // XLAT_SIZE_INFO::ReturnSize
  372. //
  373. // Notes:
  374. //
  375. // Copy the size information up into the parent.
  376. //
  377. //--------------------------------------------------------------------
  378. void
  379. XLAT_SIZE_INFO::ReturnSize( XLAT_SIZE_INFO & pCtxt )
  380. {
  381. if ( pCtxt.MemAlign > MemAlign ) MemAlign = pCtxt.MemAlign;
  382. MemSize = pCtxt.MemSize;
  383. if ( pCtxt.WireAlign > WireAlign ) WireAlign = pCtxt.WireAlign;
  384. WireSize = pCtxt.WireSize;
  385. // note: ZeePee is NOT propogated up, only down
  386. // note: offsets are propogated up specially
  387. }
  388. //--------------------------------------------------------------------
  389. //
  390. // XLAT_SIZE_INFO::ReturnConfSize
  391. //
  392. // Notes:
  393. //
  394. // Copy the size information up into the parent.
  395. // Don't overwrite the wire size the parent already has
  396. //
  397. //--------------------------------------------------------------------
  398. void
  399. XLAT_SIZE_INFO::ReturnConfSize( XLAT_SIZE_INFO & pCtxt )
  400. {
  401. if ( pCtxt.MemAlign > MemAlign ) MemAlign = pCtxt.MemAlign;
  402. MemSize = pCtxt.MemSize;
  403. if ( pCtxt.WireAlign > WireAlign ) WireAlign = pCtxt.WireAlign;
  404. // WireSize = pCtxt.WireSize;
  405. // note: ZeePee is NOT propogated up, only down
  406. // note: offsets are propogated up specially
  407. }
  408. //--------------------------------------------------------------------
  409. //
  410. // XLAT_SIZE_INFO::ReturnUnionSize
  411. //
  412. // Notes:
  413. //
  414. // Copy the size information up into the parent.
  415. //
  416. //--------------------------------------------------------------------
  417. void
  418. XLAT_SIZE_INFO::ReturnUnionSize( XLAT_SIZE_INFO & pCtxt )
  419. {
  420. if ( pCtxt.MemAlign > MemAlign ) MemAlign = pCtxt.MemAlign;
  421. if ( pCtxt.MemSize > MemSize ) MemSize = pCtxt.MemSize;
  422. if ( pCtxt.WireAlign > WireAlign ) WireAlign = pCtxt.WireAlign;
  423. if ( pCtxt.WireSize > WireSize ) WireSize = pCtxt.WireSize;
  424. // note: ZeePee is NOT propogated up, only down
  425. // note: offsets are propogated up specially
  426. }