@@ -1,3 +1,12 @@
+2013-10-21 David Malcolm <dmalcolm@redhat.com>
+
+ * TODO.rst ("the C unary prefix "&" operator"): Remove completed item.
+ * internal-api.c (gcc::jit::lvalue::get_address): New.
+ * internal-api.h (gcc::jit::lvalue::get_address): New.
+ * libgccjit.c (gcc_jit_lvalue_get_address): New.
+ * libgccjit.h (gcc_jit_lvalue_get_address): New.
+ * libgccjit.map (gcc_jit_lvalue_get_address): New.
+
2013-10-18 David Malcolm <dmalcolm@redhat.com>
* internal-api.c (gcc::jit::context::new_param): Add context
@@ -55,11 +55,6 @@ Initial Release
and, indeed, clarify all of the other operations.
-* the C unary prefix "&" operator::
-
- extern gcc_jit_rvalue *
- gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue);
-
* array types, in case they're needed for structs::
extern gcc_jit_type *
@@ -757,6 +757,19 @@ dereference (gcc::jit::location *loc)
return new lvalue (get_context (), datum);
}
+gcc::jit::rvalue *
+gcc::jit::lvalue::
+get_address (location *loc)
+{
+ tree t_lvalue = as_tree ();
+ tree t_thistype = TREE_TYPE (t_lvalue);
+ tree t_ptrtype = build_pointer_type (t_thistype);
+ tree ptr = build1 (ADDR_EXPR, t_ptrtype, t_lvalue);
+ if (loc)
+ get_context ()->set_tree_location (ptr, loc);
+ return new rvalue (get_context (), ptr);
+}
+
void *
gcc::jit::wrapper::
operator new (size_t sz)
@@ -422,6 +422,9 @@ public:
access_field (location *loc,
const char *fieldname);
+ rvalue *
+ get_address (location *loc);
+
};
class param : public lvalue
@@ -529,6 +529,15 @@ gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue,
return (gcc_jit_lvalue *)rvalue->dereference (loc);
}
+gcc_jit_rvalue *
+gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue,
+ gcc_jit_location *loc)
+{
+ RETURN_NULL_IF_FAIL (lvalue, NULL, "NULL lvalue");
+
+ return (gcc_jit_rvalue *)lvalue->get_address (loc);
+}
+
gcc_jit_lvalue *
gcc_jit_function_new_local (gcc_jit_function *func,
gcc_jit_location *loc,
@@ -601,6 +601,13 @@ extern gcc_jit_lvalue *
gcc_jit_rvalue_dereference (gcc_jit_rvalue *rvalue,
gcc_jit_location *loc);
+/* Taking the address of an lvalue; analogous to:
+ &(EXPR)
+ in C. */
+extern gcc_jit_rvalue *
+gcc_jit_lvalue_get_address (gcc_jit_lvalue *lvalue,
+ gcc_jit_location *loc);
+
extern gcc_jit_lvalue *
gcc_jit_function_new_local (gcc_jit_function *func,
gcc_jit_location *loc,
@@ -41,6 +41,7 @@
gcc_jit_loop_end;
gcc_jit_lvalue_as_rvalue;
gcc_jit_lvalue_access_field;
+ gcc_jit_lvalue_get_address;
gcc_jit_param_as_lvalue;
gcc_jit_param_as_rvalue;
gcc_jit_result_get_code;
@@ -1,3 +1,11 @@
+2013-10-21 David Malcolm <dmalcolm@redhat.com>
+
+ * jit.dg/test-expressions.c (test_global): New.
+ (make_test_of_get_address): New.
+ (verify_get_address): New.
+ (code_making_callback): Add call to make_test_of_get_address.
+ (verify_code): Add call to verify_get_address.
+
2013-10-18 David Malcolm <dmalcolm@redhat.com>
* jit.dg/test-expressions.c: New.
@@ -492,6 +492,58 @@ verify_dereferences (gcc_jit_result *result)
}
/**********************************************************************
+ gcc_jit_lvalue_get_address
+ **********************************************************************/
+
+int test_global;
+static void
+make_test_of_get_address (gcc_jit_context *ctxt)
+{
+ /*
+ void *test_get_address (void)
+ {
+ return &test_global;
+ }
+ */
+ gcc_jit_type *int_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
+ gcc_jit_lvalue *test_global =
+ gcc_jit_context_new_global (
+ ctxt,
+ NULL,
+ int_type,
+ "test_global");
+
+ gcc_jit_type *void_ptr_type =
+ gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_VOID_PTR);
+
+ gcc_jit_function *test_get_address =
+ gcc_jit_context_new_function (ctxt, NULL,
+ GCC_JIT_FUNCTION_EXPORTED,
+ void_ptr_type,
+ "test_get_address",
+ 0, NULL,
+ 0);
+ gcc_jit_function_add_return (
+ test_get_address,
+ NULL,
+ gcc_jit_lvalue_get_address (
+ test_global,
+ NULL));
+}
+
+static void
+verify_get_address (gcc_jit_result *result)
+{
+ typedef void *(*test_fn) (void);
+ test_fn test_get_address =
+ (test_fn)gcc_jit_result_get_code (result,
+ "test_get_address");
+ CHECK_NON_NULL (test_get_address);
+ CHECK_VALUE (test_get_address (), &test_global);
+}
+
+/**********************************************************************
Code for harness
**********************************************************************/
@@ -502,6 +554,7 @@ code_making_callback (gcc_jit_context *ctxt, void *user_data)
make_tests_of_binary_ops (ctxt);
make_tests_of_comparisons (ctxt);
make_tests_of_dereferences (ctxt);
+ make_test_of_get_address (ctxt);
return 0;
}
@@ -515,4 +568,5 @@ verify_code (gcc_jit_result *result)
verify_binary_ops (result);
verify_comparisons (result);
verify_dereferences (result);
+ verify_get_address (result);
}