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 3907 - (view) (download)

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 : jhr 3907 val globTy = N.globalsPtrTy spec
26 : jhr 3866 val fName = strandName ^ "_init"
27 : jhr 3907 val selfParam = if Spec.dualState spec
28 : jhr 3866 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 : jhr 3907 val params = if #hasGlobals spec
34 : jhr 3866 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 : jhr 3907 val globTy = N.globalsPtrTy spec
44 : jhr 3864 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 : jhr 3907 [genMethod (spec, strandName, CL.T_Named "StrandStatus_t", "initially", body)]
62 : jhr 3864
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 : jhr 3907 [genMethod (spec, strandName, CL.voidTy, "stabilize", body)]
69 : jhr 3864
70 :     fun gen (spec : TargetSpec.t, strand) = let
71 :     val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand
72 : jhr 3907 val name = Atom.toString name
73 : jhr 3864 in
74 : jhr 3866 genStateInit (spec, name, ??, stateInit) ::
75 : jhr 3864 genInitiallyMethod (spec, name, initM) @
76 :     genUpdateMethod (spec, name, updateM) ::
77 :     genStabilizeMethod (spec, name, stabilizeM)
78 :     end
79 :    
80 :     end

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