Commit ea300793 authored by Michal Cadilhac's avatar Michal Cadilhac

2005-07-13 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>

	* sample.brg: Move to...
	* tests/sample.brg: ...Here.

	* parser.y: Move to...
	* src/parser.y: ...Here.
	
	* monoburg.1: Move to...
	* src/monoburg.1: ...Here.
	
	* monoburg.c,
	* monoburg.h: Split in...
	* src/emit.c,
	* src/parser.h,
	* src/emit.h,
	* src/rule.c,
	* src/emit_kids.c,
	* src/rule.h,
	* src/check.c,
	* src/emit_files.c,
	* src/emit_pretty_print.c,
	* src/check.h,
	* src/main.c,
	* src/emit_cost.c,
	* src/emit_functions.c,
	* src/monoburg.h: ...These files.
	
	* src/Makefile.am,
	* tests/Makefile.am: New. Create accordingly.
	
	* NOTICE,
	* AUTHORS,
	* NEWS: New. Add some package related files.
	
	* configure.ac,
	* Makefile.am: Update accordingly.
parent 95d27bca
* Dietmar Maurer (dietmar@ximian.com).
* Cadilhac Michael (cadilhac@lrde.org).
2005-07-13 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
* sample.brg: Move to...
* tests/sample.brg: ...Here.
* parser.y: Move to...
* src/parser.y: ...Here.
* monoburg.1: Move to...
* src/monoburg.1: ...Here.
* monoburg.c,
* monoburg.h: Split in...
* src/emit.c,
* src/parser.h,
* src/emit.h,
* src/rule.c,
* src/emit_kids.c,
* src/rule.h,
* src/check.c,
* src/emit_files.c,
* src/emit_pretty_print.c,
* src/check.h,
* src/main.c,
* src/emit_cost.c,
* src/emit_functions.c,
* src/monoburg.h: ...These files.
* src/Makefile.am,
* tests/Makefile.am: New. Create accordingly.
* NOTICE,
* AUTHORS,
* NEWS: New. Add some package related files.
* configure.ac,
* Makefile.am: Update accordingly.
2005-06-27 Michael Cadilhac <michael.cadilhac@lrde.epita.fr>
* configure.ac: Bump to 1.0.2.
......
## Makefile.am -- Process this file with automake to produce Makefile.in
##
SUBDIRS = config
## Include path
INCLUDES = $(GLIB_CFLAGS) -I$(srcdir)
## MonoBURG binary
bin_PROGRAMS = monoburg
monoburg_SOURCES = \
parser.y \
monoburg.c monoburg.h
monoburg_LDADD = \
$(GLIB_LIBS)
## MonoBURG manual
man_MANS = monoburg.1
EXTRA_DIST = ChangeLog $(man_MANS)
## Check/Sample
check_PROGRAMS = sample
TESTS = sample
sample.c: monoburg$(EXEEXT) $(srcdir)/sample.brg
./monoburg$(EXEEXT) $(srcdir)/sample.brg > sample.c
sample_SOURCES = sample.brg
sample_LDADD = sample.o $(GLIB_LIBS)
CLEANFILES = sample.c sample.o parser.c
SUBDIRS = src config tests
EXTRA_DIST = bootstrap ChangeLog NOTICE
MonoBURG, an iburg like code generator generator.
Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
The Vaucanson Group consists of people listed in the `AUTHORS' file.
Contact: mono@novell.com.
......@@ -18,7 +18,7 @@ AC_CONFIG_AUX_DIR([config])
AC_CONFIG_FILES([config/Makefile])
# Initiate automake.
AM_INIT_AUTOMAKE([foreign 1.7.5 dist-bzip2])
AM_INIT_AUTOMAKE([1.7.5 dist-bzip2])
## -------------------------------------
## Development tools
......@@ -41,6 +41,8 @@ AM_PATH_GLIB_2_0
# Ask for Makefile creation
AC_CONFIG_FILES([
Makefile
src/Makefile
tests/Makefile
])
# Instantiate the output files
......
This diff is collapsed.
INCLUDES = $(GLIB_CFLAGS) -I$(srcdir)
bin_PROGRAMS = monoburg
monoburg_SOURCES = \
parser.y \
check.c check.h \
emit.c emit.h \
emit_cost.c emit_files.c \
emit_functions.c emit_kids.c \
emit_pretty_print.c main.c \
monoburg.h parser.h \
rule.c rule.h
monoburg_LDADD = \
$(GLIB_LIBS)
man_MANS = monoburg.1
EXTRA_DIST = $(man_MANS)
/**
** check.c: this file is part of MonoBURG.
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** The complete GNU General Public Licence Notice can be found as the
** `NOTICE' file in the root directory.
**
** \author Dietmar Maurer (dietmar@ximian.com)
** \author Cadilhac Michael (cadilhac@lrde.org)
** \brief Check parse consistency.
*/
#include "monoburg.h"
#include "rule.h"
static void check_reach (NonTerm *n);
static void mark_reached (Tree *tree);
/** Check the consistency of the parse, by checking reachability of
each non terminal symbols and arity of terminals. */
void check_result ()
{
GList *l;
for (l = term_list; l; l = l->next) {
Term *term = (Term *)l->data;
if (term->arity == -1)
g_warning ("unused terminal \"%s\"",term->name);
}
check_reach (((NonTerm *)nonterm_list->data));
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
if (!n->reached)
g_warning ("unreachable nonterm \"%s\"", n->name);
}
}
static void check_reach (NonTerm *n)
{
GList *l;
n->reached = 1;
for (l = n->rules; l; l = l->next) {
Rule *rule = (Rule *)l->data;
mark_reached (rule->tree);
}
}
static void mark_reached (Tree *tree)
{
if (tree->nonterm && !tree->nonterm->reached)
check_reach (tree->nonterm);
if (tree->left)
mark_reached (tree->left);
if (tree->right)
mark_reached (tree->right);
}
/**
** check.h: this file is part of MonoBURG.
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** The complete GNU General Public Licence Notice can be found as the
** `NOTICE' file in the root directory.
**
** \author Dietmar Maurer (dietmar@ximian.com)
** \author Cadilhac Michael (cadilhac@lrde.org)
** \brief Check parse consistency (prototypes).
*/
#ifndef __MONO_CHECK_H__
# define __MONO_CHECK_H__
void check_result ();
#endif /* __MONO_CHECK_H__ */
This diff is collapsed.
/**
** emit.h: this file is part of MonoBURG.
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** The complete GNU General Public Licence Notice can be found as the
** `NOTICE' file in the root directory.
**
** \author Dietmar Maurer (dietmar@ximian.com)
** \author Cadilhac Michael (cadilhac@lrde.org)
** \brief Prototypes of all emit functions.
*/
#ifndef __MONO_EMIT_H__
# define __MONO_EMIT_H__
# include "rule.h"
extern FILE *outputfd;
void output (char *fmt, ...);
void emit_header_file ();
void emit_code_file ();
void emit_closure ();
void emit_cost_func ();
void emit_decoders ();
void emit_emitter_func ();
void emit_header ();
void emit_includes ();
void emit_kids ();
void emit_label_func ();
void emit_nonterm ();
void emit_prototypes ();
void emit_state ();
void emit_term ();
void emit_vardefs ();
void emit_rule_string (Rule *rule, char *fill);
void emit_costs (char *st, Tree *t);
void emit_cond_assign (Rule *rule, char *cost, char *fill);
void emit_tree_string (Tree *tree);
#endif /* __MONO_EMIT_H__ */
/**
** emit_cods.c: this file is part of MonoBURG.
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** The complete GNU General Public Licence Notice can be found as the
** `NOTICE' file in the root directory.
**
** \author Dietmar Maurer (dietmar@ximian.com)
** \author Cadilhac Michael (cadilhac@lrde.org)
** \brief Emic cost functions.
*/
#include "monoburg.h"
#include "parser.h"
#include "emit.h"
/** Emit cost functions. */
void emit_cost_func ()
{
GList *l;
int i;
if (!with_exported_symbols)
output ("static int mono_burg_rule (MBState *state, int goal);\n");
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
if (rule->cfunc) {
output ("inline static guint16\n");
emit_rule_string (rule, "");
if (dag_mode)
output ("mono_burg_cost_%d (MBState *state, MBCOST_DATA *data)\n", i + 1);
else
output ("mono_burg_cost_%d (MBTREE_TYPE %ctree, MBCOST_DATA *data)\n", i + 1,
(with_references ? '&' : '*'));
output ("{\n");
output ("\t(void) data; ");
if (dag_mode)
output ("(void) state;\n");
else
output ("(void) tree;\n");
output ("%s\n", rule->cfunc);
output ("}\n\n");
}
i++;
}
}
/** Emit closure functions. */
void emit_closure ()
{
GList *l, *rl;
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
if (n->chain)
output ("static void closure_%s (MBState *p, int c);\n", n->name);
}
output ("\n");
for (l = nonterm_list; l; l = l->next) {
NonTerm *n = (NonTerm *)l->data;
if (n->chain) {
output ("static void\n");
output ("closure_%s (MBState *p, int c)\n{\n", n->name);
for (rl = n->chain; rl; rl = rl->next) {
Rule *rule = (Rule *)rl->data;
emit_rule_string (rule, "\t");
emit_cond_assign (rule, rule->cost, "\t");
}
output ("}\n\n");
}
}
}
/** Emit the cost sum. */
void emit_costs (char *st, Tree *t)
{
char *tn;
if (t->op) {
if (t->left) {
tn = g_strconcat (st, "left->", NULL);
emit_costs (tn, t->left);
g_free (tn);
}
if (t->right) {
tn = g_strconcat (st, "right->", NULL);
emit_costs (tn, t->right);
}
} else
output ("%scost[MB_NTERM_%s] + ", st, t->nonterm->name);
}
/** Emit test on cost. */
void emit_cond_assign (Rule *rule, char *cost, char *fill)
{
char *rc;
if (cost)
rc = g_strconcat ("c + ", cost, NULL);
else
rc = g_strdup ("c");
output ("%sif (%s < p->cost[MB_NTERM_%s]) {\n", fill, rc, rule->lhs->name);
output ("%s\tp->cost[MB_NTERM_%s] = %s;\n", fill, rule->lhs->name, rc);
output ("%s\tp->rule_%s = %d;\n", fill, rule->lhs->name,
g_list_index (rule->lhs->rules, rule) + 1);
if (rule->lhs->chain)
output ("%s\tclosure_%s (p, %s);\n", fill, rule->lhs->name, rc);
output ("%s}\n", fill);
g_free (rc);
}
/**
** emit_files.c: this file is part of MonoBURG.
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** The complete GNU General Public Licence Notice can be found as the
** `NOTICE' file in the root directory.
**
** \author Dietmar Maurer (dietmar@ximian.com)
** \author Cadilhac Michael (cadilhac@lrde.org)
** \brief Wrapper for C/Header file output.
*/
#include "monoburg.h"
#include "parser.h"
#include "emit.h"
/** Output header file data. */
void emit_header_file ()
{
int i;
emit_includes ();
emit_header ();
for (i = 0; i < n_namespace; ++i)
output ("namespace %s {\n", namespaces[i]);
emit_term ();
emit_nonterm ();
emit_state ();
emit_prototypes ();
for (i = 0; i < n_namespace; ++i)
output ("}\n");
}
/** Output C file data. */
void emit_code_file ()
{
int i;
for (i = 0; i < n_namespace; ++i)
output ("namespace %s {\n", namespaces[i]);
emit_vardefs ();
emit_cost_func ();
emit_emitter_func ();
emit_decoders ();
emit_closure ();
emit_label_func ();
emit_kids ();
for (i = 0; i < n_namespace; ++i)
output ("}\n");
}
/**
** emit_functions.c: this file is part of MonoBURG.
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** The complete GNU General Public Licence Notice can be found as the
** `NOTICE' file in the root directory.
**
** \author Dietmar Maurer (dietmar@ximian.com)
** \author Cadilhac Michael (cadilhac@lrde.org)
** \brief Emit rules' functions.
*/
#include "monoburg.h"
#include "emit.h"
static void emit_tree_variables (char *prefix, int depth, Tree *t);
static void emit_rule_variables (Rule *rule);
/** Emit rule functions. */
void emit_emitter_func ()
{
GList *l;
int i, rulen;
GHashTable *cache = g_hash_table_new (g_str_hash, g_str_equal);
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
if (rule->code) {
if ((rulen = GPOINTER_TO_INT (g_hash_table_lookup (cache, rule->code)))) {
emit_rule_string (rule, "");
output ("#define mono_burg_emit_%d mono_burg_emit_%d\n\n", i, rulen);
i++;
continue;
}
output ("static void ");
emit_rule_string (rule, "");
if (dag_mode)
output ("mono_burg_emit_%d (MBState *state, MBTREE_TYPE %ctree, MBCGEN_TYPE *s)\n", i,
(with_references ? '&' : '*'));
else
output ("mono_burg_emit_%d (MBTREE_TYPE %ctree, MBCGEN_TYPE *s)\n", i,
(with_references ? '&' : '*'));
output ("{\n");
output ("(void) tree; (void) s;");
if (dag_mode)
output (" (void) state;");
output ("\n");
emit_rule_variables (rule);
output ("%s\n", rule->code);
output ("}\n\n");
g_hash_table_insert (cache, rule->code, GINT_TO_POINTER (i));
}
i++;
}
g_hash_table_destroy (cache);
if (!with_exported_symbols)
output ("static ");
output ("MBEmitFunc const mono_burg_func [] = {\n");
output ("\tNULL,\n");
for (l = rule_list, i = 0; l; l = l->next) {
Rule *rule = (Rule *)l->data;
if (rule->code)
output ("\tmono_burg_emit_%d,\n", i);
else
output ("\tNULL,\n");
i++;
}
output ("};\n\n");
}
/** Emit named rule parts of a rule. */
static void emit_rule_variables (Rule *rule)
{
Tree *t = rule->tree;
if (t) {
emit_tree_variables ("", 0, t);
}
}
/** Emit named rule parts of a rule tree. */
static void emit_tree_variables (char *prefix, int depth, Tree *t)
{
char *tn;
int i;
if (t->varname) {
if (with_references) {
output ("MBTREE_TYPE &%s = *(%s(&tree))",
t->varname, prefix);
} else {
output ("MBTREE_TYPE *%s = (%s(tree))",
t->varname, prefix);
}
for (i = 0; i < depth; ++i)
output (")");
output (";\n");
}
if (t->left) {
tn = g_strconcat ("MBTREE_LEFT(", prefix, NULL);
emit_tree_variables (tn, depth + 1, t->left);
g_free (tn);
}
if (t->right) {
tn = g_strconcat ("MBTREE_RIGHT(", prefix, NULL);
emit_tree_variables (tn, depth + 1, t->right);
g_free (tn);
}
}
/**
** emit_kids.c: this file is part of MonoBURG.
**
** MonoBURG, an iburg like code generator generator.
**
** Copyright (C) 2001, 2002, 2004, 2005 Ximian, Inc.
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation; either version 2
** of the License, or (at your option) any later version.
**
** The complete GNU General Public Licence Notice can be found as the
** `NOTICE' file in the root directory.
**
** \author Dietmar Maurer (dietmar@ximian.com)
** \author Cadilhac Michael (cadilhac@lrde.org)
** \brief Functions for kids emitting.
*/
#include <string.h>
#include "monoburg.h"
#include "emit.h"
static char *compute_kids (char *ts, Tree *tree, int *n);
/** Emit `mono_burg_rule' and `mono_burg_kids'. */
void emit_kids ()
{
GList *l, *nl;
int i, j, c, n, *si;
char **sa;
if (!with_exported_symbols)
output ("static ");
output ("int\n");
output ("mono_burg_rule (MBState *state, int goal)\n{\n");
output ("\tg_return_val_if_fail (state != NULL, 0);\n");
output ("\tg_return_val_if_fail (goal > 0, 0);\n\n");
output ("\tswitch (goal) {\n");
for (nl = nonterm_list; nl; nl = nl->next) {
NonTerm *n = (NonTerm *)nl->data;
output ("\tcase MB_NTERM_%s:\n", n->name);
output ("\t\treturn mono_burg_decode_%s [state->rule_%s];\n",
n->name, n->name);
}
output ("\tdefault: g_assert_not_reached ();\n");
output ("\t}\n");
output ("\treturn 0;\n");
output ("}\n\n");
if (dag_mode) {
if (!with_exported_symbols)
output ("static ");
output ("MBState **\n");
output ("mono_burg_kids (MBState *state, int rulenr, MBState *kids [])\n{\n");
output ("\tg_return_val_if_fail (state != NULL, NULL);\n");
output ("\tg_return_val_if_fail (kids != NULL, NULL);\n\n");
} else {
if (!with_exported_symbols)
output ("static ");
output ("MBTREE_TYPE **\n");
output ("mono_burg_kids (MBTREE_TYPE *tree, int rulenr, MBTREE_TYPE *kids [])\n{\n");
output ("\tg_return_val_if_fail (tree != NULL, NULL);\n");
output ("\tg_return_val_if_fail (kids != NULL, NULL);\n\n");
}
output ("\tswitch (rulenr) {\n");
n = g_list_length (rule_list);
sa = g_new0 (char *, n);