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

SCM Repository

[diderot] Diff of /branches/pure-cfg/src/compiler/c-target/c-target.sml
ViewVC logotype

Diff of /branches/pure-cfg/src/compiler/c-target/c-target.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 565, Thu Feb 24 18:34:48 2011 UTC revision 573, Thu Mar 3 17:43:19 2011 UTC
# Line 108  Line 108 
108      structure Var =      structure Var =
109        struct        struct
110          fun global (Prog{globals, ...}, ty, name) = (          fun global (Prog{globals, ...}, ty, name) = (
111                globals := CL.D_Var([], cvtTy ty, name) :: !globals;                globals := CL.D_Var([], cvtTy ty, name, NONE) :: !globals;
112                (ty, name))                (ty, name))
113          fun param (ty, name) = (ty, name)          fun param (ty, name) = (ty, name)
114          fun state (Strand{state, ...}, ty, name) = (          fun state (Strand{state, ...}, ty, name) = (
# Line 435  Line 435 
435              selfTyDef :: List.rev (!code)              selfTyDef :: List.rev (!code)
436            end            end
437    
438      (* generate the table of strand descriptors *)
439        fun genStrandTable (ppStrm, strands) = let
440              val nStrands = length strands
441              fun genInit (Strand{name, tyName, code, ...}) = let
442                    fun fnPtr (ty, f) = CL.I_Exp(CL.mkCast(CL.T_Named ty, CL.mkVar f))
443                    in
444                      CL.I_Struct[
445                          ("name", CL.I_Exp(CL.E_Str name)),
446                          ("stateSzb", CL.I_Exp(CL.mkSizeof(CL.T_Named(RN.strandTy name)))),
447                          ("init", fnPtr("strand_init_t", RN.strandInit name)),
448                          ("update", fnPtr("strand_init_t", name ^ "_update"))
449                        ]
450                    end
451              fun genInits (_, []) = []
452                | genInits (i, s::ss) = (i, genInit s) :: genInits(i+1, ss)
453              fun ppDecl dcl = PrintAsC.output(ppStrm, dcl)
454              in
455                ppDecl (CL.D_Var([], CL.int32, RN.numStrands,
456                  SOME(CL.I_Exp(CL.E_Int(IntInf.fromInt nStrands, CL.int32)))));
457                ppDecl (CL.D_Var([], CL.T_Array(CL.T_Named RN.strandDescTy, SOME nStrands), RN.strands,
458                  SOME(CL.I_Array(genInits (0, strands)))))
459              end
460    
461      fun generate (baseName, Prog{globals, topDecls, strands}) = let      fun generate (baseName, Prog{globals, topDecls, strands}) = let
462            val fileName = OS.Path.joinBaseExt{base=baseName, ext=SOME "c"}            val fileName = OS.Path.joinBaseExt{base=baseName, ext=SOME "c"}
463            val outS = TextIO.openOut fileName            val outS = TextIO.openOut fileName
# Line 445  Line 468 
468              List.app ppDecl (List.rev (!topDecls));              List.app ppDecl (List.rev (!topDecls));
469  (* what about the strands, etc? *)  (* what about the strands, etc? *)
470              List.app (fn strand => List.app ppDecl (genStrand strand)) (!strands);              List.app (fn strand => List.app ppDecl (genStrand strand)) (!strands);
471                genStrandTable (ppStrm, !strands);
472              PrintAsC.close ppStrm;              PrintAsC.close ppStrm;
473              TextIO.closeOut outS              TextIO.closeOut outS
474            end            end

Legend:
Removed from v.565  
changed lines
  Added in v.573

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