2011-01-21 11:31:40 +00:00
|
|
|
/*
|
|
|
|
dot_expr.c
|
|
|
|
|
|
|
|
"emit" expressions to dot (graphvis).
|
|
|
|
|
|
|
|
Copyright (C) 2011 Bill Currie <bill@taniwha.org>
|
|
|
|
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
Date: 2011/01/20
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
|
|
|
Free Software Foundation, Inc.
|
|
|
|
59 Temple Place - Suite 330
|
|
|
|
Boston, MA 02111-1307, USA
|
|
|
|
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# include <string.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_STRINGS_H
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include <QF/dstring.h>
|
2012-11-26 06:47:10 +00:00
|
|
|
#include <QF/mathlib.h>
|
2012-11-19 03:14:02 +00:00
|
|
|
#include <QF/quakeio.h>
|
2011-01-21 11:31:40 +00:00
|
|
|
#include <QF/va.h>
|
|
|
|
|
2013-01-22 05:09:41 +00:00
|
|
|
#include "qfalloca.h"
|
|
|
|
|
2011-01-21 11:31:40 +00:00
|
|
|
#include "expr.h"
|
|
|
|
#include "symtab.h"
|
|
|
|
#include "type.h"
|
|
|
|
#include "qc-parse.h"
|
2012-11-19 03:14:02 +00:00
|
|
|
#include "strpool.h"
|
2011-01-21 11:31:40 +00:00
|
|
|
|
2018-10-12 05:50:55 +00:00
|
|
|
const char *expr_names[] =
|
2012-11-26 06:04:33 +00:00
|
|
|
{
|
|
|
|
"error",
|
|
|
|
"state",
|
|
|
|
"bool",
|
|
|
|
"label",
|
|
|
|
"labelref",
|
|
|
|
"block",
|
|
|
|
"expr",
|
|
|
|
"uexpr",
|
2020-03-16 16:42:46 +00:00
|
|
|
"def",
|
2012-11-26 06:04:33 +00:00
|
|
|
"symbol",
|
|
|
|
"temp",
|
2016-01-08 12:15:47 +00:00
|
|
|
"vector",
|
2012-11-26 06:04:33 +00:00
|
|
|
"nil",
|
|
|
|
"value",
|
2020-03-13 08:56:07 +00:00
|
|
|
"compound",
|
|
|
|
"memset",
|
2012-11-26 06:04:33 +00:00
|
|
|
};
|
|
|
|
|
2011-01-21 11:31:40 +00:00
|
|
|
const char *
|
|
|
|
get_op_string (int op)
|
|
|
|
{
|
|
|
|
switch (op) {
|
|
|
|
case OR: return "||";
|
|
|
|
case AND: return "&&";
|
|
|
|
case EQ: return "==";
|
|
|
|
case NE: return "!=";
|
|
|
|
case LE: return "<=";
|
|
|
|
case GE: return ">=";
|
|
|
|
case LT: return "<";
|
|
|
|
case GT: return ">";
|
|
|
|
case '=': return "=";
|
|
|
|
case '+': return "+";
|
|
|
|
case '-': return "-";
|
|
|
|
case '*': return "*";
|
|
|
|
case '/': return "/";
|
|
|
|
case '%': return "%";
|
2020-02-16 02:57:58 +00:00
|
|
|
case MOD: return "%%";
|
2011-01-21 11:31:40 +00:00
|
|
|
case '&': return "&";
|
|
|
|
case '|': return "|";
|
|
|
|
case '^': return "^";
|
|
|
|
case '~': return "~";
|
|
|
|
case '!': return "!";
|
|
|
|
case SHL: return "<<";
|
|
|
|
case SHR: return ">>";
|
|
|
|
case '.': return ".";
|
|
|
|
case 'i': return "<if>";
|
|
|
|
case 'n': return "<ifnot>";
|
|
|
|
case IFBE: return "<ifbe>";
|
|
|
|
case IFB: return "<ifb>";
|
|
|
|
case IFAE: return "<ifae>";
|
|
|
|
case IFA: return "<ifa>";
|
|
|
|
case 'g': return "<goto>";
|
|
|
|
case 'r': return "<return>";
|
|
|
|
case 's': return "<state>";
|
|
|
|
case 'c': return "<call>";
|
2011-03-03 02:06:10 +00:00
|
|
|
case 'A': return "<alias>";
|
2011-01-21 11:31:40 +00:00
|
|
|
case 'C': return "<cast>";
|
|
|
|
case 'M': return "<move>";
|
2012-11-20 07:55:19 +00:00
|
|
|
case 'm': return "<move>";
|
2011-01-21 11:31:40 +00:00
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 07:09:53 +00:00
|
|
|
typedef void (*print_f) (dstring_t *dstr, expr_t *, int, int, expr_t *);
|
|
|
|
static void _print_expr (dstring_t *dstr, expr_t *e, int level, int id,
|
|
|
|
expr_t *next);
|
2011-01-22 02:36:56 +00:00
|
|
|
|
2011-01-21 11:31:40 +00:00
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_error (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-21 11:31:40 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
2011-01-22 02:36:56 +00:00
|
|
|
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"(error)\\n%d\"];\n", indent, "", e,
|
|
|
|
e->line);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_state (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, e->e.state.frame, level, id, next);
|
|
|
|
_print_expr (dstr, e->e.state.think, level, id, next);
|
2011-01-22 02:36:56 +00:00
|
|
|
if (e->e.state.step)
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, e->e.state.step, level, id, next);
|
2012-11-26 05:18:23 +00:00
|
|
|
dasprintf (dstr, "%*se_%p:f -> \"e_%p\";\n", indent, "", e,
|
|
|
|
e->e.state.frame);
|
|
|
|
dasprintf (dstr, "%*se_%p:t -> \"e_%p\";\n", indent, "", e,
|
|
|
|
e->e.state.think);
|
2011-01-22 02:36:56 +00:00
|
|
|
if (e->e.state.step)
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p:s -> e_%p;\n", indent, "", e,
|
|
|
|
e->e.state.step);
|
|
|
|
dasprintf (dstr,
|
|
|
|
"%*se_%p [label=\"<f>state|<t>think|<s>step\",shape=record];\n",
|
|
|
|
indent, "", e);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_bool (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
2012-11-26 06:47:10 +00:00
|
|
|
int i, count;
|
2012-12-05 11:12:57 +00:00
|
|
|
int tl_count = 0, fl_count = 0;
|
2012-11-26 06:47:10 +00:00
|
|
|
ex_bool_t *bool = &e->e.bool;
|
2011-01-22 02:36:56 +00:00
|
|
|
|
2012-11-26 06:47:10 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [shape=none,label=<\n", indent, "", e);
|
|
|
|
dasprintf (dstr, "%*s<table border=\"0\" cellborder=\"1\" "
|
|
|
|
"cellspacing=\"0\">\n",
|
|
|
|
indent + 2, "");
|
|
|
|
dasprintf (dstr, "%*s<tr><td colspan=\"2\"><bool>(%d)</td></tr>\n",
|
|
|
|
indent + 4, "", e->line);
|
|
|
|
dasprintf (dstr, "%*s<tr><td>true</td><td>false</td></tr>\n",
|
|
|
|
indent + 4, "");
|
2012-12-05 11:12:57 +00:00
|
|
|
if (bool->true_list)
|
|
|
|
tl_count = bool->true_list->size;
|
|
|
|
if (bool->false_list)
|
|
|
|
fl_count = bool->false_list->size;
|
|
|
|
count = min (tl_count, fl_count);
|
2012-11-26 06:47:10 +00:00
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
dasprintf (dstr, "%*s<tr><td port=\"t%d\">t</td>"
|
|
|
|
"<td port=\"f%d\">f</td></tr>\n", indent, "", i, i);
|
2012-12-05 11:12:57 +00:00
|
|
|
for ( ; i < tl_count; i++)
|
2012-11-26 06:47:10 +00:00
|
|
|
dasprintf (dstr, "%*s<tr><td port=\"t%d\">t</td>%s</tr>\n",
|
|
|
|
indent, "", i,
|
|
|
|
i == count ? va ("<td rowspan=\"%d\"></td>",
|
|
|
|
bool->true_list->size - count)
|
|
|
|
: "");
|
2012-12-05 11:12:57 +00:00
|
|
|
for ( ; i < fl_count; i++)
|
2012-11-26 06:47:10 +00:00
|
|
|
dasprintf (dstr, "%*s<tr>%s<td port=\"f%d\">f</td></tr>\n",
|
|
|
|
indent, "",
|
|
|
|
i == count ? va ("<td rowspan=\"%d\"></td>",
|
2012-11-26 12:00:28 +00:00
|
|
|
bool->false_list->size - count)
|
2012-11-26 06:47:10 +00:00
|
|
|
: "",
|
|
|
|
i);
|
|
|
|
dasprintf (dstr, "%*s</table>\n", indent + 2, "");
|
|
|
|
dasprintf (dstr, "%*s>];\n", indent, "");
|
2012-11-26 07:09:53 +00:00
|
|
|
if (e->next)
|
|
|
|
next = e->next;
|
|
|
|
_print_expr (dstr, e->e.bool.e, level, id, next);
|
2012-12-05 11:12:57 +00:00
|
|
|
for (i = 0; i < tl_count; i++)
|
2012-11-26 06:47:10 +00:00
|
|
|
dasprintf (dstr, "%*se_%p:t%d -> e_%p;\n", indent, "", e, i,
|
|
|
|
bool->true_list->e[i]);
|
2012-12-05 11:12:57 +00:00
|
|
|
for (i = 0; i < fl_count; i++)
|
2012-11-26 06:47:10 +00:00
|
|
|
dasprintf (dstr, "%*se_%p:f%d -> e_%p;\n", indent, "", e, i,
|
|
|
|
bool->false_list->e[i]);
|
|
|
|
dasprintf (dstr, "%*se_%p -> e_%p;\n", indent, "", e, e->e.bool.e);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_label (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
|
|
|
if (e->next)
|
2012-11-26 07:09:53 +00:00
|
|
|
next = e->next;
|
|
|
|
if (next)
|
2012-12-24 11:06:38 +00:00
|
|
|
dasprintf (dstr, "%*se_%p -> e_%p [constraint=true,style=dashed];\n",
|
2012-11-26 07:09:53 +00:00
|
|
|
indent, "", e, next);
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"%s\\n%d\"];\n", indent, "", e,
|
|
|
|
e->e.label.name, e->line);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
2012-11-03 09:08:32 +00:00
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_labelref (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2012-11-03 09:08:32 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
|
|
|
if (e->next)
|
2012-11-26 07:09:53 +00:00
|
|
|
next = e->next;
|
|
|
|
if (next)
|
2012-12-24 11:06:38 +00:00
|
|
|
dasprintf (dstr, "%*se_%p -> e_%p [constraint=true,style=dashed];\n",
|
2012-11-26 07:09:53 +00:00
|
|
|
indent, "", e, e->next);
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"&%s\\n%d\"];\n", indent, "", e,
|
|
|
|
e->e.label.name, e->line);
|
2012-11-03 09:08:32 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 02:36:56 +00:00
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_block (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
2012-11-26 06:04:33 +00:00
|
|
|
int i;
|
2011-01-22 02:36:56 +00:00
|
|
|
expr_t *se;
|
|
|
|
|
2012-11-26 06:04:33 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [shape=none,label=<\n", indent, "", e);
|
2012-11-26 06:47:10 +00:00
|
|
|
dasprintf (dstr, "%*s<table border=\"0\" cellborder=\"1\" "
|
|
|
|
"cellspacing=\"0\">\n", indent + 2, "");
|
|
|
|
dasprintf (dstr, "%*s<tr><td colspan=\"2\"><block>(%d)%s</td>"
|
|
|
|
"</tr>\n", indent + 4, "", e->line,
|
|
|
|
e->e.block.is_call ? "c" : "");
|
2012-11-26 06:04:33 +00:00
|
|
|
if (e->e.block.result)
|
2012-11-26 06:47:10 +00:00
|
|
|
dasprintf (dstr, "%*s<tr><td colspan=\"2\" port=\"result\">=</td>"
|
|
|
|
"</tr>\n", indent + 4, "");
|
2012-11-26 06:04:33 +00:00
|
|
|
for (se = e->e.block.head, i = 0; se; se = se->next, i++)
|
|
|
|
dasprintf (dstr, "%*s<tr><td>%d</td><td port=\"b%d\">%s</td></tr>\n",
|
|
|
|
indent + 4, "", i, i, expr_names[se->type]);
|
|
|
|
dasprintf (dstr, "%*s</table>\n", indent + 2, "");
|
|
|
|
dasprintf (dstr, "%*s>];\n", indent, "");
|
|
|
|
|
2011-01-22 02:36:56 +00:00
|
|
|
if (e->e.block.result) {
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, e->e.block.result, level + 1, id, next);
|
2012-11-26 06:04:33 +00:00
|
|
|
dasprintf (dstr, "%*se_%p:result -> e_%p;\n", indent, "", e,
|
2012-11-19 03:14:02 +00:00
|
|
|
e->e.block.result);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
2012-11-26 07:09:53 +00:00
|
|
|
if (e->next)
|
|
|
|
next = e->next;
|
2012-11-26 06:04:33 +00:00
|
|
|
for (se = e->e.block.head, i = 0; se; se = se->next, i++) {
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, se, level + 1, id, next);
|
2012-11-26 06:04:33 +00:00
|
|
|
dasprintf (dstr, "%*se_%p:b%d -> e_%p;\n", indent, "", e,
|
|
|
|
i, se);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-23 03:59:30 +00:00
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_call (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-23 03:59:30 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
expr_t *p;
|
|
|
|
int i, count;
|
|
|
|
expr_t **args;
|
|
|
|
|
|
|
|
for (count = 0, p = e->e.expr.e2; p; p = p->next)
|
|
|
|
count++;
|
|
|
|
args = alloca (count * sizeof (expr_t *));
|
|
|
|
for (i = 0, p = e->e.expr.e2; p; p = p->next, i++)
|
|
|
|
args[count - 1 - i] = p;
|
|
|
|
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, e->e.expr.e1, level, id, next);
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"<c>call", indent, "", e);
|
2011-01-23 03:59:30 +00:00
|
|
|
for (i = 0; i < count; i++)
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "|<p%d>p%d", i, i);
|
|
|
|
dasprintf (dstr, "\",shape=record];\n");
|
2011-01-23 03:59:30 +00:00
|
|
|
for (i = 0; i < count; i++) {
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, args[i], level + 1, id, next);
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p:p%d -> e_%p;\n", indent + 2, "", e, i,
|
|
|
|
args[i]);
|
2011-01-23 03:59:30 +00:00
|
|
|
}
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p:c -> e_%p;\n", indent, "", e, e->e.expr.e1);
|
2011-01-23 03:59:30 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 02:36:56 +00:00
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_subexpr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
|
|
|
if (e->e.expr.op == 'c') {
|
2012-11-26 07:09:53 +00:00
|
|
|
print_call (dstr, e, level, id, next);
|
2011-01-23 03:59:30 +00:00
|
|
|
return;
|
2011-01-22 02:36:56 +00:00
|
|
|
} else if (e->e.expr.op == 'i' || e->e.expr.op == 'n'
|
|
|
|
|| e->e.expr.op == IFB || e->e.expr.op ==IFBE
|
|
|
|
|| e->e.expr.op == IFA || e->e.expr.op ==IFAE) {
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, e->e.expr.e1, level, id, next);
|
2012-11-26 05:18:23 +00:00
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\" [label=\"t\"];\n", indent, "", e,
|
2012-11-19 03:14:02 +00:00
|
|
|
e->e.expr.e1);
|
2012-11-26 05:18:23 +00:00
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\" [label=\"g\"];\n", indent, "", e,
|
2012-11-19 03:14:02 +00:00
|
|
|
e->e.expr.e2);
|
2012-11-26 07:09:53 +00:00
|
|
|
if (e->next)
|
|
|
|
next = e->next;
|
|
|
|
if (next)
|
2012-12-24 11:06:38 +00:00
|
|
|
dasprintf (dstr, "%*se_%p -> e_%p [constraint=true,"
|
2012-11-26 07:09:53 +00:00
|
|
|
"style=dashed];\n", indent, "", e, next);
|
2011-01-22 02:36:56 +00:00
|
|
|
} else {
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, e->e.expr.e1, level, id, next);
|
|
|
|
_print_expr (dstr, e->e.expr.e2, level, id, next);
|
2012-11-26 05:18:23 +00:00
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\" [label=\"l\"];\n", indent, "", e,
|
2012-11-19 03:14:02 +00:00
|
|
|
e->e.expr.e1);
|
2012-11-26 05:18:23 +00:00
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\" [label=\"r\"];\n", indent, "", e,
|
2012-11-19 03:14:02 +00:00
|
|
|
e->e.expr.e2);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
2019-06-10 14:48:58 +00:00
|
|
|
if (e->e.expr.op == 'A') {
|
|
|
|
dstring_t *typestr = dstring_newstr();
|
|
|
|
print_type_str (typestr, e->e.expr.type);
|
|
|
|
dasprintf (dstr, "%*se_%p [label=\"%s (%s)\\n%d\"];\n", indent, "", e,
|
|
|
|
get_op_string (e->e.expr.op), typestr->str, e->line);
|
|
|
|
dstring_delete (typestr);
|
|
|
|
} else {
|
|
|
|
dasprintf (dstr, "%*se_%p [label=\"%s\\n%d\"];\n", indent, "", e,
|
|
|
|
get_op_string (e->e.expr.op), e->line);
|
|
|
|
}
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_uexpr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
2012-11-19 03:14:02 +00:00
|
|
|
dstring_t *typestr = dstring_newstr();
|
2011-01-22 02:36:56 +00:00
|
|
|
|
2012-11-26 06:04:33 +00:00
|
|
|
if (e->e.expr.op != 'g' && e->e.expr.e1)
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, e->e.expr.e1, level, id, next);
|
2012-05-03 02:55:19 +00:00
|
|
|
if (e->e.expr.op == 'A') {
|
2012-11-19 03:14:02 +00:00
|
|
|
dstring_copystr (typestr, "\\n");
|
|
|
|
print_type_str (typestr, e->e.expr.type);
|
2012-05-03 02:55:19 +00:00
|
|
|
}
|
2012-11-19 04:49:34 +00:00
|
|
|
if (e->e.expr.op != 'r' || e->e.expr.e1)
|
2012-11-26 05:18:23 +00:00
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e,
|
|
|
|
e->e.expr.e1);
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"%s%s\\n%d\"];\n", indent, "", e,
|
|
|
|
get_op_string (e->e.expr.op), typestr->str, e->line);
|
|
|
|
dstring_delete (typestr);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 16:42:46 +00:00
|
|
|
static void
|
|
|
|
print_def (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
|
|
|
dasprintf (dstr, "%*se_%p [label=\"d %s\\n%d\"];\n", indent, "", e,
|
|
|
|
e->e.def->name, e->line);
|
|
|
|
}
|
|
|
|
|
2011-01-22 02:36:56 +00:00
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_symbol (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"%s\\n%d\"];\n", indent, "", e,
|
|
|
|
e->e.symbol->name, e->line);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_temp (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"tmp_%p\\n%d\"];\n", indent, "", e, e,
|
|
|
|
e->line);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
2013-06-24 06:37:08 +00:00
|
|
|
static void
|
|
|
|
print_vector (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
2019-06-05 21:42:31 +00:00
|
|
|
if (e->e.vector.type == &type_vector) {
|
|
|
|
expr_t *x = e->e.vector.list;
|
|
|
|
expr_t *y = x->next;
|
|
|
|
expr_t *z = y->next;
|
|
|
|
_print_expr (dstr, x, level, id, next);
|
|
|
|
_print_expr (dstr, y, level, id, next);
|
|
|
|
_print_expr (dstr, z, level, id, next);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, x);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, y);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, z);
|
|
|
|
}
|
|
|
|
if (e->e.vector.type == &type_quaternion) {
|
|
|
|
if (e->e.vector.list->next->next) {
|
|
|
|
expr_t *x = e->e.vector.list;
|
|
|
|
expr_t *y = x->next;
|
|
|
|
expr_t *z = y->next;
|
|
|
|
expr_t *w = z->next;
|
|
|
|
_print_expr (dstr, x, level, id, next);
|
|
|
|
_print_expr (dstr, y, level, id, next);
|
|
|
|
_print_expr (dstr, z, level, id, next);
|
|
|
|
_print_expr (dstr, w, level, id, next);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, x);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, y);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, z);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, w);
|
|
|
|
} else {
|
|
|
|
expr_t *v = e->e.vector.list;
|
|
|
|
expr_t *s = v->next;
|
|
|
|
_print_expr (dstr, v, level, id, next);
|
|
|
|
_print_expr (dstr, s, level, id, next);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, v);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dasprintf (dstr, "%*se_%p [label=\"vector %d\"];\n", indent, "", e,
|
|
|
|
e->line);
|
2013-06-24 06:37:08 +00:00
|
|
|
}
|
|
|
|
|
2011-01-22 02:36:56 +00:00
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_nil (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"nil\\n%d\"];\n", indent, "", e,
|
|
|
|
e->line);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
print_value (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
2011-02-07 00:57:26 +00:00
|
|
|
type_t *type;
|
2011-01-22 02:36:56 +00:00
|
|
|
const char *label = "?!?";
|
2019-06-17 15:03:02 +00:00
|
|
|
static dstring_t *type_str;
|
|
|
|
|
|
|
|
if (!type_str) {
|
|
|
|
type_str = dstring_newstr ();
|
|
|
|
}
|
2011-01-22 02:36:56 +00:00
|
|
|
|
2018-10-12 13:05:17 +00:00
|
|
|
switch (e->e.value->lltype) {
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_string:
|
2012-11-19 03:14:02 +00:00
|
|
|
label = va ("\\\"%s\\\"", quote_string (e->e.value->v.string_val));
|
2011-01-22 02:36:56 +00:00
|
|
|
break;
|
2020-02-14 07:38:37 +00:00
|
|
|
case ev_double:
|
|
|
|
label = va ("f %g", e->e.value->v.double_val);
|
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_float:
|
2012-12-23 10:34:25 +00:00
|
|
|
label = va ("f %g", e->e.value->v.float_val);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_vector:
|
|
|
|
label = va ("'%g %g %g'",
|
2012-07-18 14:01:09 +00:00
|
|
|
e->e.value->v.vector_val[0],
|
|
|
|
e->e.value->v.vector_val[1],
|
|
|
|
e->e.value->v.vector_val[2]);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_quat:
|
|
|
|
label = va ("'%g %g %g %g'",
|
2012-07-18 14:01:09 +00:00
|
|
|
e->e.value->v.quaternion_val[0],
|
|
|
|
e->e.value->v.quaternion_val[1],
|
|
|
|
e->e.value->v.quaternion_val[2],
|
|
|
|
e->e.value->v.quaternion_val[3]);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_pointer:
|
2012-07-18 14:01:09 +00:00
|
|
|
type = e->e.value->v.pointer.type;
|
2019-06-17 15:03:02 +00:00
|
|
|
dstring_clearstr(type_str);
|
|
|
|
if (type) {
|
|
|
|
print_type_str (type_str, type);
|
|
|
|
}
|
2012-07-18 14:01:09 +00:00
|
|
|
if (e->e.value->v.pointer.def)
|
2019-06-17 15:03:02 +00:00
|
|
|
label = va ("(*%s)[%d]<%s>",
|
|
|
|
type ? type_str->str : "???",
|
2012-07-18 14:01:09 +00:00
|
|
|
e->e.value->v.pointer.val,
|
|
|
|
e->e.value->v.pointer.def->name);
|
2011-02-08 05:43:57 +00:00
|
|
|
else
|
2019-06-17 15:03:02 +00:00
|
|
|
label = va ("(*%s)[%d]",
|
|
|
|
type ? type_str->str : "???",
|
2012-07-18 14:01:09 +00:00
|
|
|
e->e.value->v.pointer.val);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_field:
|
2012-07-18 14:01:09 +00:00
|
|
|
label = va ("field %d", e->e.value->v.pointer.val);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_entity:
|
2012-07-18 14:01:09 +00:00
|
|
|
label = va ("ent %d", e->e.value->v.integer_val);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_func:
|
2012-07-18 14:01:09 +00:00
|
|
|
label = va ("func %d", e->e.value->v.integer_val);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_integer:
|
2012-12-05 13:18:13 +00:00
|
|
|
label = va ("i %d", e->e.value->v.integer_val);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-04-09 01:07:47 +00:00
|
|
|
case ev_uinteger:
|
2012-12-05 13:18:13 +00:00
|
|
|
label = va ("u %u", e->e.value->v.uinteger_val);
|
2011-04-09 01:07:47 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_short:
|
2012-12-05 13:18:13 +00:00
|
|
|
label = va ("s %d", e->e.value->v.short_val);
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
2011-01-22 02:36:56 +00:00
|
|
|
case ev_void:
|
|
|
|
label = "<void>";
|
|
|
|
break;
|
|
|
|
case ev_invalid:
|
|
|
|
label = "<invalid>";
|
|
|
|
break;
|
|
|
|
case ev_type_count:
|
|
|
|
label = "<type_count>";
|
2011-01-21 11:31:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"%s\\n%d\"];\n", indent, "", e, label,
|
|
|
|
e->line);
|
2011-01-22 02:36:56 +00:00
|
|
|
}
|
|
|
|
|
2020-03-12 10:34:18 +00:00
|
|
|
static void
|
|
|
|
print_compound (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
dasprintf (dstr, "%*se_%p [label=\"compound init\"];\n", indent, "", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
print_memset (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
|
|
|
{
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
expr_t *dst = e->e.memset.dst;
|
|
|
|
expr_t *val = e->e.memset.val;
|
|
|
|
expr_t *count = e->e.memset.count;
|
|
|
|
_print_expr (dstr, dst, level, id, next);
|
|
|
|
_print_expr (dstr, val, level, id, next);
|
|
|
|
_print_expr (dstr, count, level, id, next);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, dst);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, val);
|
|
|
|
dasprintf (dstr, "%*se_%p -> \"e_%p\";\n", indent, "", e, count);
|
|
|
|
dasprintf (dstr, "%*se_%p [label=\"memset\"];\n", indent, "", e);
|
|
|
|
}
|
|
|
|
|
2011-01-22 02:36:56 +00:00
|
|
|
static void
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
2011-01-22 02:36:56 +00:00
|
|
|
{
|
|
|
|
static print_f print_funcs[] = {
|
|
|
|
print_error,
|
|
|
|
print_state,
|
|
|
|
print_bool,
|
|
|
|
print_label,
|
2012-11-03 09:08:32 +00:00
|
|
|
print_labelref,
|
2011-01-22 02:36:56 +00:00
|
|
|
print_block,
|
|
|
|
print_subexpr,
|
|
|
|
print_uexpr,
|
2020-03-16 16:42:46 +00:00
|
|
|
print_def,
|
2011-01-22 02:36:56 +00:00
|
|
|
print_symbol,
|
|
|
|
print_temp,
|
2013-06-24 06:37:08 +00:00
|
|
|
print_vector,
|
2011-01-22 02:36:56 +00:00
|
|
|
print_nil,
|
|
|
|
print_value,
|
2020-03-12 10:34:18 +00:00
|
|
|
print_compound,
|
|
|
|
print_memset,
|
2011-01-22 02:36:56 +00:00
|
|
|
};
|
|
|
|
int indent = level * 2 + 2;
|
|
|
|
|
|
|
|
if (!e) {
|
2012-11-26 05:18:23 +00:00
|
|
|
dasprintf (dstr, "%*s\"e_%p\" [label=\"(null)\"];\n", indent, "", e);
|
2011-01-22 02:36:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (e->printid == id) // already printed this expression
|
|
|
|
return;
|
|
|
|
e->printid = id;
|
|
|
|
|
2020-03-12 10:34:18 +00:00
|
|
|
if ((int) e->type < 0 || e->type > ex_memset) {
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "%*se_%p [label=\"(bad expr type)\\n%d\"];\n",
|
|
|
|
indent, "", e, e->line);
|
2011-01-22 02:36:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-11-26 07:09:53 +00:00
|
|
|
print_funcs [e->type] (dstr, e, level, id, next);
|
2012-11-19 03:14:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
dump_dot_expr (void *_e, const char *filename)
|
|
|
|
{
|
|
|
|
static int id = 0;
|
|
|
|
dstring_t *dstr = dstring_newstr ();
|
2012-11-19 03:52:24 +00:00
|
|
|
expr_t *e = (expr_t *) _e;
|
2011-01-22 02:36:56 +00:00
|
|
|
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "digraph expr_%p {\n", e);
|
2020-03-06 12:05:53 +00:00
|
|
|
dasprintf (dstr, " graph [label=\"%s\"];\n", quote_string (filename));
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, " layout=dot; rankdir=TB; compound=true;\n");
|
2012-11-26 07:09:53 +00:00
|
|
|
_print_expr (dstr, e, 0, ++id, 0);
|
2012-11-19 03:14:02 +00:00
|
|
|
dasprintf (dstr, "}\n");
|
|
|
|
|
|
|
|
if (filename) {
|
|
|
|
QFile *file;
|
|
|
|
|
|
|
|
file = Qopen (filename, "wt");
|
|
|
|
Qwrite (file, dstr->str, dstr->size - 1);
|
|
|
|
Qclose (file);
|
|
|
|
} else {
|
|
|
|
fputs (dstr->str, stdout);
|
|
|
|
}
|
|
|
|
dstring_delete (dstr);
|
2011-01-21 11:31:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_expr (expr_t *e)
|
|
|
|
{
|
2012-11-19 03:14:02 +00:00
|
|
|
dump_dot_expr (e, 0);
|
2011-01-21 11:31:40 +00:00
|
|
|
}
|