tw38267b.pp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. { %opt=-O3 -Sg }
  2. {$mode objfpc} {$longstrings+}
  3. label start1, end1, start2, end2, start3, end3;
  4. var
  5. s: string;
  6. begin
  7. writeln('31 concatenated string literals, completely folded:');
  8. start1:
  9. s :=
  10. 'Once like a Great House' + LineEnding +
  11. 'founded on sand,' + LineEnding +
  12. 'Stood our Temple' + LineEnding +
  13. 'whose pillars on troubles were based.' + LineEnding +
  14. 'Now mischievous spirits, bound,' + LineEnding +
  15. 'in dim corners stand,' + LineEnding +
  16. 'Rotted columns, but' + LineEnding +
  17. 'with iron-bound bands embraced' + LineEnding +
  18. 'Cracked, crumbling marble,' + LineEnding +
  19. 'tempered on every hand,' + LineEnding +
  20. 'By strong steel' + LineEnding +
  21. 'forged in fire and faith.' + LineEnding +
  22. 'Shackled, these wayward servants' + LineEnding +
  23. 'serve the land,' + LineEnding +
  24. 'The Temple secured' + LineEnding +
  25. 'by the Builder’s grace.';
  26. end1:
  27. writeln(Copy(s, 1, 0), PtrUint(CodePointer(@end1) - CodePointer(@start1)), ' b of code');
  28. { more than 100 bytes of code might point out that the constants are not folded }
  29. if PtrUint(CodePointer(@end1) - CodePointer(@start1))>100 then
  30. halt(1);
  31. writeln;
  32. writeln('1 dynamic string concatenated with 31 literals, they could fold but didn''t at all:');
  33. start2:
  34. s := Copy('', 1, 0) +
  35. 'Once like a Great House' + LineEnding +
  36. 'founded on sand,' + LineEnding +
  37. 'Stood our Temple' + LineEnding +
  38. 'whose pillars on troubles were based.' + LineEnding +
  39. 'Now mischievous spirits, bound,' + LineEnding +
  40. 'in dim corners stand,' + LineEnding +
  41. 'Rotted columns, but' + LineEnding +
  42. 'with iron-bound bands embraced' + LineEnding +
  43. 'Cracked, crumbling marble,' + LineEnding +
  44. 'tempered on every hand,' + LineEnding +
  45. 'By strong steel' + LineEnding +
  46. 'forged in fire and faith.' + LineEnding +
  47. 'Shackled, these wayward servants' + LineEnding +
  48. 'serve the land,' + LineEnding +
  49. 'The Temple secured' + LineEnding +
  50. 'by the Builder’s grace.';
  51. end2:
  52. writeln(Copy(s, 1, 0), PtrUint(CodePointer(@end2) - CodePointer(@start2)), ' b of code');
  53. { more than 100 bytes of code might point out that the constants are not folded,
  54. example x86_64-linux: not folded: 639 bytes; folded: 76 bytes
  55. }
  56. if PtrUint(CodePointer(@end2) - CodePointer(@start2))>100 then
  57. halt(2);
  58. writeln;
  59. writeln('16 literals concatenated with 1 dynamic string and 15 more literals, first 16 folded but last 15 did not:');
  60. start3:
  61. s :=
  62. 'Once like a Great House' + LineEnding +
  63. 'founded on sand,' + LineEnding +
  64. 'Stood our Temple' + LineEnding +
  65. 'whose pillars on troubles were based.' + LineEnding +
  66. 'Now mischievous spirits, bound,' + LineEnding +
  67. 'in dim corners stand,' + LineEnding +
  68. 'Rotted columns, but' + LineEnding +
  69. 'with iron-bound bands embraced' + LineEnding +
  70. Copy('', 1, 0) +
  71. 'Cracked, crumbling marble,' + LineEnding +
  72. 'tempered on every hand,' + LineEnding +
  73. 'By strong steel' + LineEnding +
  74. 'forged in fire and faith.' + LineEnding +
  75. 'Shackled, these wayward servants' + LineEnding +
  76. 'serve the land,' + LineEnding +
  77. 'The Temple secured' + LineEnding +
  78. 'by the Builder’s grace.';
  79. end3:
  80. writeln(Copy(s, 1, 0), PtrUint(CodePointer(@end3) - CodePointer(@start3)), ' b of code');
  81. { more than 300 bytes of code might point out that the constants are not folded,
  82. example x86_64-linux: not folded: 369 bytes; folded: 120 bytes
  83. }
  84. if PtrUint(CodePointer(@end3) - CodePointer(@start3))>300 then
  85. halt(3);
  86. writeln;
  87. writeln('ok');
  88. end.