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

SCM Repository

[smlnj] Diff of /sml/branches/SMLNJ/src/MLRISC/x86/emit/x86Asm.sml
ViewVC logotype

Diff of /sml/branches/SMLNJ/src/MLRISC/x86/emit/x86Asm.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 411, Fri Sep 3 00:25:03 1999 UTC revision 429, Wed Sep 8 09:47:00 1999 UTC
# Line 22  Line 22 
22    
23     fun error msg = MLRiscErrorMsg.error("X86Asm",msg)     fun error msg = MLRiscErrorMsg.error("X86Asm",msg)
24    
25     fun makeStream() =     fun makeStream formatAnnotations =
26     let val stream = !AsmStream.asmOutStream     let val stream = !AsmStream.asmOutStream
27         fun emit s = TextIO.output(stream,s)         fun emit' s = TextIO.output(stream,s)
28         fun nl() = emit "\n"         val newline = ref true
29           val tabs = ref 0
30           fun tabbing 0 = ()
31             | tabbing n = (emit' "\t"; tabbing(n-1))
32           fun emit s = (tabbing(!tabs); tabs := 0; newline := false; emit' s)
33           fun nl() = (tabs := 0; if !newline then () else (newline := true; emit' "\n"))
34         fun comma() = emit ","         fun comma() = emit ","
35         fun tab() = emit "\t"         fun tab() = tabs := !tabs + 1
36         fun ms n = if n<0 then "-"^Int.toString(~n)         fun ms n = let val s = Int.toString n
37                    else Int.toString n                    in  if n<0 then "-"^String.substring(s,1,size s-1)
38                          else s
39                      end
40         fun emit_label lab = emit(Label.nameOf lab)         fun emit_label lab = emit(Label.nameOf lab)
41         fun emit_labexp le = emit(LabelExp.toString le)         fun emit_labexp le = emit(LabelExp.toString le)
42         fun emit_const c = emit(Constant.toString c)         fun emit_const c = emit(Constant.toString c)
# Line 44  Line 51 
51         fun pseudoOp pOp = emit(P.toString pOp)         fun pseudoOp pOp = emit(P.toString pOp)
52         fun init size = (comment("Code Size = " ^ ms size); nl())         fun init size = (comment("Code Size = " ^ ms size); nl())
53         fun doNothing _ = ()         fun doNothing _ = ()
54           val emitRegInfo = AsmFormatUtil.reginfo(emit,formatAnnotations)
55         fun emitter regmap =         fun emitter regmap =
56         let         let
57    
58     fun emit_CC r = (emit (C.showCC (regmap r)))     fun emit_CC r =
59     and emit_GP r = (emit (C.showGP (regmap r)))         ((emit (C.showCC (regmap r)));
60     and emit_FP r = (emit (C.showFP (regmap r)))         (emitRegInfo r))
61       and emit_FP r =
62           ((emit (C.showFP (regmap r)));
63           (emitRegInfo r))
64       and emit_GP r =
65           ((emit (C.showGP (regmap r)));
66           (emitRegInfo r))
67    
68     fun asm_fbinOp (I.FADDP) = "faddp"     fun asm_unaryOp (I.DEC) = "dec"
69         | asm_unaryOp (I.INC) = "inc"
70         | asm_unaryOp (I.NEG) = "neg"
71         | asm_unaryOp (I.NOT) = "not"
72       and emit_unaryOp x = (emit (asm_unaryOp x))
73       and asm_fbinOp (I.FADDP) = "faddp"
74       | asm_fbinOp (I.FADD) = "fadd"       | asm_fbinOp (I.FADD) = "fadd"
75       | asm_fbinOp (I.FMULP) = "fmulp"       | asm_fbinOp (I.FMULP) = "fmulp"
76       | asm_fbinOp (I.FMUL) = "fmul"       | asm_fbinOp (I.FMUL) = "fmul"
# Line 64  Line 83 
83       | asm_fbinOp (I.FDIVRP) = "fdivrp"       | asm_fbinOp (I.FDIVRP) = "fdivrp"
84       | asm_fbinOp (I.FDIVR) = "fdivr"       | asm_fbinOp (I.FDIVR) = "fdivr"
85     and emit_fbinOp x = (emit (asm_fbinOp x))     and emit_fbinOp x = (emit (asm_fbinOp x))
86       and asm_funOp (I.FABS) = "fabs"
87         | asm_funOp (I.FCHS) = "fchs"
88       and emit_funOp x = (emit (asm_funOp x))
89       and asm_move (I.MOVL) = "movl"
90         | asm_move (I.MOVZX) = "movzx"
91         | asm_move (I.MOVB) = "movb"
92       and emit_move x = (emit (asm_move x))
93       and asm_multDivOp (I.UMUL) = "umul"
94         | asm_multDivOp (I.IDIV) = "idiv"
95         | asm_multDivOp (I.UDIV) = "udiv"
96       and emit_multDivOp x = (emit (asm_multDivOp x))
97       and asm_binaryOp (I.ADD) = "add"
98         | asm_binaryOp (I.SUB) = "sub"
99         | asm_binaryOp (I.AND) = "and"
100         | asm_binaryOp (I.OR) = "or"
101         | asm_binaryOp (I.XOR) = "xor"
102         | asm_binaryOp (I.SHL) = "shl"
103         | asm_binaryOp (I.SAR) = "sar"
104         | asm_binaryOp (I.SHR) = "shr"
105       and emit_binaryOp x = (emit (asm_binaryOp x))
106     and asm_cond (I.EQ) = "eq"     and asm_cond (I.EQ) = "eq"
107       | asm_cond (I.NE) = "ne"       | asm_cond (I.NE) = "ne"
108       | asm_cond (I.LT) = "lt"       | asm_cond (I.LT) = "lt"
# Line 81  Line 120 
120       | asm_cond (I.O) = "o"       | asm_cond (I.O) = "o"
121       | asm_cond (I.NO) = "no"       | asm_cond (I.NO) = "no"
122     and emit_cond x = (emit (asm_cond x))     and emit_cond x = (emit (asm_cond x))
    and asm_binaryOp (I.ADD) = "add"  
      | asm_binaryOp (I.SUB) = "sub"  
      | asm_binaryOp (I.AND) = "and"  
      | asm_binaryOp (I.OR) = "or"  
      | asm_binaryOp (I.XOR) = "xor"  
      | asm_binaryOp (I.SHL) = "shl"  
      | asm_binaryOp (I.SAR) = "sar"  
      | asm_binaryOp (I.SHR) = "shr"  
    and emit_binaryOp x = (emit (asm_binaryOp x))  
    and asm_unaryOp (I.DEC) = "dec"  
      | asm_unaryOp (I.INC) = "inc"  
      | asm_unaryOp (I.NEG) = "neg"  
      | asm_unaryOp (I.NOT) = "not"  
    and emit_unaryOp x = (emit (asm_unaryOp x))  
    and asm_move (I.MOVL) = "movl"  
      | asm_move (I.MOVZX) = "movzx"  
      | asm_move (I.MOVB) = "movb"  
    and emit_move x = (emit (asm_move x))  
    and asm_funOp (I.FABS) = "fabs"  
      | asm_funOp (I.FCHS) = "fchs"  
    and emit_funOp x = (emit (asm_funOp x))  
    and asm_multDivOp (I.UMUL) = "umul"  
      | asm_multDivOp (I.IDIV) = "idiv"  
      | asm_multDivOp (I.UDIV) = "udiv"  
    and emit_multDivOp x = (emit (asm_multDivOp x))  
123     val memReg = (MemRegs.memReg regmap)     val memReg = (MemRegs.memReg regmap)
124    
125     fun emitInt32 i = (emit (if (i < 0)     fun emitInt32 i = let
126            then ("-" ^ (Int32.toString (~ i)))  
127            else (Int32.toString i)))  (*#line 144.1 "x86/x86.md"*)
128              val s = (Int32.toString i)
129    
130    (*#line 145.1 "x86/x86.md"*)
131              val s = (if (i >= 0)
132                    then s
133                    else ("-" ^ (String.substring (s, 1, ((size s) - 1)))))
134           in (emit s)
135           end
136    
137    
138     fun emit_src2 NONE = ()     fun emit_src2 NONE = ()
139       | emit_src2 (SOME i) =       | emit_src2 (SOME i) =
# Line 142  Line 165 
165        | I.Direct r => (emit_GP r)        | I.Direct r => (emit_GP r)
166        | I.FDirect f => let        | I.FDirect f => let
167    
168  (*#line 168.1 "x86/x86.md"*)  (*#line 171.1 "x86/x86.md"*)
169             val f' = (regmap f)             val f' = (regmap f)
170          in (if (f' < (32 + 8))          in (if (f' < (32 + 8))
171                then (emit_FP f')                then (emit_FP f')
# Line 173  Line 196 
196          (emit_GP base);          (emit_GP base);
197          (comma ());          (comma ());
198          (emit_GP index);          (emit_GP index);
199            (comma ());
200          (emitScale scale);          (emitScale scale);
201          (emit ")");          (emit ")");
202          (emit_region mem))          (emit_region mem))
# Line 211  Line 235 
235          ((emit "call\t");          ((emit "call\t");
236          (stupidGas operand);          (stupidGas operand);
237          (emit_region region))          (emit_region region))
238        | I.RET => (emit "ret")        | I.RET operand =>
239            ((emit "ret");
240    
241            (
242             case operand of
243             NONE => ()
244           | SOME e =>
245             ((emit "\t");
246             (emit_operand e))
247            ))
248        | I.MOVE{mvOp, src, dst} =>        | I.MOVE{mvOp, src, dst} =>
249          ((emit_move mvOp);          ((emit_move mvOp);
250          (emit "\t");          (emit "\t");
# Line 289  Line 322 
322             (emitInstr i; app (fn i => (tab(); emitInstr i)) is)             (emitInstr i; app (fn i => (tab(); emitInstr i)) is)
323        in  emitInstr end        in  emitInstr end
324    
325     in  S.STREAM{init=init,     in  S.STREAM{beginCluster=init,
326                  pseudoOp=pseudoOp,                  pseudoOp=pseudoOp,
327                  emit=emitter,                  emit=emitter,
328                  finish=doNothing,                  endCluster=doNothing,
329                  defineLabel=defineLabel,                  defineLabel=defineLabel,
330                  entryLabel=entryLabel,                  entryLabel=entryLabel,
331                  comment=comment,                  comment=comment,
332                  exitBlock=doNothing,                  exitBlock=doNothing,
333                  blockName=blockName,                  blockName=blockName,
334                  annotation=annotation                  annotation=annotation,
335                    phi=doNothing,
336                    alias=doNothing
337                 }                 }
338     end     end
339  end  end

Legend:
Removed from v.411  
changed lines
  Added in v.429

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