Commit fb4d42dd authored by Jeffrey Lee's avatar Jeffrey Lee
Browse files

Reconstruct Squish sources by un-squishing the v1.12 binary

Detail:
  This is some reconstructed sources for the Squish tool, formed by running the 1.12 binary through Beebug's/ProAction's !BasFormat, and then fixing up a few extra bits by hand.
  Most of FNs and PROCs have had meaningful names applied to them, making the sources more readable. However only a couple of the variables have been renamed.
  The test script (Test/Squish,feb) was used to verify that this new squish (after being re-squished) produces identical output to the original binary.
  Note that squishing these sources won't produce a binary identical to the original, as the original appears to have been modified post-squishing in order to add PROCknockoutkept.
Admin:
  Tested against original Squish binary for Disc & BCM2835 builds
  Version number is currently hardcoded in sources; build procedure needs updating to take it from VersionNum


Version 1.13. Tagged as 'Squish-1_13'
parent 1890b125
| Copyright 2012 Castle Technology Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine all
| Copyright 2012 Castle Technology Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine clean
| Copyright 2012 Castle Technology Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
Dir <Obey$Dir>
amu_machine install INSTDIR=<install$dir>.HardDisc4.Utilities
bas/** gitlab-language=bbcbasic linguist-language=bbcbasic linguist-detectable=true
*,ffb gitlab-language=bbcbasic linguist-language=bbcbasic linguist-detectable=true
# Copyright 2012 Castle Technology Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Makefile for Squish
#
#
# Program specific options:
#
COMPONENT = Squish
MSGVERSION = ${AWK} -f Build:AwkVers
# Generic options:
#
AWK = GNU.gawk
MKDIR = do mkdir -p
CC = cc
CP = copy
NUMBER = util.Number
RM = remove
SQUISH = squish
XWIPE = x wipe
CFLAGS = -c++ -IC:,^ ${THROWBACK} ${DFLAGS}
CRFLAGS = %11111
CPFLAGS = ~cfr~v
SQFLAGS = -nolist
WFLAGS = ~c~v
FILES =\
squished.${COMPONENT}
#
# Generic build rules:
#
all: $(FILES)
@echo $(COMPONENT): all build complete
install: $(FILES)
${CP} squished.${COMPONENT} ${INSTDIR}.${COMPONENT} ${CPFLAGS}
@echo $(COMPONENT): installed
clean:
${XWIPE} squished ${WFLAGS}
${XWIPE} crunched ${WFLAGS}
${XWIPE} n ${WFLAGS}
@echo $(COMPONENT): cleaned
#
# Static dependencies:
#
squished.${COMPONENT}: crunched.${COMPONENT} bas.Keep
${MKDIR} squished
$(SQUISH) $(SQFLAGS) -keep bas.Keep -from crunched.${COMPONENT} -to $@
crunched.${COMPONENT}: n.${COMPONENT}
${MKDIR} crunched
crunch.${COMPONENT}; BASIC
n.${COMPONENT}: bas.${COMPONENT}
${MKDIR} n
${NUMBER} bas.${COMPONENT} $@
#---------------------------------------------------------------------------
# Dynamic dependencies:
| Copyright 2012 Castle Technology Ltd
|
| Licensed under the Apache License, Version 2.0 (the "License");
| you may not use this file except in compliance with the License.
| You may obtain a copy of the License at
|
| http://www.apache.org/licenses/LICENSE-2.0
|
| Unless required by applicable law or agreed to in writing, software
| distributed under the License is distributed on an "AS IS" BASIS,
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
| See the License for the specific language governing permissions and
| limitations under the License.
|
| Script to test if two different versions of Squish produce the same output
| Rename existing Library.Build.Squish to OldSquish, copy in your new version
| as NewSquish, and add this script as Squish.
| Note - errors probably won't halt the build, so it's best to check the log
| manually rather than relying on the build failing.
unset squish$output
set squish$temp x%1
if "<squish$temp>"="x-to" then set squish$output copy %2
set squish$temp x%2
if "<squish$temp>"="x-to" then set squish$output copy %3
set squish$temp x%3
if "<squish$temp>"="x-to" then set squish$output copy %4
set squish$temp x%4
if "<squish$temp>"="x-to" then set squish$output copy %5
set squish$temp x%5
if "<squish$temp>"="x-to" then set squish$output copy %6
set squish$temp x%6
if "<squish$temp>"="x-to" then set squish$output copy %7
set squish$temp x%7
if "<squish$temp>"="x-to" then set squish$output copy %8
set squish$temp x%8
if "<squish$temp>"="x-to" then set squish$output copy %9
if "<squish$output>"="" then error Unable to find output file
echo newsquish %*1
newsquish %*1 { > <wimp$scrapdir>.newsquishout }
do <squish$output> <wimp$scrapdir>.newsquish ~CFR~V
echo oldsquish %*1
oldsquish %*1 { > <wimp$scrapdir>.oldsquishout }
do <squish$output> <wimp$scrapdir>.oldsquish ~CFR~V
gnu.diff -q <wimp$scrapdir>.oldsquish <wimp$scrapdir>.newsquish
if "<sys$returncode>"<>"0" then error Squished output differs
/* (1.12)
/* (1.13)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.12
#define Module_MajorVersion_CMHG 1.13
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 28 Aug 2012
#define Module_MajorVersion "1.12"
#define Module_Version 112
#define Module_MajorVersion "1.13"
#define Module_Version 113
#define Module_MinorVersion ""
#define Module_Date "28 Aug 2012"
......@@ -18,6 +18,6 @@
#define Module_ComponentName "Squish"
#define Module_ComponentPath "castle/RiscOS/Tools/Sources/Squish"
#define Module_FullVersion "1.12"
#define Module_HelpVersion "1.12 (28 Aug 2012)"
#define Module_LibraryVersionInfo "1:12"
#define Module_FullVersion "1.13"
#define Module_HelpVersion "1.13 (28 Aug 2012)"
#define Module_LibraryVersionInfo "1:13"
A%
B%
C%
D%
E%
F%
G%
H%
P%
@%
REM Copyright 2012 Castle Technology Ltd
REM
REM Licensed under the Apache License, Version 2.0 (the "License");
REM you may not use this file except in compliance with the License.
REM You may obtain a copy of the License at
REM
REM http://www.apache.org/licenses/LICENSE-2.0
REM
REM Unless required by applicable law or agreed to in writing, software
REM distributed under the License is distributed on an "AS IS" BASIS,
REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
REM See the License for the specific language governing permissions and
REM limitations under the License.
REM
REM>squished.Squish
ON ERROR REPORT:PRINT " (internal error ";ERL;")":END
l$="v1.12 21-Jan-94"
DIM aa% 1000
ba%=HIMEM-END-32768
DIM z% ba%
ca%=3
FOR A=0 TO 2 STEP 2
P%=aa%
[ OPT A
; call BASIC internal routine tokenaddr
.e
STMFD R13!,{R14}
ADD R2,R14,#19*4 ; tokenaddr
ADR R14,i
ADR R12,f
MOV PC,R2
.i
STR R1,c
LDMFD R13!,{PC}
.c EQUD 0 ; tokenaddr result
.f EQUD 0 ; Fake LINE buffer used by tokenaddr
; Identifiers are stored in a linked list in the following format:
; bytes 0-3 = address of next identifier, 0 for none
; byte 4 = usage count
; bytes 5+ = identifier name, CR-terminated
.asm_add_identifier
.asm_add_identifier_ident_loop
STR R0,d
ADR R2,b
ADD R1,R0,#5
.asm_add_identifier_char_loop
LDRB R3,[R2],#1
LDRB R4,[R1],#1
TEQ R3,R4
BNE asm_add_identifier_next_ident
TEQ R3,#13
BNE asm_add_identifier_char_loop
; Match found, increase usage count
LDRB R3,[R0,#4]
ADD R3,R3,#1
TEQ R3,#256
STRNEB R3,[R0,#4]
STR R0,g
MOV R3,#1
STR R3,d
MOV PC,R14
.asm_add_identifier_next_ident
LDR R0,[R0]
TEQ R0,#0
BNE asm_add_identifier_ident_loop
MOV PC,R14
.b EQUS STRING$(206,"*") ; buffer to store string to match
ALIGN
EQUD 0
.d EQUD 0 ; address of found identifier, or where to store link to new identifier
.g EQUD -1 ; 1 = identifier found, 0 = identifier not found
]
NEXT A
x%=1
g%=-1
o%=0
da%=0
Q%=0
ea%=FALSE
Z%=TRUE
_%=0
`%=0
fa%=FALSE
m$=""
j$=""
PROCprocess_args(F$,f$)
IF F$="" INPUT "Input file: "F$
IF f$="" INPUT "Output file: "f$
SYS "OS_File",255,F$,z% TO,,ga%,ha%,ia%
ja%=(z%+ia%+256) AND NOT 3
ka%=ja%
la%=z%+ba%
IF FNtoupper(f$)=FNtoupper(F$) THEN
VDU 7
INPUT LINE "Output file same name as input - sure? "u$
IF INSTR("YES",FNtoupper(u$))<>1 THEN END
ENDIF
IF g%>0 g%=OPENOUT (n$):IF g%=0:ERROR 1,"Can't open log file"
IF o% o%=OPENOUT (o$):IF o%=0 ERROR 1,"Can't open literal log file"
ON ERROR REPORT:PRINT " (internal error ";ERL;")":PROCtidyup:END
IF g%<0 AND ea%<>0:MODE 12:COLOUR 0,7:COLOUR 7,0
c$="Squish ("+l$+") squishing program '"+F$+"' to '"+f$+"'"
PROClog_nl
PROClog_str(c$)
PROClog_nl
PROClog_nl
IF g%>=0 PRINT'c$
TIME=0
PROClog_str("Scanning for variable names....")
PROClog_nl
R%=FNnew_identifier_list
B%=FNnew_identifier_list
D%=FNnew_identifier_list
S%=FNnew_identifier_list
F%=FNnew_identifier_list
G%=FNnew_identifier_list
T%=FNnew_identifier_list
U%=FNnew_identifier_list
ma%=FNnew_identifier_list
H%=0
J%=0
d%=z%
d$="@abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_`0123456789"
g$="@abcdefghijklmnopqrstuvwxyzABCDFGHIJKLMNOPQRSTUVWXZ_`0123456789"
w$="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+CHR$ 128+CHR$ 130+CHR$ 132+CHR$ 236
ON ERROR REPORT:PRINT " (internal error ";ERL;")":PRINT "Line number in original = ";H%+256*J%:PROCtidyup:END
PROCread_program
c$="Source program read: errors "+STR$ (`%)+", warnings "+STR$ (_%)
PROClog_nl
PROClog_str(c$)
IF g%>=0 PRINT'c$
IF `%<>0 OR (x%=2 AND _%<>0) THEN
c$="** Conversion aborted: no output file produced."
PROClog_nl
PROClog_nl
PROClog_str(c$)
PROClog_nl
IF g%>=0 PRINT'c$
PROCtidyup
END
ENDIF
x%=-1
ON ERROR REPORT:PRINT " (internal error ";ERL;")":PROCtidyup:END
PROCknockoutkept(R%,"","")
PROCknockoutkept(B%,"","%")
PROCknockoutkept(D%,"","$")
PROCknockoutkept(S%,"","()")
PROCknockoutkept(F%,"","%()")
PROCknockoutkept(G%,"","$()")
PROCknockoutkept(U%,"PROC","")
PROCknockoutkept(T%,"FN","")
PROClog_nl
PROClog_nl
PROClog_str("Allocating single letter variables....")
PROClog_nl
PROCallocate_single_letter(R%)
PROCallocate_single_letter(B%)
PROCallocate_single_letter(D%)
PROCallocate_single_letter(S%)
PROCallocate_single_letter(F%)
PROCallocate_single_letter(G%)
PROCallocate_single_letter(T%)
PROCallocate_single_letter(U%)
PROClog_nl
PROClog_nl
PROClog_str("Allocating double letter variables....")
PROClog_nl
PROCallocate_double_letter(R%)
PROCallocate_double_letter(B%)
PROCallocate_double_letter(D%)
PROCallocate_double_letter(S%)
PROCallocate_double_letter(F%)
PROCallocate_double_letter(G%)
PROCallocate_double_letter(T%)
PROCallocate_double_letter(U%)
PROClog_colour(7)
PROClog_nl
PROClog_str("Creating squished code....")
PROClog_nl
ON ERROR REPORT:PRINT " (internal error ";ERL;")":PRINT "Line number in original = ";H%+256*J%:PROCtidyup:END
PROCwrite_program
PROClog_colour(7)
c$="Program '"+F$+"' squished to '"+f$+"' on "+MID$( TIME $,5,11)+" at "+MID$( TIME $,17)
PROClog_nl
PROClog_nl
PROClog_str(c$)
PROClog_nl
IF g%>=0 PRINT'c$'
c$="Errors : "+STR$ (`%)
PROClog_nl
PROClog_str(c$)
IF g%>=0 PRINT c$
c$="Warnings : "+STR$ (_%)
PROClog_nl
PROClog_str(c$)
IF g%>=0 PRINT c$
c$="Original length : &"+STR$~(ia%)
PROClog_nl
PROClog_str(c$)
IF g%>=0 PRINT c$
c$="New length : &"+STR$~(j%+2-V%)
PROClog_nl
PROClog_str(c$)
IF g%>=0 PRINT c$
c$="Saving : &"+STR$~(ia%-(j%+2-V%))
PROClog_nl
PROClog_str(c$)
IF g%>=0 PRINT c$
c$="Size of squished program is "+STR$ (((j%+2-V%)*100) DIV ia%)+"% of original"
PROClog_nl
PROClog_nl
PROClog_str(c$)
PROClog_nl
IF g%>=0 PRINT'c$'
t%=TIME
c$="Time Taken : "+STR$ (t% DIV 6000)+" mins, "+STR$ ((t% MOD 6000) DIV 100)+" secs"
PROClog_nl
PROClog_str(c$)
PROClog_nl
IF g%>=0 PRINT c$
PRINT "List of little used integers ..."
PROClist_identifiers(B%)
PRINT "List of little used integer arrays ..."
PROClist_identifiers(F%)
PRINT "List of little used strings ..."
PROClist_identifiers(D%)
PRINT "List of little used string arrays ..."
PROClist_identifiers(G%)
PROCtidyup
END
DEF PROCread_program
d%=z%
l%=0
WHILE d%?1<>255
J%=d%?1
H%=d%?2
na%=d%?3
q%=na%+d%
d%+=4
W%=0
v%=0
oa%=0
K%=0
f%=0
k%=0
r%=TRUE
WHILE d%<q% AND f%<>8
PROCget_token
CASE f% OF
WHEN 1
IF fa%=FALSE OR NOT (FNkeep_identifier(b$)) THEN
IF FNadd_identifier(b$,R%):PROClog_str(b$):PROClog_tab
ENDIF
IF x%>0 THEN PROCerror(FALSE,"Found real '"+b$+"'")
WHEN 2
IF j$<>"" AND LEN (b$)=1 AND b$>="@" AND b$<="Z" THEN
ELSE
IF fa%=FALSE OR NOT (FNkeep_identifier(b$+"%")) THEN
IF FNadd_identifier(b$,B%):PROClog_str(b$+"%"):PROClog_tab
ENDIF
ENDIF
WHEN 3
IF fa%=FALSE OR NOT (FNkeep_identifier(b$+"$")) THEN
IF FNadd_identifier(b$,D%):PROClog_str(b$+"$"):PROClog_tab
ENDIF
WHEN 4
IF fa%=FALSE OR NOT (FNkeep_identifier(b$+"()")) THEN
IF FNadd_identifier(b$,S%):PROClog_str(b$+"("):PROClog_tab
ENDIF
WHEN 12
IF fa%=FALSE OR NOT (FNkeep_identifier(b$+"%()")) THEN
IF FNadd_identifier(b$,F%):PROClog_str(b$+"%("):PROClog_tab
ENDIF
WHEN 13
IF fa%=FALSE OR NOT (FNkeep_identifier(b$+"$()")) THEN
IF FNadd_identifier(b$,G%):PROClog_str(b$+"$("):PROClog_tab
ENDIF
WHEN 5
IF fa%=FALSE OR NOT (FNkeep_identifier("PROC"+b$)) THEN
IF FNadd_identifier(b$,U%):PROClog_str("PROC"+b$):PROClog_tab
ENDIF
WHEN 6
IF fa%=FALSE OR NOT (FNkeep_identifier("FN"+b$)) THEN
IF FNadd_identifier(b$,T%):PROClog_str("FN"+b$):PROClog_tab
ENDIF
WHEN 7
WHEN 10
IF b$=""""v%=NOT v%
ENDCASE
r%=0
IF v%=0 THEN
IF f%=0 THEN
IF b$=CHR$ 223 OR b$=CHR$ 236 OR b$=CHR$ 200+CHR$ 146 OR b$=CHR$ 200+CHR$ 144:K%=1
IF Z% AND (b$=CHR$ 200+CHR$ 153) THEN
WHILE ?d%=32
d%+=1
ENDWHILE
IF ?d%=34 THEN
h$=""
WHILE d%?1<>34 AND d%?1>31
d%+=1
h$+=CHR$ ?d%
ENDWHILE
d%+=2
SYS "XOS_SWINumberFromString",,h$ TO pa%;y%
IF (y% AND 1) AND x%>0 THEN PROCerror(FALSE,"SYS - can't translate """+h$+""" to a number")
ENDIF
ENDIF
ENDIF
IF k%=2:IF b$=",":k%=1
IF b$=CHR$ 222
IF b$="["l%+=1:IF l%=1:r%=TRUE
IF b$="]"l%-=1:IF l%<0:ERROR 1,"Too many ]"
IF b$=":"r%=TRUE:k%=0:K%=0
IF (f%=1 OR f%=2) AND W%:r%=1
W%=b$="."
ENDIF
ENDWHILE
ENDWHILE
ENDPROC
DEF FNg(v,v$)
LOCAL e%
IF CHR$ ?d%=" " THEN
e%=d%+1
WHILE ?e%=32
e%+=1
ENDWHILE
IF INSTR("0123456789.E%&",CHR$ ?e%):v$+=" "
ENDIF
=v$
DEF PROCget_token
f%=-1
IF v% THEN
n%=?d%
b$=CHR$ n%
f%=10
d%+=1
ELSE
IF l%=0 OR r%<>0:WHILE ?d%=32:d%+=1:ENDWHILE
IF d%=q%:b$="":f%=8:ENDPROC
n%=?d%
CASE n% OF
WHEN 141,228,229,247,184,160,220
IF x%>=0 PROCdangerous(n%)
ENDCASE
CASE n% OF
WHEN 198,199,200
f%=0
b$=CHR$ n%+CHR$ d%?1
d%+=2
WHEN 242
f%=5
d%+=1
b$=FNread_identifier(d$)
WHEN 164
f%=6
d%+=1
b$=FNread_identifier(d$)
WHEN ASC "&"
f%=7
a=EVAL FNread_identifier("0123456789ABCDEFabcdef")
b$=STR$ a
WHEN ASC "%"
f%=7
a=EVAL FNread_identifier("01")
b$=STR$ a
WHEN 48,49,50,51,52,53,54,55,56,57
f%=7
b$=FNread_identifier("0123456789.")
a=EVAL b$
WHEN ASC "*"
IF FNk:f%=11:b$=FNh ELSE b$="*":f%=10:d%+=1
WHEN 220
f%=11
b$=FNh
WHEN 244
f%=8
b$=""
d%=q%
OTHERWISE
IF n%=239 AND d%?1=ASC ":" THEN
f%=8
b$=""
d%=q%
ELSE
IF (r%<>0) AND l% AND n%<>ASC "." THEN
WHILE ?d%=32
d%+=1
ENDWHILE
b$=""
WHILE ?d%<>32 AND d%<q% AND INSTR(w$,CHR$ ?d%)<>0 AND RIGHT$(b$,3)<>"opt" AND RIGHT$(b$,3)<>"OPT"
b$+=CHR$ ?d%
d%+=1
ENDWHILE
f%=10
WHILE ?d%=32 AND d%<q%