SCM Repository
Annotation of /sml/trunk/src/MLRISC/flowgraph/gasPseudoOps.sml
Parent Directory
|
Revision Log
Revision 1019 - (view) (download)
1 : | george | 991 | (* gasPseudoOps.sml |
2 : | * | ||
3 : | * COPYRIGHT (c) 2001 Lucent Technologies, Bell Laboratories. | ||
4 : | * | ||
5 : | * Implements the string related functions to emit pseudo-ops | ||
6 : | * in the standard GAS syntax. | ||
7 : | *) | ||
8 : | george | 984 | signature GAS_PSEUDO_OPS = sig |
9 : | structure T : MLTREE | ||
10 : | val lexpToString : T.labexp -> string | ||
11 : | val toString : (T.labexp, 'a) PseudoOpsBasisTyp.pseudo_op -> string | ||
12 : | val defineLabel : Label.label -> string | ||
13 : | end | ||
14 : | |||
15 : | functor GasPseudoOps | ||
16 : | ( structure T : MLTREE | ||
17 : | val labFmt : {gPrefix: string, aPrefix: string} | ||
18 : | ) : GAS_PSEUDO_OPS = | ||
19 : | struct | ||
20 : | structure T = T | ||
21 : | structure PB = PseudoOpsBasisTyp | ||
22 : | structure Fmt = Format | ||
23 : | |||
24 : | fun error msg = MLRiscErrorMsg.error ("GasPseudoOps.", msg) | ||
25 : | |||
26 : | fun prIntInf i = if IntInf.sign i < 0 then "-"^IntInf.toString(IntInf.~ i) | ||
27 : | else IntInf.toString i | ||
28 : | |||
29 : | fun prInt i = if i < 0 then "-"^Int.toString(~i) else Int.toString i | ||
30 : | |||
31 : | (* operator precedences: | ||
32 : | Note: these differ from C's precedences | ||
33 : | 2 MULT, DIV, LSHIFT, RSHIFT | ||
34 : | 1 AND, OR | ||
35 : | 0 PLUS, MINUS | ||
36 : | *) | ||
37 : | |||
38 : | fun parens (str, prec, op_prec) = | ||
39 : | if prec > op_prec then "(" ^ str ^ ")" else str | ||
40 : | |||
41 : | fun lexpToString le = toStr(le, 0) | ||
42 : | |||
43 : | and toStr(T.LABEL lab, _) = Label.fmt labFmt lab | ||
44 : | | toStr(T.LABEXP le, p) = toStr(le, p) | ||
45 : | | toStr(T.CONST c, _) = | ||
46 : | (prInt(T.Constant.valueOf c) handle _ => T.Constant.toString c) | ||
47 : | | toStr(T.LI i, _) = prIntInf i | ||
48 : | | toStr(T.MULS(_,lexp1, lexp2), _) = toStr(lexp1, 2) ^ "*" ^ toStr(lexp2,2) | ||
49 : | | toStr(T.DIVS(_,lexp1, lexp2), _) = toStr(lexp1, 2) ^ "/" ^ toStr(lexp2,2) | ||
50 : | | toStr(T.SLL(_,lexp, cnt), prec) = toStr(lexp,2) ^ "<<" ^ toStr(cnt,2) | ||
51 : | | toStr(T.SRL(_,lexp, cnt), prec) = toStr(lexp,2) ^ ">>" ^ toStr(cnt,2) | ||
52 : | | toStr(T.ANDB(_,lexp, mask), prec) = | ||
53 : | parens(toStr(lexp,1) ^ "&" ^ toStr(mask, 1), prec, 1) | ||
54 : | | toStr(T.ORB(_,lexp, mask), prec) = | ||
55 : | parens(toStr(lexp, 1) ^ "|" ^ toStr(mask, 1), prec, 1) | ||
56 : | | toStr(T.ADD(_,lexp1, lexp2), prec) = | ||
57 : | parens(toStr(lexp1, 0) ^ "+" ^ toStr(lexp2, 0), prec, 0) | ||
58 : | | toStr(T.SUB(_,lexp1, lexp2), prec) = | ||
59 : | parens(toStr(lexp1, 0) ^ "-" ^ toStr(lexp2, 0), prec, 0) | ||
60 : | | toStr _ = error "toStr" | ||
61 : | |||
62 : | fun defineLabel lab = lexpToString (T.LABEL lab) ^ ":" | ||
63 : | |||
64 : | fun decls (fmt, labs) = | ||
65 : | String.concat | ||
66 : | (map (fn lab => (Fmt.format fmt [Fmt.STR (lexpToString(T.LABEL lab))])) labs) | ||
67 : | |||
68 : | fun toString(PB.ALIGN_SZ n) = Fmt.format ".align %d" [Fmt.INT n] | ||
69 : | | toString(PB.ALIGN_ENTRY) = ".align 4" (* 16 byte boundary *) | ||
70 : | | toString(PB.ALIGN_LABEL) = ".p2align 4,,7" | ||
71 : | |||
72 : | | toString(PB.DATA_LABEL lab) = Label.fmt labFmt lab ^ ":" | ||
73 : | | toString(PB.DATA_READ_ONLY) = ".section .rodata" | ||
74 : | | toString(PB.DATA) = ".data" | ||
75 : | george | 1012 | | toString(PB.BSS) = ".section .bss" |
76 : | george | 984 | | toString(PB.TEXT) = ".text" |
77 : | | toString(PB.SECTION at) = ".section " ^ Atom.toString at | ||
78 : | |||
79 : | | toString(PB.REORDER) = "" | ||
80 : | | toString(PB.NOREORDER) = "" | ||
81 : | |||
82 : | | toString(PB.INT{sz, i}) = | ||
83 : | String.concat | ||
84 : | ((case sz | ||
85 : | of 8 => ".byte " | ||
86 : | | 16 => ".short " | ||
87 : | | 32 => ".int " | ||
88 : | | 64 => error "INT64" | ||
89 : | (*esac*)) :: map (fn lexp => lexpToString lexp ^ " ") i) | ||
90 : | |||
91 : | | toString(PB.ASCII s) = Fmt.format ".ascii \"%s\"" [Fmt.STR s] | ||
92 : | george | 1018 | | toString(PB.ASCIIZ s) = |
93 : | Fmt.format ".ascii \"%s\"" [Fmt.STR (String.toCString s)] | ||
94 : | george | 984 | |
95 : | george | 1012 | | toString(PB.SPACE sz) = Fmt.format ".space %d" [Fmt.INT sz] |
96 : | |||
97 : | george | 984 | | toString(PB.FLOAT{sz, f}) = |
98 : | String.concat | ||
99 : | ((case sz | ||
100 : | of 32 => ".single " | ||
101 : | | 64 => ".double " | ||
102 : | | 128 => ".extended " | ||
103 : | (*easc*)) :: f) | ||
104 : | |||
105 : | george | 1019 | | toString(PB.IMPORT labs) = decls(".extern %s\n", labs) |
106 : | | toString(PB.EXPORT labs) = decls(".global %s\n", labs) | ||
107 : | george | 984 | |
108 : | | toString(PB.EXT _) = error "EXT" | ||
109 : | |||
110 : | end |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |