7. The Squash Options

7.1 General and introduction

StrongBS provides a large number of options that can be used to reduce the size of a BASIC program. Some 60+ options are available. The purpose of this Chapter is to briefly explain what each option does.

Squash Options are divided into 10 categories:

  1. Assembler
  2. Routines.
  3. Variables.
  4. Conversion.
  5. Concatenation.
  6. Removal.
  7. Remarks.
  8. Constructs.
  9. Miscellaneous.
  10. Make faster.

Although, in the following description, use is made of the words remove, convert, etc., StrongBS will only perform an operation such as removal of a code or conversion of a token, etc., if the test conditions which apply to the particular operation are met. For example when removing brackets, StrongBS will test the mathematical operator priority of each operator inside and outside the brackets. StrongBS also makes allowance for bugs in the current versions of the BASIC interpreter (or as Acorn prefer to call them "features") and will ensure that the result BASIC file runs correctly.

The following description does not explain HOW StrongBS does it, it only gives a brief description of what each option means and what are the expected results. It is assumed that you are familiar with BASIC and the BASIC assembler.

7.2 Assembler Squash Options

This category provides 11 squashing options. These options will only work on assembler listings inside a BASIC program. Although BASIC programs are very rarely distributed with an assembler source code, if you decide to distribute the source code because the program needs to generate the code at run time then StrongBS will aid in compressing the assembler listing.

7.2.1 Remove assembler remarks
This option will remove all remarks inside an assembler listing. Remarks in the main program (outside and assembler) will not be removed.
7.2.2 Remove zero shifts
This will remove LSL #0, LSR #0 and ASR #0 in the assembler listing.
7.2.3 Remove ALIGN directives
Unnecessary ALIGN directives found in the assembler listing will be removed. An ALIGN directive is not required, if it is followed by an instruction.
7.2.4 Convert register names
All register names in the form of R0, R1, PC etc will be converted into the register number form, i.e. 0, 1, 15 etc..

Note: This option is automatically selected if you select the "Variables Renaming" option, as register name are considered by StrongBS another form of variables!

7.2.5 Convert SWI name
All SWI names in an assembler listing will be converted into their SWI number equivalents.

SWI names that can not be converted will be left as is. Therefore, if a SWI name is only existent in a module that is not currently loaded, all SWI names for the that module will not be changed. You will have to load the module before compressing the BASIC program. StrongBS will not complain about the non-existence of the module.

7.2.6 Convert directives
This option allows all assembler directives in the form EQUD, EQUB and EQUW to be converted into DCD, DCB, DCW respectively.
7.2.7 Convert zero offset
This will convert all occurrences of zero offsets in load and store instructions into the shortest form.

