This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[jit] API change: access fields via (gcc_jit_field *) rather than by name
- From: David Malcolm <dmalcolm at redhat dot com>
- To: jit at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Cc: David Malcolm <dmalcolm at redhat dot com>
- Date: Wed, 29 Jan 2014 11:21:57 -0500
- Subject: [jit] API change: access fields via (gcc_jit_field *) rather than by name
- Authentication-results: sourceware.org; auth=none
Committed to branch dmalcolm/jit:
Currently there's almost no type-checking within libgccjit - if client
code uses the API in such a way as to generate bogus code, this is
likely to violate assumptions made later on within GCC proper, leading
to errors deep inside GCC (e.g. with
internal compiler error: verify_gimple failed
when converting tree to gimple, when expanding gimple to RTL, or indeed
in other places; see the results of test-fuzzer.c for examples).
The API will be more developer-friendly if we catch such type errors
at the API boundary (similar to how the other language frontends enforce
these assumptions).
As a step towards this, change the API for accessing fields to use
gcc_jit_field pointers, rather than passing field name as strings,
avoiding the need to do a lookup in the replay code, and allowing
for the possibility of directly examining the type of the
field when implementing type-checking.
gcc/jit/
* libgccjit.h (gcc_jit_lvalue_access_field): Require
a (gcc_jit_field *) rather than a field name.
(gcc_jit_rvalue_access_field): Likewise.
(gcc_jit_rvalue_dereference_field): Likewise.
* libgccjit.c (gcc_jit_lvalue_access_field): Require
a (gcc_jit_field *) rather than a field name.
(gcc_jit_rvalue_access_field): Likewise.
(gcc_jit_rvalue_dereference_field): Likewise.
* internal-api.c (gcc::jit::recording::rvalue::access_field):
Require a field rather than a fieldname string.
(gcc::jit::recording::rvalue::dereference_field): Likewise.
(gcc::jit::recording::lvalue::access_field): Likewise.
(gcc::jit::recording::access_field_of_lvalue::replay_into): Update
given that this now has a field, rather than a fieldname.
(gcc::jit::recording::access_field_rvalue::replay_into): Likewise.
(gcc::jit::recording::dereference_field_rvalue::replay_into): Likewise.
(get_field): Delete, as we no longer need to convert
from (struct, identifier) pairs to fields, instead directly using
fields.
(gcc::jit::playback::context::new_field_access): Require a field
rather than a fieldname, removing the need to look up the field by
name within the struct.
(gcc::jit::playback::lvalue::access_field): Likewise.
(gcc::jit::playback::rvalue::access_field): Likewise.
(gcc::jit::playback::rvalue::dereference_field): Likewise.
* internal-api.h (gcc::jit::recording::rvalue::access_field):
Require a field rather than a fieldname string.
(gcc::jit::recording::rvalue::dereference_field): Likewise.
(gcc::jit::recording::lvalue::access_field): Likewise.
(gcc::jit::recording::access_field_of_lvalue::access_field_of_lvalue):
Likewise.
(gcc::jit::recording::access_field_of_lvalue::m_fieldname): Drop
string field in favor of...
(gcc::jit::recording::access_field_of_lvalue::m_field):
..."field" field, as it were.
(gcc::jit::recording::access_field_of_rvalue::access_field_of_rvalue):
Likewise.
(gcc::jit::recording::access_field_of_rvalue::m_fieldname): Drop
string field in favor of...
(gcc::jit::recording::access_field_of_rvalue::m_field):
..."field" field.
(gcc::jit::recording::dereference_field_rvalue::
dereference_field_rvalue): Likewise.
(gcc::jit::recording::dereference_field_rvalue::m_fieldname): Drop
string field in favor of...
(gcc::jit::recording::dereference_field_rvalue::m_field):
..."field" field.
(gcc::jit::playback::context::new_field_access): Require a field
rather than a fieldname string.
(gcc::jit::playback::context::access_field): Likewise.
(gcc::jit::playback::context::dereference_field): Likewise.
(gcc::jit::playback::rvalue::access_field):
gcc/testsuite/
* jit.dg/test-accessing-struct.c (create_code): Update for API change
for accessing fields in terms of gcc_jit_field pointers rather than
by name.
* jit.dg/test-nested-contexts.c (make_calc_discriminant): Likewise.
(make_test_quadratic): Likewise.
* jit.dg/test-quadratic.c (make_calc_discriminant): Likewise.
(make_test_quadratic): Likewise.
* jit.dg/test-reading-struct.c (create_code): Likewise.
* jit.dg/test-types.c: Likewise.
---
gcc/jit/ChangeLog.jit | 66 ++++++++++
gcc/jit/internal-api.c | 59 +++------
gcc/jit/internal-api.h | 34 ++---
gcc/jit/libgccjit.c | 18 +--
gcc/jit/libgccjit.h | 6 +-
gcc/testsuite/ChangeLog.jit | 12 ++
gcc/testsuite/jit.dg/test-accessing-struct.c | 6 +-
gcc/testsuite/jit.dg/test-nested-contexts.c | 20 +--
gcc/testsuite/jit.dg/test-quadratic.c | 20 +--
gcc/testsuite/jit.dg/test-reading-struct.c | 8 +-
gcc/testsuite/jit.dg/test-types.c | 185 ++++++++++++++++-----------
11 files changed, 268 insertions(+), 166 deletions(-)
diff --git a/gcc/jit/ChangeLog.jit b/gcc/jit/ChangeLog.jit
index 67856f4..36e69e4 100644
--- a/gcc/jit/ChangeLog.jit
+++ b/gcc/jit/ChangeLog.jit
@@ -1,3 +1,69 @@
+2014-01-29 David Malcolm <dmalcolm@redhat.com>
+
+ * libgccjit.h (gcc_jit_lvalue_access_field): Require
+ a (gcc_jit_field *) rather than a field name.
+ (gcc_jit_rvalue_access_field): Likewise.
+ (gcc_jit_rvalue_dereference_field): Likewise.
+
+ * libgccjit.c (gcc_jit_lvalue_access_field): Require
+ a (gcc_jit_field *) rather than a field name.
+ (gcc_jit_rvalue_access_field): Likewise.
+ (gcc_jit_rvalue_dereference_field): Likewise.
+
+ * internal-api.c (gcc::jit::recording::rvalue::access_field):
+ Require a field rather than a fieldname string.
+ (gcc::jit::recording::rvalue::dereference_field): Likewise.
+ (gcc::jit::recording::lvalue::access_field): Likewise.
+
+ (gcc::jit::recording::access_field_of_lvalue::replay_into): Update
+ given that this now has a field, rather than a fieldname.
+ (gcc::jit::recording::access_field_rvalue::replay_into): Likewise.
+ (gcc::jit::recording::dereference_field_rvalue::replay_into): Likewise.
+
+ (get_field): Delete, as we no longer need to convert
+ from (struct, identifier) pairs to fields, instead directly using
+ fields.
+
+ (gcc::jit::playback::context::new_field_access): Require a field
+ rather than a fieldname, removing the need to look up the field by
+ name within the struct.
+
+ (gcc::jit::playback::lvalue::access_field): Likewise.
+ (gcc::jit::playback::rvalue::access_field): Likewise.
+ (gcc::jit::playback::rvalue::dereference_field): Likewise.
+
+ * internal-api.h (gcc::jit::recording::rvalue::access_field):
+ Require a field rather than a fieldname string.
+ (gcc::jit::recording::rvalue::dereference_field): Likewise.
+ (gcc::jit::recording::lvalue::access_field): Likewise.
+
+ (gcc::jit::recording::access_field_of_lvalue::access_field_of_lvalue):
+ Likewise.
+ (gcc::jit::recording::access_field_of_lvalue::m_fieldname): Drop
+ string field in favor of...
+ (gcc::jit::recording::access_field_of_lvalue::m_field):
+ ..."field" field, as it were.
+
+ (gcc::jit::recording::access_field_of_rvalue::access_field_of_rvalue):
+ Likewise.
+ (gcc::jit::recording::access_field_of_rvalue::m_fieldname): Drop
+ string field in favor of...
+ (gcc::jit::recording::access_field_of_rvalue::m_field):
+ ..."field" field.
+
+ (gcc::jit::recording::dereference_field_rvalue::
+ dereference_field_rvalue): Likewise.
+ (gcc::jit::recording::dereference_field_rvalue::m_fieldname): Drop
+ string field in favor of...
+ (gcc::jit::recording::dereference_field_rvalue::m_field):
+ ..."field" field.
+
+ (gcc::jit::playback::context::new_field_access): Require a field
+ rather than a fieldname string.
+ (gcc::jit::playback::context::access_field): Likewise.
+ (gcc::jit::playback::context::dereference_field): Likewise.
+ (gcc::jit::playback::rvalue::access_field):
+
2014-01-28 David Malcolm <dmalcolm@redhat.com>
* libgccjit.h (gcc_jit_context_new_child_context): New function.
diff --git a/gcc/jit/internal-api.c b/gcc/jit/internal-api.c
index 30c578c..39d434f 100644
--- a/gcc/jit/internal-api.c
+++ b/gcc/jit/internal-api.c
@@ -552,22 +552,20 @@ recording::struct_::replay_into (replayer *r)
recording::rvalue *
recording::rvalue::access_field (recording::location *loc,
- const char *fieldname)
+ field *field)
{
recording::rvalue *result =
- new access_field_rvalue (m_ctxt, loc, this,
- new_string (fieldname));
+ new access_field_rvalue (m_ctxt, loc, this, field);
m_ctxt->record (result);
return result;
}
recording::lvalue *
recording::rvalue::dereference_field (recording::location *loc,
- const char *fieldname)
+ field *field)
{
recording::lvalue *result =
- new dereference_field_rvalue (m_ctxt, loc, this,
- new_string (fieldname));
+ new dereference_field_rvalue (m_ctxt, loc, this, field);
m_ctxt->record (result);
return result;
}
@@ -585,11 +583,10 @@ recording::rvalue::dereference (recording::location *loc)
recording::lvalue *
recording::lvalue::access_field (recording::location *loc,
- const char *fieldname)
+ field *field)
{
recording::lvalue *result =
- new access_field_of_lvalue (m_ctxt, loc, this,
- new_string (fieldname));
+ new access_field_of_lvalue (m_ctxt, loc, this, field);
m_ctxt->record (result);
return result;
}
@@ -881,7 +878,8 @@ recording::access_field_of_lvalue::replay_into (replayer *)
set_playback_obj (
m_lvalue->playback_lvalue ()
->access_field (playback_location (m_loc),
- m_fieldname->c_str ()));
+ m_field->playback_field ()));
+
}
void
@@ -890,7 +888,7 @@ recording::access_field_rvalue::replay_into (replayer *)
set_playback_obj (
m_rvalue->playback_rvalue ()
->access_field (playback_location (m_loc),
- m_fieldname->c_str ()));
+ m_field->playback_field ()));
}
void
@@ -899,7 +897,7 @@ recording::dereference_field_rvalue::replay_into (replayer *)
set_playback_obj (
m_rvalue->playback_rvalue ()->
dereference_field (playback_location (m_loc),
- m_fieldname->c_str ()));
+ m_field->playback_field ()));
}
void
@@ -1673,23 +1671,14 @@ new_array_lookup (location *loc,
}
}
-static tree
-get_field (tree type, tree component)
-{
- for (tree field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field))
- if (DECL_NAME (field) == component)
- return field;
- return NULL;
-}
-
tree
playback::context::
new_field_access (location *loc,
tree datum,
- const char *fieldname)
+ field *field)
{
gcc_assert (datum);
- gcc_assert (fieldname);
+ gcc_assert (field);
/* Compare with c/c-typeck.c:lookup_field, build_indirect_ref, and
build_component_ref. */
@@ -1697,15 +1686,9 @@ new_field_access (location *loc,
gcc_assert (type);
gcc_assert (TREE_CODE (type) != POINTER_TYPE);
- tree component = get_identifier (fieldname);
- tree field = get_field (type, component);
- if (!field)
- {
- add_error ("field not found: \"%s\"", fieldname);
- return NULL;
- }
- tree ref = build3 (COMPONENT_REF, TREE_TYPE (field), datum,
- field, NULL_TREE);
+ tree t_field = field->as_tree ();
+ tree ref = build3 (COMPONENT_REF, TREE_TYPE (t_field), datum,
+ t_field, NULL_TREE);
if (loc)
set_tree_location (ref, loc);
return ref;
@@ -1728,10 +1711,10 @@ new_dereference (tree ptr,
playback::lvalue *
playback::lvalue::
access_field (location *loc,
- const char *fieldname)
+ field *field)
{
tree datum = as_tree ();
- tree ref = get_context ()->new_field_access (loc, datum, fieldname);
+ tree ref = get_context ()->new_field_access (loc, datum, field);
if (!ref)
return NULL;
return new lvalue (get_context (), ref);
@@ -1740,10 +1723,10 @@ access_field (location *loc,
playback::rvalue *
playback::rvalue::
access_field (location *loc,
- const char *fieldname)
+ field *field)
{
tree datum = as_tree ();
- tree ref = get_context ()->new_field_access (loc, datum, fieldname);
+ tree ref = get_context ()->new_field_access (loc, datum, field);
if (!ref)
return NULL;
return new rvalue (get_context (), ref);
@@ -1752,13 +1735,13 @@ access_field (location *loc,
playback::lvalue *
playback::rvalue::
dereference_field (location *loc,
- const char *fieldname)
+ field *field)
{
tree ptr = as_tree ();
tree datum = get_context ()->new_dereference (ptr, loc);
if (!datum)
return NULL;
- tree ref = get_context ()->new_field_access (loc, datum, fieldname);
+ tree ref = get_context ()->new_field_access (loc, datum, field);
if (!ref)
return NULL;
return new lvalue (get_context (), ref);
diff --git a/gcc/jit/internal-api.h b/gcc/jit/internal-api.h
index db7e048..66d8cdb 100644
--- a/gcc/jit/internal-api.h
+++ b/gcc/jit/internal-api.h
@@ -472,11 +472,11 @@ public:
}
rvalue *
access_field (location *loc,
- const char *fieldname);
+ field *field);
lvalue *
dereference_field (location *loc,
- const char *fieldname);
+ field *field);
lvalue *
dereference (location *loc);
@@ -501,7 +501,7 @@ public:
lvalue *
access_field (location *loc,
- const char *fieldname);
+ field *field);
rvalue *
get_address (location *loc);
@@ -844,17 +844,17 @@ public:
access_field_of_lvalue (context *ctxt,
location *loc,
lvalue *val,
- string *fieldname)
+ field *field)
: lvalue (ctxt, loc),
m_lvalue (val),
- m_fieldname (fieldname)
+ m_field (field)
{}
void replay_into (replayer *r);
private:
lvalue *m_lvalue;
- string *m_fieldname;
+ field *m_field;
};
class access_field_rvalue : public rvalue
@@ -863,16 +863,17 @@ public:
access_field_rvalue (context *ctxt,
location *loc,
rvalue *val,
- string *fieldname)
+ field *field)
: rvalue (ctxt, loc),
m_rvalue (val),
- m_fieldname (fieldname) {}
+ m_field (field)
+ {}
void replay_into (replayer *r);
private:
rvalue *m_rvalue;
- string *m_fieldname;
+ field *m_field;
};
class dereference_field_rvalue : public lvalue
@@ -881,16 +882,17 @@ public:
dereference_field_rvalue (context *ctxt,
location *loc,
rvalue *val,
- string *fieldname)
+ field *field)
: lvalue (ctxt, loc),
m_rvalue (val),
- m_fieldname (fieldname) {}
+ m_field (field)
+ {}
void replay_into (replayer *r);
private:
rvalue *m_rvalue;
- string *m_fieldname;
+ field *m_field;
};
class dereference_rvalue : public lvalue
@@ -1306,7 +1308,7 @@ public:
tree
new_field_access (location *loc,
tree datum,
- const char *fieldname);
+ field *field);
tree
new_dereference (tree ptr, location *loc);
@@ -1519,11 +1521,11 @@ public:
rvalue *
access_field (location *loc,
- const char *fieldname);
+ field *field);
lvalue *
dereference_field (location *loc,
- const char *fieldname);
+ field *field);
lvalue *
dereference (location *loc);
@@ -1545,7 +1547,7 @@ public:
lvalue *
access_field (location *loc,
- const char *fieldname);
+ field *field);
rvalue *
get_address (location *loc);
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 7d1f9ae..ded581e 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -447,34 +447,34 @@ gcc_jit_context_new_array_lookup (gcc_jit_context *ctxt,
gcc_jit_lvalue *
gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_,
gcc_jit_location *loc,
- const char *fieldname)
+ gcc_jit_field *field)
{
RETURN_NULL_IF_FAIL (struct_, NULL, "NULL struct");
- RETURN_NULL_IF_FAIL (fieldname, NULL, "NULL fieldname");
+ RETURN_NULL_IF_FAIL (field, NULL, "NULL field");
- return (gcc_jit_lvalue *)struct_->access_field (loc, fieldname);
+ return (gcc_jit_lvalue *)struct_->access_field (loc, field);
}
gcc_jit_rvalue *
gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_,
gcc_jit_location *loc,
- const char *fieldname)
+ gcc_jit_field *field)
{
RETURN_NULL_IF_FAIL (struct_, NULL, "NULL struct");
- RETURN_NULL_IF_FAIL (fieldname, NULL, "NULL fieldname");
+ RETURN_NULL_IF_FAIL (field, NULL, "NULL field");
- return (gcc_jit_rvalue *)struct_->access_field (loc, fieldname);
+ return (gcc_jit_rvalue *)struct_->access_field (loc, field);
}
gcc_jit_lvalue *
gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr,
gcc_jit_location *loc,
- const char *fieldname)
+ gcc_jit_field *field)
{
RETURN_NULL_IF_FAIL (ptr, NULL, "NULL ptr");
- RETURN_NULL_IF_FAIL (fieldname, NULL, "NULL fieldname");
+ RETURN_NULL_IF_FAIL (field, NULL, "NULL field");
- return (gcc_jit_lvalue *)ptr->dereference_field (loc, fieldname);
+ return (gcc_jit_lvalue *)ptr->dereference_field (loc, field);
}
gcc_jit_lvalue *
diff --git a/gcc/jit/libgccjit.h b/gcc/jit/libgccjit.h
index 8384a58..6a19b29 100644
--- a/gcc/jit/libgccjit.h
+++ b/gcc/jit/libgccjit.h
@@ -568,7 +568,7 @@ gcc_jit_context_new_array_lookup (gcc_jit_context *ctxt,
extern gcc_jit_lvalue *
gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_,
gcc_jit_location *loc,
- const char *fieldname);
+ gcc_jit_field *field);
/* Accessing a field of an rvalue of struct type, analogous to:
(EXPR).field
@@ -576,7 +576,7 @@ gcc_jit_lvalue_access_field (gcc_jit_lvalue *struct_,
extern gcc_jit_rvalue *
gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_,
gcc_jit_location *loc,
- const char *fieldname);
+ gcc_jit_field *field);
/* Accessing a field of an rvalue of pointer type, analogous to:
(EXPR)->field
@@ -584,7 +584,7 @@ gcc_jit_rvalue_access_field (gcc_jit_rvalue *struct_,
extern gcc_jit_lvalue *
gcc_jit_rvalue_dereference_field (gcc_jit_rvalue *ptr,
gcc_jit_location *loc,
- const char *fieldname);
+ gcc_jit_field *field);
/* Dereferencing a pointer; analogous to:
*(EXPR)
diff --git a/gcc/testsuite/ChangeLog.jit b/gcc/testsuite/ChangeLog.jit
index 6b7413c..a225efd 100644
--- a/gcc/testsuite/ChangeLog.jit
+++ b/gcc/testsuite/ChangeLog.jit
@@ -1,3 +1,15 @@
+2014-01-29 David Malcolm <dmalcolm@redhat.com>
+
+ * jit.dg/test-accessing-struct.c (create_code): Update for API change
+ for accessing fields in terms of gcc_jit_field pointers rather than
+ by name.
+ * jit.dg/test-nested-contexts.c (make_calc_discriminant): Likewise.
+ (make_test_quadratic): Likewise.
+ * jit.dg/test-quadratic.c (make_calc_discriminant): Likewise.
+ (make_test_quadratic): Likewise.
+ * jit.dg/test-reading-struct.c (create_code): Likewise.
+ * jit.dg/test-types.c: Likewise.
+
2014-01-28 David Malcolm <dmalcolm@redhat.com>
* jit.dg/harness.h (test_jit): Add the possibility of turning off
diff --git a/gcc/testsuite/jit.dg/test-accessing-struct.c b/gcc/testsuite/jit.dg/test-accessing-struct.c
index 031916a..b28adeb 100644
--- a/gcc/testsuite/jit.dg/test-accessing-struct.c
+++ b/gcc/testsuite/jit.dg/test-accessing-struct.c
@@ -67,12 +67,12 @@ create_code (gcc_jit_context *ctxt, void *user_data)
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_f),
NULL,
- "x")),
+ x)),
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_f),
NULL,
- "y")));
+ y)));
/* f->z = ... */
gcc_jit_function_add_assignment (
@@ -81,7 +81,7 @@ create_code (gcc_jit_context *ctxt, void *user_data)
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_f),
NULL,
- "z"),
+ z),
sum);
}
diff --git a/gcc/testsuite/jit.dg/test-nested-contexts.c b/gcc/testsuite/jit.dg/test-nested-contexts.c
index 14f90e7..eaedd75 100644
--- a/gcc/testsuite/jit.dg/test-nested-contexts.c
+++ b/gcc/testsuite/jit.dg/test-nested-contexts.c
@@ -180,17 +180,17 @@ make_calc_discriminant (struct top_level *top_level,
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_q),
- NULL, "a"));
+ NULL, top_level->a));
gcc_jit_rvalue *q_b =
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_q),
- NULL, "b"));
+ NULL, top_level->b));
gcc_jit_rvalue *q_c =
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_q),
- NULL, "c"));
+ NULL, top_level->c));
gcc_jit_function_add_assignment (
middle_level->calc_discriminant, NULL,
@@ -199,7 +199,7 @@ make_calc_discriminant (struct top_level *top_level,
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_q),
NULL,
- "discriminant"),
+ top_level->discriminant),
/* (q->b * q->b) - (4 * q->a * q->c) */
gcc_jit_context_new_binary_op (
@@ -270,17 +270,17 @@ make_test_quadratic (struct top_level *top_level,
/* q.a = a; */
gcc_jit_function_add_assignment (
test_quadratic, NULL,
- gcc_jit_lvalue_access_field (q, NULL, "a"),
+ gcc_jit_lvalue_access_field (q, NULL, top_level->a),
gcc_jit_param_as_rvalue (a));
/* q.b = b; */
gcc_jit_function_add_assignment (
test_quadratic, NULL,
- gcc_jit_lvalue_access_field (q, NULL, "b"),
+ gcc_jit_lvalue_access_field (q, NULL, top_level->b),
gcc_jit_param_as_rvalue (b));
/* q.c = c; */
gcc_jit_function_add_assignment (
test_quadratic, NULL,
- gcc_jit_lvalue_access_field (q, NULL, "c"),
+ gcc_jit_lvalue_access_field (q, NULL, top_level->c),
gcc_jit_param_as_rvalue (c));
/* calc_discriminant (&q); */
gcc_jit_rvalue *address_of_q = gcc_jit_lvalue_get_address (q, NULL);
@@ -318,7 +318,7 @@ make_test_quadratic (struct top_level *top_level,
gcc_jit_rvalue_access_field (
gcc_jit_lvalue_as_rvalue (q),
NULL,
- "discriminant"),
+ top_level->discriminant),
top_level->zero),
on_positive_discriminant,
on_nonpositive_discriminant);
@@ -334,7 +334,7 @@ make_test_quadratic (struct top_level *top_level,
gcc_jit_rvalue *discriminant_of_q =
gcc_jit_rvalue_access_field (gcc_jit_lvalue_as_rvalue (q),
NULL,
- "discriminant");
+ top_level->discriminant);
gcc_jit_function_add_assignment (
test_quadratic, NULL,
s,
@@ -429,7 +429,7 @@ make_test_quadratic (struct top_level *top_level,
gcc_jit_rvalue_access_field (
gcc_jit_lvalue_as_rvalue (q),
NULL,
- "discriminant"),
+ top_level->discriminant),
top_level->zero),
on_zero_discriminant,
on_negative_discriminant);
diff --git a/gcc/testsuite/jit.dg/test-quadratic.c b/gcc/testsuite/jit.dg/test-quadratic.c
index fad4b72..9b02c06 100644
--- a/gcc/testsuite/jit.dg/test-quadratic.c
+++ b/gcc/testsuite/jit.dg/test-quadratic.c
@@ -157,17 +157,17 @@ make_calc_discriminant (struct quadratic_test *testcase)
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_q),
- NULL, "a"));
+ NULL, testcase->a));
gcc_jit_rvalue *q_b =
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_q),
- NULL, "b"));
+ NULL, testcase->b));
gcc_jit_rvalue *q_c =
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_q),
- NULL, "c"));
+ NULL, testcase->c));
gcc_jit_function_add_assignment (
testcase->calc_discriminant, NULL,
@@ -176,7 +176,7 @@ make_calc_discriminant (struct quadratic_test *testcase)
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_q),
NULL,
- "discriminant"),
+ testcase->discriminant),
/* (q->b * q->b) - (4 * q->a * q->c) */
gcc_jit_context_new_binary_op (
@@ -245,17 +245,17 @@ make_test_quadratic (struct quadratic_test *testcase)
/* q.a = a; */
gcc_jit_function_add_assignment (
test_quadratic, NULL,
- gcc_jit_lvalue_access_field (q, NULL, "a"),
+ gcc_jit_lvalue_access_field (q, NULL, testcase->a),
gcc_jit_param_as_rvalue (a));
/* q.b = b; */
gcc_jit_function_add_assignment (
test_quadratic, NULL,
- gcc_jit_lvalue_access_field (q, NULL, "b"),
+ gcc_jit_lvalue_access_field (q, NULL, testcase->b),
gcc_jit_param_as_rvalue (b));
/* q.c = c; */
gcc_jit_function_add_assignment (
test_quadratic, NULL,
- gcc_jit_lvalue_access_field (q, NULL, "c"),
+ gcc_jit_lvalue_access_field (q, NULL, testcase->c),
gcc_jit_param_as_rvalue (c));
/* calc_discriminant (&q); */
gcc_jit_rvalue *address_of_q = gcc_jit_lvalue_get_address (q, NULL);
@@ -293,7 +293,7 @@ make_test_quadratic (struct quadratic_test *testcase)
gcc_jit_rvalue_access_field (
gcc_jit_lvalue_as_rvalue (q),
NULL,
- "discriminant"),
+ testcase->discriminant),
testcase->zero),
on_positive_discriminant,
on_nonpositive_discriminant);
@@ -309,7 +309,7 @@ make_test_quadratic (struct quadratic_test *testcase)
gcc_jit_rvalue *discriminant_of_q =
gcc_jit_rvalue_access_field (gcc_jit_lvalue_as_rvalue (q),
NULL,
- "discriminant");
+ testcase->discriminant);
gcc_jit_function_add_assignment (
test_quadratic, NULL,
s,
@@ -404,7 +404,7 @@ make_test_quadratic (struct quadratic_test *testcase)
gcc_jit_rvalue_access_field (
gcc_jit_lvalue_as_rvalue (q),
NULL,
- "discriminant"),
+ testcase->discriminant),
testcase->zero),
on_zero_discriminant,
on_negative_discriminant);
diff --git a/gcc/testsuite/jit.dg/test-reading-struct.c b/gcc/testsuite/jit.dg/test-reading-struct.c
index eeb6321..fd53f84 100644
--- a/gcc/testsuite/jit.dg/test-reading-struct.c
+++ b/gcc/testsuite/jit.dg/test-reading-struct.c
@@ -72,12 +72,12 @@ create_code (gcc_jit_context *ctxt, void *user_data)
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_f),
NULL,
- "x")),
+ x)),
gcc_jit_lvalue_as_rvalue (
gcc_jit_rvalue_dereference_field (
gcc_jit_param_as_rvalue (param_f),
NULL,
- "y"))));
+ y))));
/* Build "test_writing". */
gcc_jit_function *fn_test_writing =
@@ -96,13 +96,13 @@ create_code (gcc_jit_context *ctxt, void *user_data)
/* tmp.x = 5; */
gcc_jit_function_add_assignment (
fn_test_writing, NULL,
- gcc_jit_lvalue_access_field (local_tmp, NULL, "x"),
+ gcc_jit_lvalue_access_field (local_tmp, NULL, x),
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 5));
/* tmp.y = 7; */
gcc_jit_function_add_assignment (
fn_test_writing, NULL,
- gcc_jit_lvalue_access_field (local_tmp, NULL, "y"),
+ gcc_jit_lvalue_access_field (local_tmp, NULL, y),
gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 7));
/* return test_reading (&tmp); */
diff --git a/gcc/testsuite/jit.dg/test-types.c b/gcc/testsuite/jit.dg/test-types.c
index 1d5758d..90b5f6e 100644
--- a/gcc/testsuite/jit.dg/test-types.c
+++ b/gcc/testsuite/jit.dg/test-types.c
@@ -37,46 +37,6 @@ struct zoo
FILE *m_FILE_ptr;
};
-/* Now describe the struct in libgccjit terms. */
-struct field
-{
- enum gcc_jit_types type_;
- const char *name;
-};
-
-const struct field fields[] = {
- {GCC_JIT_TYPE_VOID_PTR, "m_void_ptr"},
-
- {GCC_JIT_TYPE_CHAR, "m_char"},
- {GCC_JIT_TYPE_SIGNED_CHAR, "m_signed_char"},
- {GCC_JIT_TYPE_UNSIGNED_CHAR, "m_unsigned_char"},
-
- {GCC_JIT_TYPE_SHORT, "m_short"},
- {GCC_JIT_TYPE_UNSIGNED_SHORT, "m_unsigned_short"},
-
- {GCC_JIT_TYPE_INT, "m_int"},
- {GCC_JIT_TYPE_UNSIGNED_INT, "m_unsigned_int"},
-
- {GCC_JIT_TYPE_LONG, "m_long"},
- {GCC_JIT_TYPE_UNSIGNED_LONG, "m_unsigned_long"},
-
- {GCC_JIT_TYPE_LONG_LONG, "m_long_long"},
- {GCC_JIT_TYPE_UNSIGNED_LONG_LONG, "m_unsigned_long_long"},
-
- {GCC_JIT_TYPE_FLOAT, "m_float"},
- {GCC_JIT_TYPE_DOUBLE, "m_double"},
- {GCC_JIT_TYPE_LONG_DOUBLE, "m_long_double"},
-
- {GCC_JIT_TYPE_CONST_CHAR_PTR, "m_const_char_ptr"},
-
- {GCC_JIT_TYPE_SIZE_T, "m_size_t"},
-
- {GCC_JIT_TYPE_FILE_PTR, "m_FILE_ptr"},
-
-};
-
-#define NUM_FIELDS (sizeof(fields)/sizeof(fields[0]))
-
int test_int = 42;
int *test_ptr = &test_int;
@@ -94,22 +54,101 @@ create_code (gcc_jit_context *ctxt, void *user_data)
z->m_field = ...some data;
}
*/
- int i;
gcc_jit_type *void_type =
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID);
- gcc_jit_field *zoo_fields[NUM_FIELDS];
- for (i = 0; i < NUM_FIELDS; i++)
- zoo_fields[i] =
- gcc_jit_context_new_field (
- ctxt, NULL,
- gcc_jit_context_get_type (ctxt, fields[i].type_),
- fields[i].name);
+
+#define CREATE_FIELD(TYPE, NAME) \
+ gcc_jit_context_new_field ( \
+ ctxt, NULL, \
+ gcc_jit_context_get_type (ctxt, TYPE), \
+ NAME)
+
+ gcc_jit_field *field_m_void_ptr =
+ CREATE_FIELD (GCC_JIT_TYPE_VOID_PTR, "m_void_ptr");
+
+ gcc_jit_field *field_m_char =
+ CREATE_FIELD (GCC_JIT_TYPE_CHAR, "m_char");
+ gcc_jit_field *field_m_signed_char =
+ CREATE_FIELD (GCC_JIT_TYPE_SIGNED_CHAR, "m_signed_char");
+ gcc_jit_field *field_m_unsigned_char =
+ CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_CHAR, "m_unsigned_char");
+
+ gcc_jit_field *field_m_short =
+ CREATE_FIELD (GCC_JIT_TYPE_SHORT, "m_short");
+ gcc_jit_field *field_m_unsigned_short =
+ CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_SHORT, "m_unsigned_short");
+
+ gcc_jit_field *field_m_int =
+ CREATE_FIELD (GCC_JIT_TYPE_INT, "m_int");
+ gcc_jit_field *field_m_unsigned_int =
+ CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_INT, "m_unsigned_int");
+
+ gcc_jit_field *field_m_long =
+ CREATE_FIELD (GCC_JIT_TYPE_LONG, "m_long");
+ gcc_jit_field *field_m_unsigned_long =
+ CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_LONG, "m_unsigned_long");
+
+ gcc_jit_field *field_m_long_long =
+ CREATE_FIELD (GCC_JIT_TYPE_LONG_LONG, "m_long_long");
+ gcc_jit_field *field_m_unsigned_long_long =
+ CREATE_FIELD (GCC_JIT_TYPE_UNSIGNED_LONG_LONG, "m_unsigned_long_long");
+
+ gcc_jit_field *field_m_float =
+ CREATE_FIELD (GCC_JIT_TYPE_FLOAT, "m_float");
+ gcc_jit_field *field_m_double =
+ CREATE_FIELD (GCC_JIT_TYPE_DOUBLE, "m_double");
+ gcc_jit_field *field_m_long_double =
+ CREATE_FIELD (GCC_JIT_TYPE_LONG_DOUBLE, "m_long_double");
+
+ gcc_jit_field *field_m_const_char_ptr =
+ CREATE_FIELD (GCC_JIT_TYPE_CONST_CHAR_PTR, "m_const_char_ptr");
+
+ gcc_jit_field *field_m_size_t =
+ CREATE_FIELD (GCC_JIT_TYPE_SIZE_T, "m_size_t");
+
+ gcc_jit_field *field_m_FILE_ptr =
+ CREATE_FIELD (GCC_JIT_TYPE_FILE_PTR, "m_FILE_ptr");
+
+#undef CREATE_FIELD
+
+ gcc_jit_field *zoo_fields[] = {
+ field_m_void_ptr,
+
+ field_m_char,
+ field_m_signed_char,
+ field_m_unsigned_char,
+
+ field_m_short,
+ field_m_unsigned_short,
+
+ field_m_int,
+ field_m_unsigned_int,
+
+ field_m_long,
+ field_m_unsigned_long,
+
+ field_m_long_long,
+ field_m_unsigned_long_long,
+
+ field_m_float,
+ field_m_double,
+ field_m_long_double,
+
+ field_m_const_char_ptr,
+
+ field_m_size_t,
+
+ field_m_FILE_ptr
+ };
+
gcc_jit_type *zoo_type =
- gcc_jit_context_new_struct_type (ctxt,
- NULL,
- "zoo",
- NUM_FIELDS,
- zoo_fields);
+ gcc_jit_context_new_struct_type (
+ ctxt,
+ NULL,
+ "zoo",
+ sizeof (zoo_fields) / sizeof (zoo_fields[0]),
+ zoo_fields);
+
gcc_jit_type *zoo_ptr_type =
gcc_jit_type_get_pointer (zoo_type);
@@ -125,111 +164,111 @@ create_code (gcc_jit_context *ctxt, void *user_data)
0);
/* Write to the various fields of param "z". */
-#define ASSIGN(FIELDNAME, EXPR) \
+#define ASSIGN(FIELD, EXPR) \
gcc_jit_function_add_assignment ( \
test_fn, NULL, \
gcc_jit_rvalue_dereference_field ( \
gcc_jit_param_as_rvalue (param_z), \
NULL, \
- (FIELDNAME)), \
+ (FIELD)), \
(EXPR));
ASSIGN(
- "m_void_ptr",
+ field_m_void_ptr,
gcc_jit_context_new_rvalue_from_ptr (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR),
test_ptr))
- ASSIGN("m_char",
+ ASSIGN(field_m_char,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CHAR),
'V'))
- ASSIGN("m_signed_char",
+ ASSIGN(field_m_signed_char,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_SIGNED_CHAR),
-37))
- ASSIGN("m_unsigned_char",
+ ASSIGN(field_m_unsigned_char,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_CHAR),
200))
- ASSIGN("m_short",
+ ASSIGN(field_m_short,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_SHORT),
-900))
- ASSIGN("m_unsigned_short",
+ ASSIGN(field_m_unsigned_short,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_SHORT),
0x3000))
- ASSIGN("m_int",
+ ASSIGN(field_m_int,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT),
-0x2000))
- ASSIGN("m_unsigned_int",
+ ASSIGN(field_m_unsigned_int,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_INT),
1234567))
- ASSIGN("m_long",
+ ASSIGN(field_m_long,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG),
-5))
- ASSIGN("m_unsigned_long",
+ ASSIGN(field_m_unsigned_long,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_LONG),
12345678))
- ASSIGN("m_long_long",
+ ASSIGN(field_m_long_long,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG_LONG),
-42))
- ASSIGN("m_unsigned_long_long",
+ ASSIGN(field_m_unsigned_long_long,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_UNSIGNED_LONG_LONG),
123456789))
- ASSIGN("m_float",
+ ASSIGN(field_m_float,
gcc_jit_context_new_rvalue_from_double (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FLOAT),
3.141))
- ASSIGN("m_double",
+ ASSIGN(field_m_double,
gcc_jit_context_new_rvalue_from_double (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE),
3.141))
- ASSIGN("m_long_double",
+ ASSIGN(field_m_long_double,
gcc_jit_context_new_rvalue_from_double (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_LONG_DOUBLE),
3.141))
- ASSIGN("m_const_char_ptr",
+ ASSIGN(field_m_const_char_ptr,
gcc_jit_context_new_rvalue_from_ptr (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_CONST_CHAR_PTR),
(char *)test_string))
- ASSIGN("m_size_t",
+ ASSIGN(field_m_size_t,
gcc_jit_context_new_rvalue_from_int (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_SIZE_T),
sizeof (struct zoo)))
- ASSIGN("m_FILE_ptr",
+ ASSIGN(field_m_FILE_ptr,
gcc_jit_context_new_rvalue_from_ptr (
ctxt,
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_FILE_PTR),
--
1.7.11.7