]> Joshua Wise's Git repositories - snipe.git/blame_incremental - trans/temp.sml
Rename output binary from l5c to snipe
[snipe.git] / trans / temp.sml
... / ...
CommitLineData
1(* L3 Compiler
2 * Temporaries
3 * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
4 * Modified: Alex Vaynberg <alv@andrew.cmu.edu>
5 * Modified: Frank Pfenning <fp@cs.cmu.edu>
6 *)
7
8signature TEMP =
9sig
10 type temp
11 datatype size = Byte | Word | Long | Quad
12
13 val reset : unit -> unit (* resets temp numbering *)
14 val new : string -> size -> temp (* returns a unique new temp *)
15 val name : temp -> string (* returns the name of a temp *)
16 val size : temp -> size (* returns the size of a temp *)
17 val compare : temp * temp -> order (* comparison function *)
18 val eq : temp * temp -> bool
19 val cmpsize : size * size -> order
20 val sfx : size -> string
21 val sts : int -> size
22end
23
24structure Temp :> TEMP =
25struct
26 datatype size = Byte | Word | Long | Quad
27 type temp = int * string * size
28
29 local
30 val counter = ref 1
31 in
32 (* warning: calling reset() may jeopardize uniqueness of temps! *)
33 fun reset () = ( counter := 1 )
34 fun new str size = (!counter, str, size) before ( counter := !counter + 1 )
35 end
36
37 fun sfx Byte = "b"
38 | sfx Word = "w"
39 | sfx Long = "l"
40 | sfx Quad = "q"
41
42 fun name (t,s, sz) = "+t" ^ Int.toString t ^ "[" ^ s ^ "]" ^ sfx sz
43 fun size (t, s, sz) = sz
44 fun compare ((t1,_,_),(t2,_,_)) = Int.compare (t1,t2)
45
46 fun eq ((t1,_,_), (t2,_,_)) = t1 = t2
47
48 fun cmpsize (Quad,Quad) = EQUAL
49 | cmpsize (Quad,_) = GREATER
50 | cmpsize (_,Quad) = LESS
51 | cmpsize (Long,Long) = EQUAL
52 | cmpsize (Long,_) = GREATER
53 | cmpsize (_,Long) = LESS
54 | cmpsize (Word,Word) = EQUAL
55 | cmpsize (Word,_) = GREATER
56 | cmpsize (_,Word) = LESS
57 | cmpsize (Byte,Byte) = EQUAL
58
59 fun sts 8 = Quad
60 | sts 4 = Long
61 | sts 2 = Word
62 | sts 1 = Byte
63 | sts _ = raise ErrorMsg.InternalError "Temp.sts: invalid size"
64
65end
This page took 0.029325 seconds and 5 git commands to generate.