Debian Codegraph @

lib/mlrisc-lib/MLRISC/Tools/MDL/mdl-rtl-comp.sig

raw
1 (*
2 * Process rtl descriptions
3 *)
4 signature MDL_RTL_COMP =
5 sig
6 structure Ast : MDL_AST
7 structure Comp : MDL_COMPILE
8 structure RTL : MLTREE_RTL
9 structure MLRiscTypes : MLRISC_TYPES
10 sharing Comp.Ast = MLRiscTypes.Ast = Ast
11 sharing MLRiscTypes.RTL = RTL
12
13 type compiled_rtls (* rtl in digested form *)
14
15 datatype rtl_def = RTLDEF of {id:Ast.id,args:Ast.id list,rtl:RTL.rtl}
16
17 (* current set of rtls *)
18 val current_rtls : rtl_def list ref
19
20 (* process the rtl *)
21 val compile : Comp.md -> compiled_rtls
22
23 (* extract the md component *)
24 val md : compiled_rtls -> Comp.md
25
26 (* extract the rtls *)
27 val rtls : compiled_rtls -> rtl_def list
28
29 (* emit and execute code for building the rtls *)
30 val gen : compiled_rtls -> unit
31
32 (* dump out all the rtl definitions *)
33 val dumpLog : compiled_rtls -> unit
34
35 (* A generic combinator for generate query functions.
36 * Use this method if you want to create new query routines.
37 *)
38 val mkQuery : compiled_rtls ->
39 { name : Ast.id, (* name of function *)
40 namedArguments : bool, (* use record arguments? *)
41 args : Ast.id list list, (* labeled arguments, may be curried *)
42 decls : Ast.decl list, (* local definitions *)
43 caseArgs : Ast.id list, (* extra arguments to the case exp *)
44 (* Callback to generate the actual code.
45 * An instruction constructor may represent a set of
46 * different instructions with different rtl templates.
47 * We enumerate all of them and let you decide
48 * how to generate the code.
49 *)
50 body : {instr : Ast.consbind, (* current instruction *)
51 rtl : rtl_def, (* rtl for this instruction *)
52 const : Ast.exp -> Ast.exp (* callback for making constants*)
53 } ->
54 { casePats : Ast.pat list, (* extra patterns *)
55 exp : Ast.exp (* and clause *)
56 }
57 } -> Ast.decl
58
59 (*
60 * A generic routine for generating def/use like queries
61 *)
62 val mkDefUseQuery : compiled_rtls ->
63 { name : Ast.id, (* name of function *)
64 args : Ast.id list list,
65 namedArguments : bool,
66 decls : Ast.decl list, (* local definitions *)
67 def : Ast.exp * RTL.exp * Ast.exp -> Ast.exp option,
68 use : Ast.exp * RTL.exp * Ast.exp -> Ast.exp option
69 } -> Ast.decl
70
71
72
73 (*
74 * Analyze all the arguments in an expression according to its
75 * rtl definition.
76 *)
77 val forallArgs : {instr : Ast.consbind, (* current instruction *)
78 rtl : rtl_def, (* current rtl *)
79 rtlArg : Ast.id * Ast.ty * RTL.exp * RTL.pos * 'a -> 'a,
80 nonRtlArg : Ast.id * Ast.ty * 'a -> 'a
81 } -> 'a -> 'a
82 (*
83 * Analyze all the arguments in an expression according to its
84 * rtl definition, create an expression that recreate that instruction.
85 *)
86 val mapInstr : {instr : Ast.consbind, (* current instruction *)
87 rtl : rtl_def, (* current rtl *)
88 rtlArg : Ast.id * Ast.ty * RTL.exp * RTL.pos ->
89 Ast.exp option,
90 nonRtlArg : Ast.id * Ast.ty -> Ast.exp option
91 } -> Ast.exp
92 (*
93 * Make an error handler
94 *)
95 val simpleErrorHandler : string -> Ast.decl
96 val complexErrorHandler : string -> Ast.decl
97 val complexErrorHandlerDef : unit -> Ast.decl
98
99 end