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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (download) (annotate)
Sat Apr 5 20:42:58 2014 UTC (5 years ago) by jhr
File size: 4184 byte(s)
  Working on FI generation
(* gen-consts.sml
 *
 * COPYRIGHT (c) 2014 The SML3d Project (http://sml3d.cs.uchicago.edu)
 * All rights reserved.
 *
 *)

structure GenConsts : sig

  (* Generate a structure containing all of the constant (i.e., enum) definitions
   * in the database.
   *)
    val gen : {db : DBXMLRep.db, outFile : string, structName : string} -> unit

    val test : string -> unit

  end = struct

    structure X = DBXMLRep
    structure F = Format

  (* header and footer for the output file *)
    val header = "\
	  \(* %s\n\
	  \ *\n\
	  \ * COPYRIGHT (c) %4d The SML3d Project (http://sml3d.cs.uchicago.edu)\n\
	  \ * All rights reserved.\n\
	  \ *\n\
	  \ * These are the OpenGL constants taken from %s, which has the following\n\
	  \ * copyright notice:\n\
	  \ *\n\
	  \ * Copyright (c) 2013-2014 The Khronos Group Inc.\n\
	  \ *\n\
	  \ * Permission is hereby granted, free of charge, to any person obtaining a\n\
	  \ * copy of this software and/or associated documentation files (the\n\
	  \ * \"Materials\"), to deal in the Materials without restriction, including\n\
	  \ * without limitation the rights to use, copy, modify, merge, publish,\n\
	  \ * distribute, sublicense, and/or sell copies of the Materials, and to\n\
	  \ * permit persons to whom the Materials are furnished to do so, subject to\n\
	  \ * the following conditions:\n\
	  \ *\n\
	  \ * The above copyright notice and this permission notice shall be included\n\
	  \ * in all copies or substantial portions of the Materials.\n\
	  \ *\n\
	  \ * THE MATERIALS ARE PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n\
	  \ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\
	  \ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n\
	  \ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n\
	  \ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n\
	  \ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n\
	  \ * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.\n\
          \ *\n\
          \ * WARNING: this file is generated; do not edit!!!\n\
	  \ *)\n\
	  \\n\
	  \structure %s =\n\
	  \  struct\n\
	  \\n\
	  \    local\n\
	  \      type glint = GLTypes.glint\n\
	  \      type glenum = GLTypes.glenum\n\
	  \      type gluint = GLTypes.gluint\n\
	  \      type gluint64 = GLTypes.gluint64\n\
	  \    in\n\
	  \\n\
          \"
    val footer = "\
	  \\n\
	  \    end (* local *)\n\
	  \\n\
	  \  end (* %s *)\n\
          \"

    val a_GLint = Atom.atom "GLint"
    val a_GLenum = Atom.atom "GLenum"
    val a_GLuint = Atom.atom "GLuint"
    val a_GLuint64 = Atom.atom "GLuint64"

    fun gen {db, outFile, structName} = let
          val outS = TextIO.openOut outFile
          fun pr s = TextIO.output(outS, s)
          fun prf (fmt, items) = pr(F.format fmt items)
          val X.DB{registry, enums, ...} = db
	  fun genEnum {name, ty, value} = let
		val (isSigned, mlty) = (case ty
		       of NONE => (false, "glenum")
			| SOME(CType.NamedTy ty) =>
			    if Atom.same(ty, a_GLint) then (true, "glint")
			    else if Atom.same(ty, a_GLenum) then (false, "glenum")
			    else if Atom.same(ty, a_GLuint) then (false, "gluint")
			    else if Atom.same(ty, a_GLuint64) then (false, "gluint64")
			    else raise Fail "unknown C type"
			| _ => raise Fail "unknown C type"
		      (* end case *))
		in
		  if not isSigned
		    then prf("    val %s : %s = 0wx%08x\n", [F.ATOM name, F.STR mlty, F.LINT value])
		  else if (value < 0)
		    then prf("    val %s : %s = ~%d\n", [F.ATOM name, F.STR mlty, F.LINT(~value)])
		    else prf("    val %s : %s = %d\n", [F.ATOM name, F.STR mlty, F.LINT value])
		end
          in
            prf (header, [
		F.STR(OS.Path.file outFile), F.INT(Date.year(Date.fromTimeLocal(Time.now()))),
		F.STR registry, F.STR structName
	      ]);
            List.app genEnum enums;
            prf (footer, [F.STR structName]);
            TextIO.closeOut outS
          end

    fun test dbFile = let
          val db = DBXMLParser.parseFile dbFile
          in
            gen {db = db, outFile = "consts.sml", structName = "Consts"}
          end

  end

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