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.

578 lines
13 KiB

  1. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Copyright (c) 1989-1999 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 = pCommand->GetZeePee();
  44. MemAlign = pCG->GetMemoryAlignment();
  45. WireAlign = pCG->GetWireAlignment();
  46. MemSize = pCG->GetMemorySize();
  47. WireSize = pCG->GetWireSize();
  48. MemOffset = 0;
  49. WireOffset = 0;
  50. MustAlign = false;
  51. }
  52. //--------------------------------------------------------------------
  53. //
  54. // ::RoundToAlignment
  55. //
  56. // Helper round-up routine
  57. //
  58. // Notes:
  59. //
  60. //
  61. //
  62. //--------------------------------------------------------------------
  63. inline unsigned long
  64. RoundToAlignment( unsigned long & Offset, unsigned short Alignment )
  65. {
  66. unsigned long AlignFactor = Alignment - 1;
  67. return (Offset = (Offset + AlignFactor) & ~AlignFactor );
  68. }
  69. //--------------------------------------------------------------------
  70. //
  71. // XLAT_SIZE_INFO::BaseTypeSizes
  72. //
  73. // Notes:
  74. //
  75. // Merges attributes for a base type with the given context.
  76. //
  77. //--------------------------------------------------------------------
  78. void
  79. XLAT_SIZE_INFO::BaseTypeSizes( node_skl * pNode )
  80. {
  81. unsigned short MS, WS;
  82. switch( pNode->NodeKind() )
  83. {
  84. case NODE_DOUBLE:
  85. case NODE_HYPER:
  86. case NODE_INT64:
  87. case NODE_LONGLONG:
  88. {
  89. MS=8; WS=8;
  90. break;
  91. };
  92. case NODE_INT128:
  93. case NODE_FLOAT80: //BUG, BUG double check this once VC supports
  94. case NODE_FLOAT128:
  95. {
  96. MS=16; WS = 16;
  97. break;
  98. }
  99. case NODE_POINTER:
  100. case NODE_HANDLE_T:
  101. {
  102. MS = (unsigned short) SIZEOF_MEM_PTR();
  103. WS = (unsigned short) SIZEOF_WIRE_PTR();
  104. break;
  105. };
  106. case NODE_INT3264:
  107. {
  108. MS = (unsigned short) SIZEOF_MEM_INT3264();
  109. WS = (unsigned short) SIZEOF_WIRE_INT3264();
  110. break;
  111. };
  112. case NODE_FLOAT:
  113. case NODE_LONG:
  114. case NODE_INT32:
  115. case NODE_INT:
  116. case NODE_E_STATUS_T:
  117. {
  118. MS=4; WS=4;
  119. break;
  120. };
  121. case NODE_SHORT:
  122. case NODE_WCHAR_T:
  123. {
  124. MS=2; WS=2;
  125. break;
  126. };
  127. case NODE_SMALL:
  128. case NODE_CHAR:
  129. case NODE_BOOLEAN:
  130. case NODE_BYTE:
  131. {
  132. MS=1; WS=1;
  133. break;
  134. };
  135. default:
  136. {
  137. MS=0; WS=0;
  138. break;
  139. }
  140. }
  141. GetMemSize() = MS;
  142. GetMemAlign() = __max(MS,GetMemAlign());
  143. GetWireSize() = WS;
  144. GetWireAlign() = __max(WS,GetWireAlign());
  145. };
  146. //--------------------------------------------------------------------
  147. //
  148. // XLAT_SIZE_INFO::EnumTypeSizes
  149. //
  150. // Notes:
  151. //
  152. // Merges in the sizes for an enum.
  153. //
  154. //--------------------------------------------------------------------
  155. void
  156. XLAT_SIZE_INFO::EnumTypeSizes( node_skl*, BOOL Enum32 )
  157. /*
  158. Called when xlating node_enum: Enum32 means [enum_v1] used.
  159. */
  160. {
  161. unsigned short MS, WS;
  162. // note - this needs to check environment
  163. WS = unsigned short( ( Enum32 ) ? 4 : 2 );
  164. MS = 4;
  165. GetMemSize() = MS;
  166. GetMemAlign() = __max(MS, GetMemAlign());
  167. GetWireSize() = WS;
  168. GetWireAlign() = __max(WS, GetWireAlign());
  169. };
  170. //--------------------------------------------------------------------
  171. //
  172. // XLAT_SIZE_INFO::ContextHandleSizes
  173. //
  174. // Notes:
  175. //
  176. //
  177. //
  178. //--------------------------------------------------------------------
  179. void
  180. XLAT_SIZE_INFO::ContextHandleSizes( node_skl * pNode )
  181. {
  182. FixMemSizes( pNode );
  183. GetWireSize() = 20;
  184. GetWireAlign() = 4;
  185. };
  186. //--------------------------------------------------------------------
  187. //
  188. // XLAT_SIZE_INFO::ArraySize
  189. //
  190. // Notes:
  191. //
  192. //
  193. //
  194. //--------------------------------------------------------------------
  195. void
  196. XLAT_SIZE_INFO::ArraySize( node_skl*, FIELD_ATTR_INFO * pFA )
  197. {
  198. // if conformant, set sizes to 0 and return
  199. if ( pFA->Kind & FA_CONFORMANT )
  200. {
  201. MemSize =
  202. WireSize = 0;
  203. return;
  204. }
  205. // round up element size to alignment boundary
  206. // Element is already rounded up.
  207. // RoundToAlignment( MemSize, MemAlign );
  208. // RoundToAlignment( WireSize, WireAlign );
  209. // compute number of elements and multiply...
  210. unsigned long ElementCount;
  211. ElementCount = (ulong) pFA->pSizeIsExpr->GetValue();
  212. MemSize *= ElementCount;
  213. WireSize *= ElementCount;
  214. }
  215. //--------------------------------------------------------------------
  216. //
  217. // XLAT_SIZE_INFO::GetOffset
  218. //
  219. // Notes:
  220. // For use only by field nodes !!
  221. //
  222. // Fetch the offsets from another size info block
  223. //
  224. //--------------------------------------------------------------------
  225. void
  226. XLAT_SIZE_INFO::GetOffset( XLAT_SIZE_INFO & pInfo )
  227. {
  228. MemOffset = pInfo.MemOffset;
  229. WireOffset = pInfo.WireOffset;
  230. }
  231. //--------------------------------------------------------------------
  232. //
  233. // XLAT_SIZE_INFO::AlignOffset
  234. //
  235. // Notes:
  236. // For use only by field and struct/union nodes!!
  237. //
  238. // Round the offsets up to the corresponding alignments.
  239. //
  240. //--------------------------------------------------------------------
  241. void
  242. XLAT_SIZE_INFO::AlignOffset()
  243. {
  244. RoundToAlignment( MemOffset, MemAlign );
  245. RoundToAlignment( WireOffset, WireAlign );
  246. }
  247. //--------------------------------------------------------------------
  248. //
  249. // XLAT_SIZE_INFO::AlignEmbeddedUnion
  250. //
  251. // Notes:
  252. // For use only by field and struct/union nodes!!
  253. //
  254. // Round the offsets up to the corresponding alignments.
  255. // don't round up the wire offset
  256. //
  257. //--------------------------------------------------------------------
  258. void
  259. XLAT_SIZE_INFO::AlignEmbeddedUnion()
  260. {
  261. RoundToAlignment( MemOffset, MemAlign );
  262. RoundToAlignment( MemSize, MemAlign );
  263. // RoundToAlignment( WireOffset, WireAlign );
  264. }
  265. //--------------------------------------------------------------------
  266. //
  267. // XLAT_SIZE_INFO::AlignConfOffset
  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. // the Mem offset passed down from the parent
  275. // of the conformant field is aligned
  276. // the Wire offset passed down from the parent is advanced by
  277. // the wire size and then aligned
  278. //
  279. //--------------------------------------------------------------------
  280. void
  281. XLAT_SIZE_INFO::AlignConfOffset()
  282. {
  283. RoundToAlignment( MemOffset, MemAlign );
  284. //WireSize += WireOffset;
  285. WireOffset += WireSize;
  286. RoundToAlignment( WireOffset, WireAlign );
  287. }
  288. //--------------------------------------------------------------------
  289. //
  290. // XLAT_SIZE_INFO::AdjustForZP
  291. //
  292. // Notes:
  293. // For use only by field and struct/union nodes!!
  294. //
  295. // Round the offsets up to the corresponding alignments.
  296. //
  297. //--------------------------------------------------------------------
  298. void
  299. XLAT_SIZE_INFO::AdjustForZP()
  300. {
  301. if ( ( MemAlign > ZeePee ) && !MustAlign ) MemAlign = ZeePee;
  302. }
  303. //--------------------------------------------------------------------
  304. //
  305. // XLAT_SIZE_INFO::AdjustSize
  306. //
  307. // Notes:
  308. // For use only by field and struct nodes!!
  309. //
  310. // Add current offsets to current sizes
  311. // pad MemSize out to ZeePee
  312. //
  313. //--------------------------------------------------------------------
  314. void
  315. XLAT_SIZE_INFO::AdjustSize()
  316. {
  317. MemSize += MemOffset;
  318. MemOffset = MemSize;
  319. WireSize += WireOffset;
  320. WireOffset = WireSize;
  321. }
  322. //--------------------------------------------------------------------
  323. //
  324. // XLAT_SIZE_INFO::AdjustConfSize
  325. //
  326. // Notes:
  327. // For use only by field and struct nodes!!
  328. //
  329. // Add current offsets to current sizes
  330. // pad MemSize out to ZeePee
  331. //
  332. //--------------------------------------------------------------------
  333. void
  334. XLAT_SIZE_INFO::AdjustConfSize()
  335. {
  336. MemSize += MemOffset;
  337. MemOffset = MemSize;
  338. // don't count padding before the conformance (in case it has size 0)
  339. /*****
  340. WireSize += WireOffset;
  341. WireOffset = WireSize;
  342. ******/
  343. }
  344. //--------------------------------------------------------------------
  345. //
  346. // XLAT_SIZE_INFO::AdjustTotalSize
  347. //
  348. // Notes:
  349. // For use only by field and struct/union nodes!!
  350. //
  351. // Add current offsets to current sizes
  352. // pad MemSize out to ZeePee
  353. //
  354. //--------------------------------------------------------------------
  355. void
  356. XLAT_SIZE_INFO::AdjustTotalSize()
  357. {
  358. RoundToAlignment( MemSize, MemAlign );
  359. }
  360. //--------------------------------------------------------------------
  361. //
  362. // XLAT_SIZE_INFO::Ndr64AdjustTotalStructSize
  363. //
  364. // Notes:
  365. // For use only by field and struct nodes!!
  366. //
  367. // Add current offsets to current sizes
  368. // pad MemSize and BuffSize out to ZeePee
  369. //
  370. //--------------------------------------------------------------------
  371. void
  372. XLAT_SIZE_INFO::Ndr64AdjustTotalStructSize()
  373. {
  374. RoundToAlignment( WireSize, WireAlign );
  375. RoundToAlignment( MemSize, MemAlign );
  376. }
  377. //--------------------------------------------------------------------
  378. //
  379. // XLAT_SIZE_INFO::FixMemSizes
  380. //
  381. // Notes:
  382. //
  383. // This routine fixes up mem sizes when they are different from what
  384. // the IL translate of children generated
  385. //
  386. //--------------------------------------------------------------------
  387. void
  388. XLAT_SIZE_INFO::FixMemSizes( node_skl * pNode )
  389. {
  390. FRONT_MEMORY_INFO MemInfo = pNode->GetMemoryInfo();
  391. MemSize = MemInfo.Size;
  392. MemAlign = MemInfo.Align;
  393. MustAlign = MemInfo.IsMustAlign;
  394. }
  395. //--------------------------------------------------------------------
  396. //
  397. // XLAT_SIZE_INFO::IgnoredPointerSizes
  398. //
  399. // Notes:
  400. //
  401. // This routine fixes up sizes for an ignored pointer
  402. //
  403. //--------------------------------------------------------------------
  404. void
  405. XLAT_SIZE_INFO::IgnoredPtrSizes()
  406. {
  407. MemSize = SIZEOF_MEM_PTR();
  408. MemAlign = (unsigned short) SIZEOF_MEM_PTR();
  409. }
  410. //--------------------------------------------------------------------
  411. //
  412. // XLAT_SIZE_INFO::ReturnSize
  413. //
  414. // Notes:
  415. //
  416. // Copy the size information up into the parent.
  417. //
  418. //--------------------------------------------------------------------
  419. void
  420. XLAT_SIZE_INFO::ReturnSize( XLAT_SIZE_INFO & pCtxt )
  421. {
  422. if ( pCtxt.MemAlign > MemAlign )
  423. MemAlign = pCtxt.MemAlign;
  424. MemSize = pCtxt.MemSize;
  425. if ( pCtxt.WireAlign > WireAlign )
  426. WireAlign = pCtxt.WireAlign;
  427. WireSize = pCtxt.WireSize;
  428. MustAlign = MustAlign || pCtxt.MustAlign;
  429. // note: ZeePee is NOT propogated up, only down
  430. // note: offsets are propogated up specially
  431. }
  432. //--------------------------------------------------------------------
  433. //
  434. // XLAT_SIZE_INFO::ReturnConfSize
  435. //
  436. // Notes:
  437. //
  438. // Copy the size information up into the parent.
  439. // Don't overwrite the wire size the parent already has
  440. //
  441. //--------------------------------------------------------------------
  442. void
  443. XLAT_SIZE_INFO::ReturnConfSize( XLAT_SIZE_INFO & pCtxt )
  444. {
  445. if ( pCtxt.MemAlign > MemAlign )
  446. MemAlign = pCtxt.MemAlign;
  447. MemSize = pCtxt.MemSize;
  448. if ( pCtxt.WireAlign > WireAlign )
  449. WireAlign = pCtxt.WireAlign;
  450. // WireSize = pCtxt.WireSize;
  451. MustAlign = MustAlign || pCtxt.MustAlign;
  452. // note: ZeePee is NOT propogated up, only down
  453. // note: offsets are propogated up specially
  454. }
  455. //--------------------------------------------------------------------
  456. //
  457. // XLAT_SIZE_INFO::ReturnUnionSize
  458. //
  459. // Notes:
  460. //
  461. // Copy the size information up into the parent.
  462. //
  463. //--------------------------------------------------------------------
  464. void
  465. XLAT_SIZE_INFO::ReturnUnionSize( XLAT_SIZE_INFO & pCtxt )
  466. {
  467. if ( pCtxt.MemAlign > MemAlign ) MemAlign = pCtxt.MemAlign;
  468. if ( pCtxt.MemSize > MemSize ) MemSize = pCtxt.MemSize;
  469. if ( pCtxt.WireAlign > WireAlign ) WireAlign = pCtxt.WireAlign;
  470. if ( pCtxt.WireSize > WireSize ) WireSize = pCtxt.WireSize;
  471. MustAlign = MustAlign || pCtxt.MustAlign;
  472. // note: ZeePee is NOT propogated up, only down
  473. // note: offsets are propogated up specially
  474. }