+ lf_indent_suppress (file);
+ lf_printf (file, "#undef ");
+ print_function_name (file,
+ basename, format_name, NULL,
+ expanded_bits, function_name_prefix_none);
+ lf_printf (file, "\n");
+ lf_indent_suppress (file);
+ lf_printf (file, "#undef MY_PREFIX\n");
+ lf_indent_suppress (file);
+ lf_printf (file, "#define MY_PREFIX ");
+ print_function_name (file,
+ basename, format_name, NULL,
+ expanded_bits, function_name_prefix_none);
+ lf_printf (file, "\n");
+ /* #define MY_NAME xxxxxx */
+ lf_indent_suppress (file);
+ lf_indent_suppress (file);
+ lf_printf (file, "#undef MY_NAME\n");
+ lf_indent_suppress (file);
+ lf_printf (file, "#define MY_NAME \"");
+ print_function_name (file,
+ basename, format_name, NULL,
+ expanded_bits, function_name_prefix_none);
+ lf_printf (file, "\"\n");
+}
+
+
+static int
+print_itrace_prefix (lf *file)
+{
+ const char *prefix = "trace_prefix (";
+ int indent = strlen (prefix);
+ lf_printf (file, "%sSD, CPU, cia, CIA, TRACE_LINENUM_P (CPU), \\\n",
+ prefix);
+ lf_indent (file, +indent);
+ lf_printf (file, "%sitable[MY_INDEX].file, \\\n",
+ options.module.itable.prefix.l);
+ lf_printf (file, "%sitable[MY_INDEX].line_nr, \\\n",
+ options.module.itable.prefix.l);
+ lf_printf (file, "\"");
+ return indent;
+}
+
+
+static void
+print_itrace_format (lf *file, insn_mnemonic_entry *assembler)
+{
+ /* pass=1 is fmt string; pass=2 is arguments */
+ int pass;
+ /* print the format string */
+ for (pass = 1; pass <= 2; pass++)
+ {
+ const char *chp = assembler->format;
+ chp++; /* skip the leading quote */
+ /* write out the format/args */
+ while (*chp != '\0')
+ {
+ if (chp[0] == '\\' && (chp[1] == '<' || chp[1] == '>'))
+ {
+ if (pass == 1)
+ lf_putchr (file, chp[1]);
+ chp += 2;
+ }
+ else if (chp[0] == '<' || chp[0] == '%')
+ {
+ /* parse [ "%" ... ] "<" [ func "#" ] param ">" */
+ const char *fmt;
+ const char *func;
+ int strlen_func;
+ const char *param;
+ int strlen_param;
+ /* the "%" ... "<" format */
+ fmt = chp;
+ while (chp[0] != '<' && chp[0] != '\0')
+ chp++;
+ if (chp[0] != '<')
+ error (assembler->line, "Missing `<' after `%%'\n");
+ chp++;
+ /* [ "func" # ] OR "param" */
+ func = chp;
+ param = chp;
+ while (chp[0] != '>' && chp[0] != '#' && chp[0] != '\0')
+ chp++;
+ strlen_func = chp - func;
+ if (chp[0] == '#')
+ {
+ chp++;
+ param = chp;
+ while (chp[0] != '>' && chp[0] != '\0')
+ chp++;
+ }
+ strlen_param = chp - param;
+ if (chp[0] != '>')
+ error (assembler->line,
+ "Missing closing `>' in assembler string\n");
+ chp++;
+ /* now process it */
+ if (pass == 2)
+ lf_printf (file, ", \\\n");
+ if (strncmp (fmt, "<", 1) == 0)
+ /* implicit long int format */
+ {
+ if (pass == 1)
+ lf_printf (file, "%%ld");
+ else
+ {
+ lf_printf (file, "(long) ");
+ lf_write (file, param, strlen_param);
+ }
+ }
+ else if (strncmp (fmt, "%<", 2) == 0)
+ /* explicit format */
+ {
+ if (pass == 1)
+ lf_printf (file, "%%");
+ else
+ lf_write (file, param, strlen_param);
+ }
+ else if (strncmp (fmt, "%s<", 3) == 0)
+ /* string format */
+ {
+ if (pass == 1)
+ lf_printf (file, "%%s");
+ else
+ {
+ lf_printf (file, "%sstr_",
+ options.module.global.prefix.l);
+ lf_write (file, func, strlen_func);
+ lf_printf (file, " (SD_, ");
+ lf_write (file, param, strlen_param);
+ lf_printf (file, ")");
+ }
+ }
+ else if (strncmp (fmt, "%lx<", 4) == 0)
+ /* simple hex */
+ {
+ if (pass == 1)
+ lf_printf (file, "%%lx");
+ else
+ {
+ lf_printf (file, "(unsigned long) ");
+ lf_write (file, param, strlen_param);
+ }
+ }
+ else if (strncmp (fmt, "%#lx<", 5) == 0)
+ /* simple hex with 0x prefix */
+ {
+ if (pass == 1)
+ lf_printf (file, "%%#lx");
+ else
+ {
+ lf_printf (file, "(unsigned long) ");
+ lf_write (file, param, strlen_param);
+ }
+ }
+ else if (strncmp (fmt, "%08lx<", 6) == 0)
+ /* simple hex */
+ {
+ if (pass == 1)
+ lf_printf (file, "%%08lx");
+ else
+ {
+ lf_printf (file, "(unsigned long) ");
+ lf_write (file, param, strlen_param);
+ }
+ }
+ else
+ error (assembler->line, "Unknown assembler string format\n");
+ }
+ else
+ {
+ if (pass == 1)
+ lf_putchr (file, chp[0]);
+ chp += 1;
+ }
+ }
+ }
+ lf_printf (file, ");\n");
+}
+
+
+void
+print_itrace (lf *file, insn_entry * insn, int idecode)
+{
+ /* NB: Here we escape each EOLN. This is so that the the compiler
+ treats a trace function call as a single line. Consequently any
+ errors in the line are refered back to the same igen assembler
+ source line */
+ const char *phase = (idecode) ? "DECODE" : "INSN";
+ lf_printf (file, "\n");
+ lf_indent_suppress (file);
+ lf_printf (file, "#if defined (WITH_TRACE)\n");
+ lf_printf (file, "/* generate a trace prefix if any tracing enabled */\n");
+ lf_printf (file, "if (TRACE_ANY_P (CPU))\n");
+ lf_printf (file, " {\n");
+ lf_indent (file, +4);
+ {
+ if (insn->mnemonics != NULL)
+ {
+ insn_mnemonic_entry *assembler = insn->mnemonics;
+ int is_first = 1;
+ do
+ {
+ if (assembler->condition != NULL)
+ {
+ int indent;
+ lf_printf (file, "%sif (%s)\n",
+ is_first ? "" : "else ", assembler->condition);
+ lf_indent (file, +2);
+ lf_print__line_ref (file, assembler->line);
+ indent = print_itrace_prefix (file);
+ print_itrace_format (file, assembler);
+ lf_print__internal_ref (file);
+ lf_indent (file, -indent);
+ lf_indent (file, -2);
+ if (assembler->next == NULL)
+ error (assembler->line,
+ "Missing final unconditional assembler\n");
+ }
+ else
+ {
+ int indent;
+ if (!is_first)
+ {
+ lf_printf (file, "else\n");
+ lf_indent (file, +2);
+ }
+ lf_print__line_ref (file, assembler->line);
+ indent = print_itrace_prefix (file);
+ print_itrace_format (file, assembler);
+ lf_print__internal_ref (file);
+ lf_indent (file, -indent);
+ if (!is_first)
+ lf_indent (file, -2);
+ if (assembler->next != NULL)
+ error (assembler->line,
+ "Unconditional assembler is not last\n");
+ }
+ is_first = 0;
+ assembler = assembler->next;
+ }
+ while (assembler != NULL);
+ }
+ else
+ {
+ int indent;
+ lf_indent (file, +2);
+ lf_print__line_ref (file, insn->line);
+ indent = print_itrace_prefix (file);
+ lf_printf (file, "%%s\", \\\n");
+ lf_printf (file, "itable[MY_INDEX].name);\n");
+ lf_print__internal_ref (file);
+ lf_indent (file, -indent);
+ lf_indent (file, -2);
+ }
+ lf_printf (file, "/* trace the instruction execution if enabled */\n");
+ lf_printf (file, "if (TRACE_%s_P (CPU))\n", phase);
+ lf_printf (file,
+ " trace_generic (SD, CPU, TRACE_%s_IDX, \" %%s\", itable[MY_INDEX].name);\n",
+ phase);
+ }
+ lf_indent (file, -4);
+ lf_printf (file, " }\n");
+ lf_indent_suppress (file);
+ lf_printf (file, "#endif\n");
+}
+
+
+void
+print_sim_engine_abort (lf *file, const char *message)
+{
+ lf_printf (file, "sim_engine_abort (SD, CPU, cia, ");
+ lf_printf (file, "\"%s\"", message);
+ lf_printf (file, ");\n");
+}
+
+
+void
+print_include (lf *file, igen_module module)
+{
+ lf_printf (file, "#include \"%s%s.h\"\n", module.prefix.l, module.suffix.l);