Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/ml-nlffigen/main.sml
ViewVC logotype

Annotation of /sml/trunk/src/ml-nlffigen/main.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1011 - (view) (download)

1 : blume 828 (*
2 :     * main.sml - Driver routine ("main") for ml-ffigen.
3 :     *
4 :     * (C) 2001, Lucent Technologies, Bell Labs
5 :     *
6 :     * author: Matthias Blume (blume@research.bell-labs.com)
7 :     *)
8 :     structure Main = struct
9 :     local
10 : blume 840
11 :     fun tgt (n, sz, sh, cc) =
12 :     { name = n, sizes = sz, shift = sh, stdcall = cc }
13 :    
14 :     val default_target =
15 :     tgt (DefaultName.name,
16 :     DefaultSizes.sizes, DefaultEndian.shift, DefaultCC.stdcall)
17 :    
18 :     val target_table =
19 :     [tgt ("sparc-unix",
20 :     SizesSparc.sizes, EndianBig.shift, CC_ccall.stdcall),
21 :     tgt ("x86-unix",
22 :     SizesX86.sizes, EndianLittle.shift, CC_ccall.stdcall),
23 :     tgt ("x86-win32",
24 :     SizesX86.sizes, EndianLittle.shift, CC_stdcall.stdcall)
25 :     (* needs to be extended ... *)
26 :     ]
27 :    
28 :     fun find_target tg =
29 :     case List.find (fn x => tg = #name x) target_table of
30 :     SOME t => t
31 :     | NONE => raise Fail (concat ["unknown target: " ^ tg])
32 :    
33 : blume 828 fun main0 (arg0, args) = let
34 :     fun substitute (tmpl, s, t) = let
35 :     fun loop ([], a) = String.implode (rev a)
36 :     | loop (#"%" :: #"s" :: l, a) = loop (l, push (s, a))
37 :     | loop (#"%" :: #"t" :: l, a) = loop (l, push (t, a))
38 :     | loop (c :: l, a) = loop (l, c :: a)
39 :     and push (x, a) = List.revAppend (String.explode x, a)
40 :     in
41 :     loop (String.explode tmpl, [])
42 :     end
43 : blume 975
44 : blume 1011 val dir = ref "NLFFI-Generated"
45 :     val cmf = ref "nlffi-generated.cm"
46 :     val prefix = ref ""
47 :     val ems = ref []
48 :     val libh = ref "Library.libh"
49 :     val cmpl = ref true
50 : blume 975 val asu = ref false
51 :     val wid = ref NONE
52 :     val lsp = ref NONE
53 :     val target = ref default_target
54 :     val wrq = ref NONE
55 : blume 977 val namedargs = ref false
56 : blume 975
57 : blume 1011 fun finish cfiles = let
58 :     fun mkidlsource cfile = let
59 :     val ifile = OS.FileSys.tmpName ()
60 : blume 828 val cpp_tmpl = getOpt (OS.Process.getEnv "FFIGEN_CPP",
61 :     "gcc -E -U__GNUC__ %s > %t")
62 : blume 1011 val cpp = substitute (cpp_tmpl, cfile, ifile)
63 : blume 828 in
64 : blume 1011 if OS.Process.system cpp <> OS.Process.success then
65 :     raise Fail ("C-preprocessor failed: " ^ cpp)
66 :     else ();
67 :     ifile
68 : blume 828 end
69 : blume 1011 in
70 :     Gen.gen { cfiles = cfiles,
71 :     mkidlsource = mkidlsource,
72 :     dirname = !dir,
73 :     cmfile = !cmf,
74 :     prefix = !prefix,
75 :     extramembers = !ems,
76 :     libraryhandle = !libh,
77 :     complete = !cmpl,
78 :     allSU = !asu,
79 :     lambdasplit = !lsp,
80 :     weightreq = !wrq,
81 :     wid = getOpt (!wid, 75),
82 :     namedargs = !namedargs,
83 :     target = !target };
84 :     OS.Process.success
85 :     end
86 :    
87 :     fun proc ("-allSU" :: l) = (asu := true; proc l)
88 : blume 975 | proc ("-width" :: i :: l) = (wid := Int.fromString i; proc l)
89 :     | proc ("-lambdasplit" :: s :: l) = (lsp := SOME s; proc l)
90 :     | proc ("-target" :: tg :: l) = (target := find_target tg; proc l)
91 :     | proc ("-light" :: l) = (wrq := SOME false; proc l)
92 :     | proc ("-heavy" :: l) = (wrq := SOME true; proc l)
93 : blume 977 | proc ("-namedargs" :: l) = (namedargs := true; proc l)
94 : blume 1011 | proc ("-incomplete" :: l) = (cmpl := false; proc l)
95 :     | proc ("-libhandle" :: lh :: l) = (libh := lh; proc l)
96 :     | proc ("-include" :: es :: l) = (ems := es :: !ems; proc l)
97 :     | proc ("-prefix" :: p :: l) = (prefix := p; proc l)
98 :     | proc ("-dir" :: d :: l) = (dir := d; proc l)
99 :     | proc ("-cmfile" :: f :: l) = (cmf := f; proc l)
100 :     | proc ("--" :: cfiles) = finish cfiles
101 :     | proc cfiles = finish cfiles
102 : blume 828 in
103 : blume 975 proc args
104 : blume 828 end
105 :     in
106 :     fun main args = main0 args
107 :     handle exn => (TextIO.output (TextIO.stdErr, General.exnMessage exn);
108 :     TextIO.output (TextIO.stdErr, "\n");
109 :     OS.Process.failure)
110 :     end
111 :     end

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