File: cfgEmit.sml

package info (click to toggle)
mlton 20210117%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,464 kB
  • sloc: ansic: 27,682; sh: 4,455; asm: 3,569; lisp: 2,879; makefile: 2,347; perl: 1,169; python: 191; pascal: 68; javascript: 7
file content (75 lines) | stat: -rw-r--r-- 3,117 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
(* cfgEmit.sml
 *
 * COPYRIGHT (c) 2001 Bell Labs, Lucent Technologies
 *
 * This module takes a flowgraph and an assembly emitter module and 
 * ties them together into one.  The output is sent to AsmStream.
 *  --Allen
 *
 * TODO: Need to check for the REORDER/NOREORDER annotation on
 * blocks and call P.Client.AsmPseudoOps.toString function to
 * print out the appropriate assembler directive. -- Lal.
 *)

functor CFGEmit
  (structure E   : INSTRUCTION_EMITTER
   structure CFG : CONTROL_FLOW_GRAPH (* where I = E.I and P = E.S.P *)
                   where type I.addressing_mode = E.I.addressing_mode
                     and type I.ea = E.I.ea
                     and type I.instr = E.I.instr
                     and type I.instruction = E.I.instruction
                     and type I.operand = E.I.operand
                   where type P.Client.pseudo_op = E.S.P.Client.pseudo_op
                     and type P.T.Basis.cond = E.S.P.T.Basis.cond
                     and type P.T.Basis.div_rounding_mode = E.S.P.T.Basis.div_rounding_mode
                     and type P.T.Basis.ext = E.S.P.T.Basis.ext
                     and type P.T.Basis.fcond = E.S.P.T.Basis.fcond
                     and type P.T.Basis.rounding_mode = E.S.P.T.Basis.rounding_mode
                     and type P.T.Constant.const = E.S.P.T.Constant.const
                     and type ('s,'r,'f,'c) P.T.Extension.ccx = ('s,'r,'f,'c) E.S.P.T.Extension.ccx
                     and type ('s,'r,'f,'c) P.T.Extension.fx = ('s,'r,'f,'c) E.S.P.T.Extension.fx
                     and type ('s,'r,'f,'c) P.T.Extension.rx = ('s,'r,'f,'c) E.S.P.T.Extension.rx
                     and type ('s,'r,'f,'c) P.T.Extension.sx = ('s,'r,'f,'c) E.S.P.T.Extension.sx
                     and type P.T.I.div_rounding_mode = E.S.P.T.I.div_rounding_mode
                     and type P.T.Region.region = E.S.P.T.Region.region
                     and type P.T.ccexp = E.S.P.T.ccexp
                     and type P.T.fexp = E.S.P.T.fexp
                     (* and type P.T.labexp = E.S.P.T.labexp *)
                     and type P.T.mlrisc = E.S.P.T.mlrisc
                     and type P.T.oper = E.S.P.T.oper
                     and type P.T.rep = E.S.P.T.rep
                     and type P.T.rexp = E.S.P.T.rexp
                     and type P.T.stm = E.S.P.T.stm
  )  : ASSEMBLY_EMITTER =
struct
  structure CFG = CFG

  fun asmEmit (Graph.GRAPH graph, blocks) = let
	val CFG.INFO{annotations=an, data, decls, ...} = #graph_info graph
	val E.S.STREAM{pseudoOp,defineLabel,emit,annotation,comment,...} = 
             E.makeStream (!an)
	fun emitIt (id, CFG.BLOCK{labels, annotations=a, align, insns, ...}) = (
              case !align of NONE => () | SOME p => (pseudoOp p);
	      List.app defineLabel (!labels); 
	      List.app emitAn (!a);
	      List.app emit (rev (!insns)))
	and emitAn a = if Annotations.toString a = "" then () else annotation(a)
	in
	  List.app emitAn (!an);
	  List.app pseudoOp (rev (!decls));
	  pseudoOp(PseudoOpsBasisTyp.TEXT);
	  List.app emitIt blocks;
	  List.app pseudoOp (rev (!data))
	  
	end
end