Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] Annotation of /trunk/sml3d/gen/gen-from-xml/glgen/gen-consts.sml
ViewVC logotype

Annotation of /trunk/sml3d/gen/gen-from-xml/glgen/gen-consts.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1384 - (view) (download)

1 : jhr 1369 (* gen-consts.sml
2 :     *
3 :     * COPYRIGHT (c) 2014 The SML3d Project (http://sml3d.cs.uchicago.edu)
4 :     * All rights reserved.
5 :     *
6 :     *)
7 :    
8 :     structure GenConsts : sig
9 :    
10 :     (* Generate a structure containing all of the constant (i.e., enum) definitions
11 :     * in the database.
12 :     *)
13 :     val gen : {db : DBXMLRep.db, outFile : string, structName : string} -> unit
14 :    
15 :     val test : string -> unit
16 :    
17 :     end = struct
18 :    
19 :     structure X = DBXMLRep
20 :     structure F = Format
21 :    
22 :     (* header and footer for the output file *)
23 :     val header = "\
24 :     \(* %s\n\
25 :     \ *\n\
26 :     \ * COPYRIGHT (c) %4d The SML3d Project (http://sml3d.cs.uchicago.edu)\n\
27 :     \ * All rights reserved.\n\
28 :     \ *\n\
29 : jhr 1380 \ * These are the OpenGL constants taken from %s, which has the following\n\
30 :     \ * copyright notice:\n\
31 :     \ *\n\
32 :     \ * Copyright (c) 2013-2014 The Khronos Group Inc.\n\
33 :     \ *\n\
34 :     \ * Permission is hereby granted, free of charge, to any person obtaining a\n\
35 :     \ * copy of this software and/or associated documentation files (the\n\
36 :     \ * \"Materials\"), to deal in the Materials without restriction, including\n\
37 :     \ * without limitation the rights to use, copy, modify, merge, publish,\n\
38 :     \ * distribute, sublicense, and/or sell copies of the Materials, and to\n\
39 :     \ * permit persons to whom the Materials are furnished to do so, subject to\n\
40 :     \ * the following conditions:\n\
41 :     \ *\n\
42 :     \ * The above copyright notice and this permission notice shall be included\n\
43 :     \ * in all copies or substantial portions of the Materials.\n\
44 :     \ *\n\
45 :     \ * THE MATERIALS ARE PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n\
46 :     \ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\
47 :     \ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n\
48 :     \ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n\
49 :     \ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n\
50 :     \ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\
51 :     \ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.\n\
52 : jhr 1369 \ *\n\
53 :     \ * WARNING: this file is generated; do not edit!!!\n\
54 :     \ *)\n\
55 :     \\n\
56 :     \structure %s =\n\
57 :     \ struct\n\
58 :     \\n\
59 :     \ type glenum = GLTypes.glenum\n\
60 :     \\n\
61 :     \"
62 :     val footer = "\
63 :     \\n\
64 :     \ end (* %s *)\n\
65 :     \"
66 :    
67 :     val a_GLint = Atom.atom "GLint"
68 : jhr 1379 val a_GLenum = Atom.atom "GLenum"
69 : jhr 1369 val a_GLuint = Atom.atom "GLuint"
70 :     val a_GLuint64 = Atom.atom "GLuint64"
71 :    
72 :     fun gen {db, outFile, structName} = let
73 :     val outS = TextIO.openOut outFile
74 :     fun pr s = TextIO.output(outS, s)
75 :     fun prf (fmt, items) = pr(F.format fmt items)
76 :     val X.DB{registry, enums, ...} = db
77 :     fun genEnum {name, ty, value} = let
78 :     val (isSigned, mlty) = (case ty
79 : jhr 1379 of NONE => (false, "glenum")
80 : jhr 1369 | SOME(CType.NamedTy ty) =>
81 :     if Atom.same(ty, a_GLint) then (true, "glint")
82 : jhr 1379 else if Atom.same(ty, a_GLenum) then (false, "glenum")
83 :     else if Atom.same(ty, a_GLuint) then (false, "gluint")
84 : jhr 1384 else if Atom.same(ty, a_GLuint64) then (false, "gluint64")
85 : jhr 1369 else raise Fail "unknown C type"
86 :     | _ => raise Fail "unknown C type"
87 :     (* end case *))
88 :     in
89 : jhr 1379 if not isSigned
90 :     then prf(" val %s : %s = 0wx%08x\n", [F.ATOM name, F.STR mlty, F.LINT value])
91 :     else if (value < 0)
92 :     then prf(" val %s : %s = ~%d\n", [F.ATOM name, F.STR mlty, F.LINT(~value)])
93 :     else prf(" val %s : %s = %d\n", [F.ATOM name, F.STR mlty, F.LINT value])
94 : jhr 1369 end
95 :     in
96 :     prf (header, [
97 :     F.STR(OS.Path.file outFile), F.INT(Date.year(Date.fromTimeLocal(Time.now()))),
98 :     F.STR registry, F.STR structName
99 :     ]);
100 :     List.app genEnum enums;
101 :     prf (footer, [F.STR structName]);
102 :     TextIO.closeOut outS
103 :     end
104 :    
105 :     fun test dbFile = let
106 :     val db = DBXMLParser.parseFile dbFile
107 :     in
108 :     gen {db = db, outFile = "consts.sml", structName = "Consts"}
109 :     end
110 :    
111 :     end

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