[fpc-devel] Question about $OPTIMIZATION LEVELn

Martok listbox at martoks-place.de
Wed Jan 17 21:03:36 CET 2018


Am 17.01.2018 um 16:38 schrieb Jonas Maebe:
> The LevelX switches are only intended for internal use by the compiler, 
> and were never intended to be exposed.
Good, that's what I thought too.

> The ability to have the equivalent of 
> -O1/-O2/-O3/-O4 in source code was never planned.
Florian wrote in 0025873,
> But there is indeed no equivalent for -O3/4 at source level ({$optimizations on} equals to -O2). I'am open for suggestions how such a directive should look like. 

May I propose to redefine {$optimization levelN} to do that? Reasons:
a) we agree the flags alone (should) have no use
b) it's always been documented that way
c) it's used as if that was true in live code

Rough patch attached...

-- 
Regards,
Martok

Ceterum censeo b32079 esse sanandam.
-------------- next part --------------
Index: scandir.pas
===================================================================
--- scandir.pas	(revision 37943)
+++ scandir.pas	(working copy)
@@ -1039,17 +1039,20 @@
         current_scanner.skipspace;
         { Support also the ON and OFF as switch }
         hs:=current_scanner.readid;
-        if (hs='ON') then
-          current_settings.optimizerswitches:=level2optimizerswitches
-        else if (hs='OFF') then
-          current_settings.optimizerswitches:=[]
-        else if (hs='DEFAULT') then
-          current_settings.optimizerswitches:=init_settings.optimizerswitches
+        case hs of
+          'OFF': current_settings.optimizerswitches:=[];
+          'ON': current_settings.optimizerswitches:=level2optimizerswitches;
+          'DEFAULT': current_settings.optimizerswitches:=init_settings.optimizerswitches;
+          'LEVEL1': current_settings.optimizerswitches:=level1optimizerswitches;
+          'LEVEL2': current_settings.optimizerswitches:=level2optimizerswitches;
+          'LEVEL3': current_settings.optimizerswitches:=level3optimizerswitches;
+          'LEVEL4': current_settings.optimizerswitches:=level4optimizerswitches;
         else
           begin
             if not UpdateOptimizerStr(hs,current_settings.optimizerswitches) then
               Message1(scan_e_illegal_optimization_specifier,hs);
           end;
+        end;
       end;
 
     procedure dir_overflowchecks;


More information about the fpc-devel mailing list