tneg.pp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. {****************************************************************}
  2. { CODE GENERATOR TEST PROGRAM }
  3. {****************************************************************}
  4. { NODE TESTED : secondunaryminus() }
  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. Program tneg;
  19. {----------------------------------------------------}
  20. { Cases to test: }
  21. { CURRENT NODE (result value) }
  22. { - LOC_REGISTER }
  23. { - LOC_FPU }
  24. { LEFT NODE (value to negate) }
  25. { - LOC_CREGISTER }
  26. { - LOC_REFERENCE / LOC_MEM }
  27. { - LOC_REGISTER }
  28. { - LOC_FPU }
  29. {----------------------------------------------------}
  30. procedure test(value, required: longint);
  31. begin
  32. if value <> required then
  33. begin
  34. writeln('Got ',value,' instead of ',required);
  35. halt(1);
  36. end
  37. else
  38. writeln('Passed!');
  39. end;
  40. procedure fail;
  41. begin
  42. writeln('Failure.');
  43. halt(1);
  44. end;
  45. function getreal: real;
  46. begin
  47. getreal := 1.0;
  48. end;
  49. var
  50. longval : longint;
  51. realval : real;
  52. byteval : longint;
  53. {$IFDEF FPC}
  54. int64val : int64;
  55. {$ENDIF}
  56. Begin
  57. WriteLn('------------------------------ LONGINT --------------------------------');
  58. { CURRENT NODE: REGISTER }
  59. { LEFT NODE : REFERENCE }
  60. longval := 1;
  61. longval := - longval;
  62. Write('Value should be -1...');
  63. test(longval, -1);
  64. { CURRENT NODE : REGISTER }
  65. { LEFT NODE: REGISTER }
  66. byteval := 2;
  67. longval := - byteval;
  68. Write('Value should be -2...');
  69. test(longval, -2);
  70. { CURRENT NODE: LOC_FPU }
  71. { LEFT NODE : LOC_REFERENCE }
  72. realval := -1.0;
  73. realval := - realval;
  74. Write('Value should 1.0...');
  75. if realval - 1.0 = 0.0 then
  76. WriteLn('Passed!')
  77. else
  78. Fail;
  79. { LEFT NODE : LOC_FPU }
  80. { CURRENT NODE : LOC_FPU }
  81. realval := -1.0;
  82. realval := -(getreal*(realval));
  83. Write('Value should 1.0...');
  84. if realval - 1.0 = 0.0 then
  85. WriteLn('Passed!')
  86. else
  87. Fail;
  88. {$IFDEF FPC}
  89. WriteLn('------------------------------ INT64 --------------------------------');
  90. { CURRENT NODE: REGISTER }
  91. { LEFT NODE : REFERENCE }
  92. int64val := 1;
  93. int64val := - int64val;
  94. Write('Value should be -1...');
  95. test(int64val and $FFFFFFFF, -1);
  96. { CURRENT NODE : REGISTER }
  97. { LEFT NODE: REGISTER }
  98. byteval := 2;
  99. int64val := - byteval;
  100. Write('Value should be -2...');
  101. test(int64val and $FFFFFFFF, -2);
  102. {$ENDIF}
  103. end.