mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 23:32:09 +00:00
[qfcc] Merge printing of values into the one place
Having three very similar sets of code for outputting values (just for debug purposes even) got to be a tad annoying. Now there's only one, and in the right place, too (with the other value code).
This commit is contained in:
parent
8ac53664d7
commit
14545c37cf
4 changed files with 160 additions and 201 deletions
|
@ -62,6 +62,7 @@ struct ex_value_s *new_type_value (const struct type_s *type,
|
|||
const struct pr_type_s *data);
|
||||
void value_store (pr_type_t *dst, const struct type_s *dstType,
|
||||
const struct expr_s *src);
|
||||
const char *get_value_string (const struct ex_value_s *value);
|
||||
|
||||
struct ex_value_s *convert_value (struct ex_value_s *value,
|
||||
struct type_s *type);
|
||||
|
|
|
@ -49,9 +49,10 @@
|
|||
|
||||
#include "tools/qfcc/include/expr.h"
|
||||
#include "tools/qfcc/include/method.h"
|
||||
#include "tools/qfcc/include/strpool.h"
|
||||
#include "tools/qfcc/include/symtab.h"
|
||||
#include "tools/qfcc/include/type.h"
|
||||
#include "tools/qfcc/include/strpool.h"
|
||||
#include "tools/qfcc/include/value.h"
|
||||
|
||||
#include "tools/qfcc/source/qc-parse.h"
|
||||
|
||||
|
@ -491,96 +492,11 @@ static void
|
|||
print_value (dstring_t *dstr, expr_t *e, int level, int id, expr_t *next)
|
||||
{
|
||||
int indent = level * 2 + 2;
|
||||
type_t *type;
|
||||
const char *label = "?!?";
|
||||
static dstring_t *type_str;
|
||||
|
||||
if (!type_str) {
|
||||
type_str = dstring_newstr ();
|
||||
}
|
||||
|
||||
switch (e->e.value->lltype) {
|
||||
case ev_string:
|
||||
label = va (0, "\\\"%s\\\"",
|
||||
quote_string (e->e.value->v.string_val));
|
||||
break;
|
||||
case ev_double:
|
||||
label = va (0, "f %g", e->e.value->v.double_val);
|
||||
break;
|
||||
case ev_float:
|
||||
label = va (0, "f %g", e->e.value->v.float_val);
|
||||
break;
|
||||
case ev_vector:
|
||||
label = va (0, "'%g %g %g'",
|
||||
e->e.value->v.vector_val[0],
|
||||
e->e.value->v.vector_val[1],
|
||||
e->e.value->v.vector_val[2]);
|
||||
break;
|
||||
case ev_quaternion:
|
||||
label = va (0, "'%g %g %g %g'",
|
||||
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]);
|
||||
break;
|
||||
case ev_ptr:
|
||||
type = e->e.value->v.pointer.type;
|
||||
dstring_clearstr(type_str);
|
||||
if (type) {
|
||||
print_type_str (type_str, type);
|
||||
}
|
||||
if (e->e.value->v.pointer.def)
|
||||
label = va (0, "(*%s)[%d]<%s>",
|
||||
type ? type_str->str : "???",
|
||||
e->e.value->v.pointer.val,
|
||||
e->e.value->v.pointer.def->name);
|
||||
else
|
||||
label = va (0, "(*%s)[%d]",
|
||||
type ? type_str->str : "???",
|
||||
e->e.value->v.pointer.val);
|
||||
break;
|
||||
case ev_field:
|
||||
if (e->e.value->v.pointer.def) {
|
||||
int offset = e->e.value->v.pointer.val;
|
||||
offset += e->e.value->v.pointer.def->offset;
|
||||
label = va (0, "field %d", offset);
|
||||
} else {
|
||||
label = va (0, "field %d", e->e.value->v.pointer.val);
|
||||
}
|
||||
break;
|
||||
case ev_entity:
|
||||
label = va (0, "ent %d", e->e.value->v.int_val);
|
||||
break;
|
||||
case ev_func:
|
||||
label = va (0, "func %d", e->e.value->v.int_val);
|
||||
break;
|
||||
case ev_int:
|
||||
label = va (0, "i %d", e->e.value->v.int_val);
|
||||
break;
|
||||
case ev_uint:
|
||||
label = va (0, "u %u", e->e.value->v.uint_val);
|
||||
break;
|
||||
case ev_long:
|
||||
label = va (0, "i %"PRIi64, e->e.value->v.long_val);
|
||||
break;
|
||||
case ev_ulong:
|
||||
label = va (0, "u %"PRIu64, e->e.value->v.ulong_val);
|
||||
break;
|
||||
case ev_short:
|
||||
label = va (0, "s %d", e->e.value->v.short_val);
|
||||
break;
|
||||
case ev_ushort:
|
||||
label = va (0, "us %d", e->e.value->v.ushort_val);
|
||||
break;
|
||||
case ev_void:
|
||||
label = "<void>";
|
||||
break;
|
||||
case ev_invalid:
|
||||
label = "<invalid>";
|
||||
break;
|
||||
case ev_type_count:
|
||||
label = "<type_count>";
|
||||
break;
|
||||
label = get_value_string (e->e.value);
|
||||
if (is_string (e->e.value->type)) {
|
||||
label = quote_string (html_string (label));
|
||||
}
|
||||
dasprintf (dstr, "%*se_%p [label=\"%s\\n%d\"];\n", indent, "", e, label,
|
||||
e->line);
|
||||
|
|
|
@ -123,63 +123,7 @@ operand_string (operand_t *op)
|
|||
case op_def:
|
||||
return op->def->name;
|
||||
case op_value:
|
||||
switch (op->value->lltype) {
|
||||
case ev_string:
|
||||
return va (0, "\"%s\"",
|
||||
quote_string (op->value->v.string_val));
|
||||
case ev_double:
|
||||
return va (0, "%g", op->value->v.double_val);
|
||||
case ev_float:
|
||||
return va (0, "%g", op->value->v.float_val);
|
||||
case ev_vector:
|
||||
return va (0, "'%g %g %g'",
|
||||
op->value->v.vector_val[0],
|
||||
op->value->v.vector_val[1],
|
||||
op->value->v.vector_val[2]);
|
||||
case ev_quaternion:
|
||||
return va (0, "'%g %g %g %g'",
|
||||
op->value->v.quaternion_val[0],
|
||||
op->value->v.quaternion_val[1],
|
||||
op->value->v.quaternion_val[2],
|
||||
op->value->v.quaternion_val[3]);
|
||||
case ev_ptr:
|
||||
if (op->value->v.pointer.def) {
|
||||
return va (0, "ptr %s+%d",
|
||||
op->value->v.pointer.def->name,
|
||||
op->value->v.pointer.val);
|
||||
} else if(op->value->v.pointer.tempop) {
|
||||
operand_t *tempop = op->value->v.pointer.tempop;
|
||||
return va (0, "ptr %s+%d", tempop_string (tempop),
|
||||
op->value->v.pointer.val);
|
||||
} else {
|
||||
return va (0, "ptr %d", op->value->v.pointer.val);
|
||||
}
|
||||
case ev_field:
|
||||
return va (0, "field %d", op->value->v.pointer.val);
|
||||
case ev_entity:
|
||||
return va (0, "ent %d", op->value->v.int_val);
|
||||
case ev_func:
|
||||
return va (0, "func %d", op->value->v.int_val);
|
||||
case ev_int:
|
||||
return va (0, "int %d", op->value->v.int_val);
|
||||
case ev_uint:
|
||||
return va (0, "uint %u", op->value->v.uint_val);
|
||||
case ev_long:
|
||||
return va (0, "long %"PRIi64, op->value->v.long_val);
|
||||
case ev_ulong:
|
||||
return va (0, "ulong %"PRIu64, op->value->v.ulong_val);
|
||||
case ev_short:
|
||||
return va (0, "short %d", op->value->v.short_val);
|
||||
case ev_ushort:
|
||||
return va (0, "ushort %d", op->value->v.ushort_val);
|
||||
case ev_void:
|
||||
return "(void)";
|
||||
case ev_invalid:
|
||||
return "(invalid)";
|
||||
case ev_type_count:
|
||||
return "(type_count)";
|
||||
}
|
||||
break;
|
||||
return get_value_string (op->value);
|
||||
case op_label:
|
||||
return op->label->name;
|
||||
case op_temp:
|
||||
|
@ -209,61 +153,8 @@ _print_operand (operand_t *op)
|
|||
printf ("%s", op->def->name);
|
||||
break;
|
||||
case op_value:
|
||||
printf ("(%s) ", pr_type_name[op->type->type]);
|
||||
switch (op->value->lltype) {
|
||||
case ev_string:
|
||||
printf ("\"%s\"", op->value->v.string_val);
|
||||
break;
|
||||
case ev_double:
|
||||
printf ("%g", op->value->v.double_val);
|
||||
break;
|
||||
case ev_float:
|
||||
printf ("%g", op->value->v.float_val);
|
||||
break;
|
||||
case ev_vector:
|
||||
printf ("'%g", op->value->v.vector_val[0]);
|
||||
printf (" %g", op->value->v.vector_val[1]);
|
||||
printf (" %g'", op->value->v.vector_val[2]);
|
||||
break;
|
||||
case ev_quaternion:
|
||||
printf ("'%g", op->value->v.quaternion_val[0]);
|
||||
printf (" %g", op->value->v.quaternion_val[1]);
|
||||
printf (" %g", op->value->v.quaternion_val[2]);
|
||||
printf (" %g'", op->value->v.quaternion_val[3]);
|
||||
break;
|
||||
case ev_ptr:
|
||||
printf ("(%s)[%d]",
|
||||
pr_type_name[op->value->v.pointer.type->type],
|
||||
op->value->v.pointer.val);
|
||||
break;
|
||||
case ev_field:
|
||||
printf ("%d", op->value->v.pointer.val);
|
||||
break;
|
||||
case ev_entity:
|
||||
case ev_func:
|
||||
case ev_int:
|
||||
printf ("%d", op->value->v.int_val);
|
||||
break;
|
||||
case ev_uint:
|
||||
printf ("%u", op->value->v.uint_val);
|
||||
break;
|
||||
case ev_long:
|
||||
printf ("%"PRIu64, op->value->v.long_val);
|
||||
break;
|
||||
case ev_ulong:
|
||||
printf ("%"PRIu64, op->value->v.ulong_val);
|
||||
break;
|
||||
case ev_short:
|
||||
printf ("%d", op->value->v.short_val);
|
||||
break;
|
||||
case ev_ushort:
|
||||
printf ("%d", op->value->v.ushort_val);
|
||||
break;
|
||||
case ev_void:
|
||||
case ev_invalid:
|
||||
case ev_type_count:
|
||||
internal_error (op->expr, "weird value type");
|
||||
}
|
||||
printf ("(%s) %s", pr_type_name[op->type->type],
|
||||
get_value_string (op->value));
|
||||
break;
|
||||
case op_label:
|
||||
printf ("block %p", op->label->dest);
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#include "QF/mathlib.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "QF/simd/types.h"
|
||||
|
||||
#include "tools/qfcc/include/qfcc.h"
|
||||
#include "tools/qfcc/include/def.h"
|
||||
#include "tools/qfcc/include/defspace.h"
|
||||
|
@ -308,6 +310,155 @@ value_store (pr_type_t *dst, const type_t *dstType, const expr_t *src)
|
|||
memcpy (dst, &val->v, dstSize);
|
||||
}
|
||||
|
||||
const char *
|
||||
get_value_string (const ex_value_t *value)
|
||||
{
|
||||
const type_t *type = value->type;
|
||||
const char *str = "";
|
||||
switch (type->type) {
|
||||
case ev_string:
|
||||
return va (0, "\"%s\"", quote_string (value->v.string_val));
|
||||
case ev_vector:
|
||||
case ev_quaternion:
|
||||
case ev_float:
|
||||
switch (type_width (type)) {
|
||||
case 1:
|
||||
str = va (0, "%.9g", value->v.float_val);
|
||||
break;
|
||||
case 2:
|
||||
str = va (0, VEC2F_FMT, VEC2_EXP (value->v.vec2_val));
|
||||
break;
|
||||
case 3:
|
||||
str = va (0, "[%.9g, %.9g, %.9g]",
|
||||
VectorExpand (value->v.vec3_val));
|
||||
break;
|
||||
case 4:
|
||||
str = va (0, VEC4F_FMT, VEC4_EXP (value->v.vec4_val));
|
||||
break;
|
||||
}
|
||||
return va (0, "%s %s", type->name, str);
|
||||
case ev_entity:
|
||||
case ev_func:
|
||||
return va (0, "%s %d", type->name, value->v.int_val);
|
||||
case ev_field:
|
||||
if (value->v.pointer.def) {
|
||||
int offset = value->v.pointer.val;
|
||||
offset += value->v.pointer.def->offset;
|
||||
return va (0, "field %d", offset);
|
||||
} else {
|
||||
return va (0, "field %d", value->v.pointer.val);
|
||||
}
|
||||
case ev_ptr:
|
||||
if (value->v.pointer.def) {
|
||||
str = va (0, "<%s>", value->v.pointer.def->name);
|
||||
}
|
||||
return va (0, "(* %s)[%d]%s",
|
||||
value->v.pointer.type
|
||||
? get_type_string (value->v.pointer.type) : "???",
|
||||
value->v.pointer.val, str);
|
||||
case ev_int:
|
||||
switch (type_width (type)) {
|
||||
case 1:
|
||||
str = va (0, "%"PRIi32, value->v.int_val);
|
||||
break;
|
||||
case 2:
|
||||
str = va (0, VEC2I_FMT, VEC2_EXP (value->v.ivec2_val));
|
||||
break;
|
||||
case 3:
|
||||
str = va (0, "[%"PRIi32", %"PRIi32", %"PRIi32"]",
|
||||
VectorExpand (value->v.ivec3_val));
|
||||
break;
|
||||
case 4:
|
||||
str = va (0, VEC4I_FMT, VEC4_EXP (value->v.ivec4_val));
|
||||
break;
|
||||
}
|
||||
return va (0, "%s %s", type->name, str);
|
||||
case ev_uint:
|
||||
switch (type_width (type)) {
|
||||
case 1:
|
||||
str = va (0, "%"PRIu32, value->v.uint_val);
|
||||
break;
|
||||
case 2:
|
||||
str = va (0, "[%"PRIu32", %"PRIi32"]",
|
||||
VEC2_EXP (value->v.uivec2_val));
|
||||
break;
|
||||
case 3:
|
||||
str = va (0, "[%"PRIu32", %"PRIi32", %"PRIi32"]",
|
||||
VectorExpand (value->v.uivec3_val));
|
||||
break;
|
||||
case 4:
|
||||
str = va (0, "[%"PRIu32", %"PRIi32", %"PRIi32", %"PRIi32"]",
|
||||
VEC4_EXP (value->v.uivec4_val));
|
||||
break;
|
||||
}
|
||||
return va (0, "%s %s", type->name, str);
|
||||
case ev_short:
|
||||
return va (0, "%s %"PRIi16, type->name, value->v.short_val);
|
||||
case ev_ushort:
|
||||
return va (0, "%s %"PRIu16, type->name, value->v.ushort_val);
|
||||
case ev_double:
|
||||
switch (type_width (type)) {
|
||||
case 1:
|
||||
str = va (0, "%.17g", value->v.double_val);
|
||||
break;
|
||||
case 2:
|
||||
str = va (0, VEC2D_FMT, VEC2_EXP (value->v.dvec2_val));
|
||||
break;
|
||||
case 3:
|
||||
str = va (0, "[%.17g, %.17g, %.17g]",
|
||||
VectorExpand (value->v.dvec3_val));
|
||||
break;
|
||||
case 4:
|
||||
str = va (0, VEC4D_FMT, VEC4_EXP (value->v.dvec4_val));
|
||||
break;
|
||||
}
|
||||
return va (0, "%s %s", type->name, str);
|
||||
case ev_long:
|
||||
switch (type_width (type)) {
|
||||
case 1:
|
||||
str = va (0, "%"PRIi64, value->v.long_val);
|
||||
break;
|
||||
case 2:
|
||||
str = va (0, VEC2L_FMT, VEC2_EXP (value->v.lvec2_val));
|
||||
break;
|
||||
case 3:
|
||||
str = va (0, "[%"PRIi64", %"PRIi64", %"PRIi64"]",
|
||||
VectorExpand (value->v.lvec3_val));
|
||||
break;
|
||||
case 4:
|
||||
str = va (0, VEC4L_FMT, VEC4_EXP (value->v.lvec4_val));
|
||||
break;
|
||||
}
|
||||
return va (0, "%s %s", type->name, str);
|
||||
case ev_ulong:
|
||||
switch (type_width (type)) {
|
||||
case 1:
|
||||
str = va (0, "%"PRIu64, value->v.ulong_val);
|
||||
break;
|
||||
case 2:
|
||||
str = va (0, "[%"PRIu64", %"PRIi64"]",
|
||||
VEC2_EXP (value->v.ulvec2_val));
|
||||
break;
|
||||
case 3:
|
||||
str = va (0, "[%"PRIu64", %"PRIi64", %"PRIi64"]",
|
||||
VectorExpand (value->v.ulvec3_val));
|
||||
break;
|
||||
case 4:
|
||||
str = va (0, "[%"PRIu64", %"PRIi64", %"PRIi64", %"PRIi64"]",
|
||||
VEC4_EXP (value->v.ulvec4_val));
|
||||
break;
|
||||
}
|
||||
return va (0, "%s %s", type->name, str);
|
||||
case ev_void:
|
||||
return "<void>";
|
||||
case ev_invalid:
|
||||
return "<invalid>";
|
||||
case ev_type_count:
|
||||
return "<type_count>";
|
||||
}
|
||||
return "invalid type";
|
||||
}
|
||||
|
||||
static hashtab_t *string_imm_defs;
|
||||
static hashtab_t *float_imm_defs;
|
||||
static hashtab_t *vector_imm_defs;
|
||||
|
|
Loading…
Reference in a new issue