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

SCM Repository

[sml3d] View of /trunk/sml3d/src/fi-gen/ml-gen.c
ViewVC logotype

View of /trunk/sml3d/src/fi-gen/ml-gen.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 292 - (download) (as text) (annotate)
Tue Sep 30 07:54:18 2008 UTC (11 years ago) by jhr
File size: 2130 byte(s)
repository restructuring
/* ml-gen.c
 *
 * COPYRIGHT (c) 2007 John Reppy (http://www.cs.uchicago.edu/~jhr)
 * All rights reserved.
 */

#include "ml-gen.h"
#include <stdbool.h>

char	*MLTypeName[] = {
	[U8]  = "Word8.word",
	[U16] = "Word16.word",
	[U32] = "Word32.word",
	[U64] = "Word64.word",
	[S8]  = "Int8.int",
	[S16] = "Int16.int",
	[S32] = "Int32.int",
	[S64] = "Int64.int",
	[F32] = "Real32.real",
	[F64] = "Real64.real",
	[PTR] = "MLton.Pointer.t"
   };

bool	Signed[] = {
	[U8]  = false,
	[U16] = false,
	[U32] = false,
	[U64] = false,
	[S8]  = true,
	[S16] = true,
	[S32] = true,
	[S64] = true,
	[F32] = true,
	[F64] = true,
	[PTR] = false
    };

char	*Suffix[] = {
	[U8]  = "Word8",
	[U16] = "Word16",
	[U32] = "Word32",
	[U64] = "Word64",
	[S8]  = "Int8",
	[S16] = "Int16",
	[S32] = "Int32",
	[S64] = "Int64",
	[F32] = "Real32",
	[F64] = "Real64",
	[PTR] = "Pointer"
   };

void prField (const char *fld, CType_t fldTy, off_t off)
{
    prOffset (0, fld, off);
    printf("\tfun get'%s p = MLton.Pointer.get%s(offset'%s p, 0)\n",
	fld, Suffix[fldTy], fld);
    printf("\tfun set'%s (p, v) = MLton.Pointer.set%s(offset'%s p, 0, v)\n",
	fld, Suffix[fldTy], fld);
}

void prSize (const char *ty, size_t sz)
{
    printf ("    val sizeof'%s : Word32.word = 0w%d\n", ty, (int)sz);
}

void prOffset (const char *ty, const char *fld, off_t off)
{
    if (ty == 0)
	printf ("\tfun offset'%s p = MLton.Pointer.add(p, 0w%d)\n",
	    fld, (int)off);
    else
	printf ("    fun offset'%s'%s p = MLton.Pointer.add(p, 0w%d)\n",
	    ty, fld, (int)off);
}

void prIndex (const char *ty, const char *fld, off_t off, size_t fldSz)
{
    if (ty == 0)
	printf ("\tfun offset'%s (p, i) = ", fld);
    else
	printf ("    fun offset'%s'%s (p, i) = ", ty, fld);
    printf ("MLton.Pointer.add(p, 0w%d + 0w%d*Word32.fromInt i)\n",
	(int)off, (int)fldSz);
}

void prConst (const char *name, CType_t ty, int val)
{
    if (Signed[ty]) {
	char *sign = "";
	if (val < 0) { val = -val; sign="~"; }
	printf ("    val %s : %s = %s%d\n", name, MLTypeName[ty], sign, val);
    }
    else {
	printf ("    val %s : %s = 0w%u\n", name, MLTypeName[ty], (unsigned)val);
    }
}

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