Commit dae3a50e authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Add ability to get SWI names from C exports

Squish will now make a list of SWI names from CLib:h.swis (or some override header file provided by the -SYSFROM switch) before falling back to using OS_SWINumberFromString. This avoids the need to have all the modules in the world loaded when squishing a BASIC program.

Version 1.15. Tagged as 'Squish-1_15'
parent 0b40e305
/* (1.14)
/* (1.15)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.14
#define Module_MajorVersion_CMHG 1.15
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 27 Oct 2012
#define Module_Date_CMHG 02 Apr 2013
#define Module_MajorVersion "1.14"
#define Module_Version 114
#define Module_MajorVersion "1.15"
#define Module_Version 115
#define Module_MinorVersion ""
#define Module_Date "27 Oct 2012"
#define Module_Date "02 Apr 2013"
#define Module_ApplicationDate "27-Oct-12"
#define Module_ApplicationDate "02-Apr-13"
#define Module_ComponentName "Squish"
#define Module_ComponentPath "castle/RiscOS/Tools/Sources/Squish"
#define Module_FullVersion "1.14"
#define Module_HelpVersion "1.14 (27 Oct 2012)"
#define Module_LibraryVersionInfo "1:14"
#define Module_FullVersion "1.15"
#define Module_HelpVersion "1.15 (02 Apr 2013)"
#define Module_LibraryVersionInfo "1:15"
......@@ -12,9 +12,9 @@ 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
REM>bas.Squish
ON ERROR REPORT:PRINT " (internal error ";ERL;")":END
l$="v1.14 27-Oct-12"
l$="v1.15 02-Apr-13"
DIM aa% 1000
ba%=HIMEM-END-32768
DIM z% ba%
......@@ -84,8 +84,8 @@ g%=-1
o%=0
da%=0
Q%=0
ea%=FALSE
Z%=TRUE
colour%=FALSE
sys%=TRUE
_%=0
`%=0
fa%=FALSE
......@@ -103,10 +103,14 @@ IF FNtoupper(f$)=FNtoupper(F$) THEN
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 g%>0 g%=OPENOUT (list$):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
IF g%<0 AND colour%<>0:MODE 12:COLOUR 0,7:COLOUR 7,0
IF sys% AND NOT FNread_swis_h THEN
PROClog_str("Couldn't parse SWI names from "+sysfrom$+", falling back to OS_SWINumberFromString")
PROClog_nl
ENDIF
c$="Squish ("+l$+") squishing program '"+F$+"' to '"+f$+"'"
PROClog_nl
PROClog_str(c$)
......@@ -300,7 +304,8 @@ WHILE d%?1<>255
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
IF sys% AND (b$=CHR$ 200+CHR$ 153) THEN
REM Found TESCSTMT + TSYS
WHILE ?d%=32
d%+=1
ENDWHILE
......@@ -311,8 +316,8 @@ WHILE d%?1<>255
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")
y%=FNresolve_swi_name(h$,pa%)
IF (NOT y%) AND x%>0 THEN PROCerror(FALSE,"SYS - can't translate """+h$+""" to a number")
ENDIF
ENDIF
ENDIF
......@@ -659,7 +664,7 @@ WHILE d%?1<>255
PROCwrite(FNg(a,b$))
WHEN 10
IF l%:IF b$=":":WHILE h%?-1=32:h%-=1:ENDWHILE
IF Z% AND m% THEN
IF sys% AND m% THEN
IF v% AND b$<>""""h$+=b$
ELSE
PROClog_str(b$)
......@@ -670,9 +675,9 @@ WHILE d%?1<>255
v%=NOT v%
IF NOT v% THEN
IF o% AND da%<>PTR #o% BPUT #o%,10
IF Z% AND m% THEN
SYS "XOS_SWINumberFromString",,h$ TO pa%;y%
IF (y% AND 1) THEN
IF sys% AND m% THEN
y%=FNresolve_swi_name(h$,pa%)
IF NOT y% THEN
PROClog_str(""""+h$+"""")
PROCwrite(""""+h$+"""")
ELSE
......@@ -889,14 +894,15 @@ h%+=4
qa%+=5
ENDPROC
DEF PROCprocess_args(RETURN q$,RETURN r$)
DEF PROCprocess_args(RETURN from$,RETURN to$)
LOCAL z%,p%,w%,e$,a$()
DIM a$(20)
DIM z% 256
w%=0
q$=""
r$=""
n$=""
from$=""
to$=""
list$=""
sysfrom$="CLib:h.swis":REM Default unless overridden
SYS "OS_GetEnv" TO e$
WHILE RIGHT$(e$,1)=" "
e$=LEFT$(e$,LEN (e$)-1)
......@@ -919,16 +925,16 @@ WHILE p%<w%
WHEN "-HELP"
PRINT "Squish ("+l$+")"'
PRINT "Syntax: *Squish -from <file> -to <file> [-warn <level>] [-literal <file>]"
PRINT " [-list <file> | -nolist] [-colour] [-nosys]"
PRINT " [-list <file> | -nolist] [-colour] [-nosys] [-sysfrom <file>]"
END
WHEN "-FROM"
IF p%<w%-1 THEN
q$=a$(p%+1)
from$=a$(p%+1)
p%+=1
ENDIF
WHEN "-TO"
IF p%<w%-1 THEN
r$=a$(p%+1)
to$=a$(p%+1)
p%+=1
ENDIF
WHEN "-WARN"
......@@ -947,14 +953,19 @@ WHILE p%<w%
ENDIF
WHEN "-LIST"
IF p%<w%-1 THEN
n$=a$(p%+1)
list$=a$(p%+1)
p%+=1
g%=1
ENDIF
WHEN "-COLOUR"
ea%=TRUE
colour%=TRUE
WHEN "-NOSYS"
Z%=FALSE
sys%=FALSE
WHEN "-SYSFROM"
IF p%<w%-1 THEN
sysfrom$=a$(p%+1)
p%+=1
ENDIF
WHEN "-KEEP"
IF p%<w%-1 THEN
m$=a$(p%+1)
......@@ -998,7 +1009,7 @@ ENDIF
=s$
DEF PROClog_colour(C%)
IF g%<0 AND ea%<>0:COLOUR C%
IF g%<0 AND colour%<>0:COLOUR C%
ENDPROC
DEF FNi
......@@ -1094,3 +1105,65 @@ FOR O%=2 TO LEN g$-10
IF fa%=TRUE AND FNkeep_identifier(pre$+MID$(g$,O%,1)+post$) THEN ?(e%+8+O%)=255
NEXT
ENDPROC
DEF FNread_swis_h
LOCAL y%,line$,name$,value$,c%,f%
REM Always create at least a zero length list
REM The list uses the format
REM <next><SWI number><SWI name><&0D>...
syslist%=0
y%=OPENIN (sysfrom$)
IF y%<>0 THEN
WHILE NOT EOF #y%
line$=GET$ #y%
name$="":value$=""
IF LEFT$(line$,8)="#define " THEN
line$=MID$(line$,9)
REPEAT
c%=ASC LEFT$(line$,1)
IF c%>32 AND c%<127 THEN name$=name$+CHR$ c%:c%=-2
line$=MID$(line$,2)
UNTIL c%<>-2
WHILE LEFT$(line$,1)=" "
line$=MID$(line$,2)
ENDWHILE
REPEAT
c%=ASC LEFT$(line$,1)
IF c%>32 AND c%<127 THEN value$=value$+CHR$ c%:c%=-2
line$=MID$(line$,2)
UNTIL c%<>-2
REM Names mustn't start with X or underscore, must include an underscore
IF LEFT$(name$,1)<>"X" AND INSTR(name$,"_") >= 2 THEN
IF FNtoupper(LEFT$(value$,2))="0X" THEN value$="&"+MID$(value$,3)
SYS"XOS_ReadUnsigned",10,value$ TO,,c%;f%
REM And the value must be in 24 bit SWI range
IF ((f% AND 1)=0) AND ((c% AND &FF000000)=0) THEN
slot%=FNalloc(4+4+LEN(name$)+1)
slot%!0=syslist%:slot%!4=c%:$(slot%+8)=name$
syslist%=slot%
ENDIF
ENDIF
ENDIF
ENDWHILE
CLOSE #y%
ENDIF
=syslist%<>0
DEF FNresolve_swi_name(name$,RETURN swi%)
LOCAL entry%,f%
IF LEFT$(name$,1)="X" THENswi%=1<<17:name$=MID$(name$,2) ELSEswi%=0
entry%=syslist%
WHILE entry%<>0
IF $(entry%+8)=name$ THEN
swi%=swi% ORentry%!4:entry%=0
ELSE
entry%=entry%!0
ENDIF
ENDWHILE
IF (swi% AND&FDFFFF)=0 THEN
REM Not in the SYS list, ask the OS?
IF swi%=1<<17 THEN name$="X"+name$
SYS "XOS_SWINumberFromString",,name$ TO swi%;f%
IF (f% AND 1) THEN=FALSE
ENDIF
=TRUE
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment