1997-04-22 17:46:07 +00:00
|
|
|
/* This file is part of the program psim.
|
|
|
|
|
|
|
|
Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
|
|
|
|
|
|
|
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "misc.h"
|
|
|
|
#include "lf.h"
|
|
|
|
#include "table.h"
|
|
|
|
#include "filter.h"
|
|
|
|
|
1997-09-08 17:40:24 +00:00
|
|
|
#include "igen.h"
|
|
|
|
|
1997-04-22 17:46:07 +00:00
|
|
|
#include "ld-insn.h"
|
1997-09-08 17:40:24 +00:00
|
|
|
#include "ld-decode.h"
|
1997-04-22 17:46:07 +00:00
|
|
|
|
1997-09-08 17:40:24 +00:00
|
|
|
#include "gen.h"
|
1997-04-22 17:46:07 +00:00
|
|
|
|
|
|
|
#include "gen-semantics.h"
|
|
|
|
#include "gen-support.h"
|
|
|
|
|
|
|
|
static void
|
1997-09-08 17:40:24 +00:00
|
|
|
print_support_function_name (lf *file,
|
|
|
|
function_entry *function,
|
|
|
|
int is_function_definition)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
1997-09-08 17:40:24 +00:00
|
|
|
if (function->is_internal)
|
|
|
|
{
|
|
|
|
lf_print__function_type_function (file, print_semantic_function_type,
|
|
|
|
"INLINE_SUPPORT",
|
|
|
|
(is_function_definition ? "\n" : " "));
|
|
|
|
print_function_name (file,
|
|
|
|
function->name,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
function_name_prefix_semantics);
|
|
|
|
lf_printf (file, "\n(");
|
|
|
|
lf_indent (file, +1);
|
|
|
|
print_semantic_function_formal (file, 0);
|
|
|
|
lf_indent (file, -1);
|
|
|
|
lf_printf (file, ")");
|
|
|
|
if (!is_function_definition)
|
|
|
|
lf_printf (file, ";");
|
|
|
|
lf_printf (file, "\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* map the name onto a globally valid name */
|
|
|
|
if (!is_function_definition
|
|
|
|
&& strcmp (options.prefix.global.name, "") != 0)
|
|
|
|
{
|
|
|
|
lf_indent_suppress (file);
|
|
|
|
lf_printf (file, "#define %s %s%s\n",
|
|
|
|
function->name,
|
|
|
|
options.prefix.global.name,
|
|
|
|
function->name);
|
|
|
|
}
|
|
|
|
lf_print__function_type (file,
|
|
|
|
function->type,
|
|
|
|
"INLINE_SUPPORT",
|
|
|
|
(is_function_definition ? "\n" : " "));
|
|
|
|
lf_printf (file, "%s%s\n(",
|
|
|
|
options.prefix.global.name,
|
|
|
|
function->name);
|
|
|
|
if (options.gen.smp)
|
|
|
|
lf_printf (file,
|
|
|
|
"sim_cpu *cpu, %sinstruction_address cia, int MY_INDEX",
|
|
|
|
options.prefix.global.name);
|
|
|
|
else
|
|
|
|
lf_printf (file,
|
|
|
|
"SIM_DESC sd, %sinstruction_address cia, int MY_INDEX",
|
|
|
|
options.prefix.global.name);
|
|
|
|
if (function->param != NULL
|
|
|
|
&& strlen (function->param) > 0)
|
|
|
|
lf_printf (file, ", %s", function->param);
|
|
|
|
lf_printf (file, ")%s", (is_function_definition ? "\n" : ";\n"));
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
1997-09-08 17:40:24 +00:00
|
|
|
support_h_function (lf *file,
|
|
|
|
function_entry *function,
|
|
|
|
void *data)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
1997-09-08 17:40:24 +00:00
|
|
|
ASSERT (function->type != NULL);
|
|
|
|
print_support_function_name (file,
|
|
|
|
function,
|
|
|
|
0/*!is_definition*/);
|
1997-04-22 17:46:07 +00:00
|
|
|
lf_printf(file, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern void
|
1997-09-08 17:40:24 +00:00
|
|
|
gen_support_h (lf *file,
|
|
|
|
insn_table *table)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
1998-01-31 06:23:41 +00:00
|
|
|
/* output the definition of `SD_'*/
|
1997-09-08 17:40:24 +00:00
|
|
|
if (options.gen.smp)
|
|
|
|
{
|
1998-01-31 06:23:41 +00:00
|
|
|
lf_printf(file, "#define _SD cpu, cia, MY_INDEX /* depreciated */\n");
|
|
|
|
lf_printf(file, "#define SD_ cpu, cia, MY_INDEX\n");
|
1997-09-08 17:40:24 +00:00
|
|
|
lf_printf(file, "#define SD CPU_STATE (cpu)\n");
|
|
|
|
lf_printf(file, "#define CPU cpu\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1998-01-31 06:23:41 +00:00
|
|
|
lf_printf(file, "#define _SD sd, cia, MY_INDEX /* depreciated */\n");
|
|
|
|
lf_printf(file, "#define SD_ sd, cia, MY_INDEX\n");
|
1997-09-08 17:40:24 +00:00
|
|
|
lf_printf(file, "#define SD sd\n");
|
|
|
|
lf_printf(file, "#define CPU (STATE_CPU (sd, 0))\n");
|
|
|
|
}
|
1998-01-31 06:23:41 +00:00
|
|
|
if (options.gen.delayed_branch)
|
|
|
|
{
|
|
|
|
lf_printf(file, "#define CIA cia.ip\n");
|
|
|
|
lf_printf(file, "/* #define NIA nia.dp -- do not define, ambigious */\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lf_printf(file, "#define CIA cia\n");
|
|
|
|
lf_printf(file, "#define NIA nia\n");
|
|
|
|
}
|
1997-04-22 17:46:07 +00:00
|
|
|
lf_printf(file, "\n");
|
|
|
|
/* output a declaration for all functions */
|
1997-09-08 17:40:24 +00:00
|
|
|
function_entry_traverse (file, table->functions,
|
|
|
|
support_h_function,
|
|
|
|
NULL);
|
1997-04-22 17:46:07 +00:00
|
|
|
lf_printf(file, "\n");
|
|
|
|
lf_printf(file, "#if defined(SUPPORT_INLINE)\n");
|
|
|
|
lf_printf(file, "# if ((SUPPORT_INLINE & INCLUDE_MODULE)\\\n");
|
|
|
|
lf_printf(file, " && (SUPPORT_INLINE & INCLUDED_BY_MODULE))\n");
|
1997-09-08 17:40:24 +00:00
|
|
|
lf_printf(file, "# include \"%ssupport.c\"\n", options.prefix.global.name);
|
1997-04-22 17:46:07 +00:00
|
|
|
lf_printf(file, "# endif\n");
|
|
|
|
lf_printf(file, "#endif\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-09-08 17:40:24 +00:00
|
|
|
support_c_function (lf *file,
|
|
|
|
function_entry *function,
|
|
|
|
void *data)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
1997-09-08 17:40:24 +00:00
|
|
|
ASSERT (function->type != NULL);
|
1997-04-22 17:46:07 +00:00
|
|
|
print_support_function_name (file,
|
|
|
|
function,
|
|
|
|
1/*!is_definition*/);
|
|
|
|
lf_printf (file, "{\n");
|
|
|
|
lf_indent (file, +2);
|
1997-09-08 17:40:24 +00:00
|
|
|
if (function->code == NULL)
|
|
|
|
error (function->line,
|
|
|
|
"Function without body (or null statement)");
|
|
|
|
lf_print__line_ref (file, function->code->line);
|
|
|
|
table_print_code (file, function->code);
|
|
|
|
if (function->is_internal)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
1998-01-31 06:23:41 +00:00
|
|
|
lf_printf (file, "sim_engine_abort (SD, CPU, cia, \"Internal function must longjump\\n\");\n");
|
1997-04-22 17:46:07 +00:00
|
|
|
lf_printf (file, "return cia;\n");
|
|
|
|
}
|
|
|
|
lf_indent (file, -2);
|
|
|
|
lf_printf (file, "}\n");
|
1997-09-08 17:40:24 +00:00
|
|
|
lf_print__internal_ref (file);
|
1997-04-22 17:46:07 +00:00
|
|
|
lf_printf (file, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1997-09-08 17:40:24 +00:00
|
|
|
gen_support_c (lf *file,
|
|
|
|
insn_table *table)
|
1997-04-22 17:46:07 +00:00
|
|
|
{
|
|
|
|
lf_printf(file, "#include \"sim-main.h\"\n");
|
1997-09-08 17:40:24 +00:00
|
|
|
lf_printf(file, "#include \"%sidecode.h\"\n", options.prefix.idecode.name);
|
|
|
|
lf_printf(file, "#include \"%sitable.h\"\n", options.prefix.itable.name);
|
|
|
|
lf_printf(file, "#include \"%ssupport.h\"\n", options.prefix.support.name);
|
1997-04-22 17:46:07 +00:00
|
|
|
lf_printf(file, "\n");
|
|
|
|
|
|
|
|
/* output a definition (c-code) for all functions */
|
1997-09-08 17:40:24 +00:00
|
|
|
function_entry_traverse (file, table->functions,
|
|
|
|
support_c_function,
|
|
|
|
NULL);
|
1997-04-22 17:46:07 +00:00
|
|
|
}
|