tnot.pp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondnot() }
  5. {****************************************************************}
  6. { PRE-REQUISITES: secondload() }
  7. { secondassign() }
  8. {****************************************************************}
  9. { DEFINES: VERBOSE = Write test information to screen }
  10. { FPC = Target is FreePascal compiler }
  11. {****************************************************************}
  12. { REMARKS: }
  13. { }
  14. { }
  15. { }
  16. {****************************************************************}
  17. Program tnot;
  18. {----------------------------------------------------}
  19. { Cases to test: }
  20. { CURRENT NODE (result) }
  21. { - LOC_REGISTER }
  22. { - LOC_FLAGS }
  23. { LEFT NODE (value to complement) }
  24. { possible cases : int64,byte,word,longint }
  25. { boolean }
  26. { - LOC_CREGISTER }
  27. { - LOC_REFERENCE / LOC_MEM }
  28. { - LOC_REGISTER }
  29. { - LOC_FLAGS }
  30. { - LOC_JUMP }
  31. {----------------------------------------------------}
  32. {$IFNDEF FPC}
  33. type smallint = integer;
  34. {$ENDIF}
  35. function getintres : smallint;
  36. begin
  37. getintres := $7F7F;
  38. end;
  39. function getbyteboolval : boolean;
  40. begin
  41. getbyteboolval := TRUE;
  42. end;
  43. procedure test(value, required: longint);
  44. begin
  45. if value <> required then
  46. begin
  47. writeln('Got ',value,' instead of ',required);
  48. halt(1);
  49. end
  50. else
  51. writeln('Passed!');
  52. end;
  53. var
  54. longres : longint;
  55. intres : smallint;
  56. byteboolval : bytebool;
  57. wordboolval : wordbool;
  58. longboolval : longbool;
  59. byteboolres : bytebool;
  60. wordboolres : wordbool;
  61. longboolres : longbool;
  62. {$ifdef fpc}
  63. int64res : int64;
  64. {$endif}
  65. Begin
  66. WriteLn('------------------------------ LONGINT --------------------------------');
  67. { CURRENT NODE: REGISTER }
  68. { LEFT NODE : REFERENCE }
  69. WriteLn('(current) : LOC_REGISTER; (left) : LOC_REFERENCE');
  70. longres := $7F7F7F7F;
  71. longres := not longres;
  72. Write('Value should be $80808080...');
  73. { the following test give range check errors }
  74. {$R-}
  75. test(longres,$80808080);
  76. { CURRENT NODE : REGISTER }
  77. { LEFT NODE : REGISTER }
  78. WriteLn('(current) : LOC_REGISTER; (left) : LOC_REGISTER');
  79. longres := not getintres;
  80. Write('Value should be $8080...');
  81. test(longres, $FFFF8080);
  82. WriteLn('----------------------------- BOOLEAN -----------------------------------');
  83. { CURRENT NODE : LOC_REGISTER }
  84. { LEFT NODE : LOC_REFERENCE }
  85. WriteLn('(current) : LOC_REGISTER; (left) : LOC_REFERENCE');
  86. byteboolval := TRUE;
  87. byteboolres := not byteboolval;
  88. Write('Value should be FALSE...');
  89. test(ord(byteboolres),0);
  90. wordboolval := TRUE;
  91. wordboolres := not wordboolval;
  92. Write('Value should be FALSE...');
  93. test(longint(wordboolres),0);
  94. longboolval := TRUE;
  95. longboolres := not longboolval;
  96. Write('Value should be FALSE...');
  97. test(longint(longboolres),0);
  98. { CURRENT NODE : LOC_REGISTER }
  99. { LEFT NODE : LOC_REGISTER }
  100. WriteLn('(current) : LOC_REGISTER; (left) : LOC_REGISTER');
  101. longboolres := not getbyteboolval;
  102. Write('Value should be FALSE...');
  103. test(longint(longboolres),0);
  104. { CURRENT NODE : LOC_FLAGS }
  105. { LEFT NODE : LOC_FLAGS }
  106. WriteLn('(current) : LOC_FLAGS; (left) : LOC_FLAGS');
  107. intres := 1;
  108. byteboolres := TRUE;
  109. byteboolres:= not ((intres = 1));
  110. Write('Value should be FALSE...');
  111. test(ord(byteboolres),0);
  112. { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
  113. { CURRENT_NODE : LOC_JUMP }
  114. { ???????????????????????}
  115. { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
  116. { CURRENT_NODE : LOC_FLAGS }
  117. { LEFT NODE : <> LOC_FLAGS }
  118. { !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! }
  119. {$IFDEF FPC}
  120. WriteLn('------------------------------ INT64 ----------------------------------');
  121. { CURRENT NODE: REGISTER }
  122. { LEFT NODE : REFERENCE }
  123. WriteLn('(current) : LOC_REGISTER; (left) : LOC_REFERENCE');
  124. int64res := $7F7F7F7F;
  125. int64res := not int64res;
  126. Write('Value should be $80808080...');
  127. test(int64res and $FFFFFFFF,$80808080);
  128. { CURRENT NODE : REGISTER }
  129. { LEFT NODE : REGISTER }
  130. WriteLn('(current) : LOC_REGISTER; (left) : LOC_REGISTER');
  131. int64res := not (word(getintres));
  132. Write('Value should be $8080...');
  133. test(int64res and $FFFFFFFF,$00008080);
  134. {$ENDIF}
  135. end.