Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/MLRISC/x86/instructions/x86Cells.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/x86/instructions/x86Cells.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 247 - (view) (download)
Original Path: sml/branches/SMLNJ/src/MLRISC/x86/instructions/x86Cells.sml

1 : monnier 247 (* X86Cells.sml --- interface for x86 registers.
2 :     *
3 :     * COPYRIGHT (c) 1999 Bell Laboratories.
4 :     *)
5 :    
6 :     structure X86Cells : X86CELLS =
7 :     struct
8 :     structure S = SortedList
9 :     type register = int
10 :     type regmap = register Intmap.intmap
11 :     datatype cellclass = GP | FP | CC | MEM | CTRL
12 :    
13 :     exception Cells
14 :     fun error msg = MLRiscErrorMsg.impossible ("X86Cells."^msg)
15 :    
16 :     val eax = 0 val ecx = 1
17 :     val edx = 2 val ebx = 3
18 :     val esp = 4 val ebp = 5
19 :     val esi = 6 val edi = 7
20 :    
21 :     val stackptrR = esp
22 :     val asmTmpR = ~1 (* not used *)
23 :     val fasmTmp = ~1 (* '' *)
24 :    
25 :     val firstPseudo = 256
26 :     fun downto0 0 = [0]
27 :     | downto0 n = n::downto0(n-1)
28 :     val physicalRegs = downto0 31
29 :    
30 :     val counter = ref firstPseudo
31 :     val regCnt = ref 0 (* number of general registers *)
32 :     val fregCnt = ref 0 (* number of floating registers *)
33 :    
34 :     fun bump (r as ref c) = c before r := c+1
35 :    
36 :     fun newReg() = (bump regCnt; bump counter)
37 :     fun newFreg() = (bump fregCnt; bump counter)
38 :     fun newCCreg() = error "newCCreg"
39 :    
40 :     fun newCell GP = newReg
41 :     | newCell FP = newFreg
42 :     | newCell _ = fn () => bump counter
43 :    
44 :     fun resetRegs() = let
45 :     val regmap = Intmap.new(64, Cells)
46 :     val enter = Intmap.add regmap
47 :     in
48 :     counter:=firstPseudo;
49 :     regCnt :=0;
50 :     fregCnt:=0;
51 :     app (fn r => enter(r,r)) physicalRegs;
52 :     regmap
53 :     end
54 :    
55 :     fun maxCell () = !counter
56 :     fun numCell GP = (fn () => !regCnt)
57 :     | numCell FP = (fn () => !fregCnt)
58 :     | numCell _ = raise Cells
59 :    
60 :     fun cellToString(r,class) = prefix class^Int.toString r
61 :     and prefix GP = "r"
62 :     | prefix FP = "f"
63 :     | prefix CC = "cc"
64 :     | prefix MEM = "m"
65 :     | prefix CTRL = "ctrl"
66 :    
67 :     fun zero _ = NONE
68 :    
69 :     type cellset = int list * int list * int list
70 :     fun cellset2string(regs, fregs, ccregs) = let
71 :     val cc = "cc=" :: map (fn 0 => "cc ") ccregs
72 :     val gp = "gp=" :: map (fn r => (" $" ^ Int.toString r)) regs
73 :     val fp = " fp=" :: map (fn f => (" $f" ^ Int.toString f)) fregs
74 :     in String.concat(cc @ (gp @ fp))
75 :     end
76 :     val empty = ([], [], [])
77 :     fun addReg(r, (rc, fc, cc)) = (S.enter(r,rc), fc, cc)
78 :     fun addFreg(f, (rc, fc, cc)) = (rc, S.enter(f,fc), cc)
79 :     fun addCCreg(0, (rc, fc, cc)) = (rc, fc, [0])
80 :     fun addCell GP = addReg
81 :     | addCell FP = addFreg
82 :     | addCell CC = addCCreg
83 :     | addCell _ = raise Cells
84 :    
85 :     fun cellsetToRegs(regmap, (rc, fc, cc)) = let
86 :     fun lookup r = Intmap.map regmap r handle _ => r
87 :     fun ftrans r = let
88 :     val f = lookup r
89 :     in if f < 8 then f+8 else f
90 :     end
91 :     fun cctrans r = let
92 :     val cc = lookup r
93 :     in if cc<1 then cc+16 else cc
94 :     end
95 :     in map cctrans cc @ map ftrans fc @ map lookup rc
96 :     end
97 :    
98 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0