/* %Z%%M% %I% %E% */

/*
 * Copyright (c) 1990, 1991, 1992, 1993, 1995 by Wayne C. Gramlich.
 * All rights reserved.
 *
 * Permission to use, copy, modify, distribute, and sell this software
 * for any purpose is hereby granted without fee provided that the above
 * copyright notice and this permission are retained.  The author makes
 * no representations about the suitability of this software for any purpose.
 * It is provided "as is" without express or implied warranty.
 */

/* This file contains code for printing out module information: */

#ifndef GEN_DEFS_H
#include "gen_defs.h"
#endif

#ifndef LINT_H
#include "lint.h"
#endif

#ifndef MODULE_DEFS_H
#include "module_defs.h"
#endif

#ifndef ROUTINE_EXPORTS_H
#include "routine_exports.h"
#endif

#ifndef TYPE_EXPORTS_H
#include "type_exports.h"
#endif

#ifndef VAR_DEFS_H
#include "var_defs.h"
#endif

#ifndef VECTOR_DEFS_H
#include "vector_defs.h"
#endif

#ifndef UNIX_UNISTD_H
#include "unix_unistd.h"
#endif

LOCAL void	const_print(Var, Gen);

/*
 * module_print(module, gen)
 *	This routine will print "module" to "gen".
 */
void
module_print(
	Module		module,
	Gen		gen)
{
	Import		import;
	Type_def	type_def;
	Type_defs	type_defs;

	gen_out(gen, "%s\n", module->language);
	if (module->version != (Str)0) {
		gen_out(gen, "version %\"\n", module->version);
	}
	if (module->identify != (Str)0) {
		gen_out(gen, "identify %\"\n", module->identify);
	}
	gen_out(gen, "module %s\n", module->name);

	if (!vec_empty(Import, module->imports)) {
		gen_out(gen, "import\n");
		VEC_LOOP(Import, module->imports, import) {
			gen_out(gen, "%\t%s%\n",
				1, import->name, import->comment);
		}
	}
	type_defs = module->type_defs;
	VEC_LOOP(Type_def, type_defs, type_def) {
		gen_out(gen, "define ");
		type_def_print(type_def, gen->out_file);
	}
	gen_indented_list(gen, module->consts, const_print, 0);
	gen_indented_list(gen, module->routines, routine_print, 0);
}

/*
 * const_print(constant, gen)
 *	This routine will output "constant" to "gen".
 */
void
const_print(
	Var		constant,
	Gen		gen)
{
	gen_out(gen, "constant ");
	var_print(constant, gen->out_file, 0);
	gen_out(gen, "\n");
}
