tassign2.pp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. { By Carl Eric Codere }
  4. {****************************************************************}
  5. { NODE TESTED : secondassign() }
  6. {****************************************************************}
  7. { DEFINES: }
  8. { FPC = Target is FreePascal compiler }
  9. {****************************************************************}
  10. { REMARKS : Tested with Delphi 3 as reference implementation }
  11. {****************************************************************}
  12. program tassign2;
  13. {$ifdef fpc}
  14. {$warning Will only work on 32-bit cpu's}
  15. {$mode objfpc}
  16. {$endif}
  17. const
  18. RESULT_STRING = 'Hello world';
  19. RESULT_S64BIT = -12;
  20. RESULT_S32BIT = -124356;
  21. RESULT_U32BIT = 654321;
  22. RESULT_U8BIT = $55;
  23. RESULT_S16BIT = -12124;
  24. RESULT_REAL = 12.12;
  25. { adjusts the size of the bigrecord }
  26. MAX_INDEX = 7;
  27. type
  28. {
  29. the size of this record should *at least* be the size
  30. of a natural register for the target processor
  31. }
  32. tbigrecord = record
  33. x : cardinal;
  34. y : cardinal;
  35. z : array[0..MAX_INDEX] of byte;
  36. end;
  37. procedure fail;
  38. begin
  39. WriteLn('Failure.');
  40. halt(1);
  41. end;
  42. function getresults64bit: int64;
  43. begin
  44. getresults64bit := RESULT_S64BIT;
  45. end;
  46. function getresults32bit : longint;
  47. begin
  48. getresults32bit := RESULT_S32BIT;
  49. end;
  50. function getresultu8bit : byte;
  51. begin
  52. getresultu8bit := RESULT_U8BIT;
  53. end;
  54. function getresults16bit : smallint;
  55. begin
  56. getresults16bit := RESULT_S16BIT;
  57. end;
  58. function getresultreal : real;
  59. begin
  60. getresultreal := RESULT_REAL;
  61. end;
  62. var
  63. failed : boolean;
  64. s64bit : int64;
  65. s32bit : longint;
  66. s16bit : smallint;
  67. u8bit : byte;
  68. boolval : boolean;
  69. real_val : real;
  70. bigrecord1, bigrecord2 : tbigrecord;
  71. i: integer;
  72. Begin
  73. WriteLn('secondassign node testing.');
  74. failed := false;
  75. { possibilities : left : any, right : LOC_REFERENCE, LOC_REGISTER,
  76. LOC_FPUREGISTER, LOC_CONSTANT, LOC_JUMP and LOC_FLAGS }
  77. Write('left : LOC_REFERENCE, right : LOC_CONSTANT tests..');
  78. s64bit := RESULT_S64BIT;
  79. if s64bit <> RESULT_S64BIT then
  80. failed := true;
  81. s32bit := RESULT_S32BIT;
  82. if s32bit <> RESULT_S32BIT then
  83. failed := true;
  84. if failed then
  85. fail
  86. else
  87. WriteLn('Success!');
  88. Write('left : LOC_REFERENCE, right : LOC_REGISTER tests..');
  89. failed := false;
  90. s64bit := getresults64bit;
  91. if s64bit <> RESULT_S64BIT then
  92. failed := true;
  93. s32bit := getresults32bit;
  94. if s32bit <> RESULT_S32BIT then
  95. failed := true;
  96. s16bit := getresults16bit;
  97. if s16bit <> RESULT_S16BIT then
  98. failed := true;
  99. u8bit := getresultu8bit;
  100. if u8bit <> RESULT_U8BIT then
  101. failed := true;
  102. if failed then
  103. fail
  104. else
  105. WriteLn('Success!');
  106. Write('left : LOC_REFERENCE, right : LOC_FPUREGISTER tests..');
  107. failed := false;
  108. real_val := getresultreal;
  109. if trunc(real_val) <> trunc(RESULT_REAL) then
  110. failed := true;
  111. if failed then
  112. fail
  113. else
  114. WriteLn('Success!');
  115. Write('left : LOC_REFERENCE, right : LOC_REFERENCE tests..');
  116. failed := false;
  117. bigrecord1.x := RESULT_U32BIT;
  118. bigrecord1.y := RESULT_U32BIT;
  119. for i:=0 to MAX_INDEX do
  120. bigrecord1.z[i] := RESULT_U8BIT;
  121. fillchar(bigrecord2, sizeof(bigrecord2),#0);
  122. bigrecord2 := bigrecord1;
  123. if bigrecord2.x <> RESULT_U32BIT then
  124. failed := true;
  125. if bigrecord2.y <> RESULT_U32BIT then
  126. failed := true;
  127. for i:=0 to MAX_INDEX do
  128. begin
  129. if bigrecord2.z[i] <> RESULT_U8BIT then
  130. begin
  131. failed := true;
  132. break;
  133. end;
  134. end;
  135. if failed then
  136. fail
  137. else
  138. WriteLn('Success!');
  139. Write('left : LOC_REFERENCE, right : LOC_JUMP tests (32-bit cpus only!)..');
  140. {!!!!! This test will only work on 32-bit CPU's probably, on 64-bit CPUs
  141. the location should be in LOC_FLAGS
  142. }
  143. failed := false;
  144. s64bit := RESULT_S64BIT;
  145. boolval := s64bit = RESULT_S64BIT;
  146. if boolval = FALSE then
  147. failed := true;
  148. if failed then
  149. fail
  150. else
  151. WriteLn('Success!');
  152. Write('left : LOC_REFERENCE, right : LOC_FLAGS tests..');
  153. failed := false;
  154. s32bit := RESULT_S32BIT;
  155. boolval := s32bit = RESULT_S32BIT;
  156. if boolval = FALSE then
  157. failed := true;
  158. if failed then
  159. fail
  160. else
  161. WriteLn('Success!');
  162. end.