tvec.pp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondvecn() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. { secondfor() }
  9. { secondderef() }
  10. { Free Pascal compiler }
  11. { secondnew() }
  12. { seconddispose() }
  13. { secondinline() length() }
  14. {****************************************************************}
  15. { DEFINES: }
  16. {****************************************************************}
  17. { REMARKS: }
  18. { Missing tests : openarray tests }
  19. {****************************************************************}
  20. program tvec;
  21. { things to test : }
  22. { array/record offset with index = 0 }
  23. { array/record offset with index < MAX_CPU_DISP }
  24. { non-aligned word/dword access to record field }
  25. { ansistring }
  26. { LOC_REFERENCE, LOC_REGISTER }
  27. { string }
  28. { right (index value) }
  29. { LOC_REGISTER }
  30. { LOC_FLAGS }
  31. { LOC_JUMP }
  32. { LOC_REFERENCE, LOC_MEM }
  33. const
  34. min_small_neg_array = -127;
  35. max_small_neg_array = 255;
  36. min_small_array = 0;
  37. max_small_array = 255;
  38. min_big_neg_array = -77000;
  39. max_big_neg_array = 77000;
  40. min_big_array = 0;
  41. max_big_array = 77000;
  42. min_big_odd_array = 0;
  43. max_big_odd_array = 255;
  44. alphabet_size = ord('Z')-ord('A')+1;
  45. alphabet : array[1..alphabet_size] of char =
  46. (
  47. 'A','B','C','D','E','F','G','H','I',
  48. 'J','K','L','M','N','O','P','Q','R',
  49. 'S','T','U','V','W','X','Y','Z');
  50. type
  51. { alignment requirements are checked }
  52. { in tsubscript.pp not here }
  53. { so all elements are byte for easy }
  54. { testing. }
  55. toddelement = packed record
  56. _b0 : array[1..8] of byte;
  57. _b1 : byte;
  58. _b2 : byte;
  59. end;
  60. psmallnegarray = ^smallnegarray;
  61. smallnegarray = array[min_small_neg_array..max_small_neg_array] of word;
  62. psmallarray = ^smallarray;
  63. smallarray = array[min_small_array..max_small_array] of word;
  64. pbignegarray = ^bignegarray;
  65. bignegarray = array[min_big_neg_array..max_big_neg_array] of word;
  66. pbigarray = ^bigarray;
  67. bigarray = array[min_big_array..max_big_array] of word;
  68. { in the case of odd addresses }
  69. { call multiply in calculating offset }
  70. pbigoddarray = ^bigoddarray;
  71. bigoddarray = array[min_big_odd_array..max_big_odd_array] of toddelement;
  72. boolarray = array[boolean] of boolean;
  73. var
  74. globalsmallnegarray : smallnegarray;
  75. globalsmallarray : smallarray;
  76. globalbignegarray : bignegarray;
  77. globalbigarray : bigarray;
  78. globaloddarray : bigoddarray;
  79. globalindex : longint;
  80. globalansi : ansistring;
  81. globalboolarray : boolarray;
  82. procedure checkpassed(passed: boolean);
  83. begin
  84. if passed then
  85. begin
  86. writeln('Passed!');
  87. end
  88. else
  89. begin
  90. writeln('Failure.');
  91. halt(1);
  92. end;
  93. end;
  94. { this routine clears all arrays }
  95. { without calling secondvecn() first }
  96. procedure clearglobalarrays;
  97. begin
  98. FillChar(globalsmallnegarray,sizeof(globalsmallnegarray),0);
  99. FillChar(globalsmallarray,sizeof(globalsmallarray),0);
  100. FillChar(globalbignegarray,sizeof(globalbignegarray),0);
  101. FillChar(globalbignegarray,sizeof(globalbignegarray),0);
  102. FillChar(globalbigarray,sizeof(globalbigarray),0);
  103. FillChar(globaloddarray,sizeof(globaloddarray),0);
  104. FillChar(globalboolarray,sizeof(globalboolarray),0);
  105. end;
  106. { left: array definition }
  107. { right : index constant }
  108. { NOT OPEN ARRAY }
  109. { (current): LOC_MEM, LOC_REFERENCE (symbol) }
  110. { (current): LOC_REFERENCE (with index register) }
  111. { (current): LOC_REFERENCE (without index register) }
  112. { (current): LOC_REFERENCE (without base register) }
  113. procedure testarrayglobal;
  114. var
  115. i : longint;
  116. passed : boolean;
  117. b1: boolean;
  118. b2: boolean;
  119. p : pointer;
  120. begin
  121. passed := true;
  122. ClearGlobalArrays;
  123. Write('Testing subscriptn() global variables...');
  124. { RIGHT : LOC_JUMP }
  125. { (current) : LOC_MEM (symbol) }
  126. b1 := true;
  127. b2 := false;
  128. globalboolarray[b1 or b2] := TRUE;
  129. if globalboolarray[true] <> TRUE then
  130. passed := false;
  131. { RIGHT : LOC_FLAGS }
  132. { (current) : LOC_MEM (symbol) }
  133. { IF ASSIGNED DOES NOT HAVE }
  134. { A RESULT IN FLAGS THIS WILL }
  135. { NOT WORK (LOC_FLAGS = OK) }
  136. { for FPC v1.0.x }
  137. p:= nil;
  138. globalboolarray[assigned(p)]:=true;
  139. if globalboolarray[false] <> true then
  140. passed := false;
  141. { RIGHT : LOC_REFERENCE }
  142. { (current) : LOC_MEM (symbol) }
  143. globalindex := max_big_array;
  144. globalbigarray[globalindex] := $F0F0;
  145. if globalbigarray[globalindex] <> $F0F0 then
  146. passed := false;
  147. { RIGHT : ordconstn }
  148. { (current) : LOC_MEM (symbol) }
  149. { index 1 : 1 }
  150. globalbigarray[max_big_array] := $FF;
  151. if globalbigarray[max_big_array] <> $FF then
  152. passed := false;
  153. { RIGHT : LOC_REGISTER }
  154. { (current) : LOC_MEM (symbol) }
  155. for i:=min_small_neg_array to max_small_neg_array do
  156. begin
  157. globalsmallnegarray[i] := word(i);
  158. end;
  159. { now compare if the values are correct }
  160. for i:=min_small_neg_array to max_small_neg_array do
  161. begin
  162. if globalsmallnegarray[i] <> word(i) then
  163. passed := false;
  164. end;
  165. for i:=min_small_array to max_small_array do
  166. begin
  167. globalsmallarray[i] := i;
  168. end;
  169. { now compare if the values are correct }
  170. for i:=min_small_array to max_small_array do
  171. begin
  172. if globalsmallarray[i] <> i then
  173. passed := false;
  174. end;
  175. for i:=min_big_neg_array to max_big_neg_array do
  176. begin
  177. globalbignegarray[i] := word(i);
  178. end;
  179. { now compare if the values are correct }
  180. for i:=min_big_neg_array to max_big_neg_array do
  181. begin
  182. if globalbignegarray[i] <> word(i) then
  183. passed := false;
  184. end;
  185. for i:=min_big_array to max_big_array do
  186. begin
  187. globalbigarray[i] := word(i);
  188. end;
  189. { now compare if the values are correct }
  190. for i:=min_big_array to max_big_array do
  191. begin
  192. if globalbigarray[i] <> word(i) then
  193. passed := false;
  194. end;
  195. for i:=min_big_odd_array to max_big_odd_array do
  196. begin
  197. globaloddarray[i]._b1 := byte(i);
  198. end;
  199. { now compare if the values are correct }
  200. for i:=min_big_odd_array to max_big_odd_array do
  201. begin
  202. if globaloddarray[i]._b1 <> byte(i) then
  203. passed := false;
  204. end;
  205. checkpassed(passed);
  206. end;
  207. { left: array definition }
  208. { right : index constant }
  209. { OPEN ARRAY }
  210. { (current): LOC_MEM, LOC_REFERENCE (symbol) }
  211. { (current): LOC_REFERENCE (with index register) }
  212. { (current): LOC_REFERENCE (without index register) }
  213. { (current): LOC_REFERENCE (without base register) }
  214. procedure testarraylocal;
  215. var
  216. localsmallnegarray : psmallnegarray;
  217. localsmallarray : psmallarray;
  218. localbignegarray : pbignegarray;
  219. localbigarray : pbigarray;
  220. localindex : longint;
  221. localboolarray: boolarray;
  222. i : longint;
  223. passed : boolean;
  224. b1, b2: boolean;
  225. p : pointer;
  226. begin
  227. Write('Testing subscriptn() local variables...');
  228. new(localsmallnegarray);
  229. new(localsmallarray);
  230. new(localbignegarray);
  231. new(localbigarray);
  232. passed := true;
  233. FillChar(localsmallnegarray^,sizeof(smallnegarray),0);
  234. FillChar(localsmallarray^,sizeof(smallarray),0);
  235. FillChar(localbignegarray^,sizeof(bignegarray),0);
  236. FillChar(localbignegarray^,sizeof(bignegarray),0);
  237. FillChar(localbigarray^,sizeof(bigarray),0);
  238. FillChar(localboolarray, sizeof(localboolarray),0);
  239. { RIGHT : LOC_JUMP }
  240. { (current) : LOC_MEM (symbol) }
  241. b1 := true;
  242. b2 := true;
  243. localboolarray[b1 and b2] := TRUE;
  244. if localboolarray[true] <> TRUE then
  245. passed := false;
  246. { RIGHT : LOC_FLAGS }
  247. { (current) : LOC_MEM (symbol) }
  248. { IF ASSIGNED DOES NOT HAVE }
  249. { A RESULT IN FLAGS THIS WILL }
  250. { NOT WORK (LOC_FLAGS = OK) }
  251. { for FPC v1.0.x }
  252. p := nil;
  253. localboolarray[assigned(p)]:=true;
  254. if localboolarray[false] <> true then
  255. passed := false;
  256. { RIGHT : LOC_REFERENCE }
  257. { (current) : LOC_MEM () }
  258. localindex := max_big_array;
  259. localbigarray^[localindex] := $F0F0;
  260. if localbigarray^[localindex] <> $F0F0 then
  261. passed := false;
  262. { RIGHT : ordconstn }
  263. { (current) : LOC_MEM () }
  264. { index 1 : 1 }
  265. localbigarray^[max_big_array] := $FF;
  266. if localbigarray^[max_big_array] <> $FF then
  267. passed := false;
  268. { RIGHT : LOC_REGISTER }
  269. { (current) : LOC_MEM () }
  270. for i:=min_small_neg_array to max_small_neg_array do
  271. begin
  272. localsmallnegarray^[i] := word(i);
  273. end;
  274. { now compare if the values are correct }
  275. for i:=min_small_neg_array to max_small_neg_array do
  276. begin
  277. if localsmallnegarray^[i] <> word(i) then
  278. passed := false;
  279. end;
  280. for i:=min_small_array to max_small_array do
  281. begin
  282. localsmallarray^[i] := i;
  283. end;
  284. { now compare if the values are correct }
  285. for i:=min_small_array to max_small_array do
  286. begin
  287. if localsmallarray^[i] <> i then
  288. passed := false;
  289. end;
  290. for i:=min_big_neg_array to max_big_neg_array do
  291. begin
  292. localbignegarray^[i] := word(i);
  293. end;
  294. { now compare if the values are correct }
  295. for i:=min_big_neg_array to max_big_neg_array do
  296. begin
  297. if localbignegarray^[i] <> word(i) then
  298. passed := false;
  299. end;
  300. for i:=min_big_array to max_big_array do
  301. begin
  302. localbigarray^[i] := word(i);
  303. end;
  304. { now compare if the values are correct }
  305. for i:=min_big_array to max_big_array do
  306. begin
  307. if localbigarray^[i] <> word(i) then
  308. passed := false;
  309. end;
  310. checkpassed(passed);
  311. dispose(localbigarray);
  312. dispose(localbignegarray);
  313. dispose(localsmallarray);
  314. dispose(localsmallnegarray);
  315. end;
  316. { (current): LOC_MEM, LOC_REFERENCE (symbol) }
  317. { (current): LOC_REFERENCE (with index register) }
  318. { (current): LOC_REFERENCE (without index register) }
  319. { (current): LOC_REFERENCE (without base register) }
  320. procedure testansistring;
  321. var
  322. localansi : ansistring;
  323. passed : boolean;
  324. i : longint;
  325. begin
  326. Write('Testing subscriptn() ansistring()...');
  327. passed := true;
  328. localansi := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  329. { RIGHT : LOC_REFERENCE }
  330. { (current) : LOC_REFERENCE () }
  331. for i:=1 to length(localansi) do
  332. begin
  333. if localansi[i]<>alphabet[i] then
  334. passed := false;
  335. end;
  336. { RIGHT : LOC_REFERENCE
  337. (current) : LOC_REGISTER ()
  338. for i:=0 to length(localansi) do
  339. begin
  340. if ansistring(getansistr)[i]<>alphabet[i] then
  341. passed := false;
  342. end;
  343. }
  344. checkpassed(passed);
  345. end;
  346. { left: array definition }
  347. { right : + operator }
  348. { right right : index constant }
  349. { With -Or switch only }
  350. { left: array definition }
  351. { right : - operator }
  352. { right right : index constant }
  353. { With -Or switch only }
  354. var
  355. i: integer;
  356. b1,b2: boolean;
  357. p: pointer;
  358. begin
  359. globalansi := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
  360. testarrayglobal;
  361. testarraylocal;
  362. testansistring;
  363. end.