LDR R0,[R1,#0] -----> LDR R0,[R1]
LDR R0,[R1],#0 -----> LDR R0,[R1]

Note: Due to what seems to be a bug in the BASIC assembler, the LDRT Rd,[Rn],#0 or STRT Rd,[Rn],#0 will not be converted as the BASIC assembler will treat the shorter instructions differently.

7.2.8 Convert register list
This option is not yet enabled in this version of StrongBS.

Once enabled, the option will allow converting a register list in the STM and LDM instructions into the shortest form.

LDMFD R13!,{R0,R1,R2,PC} ------> LDMFD R13!,{R0-R2,PC}

7.2.9 Convert to shortest directives
This will convert all EQUD, EQUB, EQUW, EQUS, DCD, DCB and DCW into the shortest form using the "&" and "=" directives.

EQUS ------> =
EQUD or DCD ------> &
EQUB or DCB ------> =
EQUW or DCW ------> =

7.2.10 Concatenate directives
This option will reconstruct all those directives by assembling the directives and de-assembling them back into the shortest possible form. It can cope with all type of directives and the CHR$ keyword. With long directive listings, this can produce a very short and compact BASIC programs.
7.2.11 Assemble into Code
This option will convert (assemble) all ARM instructions into the equivalent 32-bit value and use the & directive in place with the instruction. For example:

MOV R0,R1,LSL #2 becomes &&E1A00101
LDMFD R13!,{R0-R12,PC} becomes &&E8FD9FFF
ORREQ R10,R10,R11,LSL #8 becomes &&018AA40B

7.3 Routines Squash Options

Five options are provided that work on procedures and function.
7.3.1 Rename functions
This will rename functions using the shortest possible string. One or two character names are used, with shorter names allocated to the most frequently used functions.
7.3.2 Rename procedures
This will rename procedures using the shortest possible string. One or two character names are used, with shorter names allocated to the most frequently used procedures.
7.3.3 Remove unused functions
A function definition that is not called in the main program or any Library file will cause the complete function to be removed.
7.3.4 Remove unused procedures
A procedure definition that is not called in the main program or any Library file will cause the complete procedure to be removed.
7.3.5 Remove empty procedure
This option will remove empty procedure.

7.4 Variables Squash Options

Ten options are provided that work on all type of variables.
7.4.1 Rename Integer variables
Integer variables are renamed using one or two character variable names.
7.4.2 Rename Real variables
Real variables are renamed using one or two character variable names.
7.4.3 Rename String variables
String variables are renamed using one or two character variable names.
7.4.4 Rename Integer arrays
Integer array variables are renamed using one or two character names.
7.4.5 Rename Real arrays
Real array variables are renamed using one or two character variable names.
7.4.6 Rename String arrays
String array variables are renamed using one or two character variable names.
7.4.7 Rename vars in DATA lines
This option renames variables found inside DATA lines. 99% of the time this is OK. However, it is possible that DATA lines contain data which although not being a variable is identical to a variable name in the program. For this purpose and only in this rare situation you can disable this option.

One example application that I have come across is the Acorn !Maestro application. If you want to squash the !RunImage file of this application then this Option should be selected off.

7.4.8 Remove unused variables
Unused variables are those that are only encountered once in the program, ie defined but not used. There are exceptions where some variables which fall into this description will not be removed as they will be required for proper program execution.

StrongBS will, depending on the unused variable location, either remove the variable only or remove the whole statement or the complete line.

7.4.9 Remove constant integers
Constant integer variables are replaced with their value.

Example:

10 top%=1
20 val%=3
30 result%=top%+val%

becomes

30 result%=1+3

The variables top% and val% and lines 10 and 30 are removed.

7.4.10 Remove constant reals
Constant real variables are replaced with their value.

Example:

10 start=100
20 end =300
30 final=start+end

becomes

30 final=100+300

The variables 'start' and 'end' and lines 10 and 30 are removed.

7.5 Conversion Squash Options

Ten options are currently provided in this category. Another 2 options will be enabled in the next releases of StrongBS.
7.5.1 SYS names to numbers
All SWI names in a SYS statement will be converted into their SWI number equivalents.

SWI names that can not be converted will be left as is. Therefore, if a SWI name is only existent in a module that is not currently loaded, all SWI names for the that module will not be changed. You will have to load the module before compressing the BASIC program. StrongBS will not complain about the non-existence of the module.

7.5.2 CHR$ to string
This will convert a CHR$ into a string provided the result string can be joined to the end or the start of an existing string, or the new string is shorter than the original.
7.5.3 ASC" " to number
This will convert an ASC into the equivalent ASCII code.
7.5.4 NEXT to NEXT or NEXT,,
This option all cause any optional variable after the NEXT keyword to be removed. Also repeated NEXT statements on the same line or multi-lines will be concatenated.
7.5.5 -1 to TRUE
The integer -1 is replaced with the BASIC token TRUE whenever possible.
7.5.6 Numbers to shortest form
This option will convert numbers into the shortest representation. It can cope with decimal, hexadecimal, binary and shifted numbers. The shortest form of the 4 possible representation will be used.
7.5.7 Memory operators to shortest
Memory indirection operators such as ? and ! will be converted into the shortest possible form.

Examples:

pointer%?0=A% ----> ?pointer%=A%
pointer%!0=A% ----> !pointer%=A%
?(pointer%+3)=A% ----> pointer%?3=A%
!(pointer%+4)=A% ----> pointer%!4=A%

7.5.8 Repeated spaces to SPC
Repeated spaces in a string will be converted into SPC.
7.5.9 Repeated chars to STRING$
Repeated characters in a string will be converted into STRING$.
7.5.10 *FX to SYS "OS_Byte"
This option will convert *FX calls into their equivalent SYS call using SYS "OS_Byte" or SYS 6.

7.6 Concatenation Squash Options

Nine options are currently provided in this category.
7.6.1 Concatenate Lines
This option will join all lines and statements to produce multi statements per line.
7.6.2 Concatenate LOCAL lines
This option joins together all LOCAL statements and LOCAL lines.
7.6.3 Concatenate DIM lines
This option joins together all DIM statements and DIM lines.
7.6.4 Concatenate DATA lines
This option joins together all DATA statements and DATA lines.
7.6.5 Concatenate IF...ENDIF lines
This option will convert multi-line IF...THEN...ELSE...ENDIF into a single IF..THEN..ELSE statements.
7.6.6 Concatenate strings
This option concatenates strings in the form + into one string.
7.6.7 Concatenate READ statements
This option joins together all READ statements and READ lines.
7.6.8 Concatenate VDU statements
This option joins together all VDU statements and VDU lines.
7.6.9 Concatenate PRINT statements
This will convert multi PRINT statements into the shortest form.

7.7 Removal Squash Options

Fifteen options are currently provided.
7.7.1 Removal of remarks
This will remove all REMark lines in the main program and in any attached libraries. It will also cope with *Command remarks.
7.7.2 Removal of garbage lines
Garbage lines are those between procedures and at other locations that will never be reached by the program code. These are removed. StrongBS will also remove garbage lines in between BASIC program code which are normally skipped by the program either by use of GOTO's or other constructs.

A line is not removed if it is referenced by another part of the program.

7.7.3 Removal of blank lines
Blank (empty) lines are removed.

A line is not removed if it is referenced by another part of the program.

7.7.4 Removal of spaces
Unnecessary spaces are removed.
7.7.5 Removal of brackets
Unnecessary brackets are removed.

Examples:

Z%=Y%+(1+2*3) ----> Z%=Y%+1+2*3
X%=(Y%+1)>>1 ----> X%=Y%+1>>1
X%=-(A%+B%*4-5+10) ----> X%=-A%-B%*4+5-10

X%=Y%-(A%+B%-(Z%+C%-(C%+2*-6)+4)+A%*X%)
becomes:
X%=Y%-A%-B%+(Z%+C%-C%+2*-6+4)-A%*X%

7.7.6 Removal of colons
Unnecessary colons between statements and between lines are removed.
7.7.7 Removal of fractions
Unnecessary fractional parts in floating point (real) number are removed. Example:

X=0.0 becomes X=0
X=0.1200 becomes X=.12

7.7.8 Removal of "not equal" sign
The unnecessary "<>0" sign is removed if found in IF, WHILE and UNTIL statements. Examples:
IF var<>0 THEN becomes IF var THEN
WHILE var<>0 .... becomes WHILE var ....
UNTIL var<>0 becomes UNTIL var

7.7.9 Removal of THEN
The "THEN" in a single line IF..THEN..ELSE is optional and will be removed if found.

The exception is that if ELSE is followed by a *Command

7.7.10 Removal of LEN
This option is not yet enabled in this version of StrongBS.
7.7.11 Removal of LET
The redundant LET is removed if found.
7.7.12 Removal of STEP
This option removes "STEP 1" in FOR...NEXT loops.

Example:

10 FOR loop%=0 TO 1000 STEP 1

becomes:

10 FOR loop%=0 TO 1000

7.7.13 Removal of SYS
This option removes unnecessary 0's in SYS calls. For example:

SYS "OS_xxx",0 becomes SYS "OS_xxx"
SYS "OS_xxx",A%,0 becomes SYS "OS_xxx",A%
SYS "OS_xxx",0,A% becomes SYS "OS_xxx",,A%
etc...

7.7.14 Removal of debug code
Any lines bracketed between the identifiers "REM --[" and "REM ]--" will be removed.
7.7.15 Removal of +/- assignments
This will remove unnecessary +0 or -0 in assignments. Examples:

X%=Y%+0 becomes X%=Y%
Y=Z-0 becomes Y=Z
etc...

7.8 Remarks Squash Options

7.8.1 Keep first REM line
This option will only only the First REMark line to be preserved. All other REMark lines will be removed, is the "Remove REMarks" option has been selected.
7.8.2 Keep initial REM lines
This option allows ALL REMark lines appearing at the start of a BASIC program to be preserved, and will appear in the final output file.
7.8.3 Keep REM starting with
This option allows REMark lines starting with a sequence of text or characters to be preserved everywhere in the program, and hence will not be removed.
7.8.4 Insert REMarks file
This allows a BASIC program file to be inserted at the start of the compressed output file. These will normally be BASIC files containing remark lines, but can be any BASIC file. The file is selectable from a list of files contained in the REMInsert directory. Only one file can be selected.

7.9 Constructs Squash Options

7.9.1 Remove empty IF constructs
Empty IF..THEN..ENDIF constructs are removed.
7.9.2 Remove empty CASE construct
Empty CASE...ENDCASE constructs are removed.
7.9.3 Remove duplicate WHEN statements
This option is not yet enabled in this version of StrongBS.
7.9.4 Remove empty WHEN statements
Empty WHEN statements in CASE...ENDCASE constructs are removed.
7.9.5 Remove empty OTHERWISE statements
Empty OTHERWISE statements in CASE...ENDCASE constructs are removed.
7.9.6 Convert CASE to IF construct
Converts a CASE...ENDCASE construct into the equivalent IF..ENDIF construct which is faster to execute..!!
7.9.7 Concatenate WHEN statements
This option is not yet enabled in this version of StrongBS.

7.10 Miscellaneous Squash Options

7.10.1 Evaluate integers
This option allows mathematical expressions to evaluated to produce a shorter equivalent.

Examples:

X=-4<<6 ----> X=-256
Y=Y OR -32+4 ----> Y=Y OR -28
M%=A%*100/2 ----> M%=A%*50
X%=P%+2*1024+25 ----> X%=P%+2073

4.10.2 SYS "OS_SWINumberFromString" to variable
This option will perform the function of converting the SWI string to a number and assigning it to the variable.

Examples:

10 SYS "OS_SWINumberFromString",,"OS_Write0" ¸ Write0
20 SYS "OS_SWINumberFromString",,"OS_WriteC" ¸ WriteC
30 SYS "OS_SWINumberFromString",,"OS_ReadMonotonicTime" , time


become:

10 Write0=2
20 WriteC=0
30 time=66

7.10.3 Line numbering
This option will re-number the program with increments of 10 or which ever is suitable for the particular size and number of lines in the program.
7.10.3 Insert Squash info
This will insert the line:

REM Squashed by StrongBS v.vv on dd mmm yyyy

at the start of the output file.

7.11 Make Faster

7.11.1 Convert 0 to FALSE
This will convert any 0 into the FALSE token. 0's inside assembler listings and *Commands will not be converted.
7.11.2 Convert DIV to >>>
This option is not yet enabled in this version of StrongBS.
7.11.3 Convert AND to IF
This option is not yet enabled in this version of StrongBS.
7.11.4 Convert real vars to integers
This option is not yet enabled in this version of StrongBS.