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/trunk/src/MLRISC/instructions/labelExp.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/instructions/labelExp.sml

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

revision 639, Tue May 2 21:44:37 2000 UTC revision 640, Tue May 9 02:33:09 2000 UTC
# Line 65  Line 65 
65    (* This module should be parameterised, in order to generate    (* This module should be parameterised, in order to generate
66     * target label expressions for assembly code purposes.     * target label expressions for assembly code purposes.
67     *)     *)
68    fun parenthesize str = "(" ^ str ^ ")"  (* operator precedences:
69       (Note: these differ from C's precedences)
70                    2 MULT, DIV, LSHIFT, RSHIFT
71                    1 AND, OR
72                    0 PLUS, MINUS
73    *)
74    
75      fun parens (str, prec, op_prec) =
76          if prec > op_prec then "(" ^ str ^ ")" else str
77    
78    fun pToString(lexp as LABEL _) = toString lexp    and toString le = toStr(le, 0)
     | pToString(lexp as INT _) = toString lexp  
     | pToString lexp = parenthesize(toString lexp)  
79    
80    and toString(LABEL lab) = Label.nameOf lab    and toStr(LABEL lab, _) = Label.nameOf lab
81      | toString(CONST c) =      | toStr(CONST c, _) =
82          if !resolveConstants then prInt(Constant.valueOf c)          if !resolveConstants then prInt(Constant.valueOf c)
83          else Constant.toString c          else Constant.toString c
84      | toString(INT i) = prInt i      | toStr(INT i, _) = prInt i
85      | toString(PLUS(lexp1, lexp2)) =  pToString lexp1 ^ "+" ^ pToString lexp2      | toStr(MULT(lexp1, lexp2), _) = toStr(lexp1, 2) ^ "*" ^ toStr(lexp2,2)
86      | toString(MINUS(lexp1, lexp2)) = pToString lexp1 ^ "-" ^ pToString lexp2      | toStr(DIV(lexp1, lexp2), _) =  toStr(lexp1, 2) ^ "/" ^ toStr(lexp2,2)
87      | toString(MULT(lexp1, lexp2)) = pToString lexp1 ^ "*" ^ pToString lexp2      | toStr(LSHIFT(lexp, cnt), prec) = toStr(lexp,2) ^ "<<" ^ Word.toString cnt
88      | toString(DIV(lexp1, lexp2)) = pToString lexp1 ^ "/" ^ pToString lexp2      | toStr(RSHIFT(lexp, cnt), prec) = toStr(lexp,2) ^ ">>" ^ Word.toString cnt
89      | toString(LSHIFT(lexp, cnt)) = pToString lexp ^ "<<" ^ Word.toString cnt      | toStr(AND(lexp, mask), prec) =
90      | toString(RSHIFT(lexp, cnt)) = pToString lexp ^ ">>" ^ Word.toString cnt          parens(toStr(lexp,1) ^ "&" ^ Word.toString mask, prec, 1)
91      | toString(AND(lexp, mask)) = pToString lexp ^ "&" ^ Word.toString mask      | toStr(OR(lexp, mask), prec) =
92      | toString(OR(lexp, mask)) = pToString lexp ^ "|" ^ Word.toString mask          parens(toStr(lexp, 1) ^ "|" ^ Word.toString mask, prec, 1)
93        | toStr(PLUS(lexp1, lexp2), prec) =
94            parens(toStr(lexp1, 0) ^ "+" ^ toStr(lexp2, 0), prec, 0)
95        | toStr(MINUS(lexp1, lexp2), prec) =
96            parens(toStr(lexp1, 0) ^ "-" ^ toStr(lexp2, 0), prec, 0)
97    
98    
99    fun hash(LABEL(Label.Label{id,...})) = Word.fromInt id    fun hash(LABEL(Label.Label{id,...})) = Word.fromInt id
100      | hash(INT i) = Word.fromInt i      | hash(INT i) = Word.fromInt i

Legend:
Removed from v.639  
changed lines
  Added in v.640

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