tcnvint3.pp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondtypeconvert() -> second_int_to_int }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondcalln() }
  9. { secondinline() }
  10. { secondadd() }
  11. {****************************************************************}
  12. { DEFINES: }
  13. {****************************************************************}
  14. { REMARKS: }
  15. {****************************************************************}
  16. program tcnvint3;
  17. {$ifdef VER70}
  18. {$define tp}
  19. {$endif}
  20. {$R-}
  21. {$ifdef tp}
  22. type
  23. smallint = integer;
  24. {$endif}
  25. procedure fail;
  26. begin
  27. WriteLn('Failure.');
  28. halt(1);
  29. end;
  30. const
  31. ABSOLUTE_GETS8BIT_RESULT = 63;
  32. GETS8BIT_RESULT = -63;
  33. GETU8BIT_RESULT = $55;
  34. ABSOLUTE_GETS16BIT_RESULT = 16384;
  35. GETS16BIT_RESULT = -16384;
  36. GETU16BIT_RESULT = 32767;
  37. GETS32BIT_RESULT = -1000000;
  38. GETU32BIT_RESULT = 2000000;
  39. {$ifndef tp}
  40. function gets64bit : int64;
  41. begin
  42. gets64bit := 12;
  43. end;
  44. {$endif}
  45. function gets32bit : longint;
  46. begin
  47. gets32bit := GETS32BIT_RESULT;
  48. end;
  49. { return an 8-bit signed value }
  50. function gets8bit : shortint;
  51. begin
  52. gets8bit := GETS8BIT_RESULT;
  53. end;
  54. { return an 8-bit unsigned value }
  55. function getu8bit : byte;
  56. begin
  57. getu8bit := GETU8BIT_RESULT;
  58. end;
  59. function gets16bit : smallint;
  60. begin
  61. gets16bit := GETS16BIT_RESULT;
  62. end;
  63. function getu16bit : word;
  64. begin
  65. getu16bit := GETU16BIT_RESULT;
  66. end;
  67. {$ifndef tp}
  68. function getu32bit : longword;
  69. begin
  70. getu32bit := GETU32BIT_RESULT;
  71. end;
  72. {$endif tp}
  73. var
  74. s8bit : shortint;
  75. s16bit : smallint;
  76. s32bit : longint;
  77. u16bit : word;
  78. u8bit : byte;
  79. failed : boolean;
  80. {$ifndef tp}
  81. s64bit : int64;
  82. u32bit : cardinal;
  83. {$endif}
  84. begin
  85. {--------------------- dst_size < src_size -----------------------}
  86. { Actually the destination is always a natural register }
  87. { either 32-bit / 64-bit, therefore not really important }
  88. { to do extensive checking on these nodes. }
  89. { src : LOC_REGISTER }
  90. { dst : LOC_REGISTER }
  91. writeln('type conversion src_size > dst_size');
  92. writeln('dst : LOC_REGISTER src : LOC_REGISTER ');
  93. {$ifndef tp}
  94. write('Testing dst : s32bit src : s64bit...');
  95. { s64bit -> s32bit }
  96. s32bit:=gets64bit;
  97. if s32bit <> 12 then
  98. Fail
  99. else
  100. WriteLn('Passed.');
  101. { s64bit -> s8bit }
  102. write('Testing dst : s8bit src : s64bit...');
  103. s8bit:=gets64bit;
  104. if s8bit <> 12 then
  105. Fail
  106. else
  107. WriteLn('Passed.');
  108. {$endif}
  109. { s32bit -> s16bit }
  110. write('Testing dst : s16bit src : s32bit...');
  111. s16bit := gets32bit;
  112. if s16bit <> smallint(GETS32BIT_RESULT AND $FFFF) then
  113. Fail
  114. else
  115. WriteLn('Passed.');
  116. { Here we will check each possible case of src, to test also the load }
  117. { of different memory sizes cases. }
  118. { src : LOC_REFERENCE }
  119. { dst : LOC_REGISTER }
  120. {$ifndef tp}
  121. writeln('dst : LOC_REGISTER src : LOC_REFERENCE ');
  122. write('Testing dst : s32bit src : s64bit...');
  123. s64bit:=$FF0000;
  124. s32bit:=s64bit;
  125. if s32bit <> $FF0000 then
  126. Fail
  127. else
  128. WriteLn('Passed.');
  129. {$endif}
  130. write('Testing dst : s16bit src : s32bit...');
  131. s32bit:=$FF00;
  132. s16bit:=s32bit;
  133. if s16bit <> smallint($FF00) then
  134. Fail
  135. else
  136. WriteLn('Passed.');
  137. { try a signed value }
  138. write('Testing dst : s16bit src : s32bit...');
  139. s32bit:=-14;
  140. s16bit:=s32bit;
  141. if s16bit <> smallint(-14) then
  142. Fail
  143. else
  144. WriteLn('Passed.');
  145. s16bit:=$FF;
  146. write('Testing dst : s8bit src : s16bit...');
  147. s8bit:=s16bit;
  148. if s8bit <> shortint($FF) then
  149. Fail
  150. else
  151. WriteLn('Passed.');
  152. {$ifndef tp}
  153. write('Testing dst : u16bit src : u32bit...');
  154. u32bit:=$F001;
  155. u16bit := u32bit;
  156. if u16bit <> $F001 then
  157. Fail
  158. else
  159. WriteLn('Passed.');
  160. {$endif}
  161. write('Testing dst : u8bit src : u16bit...');
  162. u16bit := $10;
  163. u8bit := u16bit;
  164. if u8bit <> $10 then
  165. Fail
  166. else
  167. WriteLn('Passed.');
  168. { That was the easy part... now : dst_size > src_size }
  169. { here we must take care of sign extension }
  170. { src : LOC_REGISTER }
  171. { dst : LOC_REGISTER }
  172. writeln('type conversion dst_size > src_size');
  173. writeln('dst : LOC_REGISTER src : LOC_REGISTER ');
  174. failed := false;
  175. write('Testing dst : u16bit src : s8bit, u8bit... ');
  176. u16bit:=gets8bit;
  177. if u16bit <> word(GETS8BIT_RESULT) then
  178. failed := true;
  179. u16bit:=getu8bit;
  180. if u16bit <> GETU8BIT_RESULT then
  181. failed := true;
  182. if failed then
  183. Fail
  184. else
  185. WriteLn('Passed.');
  186. {$ifndef tp}
  187. failed := false;
  188. write('Testing dst : u32bit src : s8bit, u8bit, s16bit, u16bit... ');
  189. u32bit:=gets8bit;
  190. if u32bit <> cardinal(GETS8BIT_RESULT) then
  191. failed := true;
  192. u32bit:=getu8bit;
  193. if u32bit <> GETU8BIT_RESULT then
  194. failed := true;
  195. u32bit:=gets16bit;
  196. if u32bit <> cardinal(GETS16BIT_RESULT) then
  197. failed := true;
  198. u32bit:=getu16bit;
  199. if u32bit <> GETU16BIT_RESULT then
  200. failed := true;
  201. if failed then
  202. Fail
  203. else
  204. WriteLn('Passed.');
  205. {$endif}
  206. failed := false;
  207. write('Testing dst : s16bit src : s8bit, u8bit...');
  208. s16bit := gets8bit;
  209. if s16bit <> GETS8BIT_RESULT then
  210. failed := true;
  211. s16bit := getu8bit;
  212. if s16bit <> GETU8BIT_RESULT then
  213. failed := true;
  214. if failed then
  215. Fail
  216. else
  217. WriteLn('Passed.');
  218. failed := false;
  219. write('Testing dst : s32bit src : s8bit, u8bit. s16bit, u16bit...');
  220. s32bit := gets8bit;
  221. if s32bit <> GETS8BIT_RESULT then
  222. failed := true;
  223. s32bit := getu8bit;
  224. if s32bit <> GETU8BIT_RESULT then
  225. failed := true;
  226. s32bit := gets16bit;
  227. if s32bit <> GETS16BIT_RESULT then
  228. failed := true;
  229. s32bit := getu16bit;
  230. if s32bit <> GETU16BIT_RESULT then
  231. failed := true;
  232. if failed then
  233. Fail
  234. else
  235. WriteLn('Passed.');
  236. {$ifndef tp}
  237. failed := false;
  238. write('Testing dst : s64bit src : s8bit, u8bit. s16bit, u16bit, s32bit, u32bit...');
  239. s64bit := gets8bit;
  240. if s64bit <> GETS8BIT_RESULT then
  241. failed := true;
  242. s64bit := getu8bit;
  243. if s64bit <> GETU8BIT_RESULT then
  244. failed := true;
  245. s64bit := gets16bit;
  246. if s64bit <> GETS16BIT_RESULT then
  247. failed := true;
  248. s64bit := getu16bit;
  249. if s64bit <> GETU16BIT_RESULT then
  250. failed := true;
  251. s64bit := gets32bit;
  252. if s64bit <> GETS32BIT_RESULT then
  253. failed := true;
  254. s64bit := getu32bit;
  255. if s64bit <> GETU32BIT_RESULT then
  256. failed := true;
  257. if failed then
  258. Fail
  259. else
  260. WriteLn('Passed.');
  261. {$endif}
  262. { src : LOC_REFERENCE }
  263. { dst : LOC_REGISTER }
  264. writeln('type conversion dst_size > src_size');
  265. writeln('dst : LOC_REGISTER src : LOC_REFERENCE ');
  266. failed := false;
  267. write('Testing dst : u16bit src : s8bit, u8bit... ');
  268. s8bit := GETS8BIT_RESULT;
  269. u16bit:=s8bit;
  270. if u16bit <> word(GETS8BIT_RESULT) then
  271. failed := true;
  272. u8bit := GETU8BIT_RESULT;
  273. u16bit:=u8bit;
  274. if u16bit <> GETU8BIT_RESULT then
  275. failed := true;
  276. if failed then
  277. Fail
  278. else
  279. WriteLn('Passed.');
  280. {$ifndef tp}
  281. failed := false;
  282. write('Testing dst : u32bit src : s8bit, u8bit, s16bit, u16bit... ');
  283. s8bit := GETS8BIT_RESULT;
  284. u32bit:=s8bit;
  285. if u32bit <> cardinal(GETS8BIT_RESULT) then
  286. failed := true;
  287. u8bit := GETU8BIT_RESULT;
  288. u32bit:=u8bit;
  289. if u32bit <> GETU8BIT_RESULT then
  290. failed := true;
  291. s16bit := GETS16BIT_RESULT;
  292. u32bit:=s16bit;
  293. if u32bit <> cardinal(GETS16BIT_RESULT) then
  294. failed := true;
  295. u16bit := GETU16BIT_RESULT;
  296. u32bit:=u16bit;
  297. if u32bit <> GETU16BIT_RESULT then
  298. failed := true;
  299. if failed then
  300. Fail
  301. else
  302. WriteLn('Passed.');
  303. {$endif}
  304. failed := false;
  305. write('Testing dst : s16bit src : s8bit, u8bit...');
  306. s8bit := GETS8BIT_RESULT;
  307. s16bit := s8bit;
  308. if s16bit <> GETS8BIT_RESULT then
  309. failed := true;
  310. u8bit := GETU8BIT_RESULT;
  311. s16bit := u8bit;
  312. if s16bit <> GETU8BIT_RESULT then
  313. failed := true;
  314. if failed then
  315. Fail
  316. else
  317. WriteLn('Passed.');
  318. failed := false;
  319. write('Testing dst : s32bit src : s8bit, u8bit. s16bit, u16bit...');
  320. s8bit := GETS8BIT_RESULT;
  321. s32bit := s8bit;
  322. if s32bit <> GETS8BIT_RESULT then
  323. failed := true;
  324. u8bit := GETU8BIT_RESULT;
  325. s32bit := u8bit;
  326. if s32bit <> GETU8BIT_RESULT then
  327. failed := true;
  328. s16bit := GETS16BIT_RESULT;
  329. s32bit := s16bit;
  330. if s32bit <> GETS16BIT_RESULT then
  331. failed := true;
  332. u16bit := GETU16BIT_RESULT;
  333. s32bit := u16bit;
  334. if s32bit <> GETU16BIT_RESULT then
  335. failed := true;
  336. if failed then
  337. Fail
  338. else
  339. WriteLn('Passed.');
  340. {$ifndef tp}
  341. failed := false;
  342. write('Testing dst : s64bit src : s8bit, u8bit. s16bit, u16bit, s32bit, u32bit...');
  343. s8bit := GETS8BIT_RESULT;
  344. s64bit := s8bit;
  345. if s64bit <> GETS8BIT_RESULT then
  346. failed := true;
  347. u8bit := GETU8BIT_RESULT;
  348. s64bit := u8bit;
  349. if s64bit <> GETU8BIT_RESULT then
  350. failed := true;
  351. s16bit := GETS16BIT_RESULT;
  352. s64bit := s16bit;
  353. if s64bit <> GETS16BIT_RESULT then
  354. failed := true;
  355. u16bit := GETU16BIT_RESULT;
  356. s64bit := u16bit;
  357. if s64bit <> GETU16BIT_RESULT then
  358. failed := true;
  359. s32bit := GETS32BIT_RESULT;
  360. s64bit := s32bit;
  361. if s64bit <> GETS32BIT_RESULT then
  362. failed := true;
  363. u32bit := GETU32BIT_RESULT;
  364. s64bit := u32bit;
  365. if s64bit <> GETU32BIT_RESULT then
  366. failed := true;
  367. if failed then
  368. Fail
  369. else
  370. WriteLn('Passed.');
  371. {$endif}
  372. end.