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/backpatch/x86Jumps.sml
ViewVC logotype

Annotation of /sml/trunk/src/MLRISC/x86/backpatch/x86Jumps.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 248 - (view) (download)

1 : monnier 247 (* X86Jumps.sml --- information to resolve jumps for runtime code generation.
2 :     *
3 :     * COPYRIGHT (c) 1997 Bell Laboratories.
4 :     *)
5 :    
6 :     functor X86Jumps
7 :     (structure Instr : X86INSTR
8 :     structure AsmEmitter : EMITTER_NEW where I = Instr
9 :     structure Shuffle : X86SHUFFLE where I = Instr
10 :     structure MCEmitter : MC_EMIT where I = Instr) : SDI_JUMPS =
11 :     struct
12 :     structure I = Instr
13 :     structure C = I.C
14 :     structure Const = I.Constant
15 :     structure LE = LabelExp
16 :    
17 :     fun error msg = MLRiscErrorMsg.impossible ("X86Jumps." ^ msg)
18 :    
19 :     val esp = 4
20 :     val ebp = 5
21 :     val branchDelayedArch = false
22 :    
23 :     fun imm8 i = ~128 <= i andalso i < 128
24 :    
25 :     fun isSdi instr = let
26 :     fun operand(I.ImmedLabel _) = true
27 :     | operand(I.Const _) = true
28 :     | operand(I.LabelEA _) = true
29 :     | operand(I.Displace{disp, ...}) = operand disp
30 :     | operand(I.Indexed{disp, ...}) = operand disp
31 :     | operand _ = false
32 :     in
33 :     case instr
34 :     of I.JMP(opnd, _) => operand opnd
35 :     | I.JCC{opnd, ...} => operand opnd
36 :     | I.BINARY{src, dst, ...} => operand src orelse operand dst
37 :     | I.MOVE{src, dst, ...} => operand src orelse operand dst
38 :     | I.LEA{addr, ...} => operand addr
39 :     | I.CMP{lsrc, rsrc} => operand lsrc orelse operand rsrc
40 :     | I.MULTDIV{src, ...} => operand src
41 :     | I.MUL3{src1, ...} => operand src1
42 :     | I.UNARY{opnd, ...} => operand opnd
43 :     | I.PUSH opnd => operand opnd
44 :     | I.POP opnd => operand opnd
45 :     | I.FSTP opnd => operand opnd
46 :     | I.FLD opnd => operand opnd
47 :     | I.FBINARY{src, dst, ...} => operand src orelse operand dst
48 :     | I.FILD opnd => operand opnd
49 :     | _ => false
50 :     end
51 :    
52 :     fun minSize(I.JMP _) = 2
53 :     | minSize(I.JCC _) = 2
54 :     | minSize _ = 1
55 :    
56 :     fun maxSize _ = 12
57 :    
58 :     (* value of span-dependent operand *)
59 :     fun operand(I.ImmedLabel le) = LE.valueOf le
60 :     | operand(I.Const c) = Const.valueOf c
61 :     | operand(I.LabelEA le) = LE.valueOf le
62 :     | operand _ = error "operand"
63 :    
64 :     fun sdiSize(instr, regmap, labmap, loc) = let
65 :     fun branch(opnd, short, long) = let
66 :     val offset = operand opnd - loc
67 :     in if imm8(offset - 2) then short else long
68 :     end
69 :    
70 :     val encode = MCEmitter.emitInstr
71 :     fun lookup r = Intmap.map regmap r handle _ => r
72 :     in
73 :     case instr
74 :     of I.JMP(opnd, _) => branch(opnd, 2, 5)
75 :     | I.JCC{opnd, ...} => branch(opnd, 2, 6)
76 :     | _ => Word8Vector.length(encode(instr, regmap))
77 :     end (*sdiSize*)
78 :    
79 :     fun expand(instr, _, loc) =
80 :     case instr
81 :     of I.JMP(opnd, labs) => [I.JMP(I.Relative(operand opnd-loc), labs)]
82 :     | I.JCC{cond, opnd} =>
83 :     [I.JCC{cond=cond, opnd=I.Relative(operand opnd-loc)}]
84 :     | opnd => [opnd]
85 :     end
86 :    

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