]> Joshua Wise's Git repositories - snipe.git/blame - trans/temp.sml
blargCPU igraph
[snipe.git] / trans / temp.sml
CommitLineData
6ade8b0a 1(* L3 Compiler
12aa4087
JW
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
5c79bb68 11 datatype size = Byte | Word | Long | Quad
12aa4087 12
5c79bb68
JW
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 *)
12aa4087 17 val compare : temp * temp -> order (* comparison function *)
6ade8b0a 18 val eq : temp * temp -> bool
5c79bb68
JW
19 val cmpsize : size * size -> order
20 val sfx : size -> string
21 val sts : int -> size
12aa4087
JW
22end
23
24structure Temp :> TEMP =
25struct
5c79bb68
JW
26 datatype size = Byte | Word | Long | Quad
27 type temp = int * string * size
12aa4087
JW
28
29 local
30 val counter = ref 1
31 in
32 (* warning: calling reset() may jeopardize uniqueness of temps! *)
33 fun reset () = ( counter := 1 )
1144856b 34 fun new str size = (!counter, str, size) before ( counter := !counter + 1 )
12aa4087
JW
35 end
36
5c79bb68
JW
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
1144856b
JW
43 fun size (t, s, sz) = sz
44 fun compare ((t1,_,_),(t2,_,_)) = Int.compare (t1,t2)
6ade8b0a 45
1144856b 46 fun eq ((t1,_,_), (t2,_,_)) = t1 = t2
5c79bb68
JW
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
12aa4087 65end
This page took 0.033437 seconds and 4 git commands to generate.