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/flowgraph/pseudo-ops-big.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/flowgraph/pseudo-ops-big.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1012 - (view) (download)

1 : george 991 (* pseudo-ops-big.sml
2 :     *
3 :     * COPYRIGHT (c) 2001 Lucent Technologies, Bell Laboratories.
4 :     *
5 :     * Subset of pseudo-ops functions that are little endian sensitive
6 :     *)
7 :    
8 : george 984 functor PseudoOpsBig
9 :     ( structure T : MLTREE
10 :     structure MLTreeEval : MLTREE_EVAL
11 :     where T = T
12 :     val icache_alignment : int (* cache line size *)
13 :     val max_alignment : int option (* maximum alignment for internal labels *)
14 :     val nop: {sz:int, en:Word32.word} (* encoding for noop *)
15 : george 991 ) : PSEUDO_OPS_ENDIAN =
16 : george 984 struct
17 :     structure W = Word
18 :     structure T = T
19 :     structure PB = PseudoOpsBasisTyp
20 : george 991 type 'a pseudo_op = (T.labexp, 'a) PB.pseudo_op
21 : george 984 fun error msg = MLRiscErrorMsg.error ("PseudoOpsBig.", msg)
22 :    
23 :     val >> = Word.>>
24 :     val ~>> = Word.~>>
25 :     val & = Word.andb
26 :     infix >> ~>> &
27 :    
28 :     (* return loc aligned at bndry *)
29 :     fun align(loc, bndry) = let
30 :     val mask = W.fromInt bndry - 0w1
31 :     in W.toIntX(W.andb(W.fromInt loc + mask, W.notb mask))
32 :     end
33 :    
34 :     (* bytes of padding required *)
35 :     fun padding(loc, bndry) = align(loc, bndry) - loc
36 :    
37 :     fun pow2(x, 0) = x
38 :     | pow2(x, n) = pow2(x * 2, n-1)
39 :    
40 :     fun bytesIn sz = Int.quot(sz, 8)
41 :    
42 :     fun sizeOf(pOp, loc) =
43 :     (case pOp
44 :     of PB.ALIGN_SZ n => padding(loc, pow2(1, n))
45 :     | PB.ALIGN_ENTRY => padding(loc, icache_alignment)
46 :     | PB.ALIGN_LABEL => let
47 :     val pad = padding(loc, icache_alignment)
48 :     in
49 :     case max_alignment
50 :     of NONE => pad
51 :     | SOME m => if pad <= m then pad else 0
52 :     end
53 :    
54 :     | PB.INT{sz, i} => length(i) * bytesIn sz
55 :    
56 :     | PB.ASCII s => String.size s
57 :     | PB.ASCIIZ s => String.size s + 1
58 :    
59 : george 1012 | PB.SPACE(sz) => sz
60 :    
61 : george 984 | PB.FLOAT{sz, f} => length(f) * bytesIn sz
62 :    
63 :     | PB.EXT _ => error "sizeOf: EXT"
64 :     | _ => 0
65 :     (*esac*))
66 :    
67 :    
68 :     fun emitValue{pOp, loc, emit} = let
69 :     val itow = W.fromInt
70 :     val toword8 = Word8.fromLargeWord o Word.toLargeWord o itow
71 :     fun emitByte n = emit (Word8.fromLargeWord (Word.toLargeWord n))
72 :     fun emitWord w = (emitByte((w >> 0w8) & 0w255); emitByte(w & 0w255))
73 :    
74 :     fun emitLongX n = let val w = itow n
75 :     in emitWord(w ~>> 0w16); emitWord(w & 0w65535)
76 :     end
77 :    
78 :     local
79 :     val {sz, en} = nop
80 :     val toWord = W.fromLargeInt o Word32.toLargeIntX
81 :     in
82 :     fun emitNop () =
83 :     case sz
84 :     of 1 => emitByte (toWord en)
85 :     | 2 => emitWord (toWord en)
86 :     | 4 => (emitWord(toWord(Word32.andb(en, 0w65535)));
87 :     emitWord(toWord(Word32.>>(en, 0w16))))
88 :    
89 :     fun insertNops 0 = ()
90 :     | insertNops n =
91 :     if n >= sz then (emitNop(); insertNops(n-sz))
92 :     else error "insertNops"
93 :     end
94 :    
95 :     fun align(loc, bndry) = let
96 :     val bndry = Word.fromInt bndry
97 :     val mask = bndry - 0w1
98 :     in
99 :     case W.andb(itow(loc), mask)
100 :     of 0w0 => ()
101 :     | w => let
102 :     val padSz = (bndry - w)
103 :     in insertNops(Word.toInt padSz)
104 :     end
105 :     (*esac*)
106 :     end
107 :    
108 :     val {ccexp, rexp} =
109 :     MLTreeEval.eval
110 :     {const = IntInf.fromInt o T.Constant.valueOf,
111 :     label = Label.addrOf}
112 :     in
113 :     case pOp
114 :     of PB.ALIGN_SZ n => insertNops(sizeOf(pOp, loc))
115 :     | PB.ALIGN_ENTRY => insertNops(sizeOf(pOp, loc))
116 :     | PB.ALIGN_LABEL => insertNops(sizeOf(pOp, loc))
117 :    
118 :     | PB.INT{sz, i} => let
119 :     val ints = map (IntInf.toInt o rexp) i
120 :     in
121 :     case sz
122 :     of 8 => app (emitByte o itow) ints
123 :     | 16 => app (emitWord o itow) ints
124 :     | 32 => app emitLongX ints
125 :     | _ => error "emitValue: INT 64"
126 :     (*esac*)
127 :     end
128 :    
129 :     | PB.ASCII s => app (emit o Word8.fromInt o Char.ord) (String.explode s)
130 :     | PB.ASCIIZ s => (emitValue{pOp=PB.ASCII s, loc=loc, emit=emit}; emit 0w0)
131 :    
132 :     | PB.FLOAT{sz, f} => error "emitValue: FLOAT - not implemented"
133 :     | PB.EXT _ => error "emitValue: EXT"
134 : george 1012 | PB.SPACE _ => error "emitValue: SPACE"
135 : george 984 | _ => ()
136 :     end
137 :    
138 :    
139 :     end

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