tmoddiv.pp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondmoddiv() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondtypeconv() }
  9. {****************************************************************}
  10. { DEFINES: }
  11. { FPC = Target is FreePascal compiler }
  12. {****************************************************************}
  13. { REMARKS: }
  14. { }
  15. { }
  16. { }
  17. {****************************************************************}
  18. { CURRENT NODE (result): }
  19. { LOC_REGISTER }
  20. { LEFT NODE (operand) (numerator) }
  21. { LOC_REFERENCE / LOC_MEM }
  22. { LOC_REGISTER / LOC_CREGISTER }
  23. { RIGHT NODE (operand (denominator) }
  24. { ord constant node }
  25. { LOC_REGISTER / LOC_CREGISTER }
  26. { LOC_REFERENCE / LOC_MEM }
  27. function getlongcnt: longint;
  28. begin
  29. getlongcnt := -10;
  30. end;
  31. {$IFDEF FPC}
  32. function getcardinalcnt: cardinal;
  33. begin
  34. getcardinalcnt := 10;
  35. end;
  36. function getint64cnt: int64;
  37. begin
  38. getint64cnt := -10;
  39. end;
  40. {$ENDIF}
  41. var
  42. longres : longint;
  43. longcnt : longint;
  44. {$IFDEF FPC}
  45. cardinalres : cardinal;
  46. cardinalcnt : cardinal;
  47. int64res : int64;
  48. int64cnt : int64;
  49. {$ENDIF}
  50. begin
  51. WriteLn('------------------- LONGINT ------------------------');
  52. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  53. { RIGHT : power of 2 ordconstn }
  54. { LEFT : LOC_REFERENCE }
  55. longres := 24;
  56. longres := longres div 4;
  57. Write('Value should be 6...');
  58. if longres = 6 then
  59. WriteLn('Success.')
  60. else
  61. WriteLn('Failure.');
  62. { RIGHT : power of 2 ordconstn }
  63. { LEFT : LOC_REFERENCE }
  64. longres := 24;
  65. longres := longres mod 4;
  66. Write('Value should be 0...');
  67. if longres = 0 then
  68. WriteLn('Success.')
  69. else
  70. WriteLn('Failure.');
  71. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  72. { RIGHT : LOC_REFERENCE }
  73. { LEFT : LOC_REFERENCE }
  74. longres := 136;
  75. longcnt := -13;
  76. longres := longres div longcnt;
  77. Write('Value should be -10...');
  78. if longres = -10 then
  79. WriteLn('Success.')
  80. else
  81. WriteLn('Failure.');
  82. { RIGHT : LOC_REFERENCE }
  83. { LEFT : LOC_REFERENCE }
  84. longres := 10101010;
  85. longcnt := -13;
  86. longres := longres mod longcnt;
  87. Write('Value should be 10...');
  88. if longres = 10 then
  89. WriteLn('Success.')
  90. else
  91. WriteLn('Failure.');
  92. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  93. { RIGHT : LOC_REGISTER }
  94. { LEFT : LOC_REFERENCE }
  95. longres := -11111111;
  96. longres := longres div getlongcnt;
  97. Write('Value should be 1111111...');
  98. if longres = 1111111 then
  99. WriteLn('Success.')
  100. else
  101. WriteLn('Failure.');
  102. { RIGHT : LOC_REGISTER }
  103. { LEFT : LOC_REFERENCE }
  104. longres := -1111111;
  105. longres := longres mod getlongcnt;
  106. Write('Value should be -1...');
  107. if longres = -1 then
  108. WriteLn('Success.')
  109. else
  110. WriteLn('Failure.');
  111. { RIGHT : LOC_REFERENCE }
  112. { LEFT : LOC_REGISTER }
  113. longcnt := 2;
  114. longres := getlongcnt div longcnt;
  115. Write('Value should be -5...');
  116. if longres = -5 then
  117. WriteLn('Success.')
  118. else
  119. WriteLn('Failure.');
  120. { RIGHT : LOC_REFERENCE }
  121. { LEFT : LOC_REGISTER }
  122. longcnt := 3;
  123. longres := getlongcnt mod longcnt;
  124. Write('Value should be -1...');
  125. if longres = -1 then
  126. WriteLn('Success.')
  127. else
  128. WriteLn('Failure.');
  129. { special tests for results }
  130. Writeln('special numeric values tests...');
  131. longres := $7FFFFFFF;
  132. longcnt := $80000000;
  133. longres := longres div longcnt;
  134. Write('Value should be 0...');
  135. if longres = 0 then
  136. WriteLn('Success.')
  137. else
  138. WriteLn('Failure.');
  139. Writeln('special numeric values tests...');
  140. longres := $7FFFFFFF;
  141. longcnt := $80000000;
  142. longres := longcnt div longres;
  143. Write('Value should be -1...');
  144. if longres = -1 then
  145. WriteLn('Success.')
  146. else
  147. WriteLn('Failure.');
  148. Writeln('special numeric values tests...');
  149. cardinalcnt := $80000;
  150. cardinalres := $12345;
  151. cardinalres := cardinalcnt div cardinalres;
  152. Write('Value should be 7...');
  153. if cardinalres = 7 then
  154. WriteLn('Success.')
  155. else
  156. WriteLn('Failure.');
  157. {$IFDEF FPC}
  158. WriteLn('------------------- CARDINAL -----------------------');
  159. { special tests for results }
  160. Writeln('special numeric values tests...');
  161. cardinalres := $7FFFFFFF;
  162. cardinalcnt := $80000000;
  163. cardinalres := cardinalres div cardinalcnt;
  164. Write('Value should be 0...');
  165. if cardinalres = 0 then
  166. WriteLn('Success.')
  167. else
  168. WriteLn('Failure.');
  169. Writeln('special numeric values tests...');
  170. cardinalres := $7FFFFFFF;
  171. cardinalcnt := $80000000;
  172. cardinalres := cardinalcnt div cardinalres;
  173. Write('Value should be 1...');
  174. if cardinalres = 1 then
  175. WriteLn('Success.')
  176. else
  177. WriteLn('Failure.');
  178. Writeln('special numeric values tests...');
  179. cardinalcnt := $80000;
  180. cardinalres := $12345;
  181. cardinalres := cardinalcnt div cardinalres;
  182. Write('Value should be 7...');
  183. if cardinalres = 7 then
  184. WriteLn('Success.')
  185. else
  186. WriteLn('Failure.');
  187. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  188. { RIGHT : power of 2 ordconstn }
  189. { LEFT : LOC_REFERENCE }
  190. cardinalres := 24;
  191. cardinalres := cardinalres div 4;
  192. Write('Value should be 6...');
  193. if cardinalres = 6 then
  194. WriteLn('Success.')
  195. else
  196. WriteLn('Failure.');
  197. { RIGHT : power of 2 ordconstn }
  198. { LEFT : LOC_REFERENCE }
  199. cardinalres := 24;
  200. cardinalres := cardinalres mod 4;
  201. Write('Value should be 0...');
  202. if cardinalres = 0 then
  203. WriteLn('Success.')
  204. else
  205. WriteLn('Failure.');
  206. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  207. { RIGHT : LOC_REFERENCE }
  208. { LEFT : LOC_REFERENCE }
  209. cardinalres := 136;
  210. cardinalcnt := 13;
  211. cardinalres := cardinalres div cardinalcnt;
  212. Write('Value should be 10...');
  213. if cardinalres = 10 then
  214. WriteLn('Success.')
  215. else
  216. WriteLn('Failure.');
  217. { RIGHT : LOC_REFERENCE }
  218. { LEFT : LOC_REFERENCE }
  219. cardinalres := 10101010;
  220. cardinalcnt := 13;
  221. cardinalres := cardinalres mod cardinalcnt;
  222. Write('Value should be 10...');
  223. if cardinalres = 10 then
  224. WriteLn('Success.')
  225. else
  226. WriteLn('Failure.');
  227. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  228. { RIGHT : LOC_REGISTER }
  229. { LEFT : LOC_REFERENCE }
  230. cardinalres := 11111111;
  231. cardinalres := cardinalres div getcardinalcnt;
  232. Write('Value should be 1111111...');
  233. if cardinalres = 1111111 then
  234. WriteLn('Success.')
  235. else
  236. WriteLn('Failure.');
  237. { RIGHT : LOC_REGISTER }
  238. { LEFT : LOC_REFERENCE }
  239. cardinalres := 1111111;
  240. cardinalres := cardinalres mod getcardinalcnt;
  241. Write('Value should be 1...');
  242. if cardinalres = 1 then
  243. WriteLn('Success.')
  244. else
  245. WriteLn('Failure.');
  246. { RIGHT : LOC_REFERENCE }
  247. { LEFT : LOC_REGISTER }
  248. cardinalcnt := 2;
  249. cardinalres := getcardinalcnt div cardinalcnt;
  250. Write('Value should be 5...');
  251. if cardinalres = 5 then
  252. WriteLn('Success.')
  253. else
  254. WriteLn('Failure.');
  255. { RIGHT : LOC_REFERENCE }
  256. { LEFT : LOC_REGISTER }
  257. cardinalcnt := 3;
  258. cardinalres := getcardinalcnt mod cardinalcnt;
  259. Write('Value should be 1...');
  260. if cardinalres = 1 then
  261. WriteLn('Success.')
  262. else
  263. WriteLn('Failure.');
  264. WriteLn('--------------------- INT64 ------------------------');
  265. { special tests for results }
  266. Writeln('special numeric values tests...');
  267. int64res := $7FFFFFFF shl 32;
  268. int64cnt := $80000000 shl 32;
  269. int64res := int64res div int64cnt;
  270. Write('Value should be 0...');
  271. if int64res = 0 then
  272. WriteLn('Success.')
  273. else
  274. WriteLn('Failure.');
  275. Writeln('special numeric values tests...');
  276. int64res := $7FFFFFFF shl 32;
  277. int64cnt := $80000000 shl 32;
  278. int64res := int64cnt div int64res;
  279. Write('Value should be -1...');
  280. if int64res = -1 then
  281. WriteLn('Success.')
  282. else
  283. WriteLn('Failure.');
  284. int64res := $7FFFFFFF;
  285. int64cnt := $80000000;
  286. int64res := int64res div int64cnt;
  287. Write('Value should be 0...');
  288. if int64res = 0 then
  289. WriteLn('Success.')
  290. else
  291. WriteLn('Failure.');
  292. Writeln('special numeric values tests...');
  293. int64res := $7FFFFFFF;
  294. int64cnt := $80000000;
  295. int64res := int64cnt div int64res;
  296. Write('Value should be -1...');
  297. if int64res = -1 then
  298. WriteLn('Success.')
  299. else
  300. WriteLn('Failure.');
  301. WriteLn('(left) : LOC_REFERENCE; (right) : ordinal constant');
  302. { RIGHT : power of 2 ordconstn }
  303. { LEFT : LOC_REFERENCE }
  304. int64res := 24;
  305. int64res := int64res div 4;
  306. Write('Value should be 6...');
  307. if int64res = 6 then
  308. WriteLn('Success.')
  309. else
  310. WriteLn('Failure.');
  311. { RIGHT : power of 2 ordconstn }
  312. { LEFT : LOC_REFERENCE }
  313. int64res := 24;
  314. int64res := int64res mod 4;
  315. Write('Value should be 0...');
  316. if int64res = 0 then
  317. WriteLn('Success.')
  318. else
  319. WriteLn('Failure.');
  320. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REFERENCE');
  321. { RIGHT : LOC_REFERENCE }
  322. { LEFT : LOC_REFERENCE }
  323. int64res := 136;
  324. int64cnt := -13;
  325. int64res := int64res div int64cnt;
  326. Write('Value should be -10...');
  327. if int64res = -10 then
  328. WriteLn('Success.')
  329. else
  330. WriteLn('Failure.');
  331. { RIGHT : LOC_REFERENCE }
  332. { LEFT : LOC_REFERENCE }
  333. int64res := 10101010;
  334. int64cnt := -13;
  335. int64res := int64res mod int64cnt;
  336. Write('Value should be 10...');
  337. if int64res = 10 then
  338. WriteLn('Success.')
  339. else
  340. WriteLn('Failure.');
  341. WriteLn('(left) : LOC_REFERENCE; (right) : LOC_REGISTER');
  342. { RIGHT : LOC_REGISTER }
  343. { LEFT : LOC_REFERENCE }
  344. int64res := -11111111;
  345. int64res := int64res div getint64cnt;
  346. Write('Value should be 1111111...');
  347. if int64res = 1111111 then
  348. WriteLn('Success.')
  349. else
  350. WriteLn('Failure.');
  351. { RIGHT : LOC_REGISTER }
  352. { LEFT : LOC_REFERENCE }
  353. int64res := -1111111;
  354. int64res := int64res mod getint64cnt;
  355. Write('Value should be -1...');
  356. if int64res = -1 then
  357. WriteLn('Success.')
  358. else
  359. WriteLn('Failure.');
  360. { RIGHT : LOC_REFERENCE }
  361. { LEFT : LOC_REGISTER }
  362. int64cnt := 2;
  363. int64res := getint64cnt div int64cnt;
  364. Write('Value should be -5...');
  365. if int64res = -5 then
  366. WriteLn('Success.')
  367. else
  368. WriteLn('Failure.');
  369. { RIGHT : LOC_REFERENCE }
  370. { LEFT : LOC_REGISTER }
  371. int64cnt := 3;
  372. int64res := getint64cnt mod int64cnt;
  373. Write('Value should be -1...');
  374. if int64res = -1 then
  375. WriteLn('Success.')
  376. else
  377. WriteLn('Failure.');
  378. {$ENDIF}
  379. end.