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 3908 - (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 : jhr 3908 val gen : CodeGenEnv.t * TreeIR.strand -> CLang.decl list
14 : jhr 3864
15 :     end = struct
16 :    
17 :     structure IR = TreeIR
18 :     structure CL = CLang
19 : jhr 3908 structure RN = CxxNames
20 :     structure Env = CodeGenEnv
21 : jhr 3864
22 : jhr 3866 (* generate the strand-state initialization code. The variables are the strand
23 :     * parameters.
24 :     *)
25 : jhr 3908 fun genStateInit (env, strandName, strandTy, params, body) = let
26 : jhr 3866 val fName = strandName ^ "_init"
27 : jhr 3908 val selfParam = if TargetSpec.dualState(Env.target env)
28 :     then RN.selfOutVar
29 :     else RN.selfVar
30 : jhr 3866 val params =
31 : jhr 3908 CL.PARAM([], strandTy, selfParam) ::
32 : jhr 3866 List.map (fn (CL.V(ty, x)) => CL.PARAM([], ty, x)) params
33 : jhr 3908 val params = if #hasGlobals(Env.target env)
34 :     then RN.globalsParam :: params
35 : jhr 3866 else params
36 : jhr 3908 val body = TreeToCxx.trBlock (env, body)
37 : jhr 3866 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 : jhr 3908 fun genMethod (env, strandName, strandTy, methTy, methName, body) = let
43 : jhr 3864 val fName = concat[strandName, "_", methName]
44 : jhr 3908 val stateParams = if TargetSpec.dualState(Env.target env)
45 : jhr 3864 then [
46 : jhr 3908 CL.PARAM(["const"], strandTy, RN.selfVar),
47 :     CL.PARAM([], strandTy, RN.selfOutVar)
48 : jhr 3864 ]
49 : jhr 3908 else [CL.PARAM([], strandTy, RN.selfVar)]
50 :     val params = if #hasGlobals(Env.target env)
51 :     then RN.globalsParam :: stateParams
52 : jhr 3864 else stateParams
53 : jhr 3908 val body = TreeToCxx.trBlock (env, body)
54 : jhr 3864 in
55 :     CL.D_Func(["static"], methTy, methName, params, body)
56 :     end
57 :    
58 : jhr 3908 fun genInitiallyMethod (_, _, _, NONE) = []
59 :     | genInitiallyMethod (spec, strandName, strandTy, SOME body) =
60 :     [genMethod (spec, strandName, strandTy, CL.T_Named "StrandStatus_t", "initially", body)]
61 : jhr 3864
62 : jhr 3908 fun genUpdateMethod (spec, strandName, strandTy, body) =
63 :     genMethod (spec, strandName, strandTy, CL.T_Named "StrandStatus_t", "update", body)
64 : jhr 3864
65 : jhr 3908 fun genStabilizeMethod (_, _, _, NONE) = []
66 :     | genStabilizeMethod (spec, strandName, strandTy, SOME body) =
67 :     [genMethod (spec, strandName, strandTy, CL.voidTy, "stabilize", body)]
68 : jhr 3864
69 : jhr 3908 fun gen (env, strand) = let
70 : jhr 3864 val IR.Strand{name, params, state, stateInit, initM, updateM, stabilizeM} = strand
71 : jhr 3907 val name = Atom.toString name
72 : jhr 3908 val strandTy = CL.T_Ptr(CL.T_Named(name ^ "_strand"))
73 : jhr 3864 in
74 : jhr 3908 genStateInit (env, name, strandTy, ??, stateInit) ::
75 :     genInitiallyMethod (env, name, strandTy, initM) @
76 :     genUpdateMethod (env, name, strandTy, updateM) ::
77 :     genStabilizeMethod (env, name, strandTy, stabilizeM)
78 : jhr 3864 end
79 :    
80 :     end

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