Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Annotation of /branches/vis15/src/compiler/target-cpu/gen-strand.sml
ViewVC logotype

Annotation of /branches/vis15/src/compiler/target-cpu/gen-strand.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3866 - (view) (download)
Original Path: branches/vis15/src/compiler/tree-to-c/gen-strand.sml

1 : jhr 3864 (* gen-strand.sml
2 :     *
3 :     * Code generation for strands
4 :     *
5 :     * This code is part of the Diderot Project (http://diderot-language.cs.uchicago.edu)
6 :     *
7 :     * COPYRIGHT (c) 2016 The University of Chicago
8 :     * All rights reserved.
9 :     *)
10 :    
11 :     structure GenStrand : sig
12 :    
13 :     val gen : TargetSpec.t * TreeIR.strand -> CLang.decl list
14 :    
15 :     end = struct
16 :    
17 :     structure IR = TreeIR
18 :     structure CL = CLang
19 :     structure Spec = TargetSpec
20 :    
21 : jhr 3866 (* generate the strand-state initialization code. The variables are the strand
22 :     * parameters.
23 :     *)
24 :     fun genStateInit (spec, strandName, params, body) = let
25 :     val globTy = N.globalsPtrTy props
26 :     val fName = strandName ^ "_init"
27 :     val selfParam = if Properties.dualState props
28 :     then "selfOut"
29 :     else "self"
30 :     val params =
31 :     CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), selfParam) ::
32 :     List.map (fn (CL.V(ty, x)) => CL.PARAM([], ty, x)) params
33 :     val params = if #hasGlobals props
34 :     then CL.PARAM([], globTy, "glob") :: params
35 :     else params
36 :     val body = ??
37 :     in
38 :     CL.D_Func(["static"], CL.voidTy, fName, params, body)
39 :     end
40 :    
41 : jhr 3864 (* generate a function definition for a strand method *)
42 :     fun genMethod (spec, strandName, methTy, methName, body) = let
43 :     val globTy = N.globalsPtrTy props
44 :     val fName = concat[strandName, "_", methName]
45 :     val stateParams = if Spec.dualState spec
46 :     then [
47 :     CL.PARAM(["const"], CL.T_Ptr(CL.T_Named tyName), "selfIn"),
48 :     CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), "selfOut")
49 :     ]
50 :     else [CL.PARAM([], CL.T_Ptr(CL.T_Named tyName), "self")]
51 :     val params = if #hasGlobals spec
52 :     then CL.PARAM([], globTy, "glob") :: stateParams
53 :     else stateParams
54 : jhr 3866 val body = ??
55 : jhr 3864 in
56 :     CL.D_Func(["static"], methTy, methName, params, body)
57 :     end
58 :    
59 :     fun genInitiallyMethod (_, _, NONE) = []
60 :     | genInitiallyMethod (spec, strandName, SOME body) =
61 :     genMethod (spec, strandName, CL.T_Named "StrandStatus_t", "initially", body)
62 :    
63 :     fun genUpdateMethod (spec, strandName, body) =
64 :     genMethod (spec, strandName, CL.T_Named "StrandStatus_t", "update", body)
65 :    
66 :     fun genStabilizeMethod (_, _, NONE) = []
67 :     | genStabilizeMethod (spec, strandName, SOME body) =
68 :     genMethod (spec, strandName, CL.voidTy, "stabilize", body)
69 :    
70 :     fun gen (spec : TargetSpec.t, strand) = let
71 :     val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand
72 :     in
73 : jhr 3866 genStateInit (spec, name, ??, stateInit) ::
74 : jhr 3864 genInitiallyMethod (spec, name, initM) @
75 :     genUpdateMethod (spec, name, updateM) ::
76 :     genStabilizeMethod (spec, name, stabilizeM)
77 :     end
78 :    
79 :     end

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