A new optimisation feature, Conditional Compilation, has been developed for the next feature release of Astrobe. Sections of code are now eliminated from the executable if they are included in an IF statement controlled by a BOOLEAN value declared in a CONST declaration as FALSE. The end result uses less memory and can result in improved performance.
This feature could have been implemented in a number of different ways but some of the advantages of this solution are that it is requires no change to the Oberon Language and can benefit existing source code without requiring any modifications.
The following is an example of how the feature can be exploited. This technique is particularly useful as it does not require any source code to be edited to switch from the test version of an application to the release version:
1. Implement a module e.g. Trace which includes a constant declaration enabled and a number of procedures to handle diagnostic information e.g.:
Code: Select all
MODULE Trace;
CONST
enabled* = TRUE;
PROCEDURE Message*(s: ARRAY OF CHAR);
...
...
Code: Select all
IMPORT Trace;
...
IF Trace.enabled THEN Trace.Message("Init started") END;
3. Implement two versions of the Trace module, each in a separate folder. The release folder has the one with enabled set TRUE and a full implementation of each diagnostic procedure. The test folder has the one with enabled set FALSE and an empty body for each diagnostic procedure.
4. Create two configuration files for your application: a release configuration with a search path that includes the release folder and a test configuration file with a search path that includes the test folder. Use the appropriate one when you compile and link your application.
If you then need to check whether or not your code has been optimised:
- At the module level, the disassembler listings clearly show statements for which no code has been generated.
- At the application level the map file shows which folder contained the trace module that was actually linked.