File: fixpt

package info (click to toggle)
smlnj 110.79-8
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 82,564 kB
  • sloc: ansic: 32,532; asm: 6,314; sh: 2,296; makefile: 1,821; perl: 1,170; pascal: 295; yacc: 190; cs: 78; python: 77; lisp: 19
file content (121 lines) | stat: -rwxr-xr-x 2,588 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/bin/sh

# fixpt
#  - to be run in src/system to iterate compilation to a fixed point
#  - assumes no sml.boot... directory in src/system (but uses it if it
#    is there and the base is set to "sml" -- which is the default)
#  - assumes that ../../../bin/sml and ../../../bin/.arch-n-opsys have
#     been installed

this=$0
here=`pwd`
cd ../..
twoup=`pwd`
cd $here

SML=$twoup/bin/sml
ARCH=sparc

#
# use the arch-n-opsys script to determine the ARCH/OS if possible
#
if [ -f $twoup/bin/.arch-n-opsys ]; then
    ARCH_N_OPSYS=`$twoup/bin/.arch-n-opsys`
    if [ "$?" = "0" ]; then
	eval $ARCH_N_OPSYS
	echo Architecture: $ARCH
    fi
fi

BIN=.bin.$ARCH-unix
BOOT=.boot.$ARCH-unix
ITER=3
BASE=sml
REBUILD="-rebuild"
SETLIGHT=""
SAVE=false		# should we save intermediate boot and bin directories?

#
# Function to do one round of compilation to get the initial set of binfiles.
# (The funky ML comment is there to un-confuse emacs fontlock mode. :)
#
initcompile() {
$SML '$smlnj/cmb.cm' <<EOF
local open OS.Process CMB in
   $SETLIGHT
   val _ = exit (if make' (SOME "$BASE") then success else failure) (* ' *)
end
EOF
}

#
# Parse command line
#
while [ "$#" != 0 ] ; do
    arg=$1; shift
    case $arg in
    -iter)
	if [ "$#" = 0 ] ; then
	    echo "$this: missing argument for \"-iter\" option"
	    exit 2
	fi
	ITER=$1; shift
	;;
    -base)
	if [ "$#" = 0 ] ; then
	    echo "$this: missing argument for \"-base\" option"
	    exit 2
	fi
	BASE=$1; shift
	;;
    -light)
	REBUILD="-lightrebuild"
	SETLIGHT='val _ = #set (CMB.symval "LIGHT") (SOME 1);'
	;;
    -save)
	SAVE=true;
	;;
    *)
	echo "$this: unknown argument \"$arg\""
	exit 2
	;;
    esac
done

iter=0
iterbase=$BASE

if initcompile ; then
    while [ $iter -lt $ITER ] ; do
	prev=$iter
	prevbase=$iterbase
	iter=`expr $iter + 1`
	iterbase=$BASE$iter
	if ./makeml -boot $prevbase$BOOT $REBUILD $iterbase ; then
	    if diff -r $prevbase$BIN $iterbase$BIN >/dev/null 2>&1 ; then
		echo "$this: fixpoint reached in round $iter"
		if $SAVE ; then
		  echo "$this: results in $iterbase$BOOT $iterbase$BIN"
		else
		# get rid of the intermediary results and move the boot/bin files
		# where they belong
		  rm -rf $BASE$BOOT $BASE$BIN
		  mv $iterbase$BOOT $BASE$BOOT
		  mv $iterbase$BIN $BASE$BIN
		  rm -rf $BASE[1-9]$BOOT $BASE[1-9]$BIN
		  echo "$this: results in $BASE$BOOT $BASE$BIN"
		fi
		exit 0
	    fi
	else
	    echo "$this: compilation failed in round $iter"
	    exit 3
	fi
    done
else
    echo "$this: initial compilation failed"
    exit 3
fi

echo "$this: no fixpoint reached after $iter rounds"
exit 1