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/flowgraph/gasPseudoOps.sml
ViewVC logotype

Diff of /sml/trunk/src/MLRISC/flowgraph/gasPseudoOps.sml

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

revision 1920, Tue Apr 11 13:15:55 2006 UTC revision 1921, Fri Apr 14 16:14:24 2006 UTC
# Line 1  Line 1 
1  (* gasPseudoOps.sml  (* gasPseudoOps.sml
2   *   *
3   * COPYRIGHT (c) 2001 Lucent Technologies, Bell Laboratories.   * COPYRIGHT (c) 2006 The Fellowship of SML/NJ (www.smlnj.org)
4     * All rights reserved.
5   *   *
6   * Implements the string related functions to emit pseudo-ops   * Implements the string related functions to emit pseudo-ops
7   * in the standard GAS syntax.   * in the standard GAS syntax (see http://www.gnu.org/software/binutils/manual/gas-2.9.1/)
8   *)   *)
 signature GAS_PSEUDO_OPS = sig  
     structure T : MLTREE  
     val lexpToString : T.labexp -> string  
     val toString : (T.labexp, 'a) PseudoOpsBasisTyp.pseudo_op -> string  
     val defineLabel : Label.label -> string  
 end  
9    
10  functor GasPseudoOps  functor GasPseudoOps (
11    ( structure T : MLTREE      structure T : MLTREE
12      val labFmt : {gPrefix: string, aPrefix: string}      val labFmt : {gPrefix: string, aPrefix: string}
13     ) : GAS_PSEUDO_OPS =    ) : AS_PSEUDO_OPS =
14  struct  struct
15    structure T = T    structure T = T
16    structure PB = PseudoOpsBasisTyp    structure PB = PseudoOpsBasisTyp
# Line 30  Line 25 
25    
26    (* operator precedences:    (* operator precedences:
27       Note: these differ from C's precedences       Note: these differ from C's precedences
28            2 MULT, DIV, LSHIFT, RSHIFT              3 NEG, NOTB
29            1 AND, OR              2 MULS, DIVS, SLL, SRA
30                1 ANDB, ORB, XORB
31            0 PLUS, MINUS            0 PLUS, MINUS
32    *)    *)
33    
34      (* NOTE: we use ">=" here instead of ">" so that we don't have to worry about associativity *)
35    fun parens (str, prec, op_prec) =    fun parens (str, prec, op_prec) =
36        if prec > op_prec then "(" ^ str ^ ")" else str          if prec >= op_prec then "(" ^ str ^ ")" else str
37    
38    fun lexpToString le = toStr(le, 0)    fun lexpToString le = toStr(le, 0)
39    
# Line 45  Line 42 
42      | toStr(T.NEG(_, T.CONST c), _) =      | toStr(T.NEG(_, T.CONST c), _) =
43          (prInt(~(T.Constant.valueOf c)) handle _ => "-"^T.Constant.toString c)          (prInt(~(T.Constant.valueOf c)) handle _ => "-"^T.Constant.toString c)
44      | toStr(T.NEG(_, T.LI i), _) = prIntInf(~i)      | toStr(T.NEG(_, T.LI i), _) = prIntInf(~i)
45      | toStr(T.NEG(_, lexp), prec) = parens(toStr(lexp, 3), prec, 3)        | toStr(T.NEG(_, lexp), prec) = "-" ^ parens(toStr(lexp, 3), prec, 3)
46          | toStr(T.NOTB(_, lexp), prec) = "~" ^ parens(toStr(lexp, 3), prec, 3)
47      | toStr(T.CONST c, _) =      | toStr(T.CONST c, _) =
48          (prInt(T.Constant.valueOf c) handle _ => T.Constant.toString c)          (prInt(T.Constant.valueOf c) handle _ => T.Constant.toString c)
49      | toStr(T.LI i, _) = prIntInf i      | toStr(T.LI i, _) = prIntInf i
# Line 55  Line 53 
53          parens(toStr(lexp1, 2) ^ "/" ^ toStr(lexp2,2), prec, 2)          parens(toStr(lexp1, 2) ^ "/" ^ toStr(lexp2,2), prec, 2)
54      | toStr(T.SLL(_,lexp, cnt), prec) =      | toStr(T.SLL(_,lexp, cnt), prec) =
55          parens(toStr(lexp,2) ^ "<<" ^ toStr(cnt,2), prec, 2)          parens(toStr(lexp,2) ^ "<<" ^ toStr(cnt,2), prec, 2)
56      | toStr(T.SRL(_,lexp, cnt), prec) =        | toStr(T.SRA(_,lexp, cnt), prec) =
57          parens(toStr(lexp,2) ^ ">>" ^ toStr(cnt,2), prec, 2)          parens(toStr(lexp,2) ^ ">>" ^ toStr(cnt,2), prec, 2)
58      | toStr(T.ANDB(_,lexp, mask), prec) =      | toStr(T.ANDB(_,lexp, mask), prec) =
59          parens(toStr(lexp,1) ^ "&" ^ toStr(mask, 1), prec, 1)          parens(toStr(lexp,1) ^ "&" ^ toStr(mask, 1), prec, 1)
60      | toStr(T.ORB(_,lexp, mask), prec) =      | toStr(T.ORB(_,lexp, mask), prec) =
61          parens(toStr(lexp, 1) ^ "|" ^ toStr(mask, 1), prec, 1)          parens(toStr(lexp, 1) ^ "|" ^ toStr(mask, 1), prec, 1)
62          | toStr(T.XORB(_,lexp, mask), prec) =
63              parens(toStr(lexp, 1) ^ "^" ^ toStr(mask, 1), prec, 1)
64      | toStr(T.ADD(_,lexp1, lexp2), prec) =      | toStr(T.ADD(_,lexp1, lexp2), prec) =
65          parens(toStr(lexp1, 0) ^ "+" ^ toStr(lexp2, 0), prec, 0)          parens(toStr(lexp1, 0) ^ "+" ^ toStr(lexp2, 0), prec, 0)
66      | toStr(T.SUB(_,lexp1, lexp2), prec) =      | toStr(T.SUB(_,lexp1, lexp2), prec) =
# Line 94  Line 94 
94          val pop = (case sz          val pop = (case sz
95                 of 8 => "\t.byte\t"                 of 8 => "\t.byte\t"
96                  | 16 => "\t.short\t"                  | 16 => "\t.short\t"
97                  | 32 => "\t.long\t"     (* NOTE: ".int" doesn't work in older versions of gas *)                    | 32 => "\t.int\t"
98                  | 64 => "\t.quad\t"                  | 64 => "\t.quad\t"
99                  | n => error ("unexpected INT size: " ^ Int.toString n)                  | n => error ("unexpected INT size: " ^ Int.toString n)
100                (* end case *))                (* end case *))
# Line 124  Line 124 
124          end          end
125    
126      | toString(PB.IMPORT labs) = decls("\t.extern\t%s", labs)      | toString(PB.IMPORT labs) = decls("\t.extern\t%s", labs)
127      | toString(PB.EXPORT labs) = decls("\t.globl\t%s", labs)        | toString(PB.EXPORT labs) = decls("\t.global\t%s", labs)
128      | toString(PB.COMMENT txt) = Fmt.format "/* %s */" [Fmt.STR txt]      | toString(PB.COMMENT txt) = Fmt.format "/* %s */" [Fmt.STR txt]
129    
130    

Legend:
Removed from v.1920  
changed lines
  Added in v.1921

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