Skip to content

Commit a033810

Browse files
authored
Merge pull request #30 from antoyo/feature/sizeof
Implement sizeof
2 parents 84a3a6b + 64dee48 commit a033810

File tree

7 files changed

+119
-0
lines changed

7 files changed

+119
-0
lines changed

gcc/jit/jit-playback.cc

+10
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,16 @@ new_rvalue_from_const <void *> (type *type,
11311131

11321132
/* Construct a playback::rvalue instance (wrapping a tree). */
11331133

1134+
playback::rvalue *
1135+
playback::context::
1136+
new_sizeof (type *type)
1137+
{
1138+
tree inner = TYPE_SIZE_UNIT (type->as_tree ());
1139+
return new rvalue (this, inner);
1140+
}
1141+
1142+
/* Construct a playback::rvalue instance (wrapping a tree). */
1143+
11341144
playback::rvalue *
11351145
playback::context::
11361146
new_string_literal (const char *value)

gcc/jit/jit-playback.h

+3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ class context : public log_user
153153
new_rvalue_from_const (type *type,
154154
HOST_TYPE value);
155155

156+
rvalue *
157+
new_sizeof (type *type);
158+
156159
rvalue *
157160
new_string_literal (const char *value);
158161

gcc/jit/jit-recording.cc

+52
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,21 @@ recording::context::new_global_init_rvalue (lvalue *variable,
11251125
gbl->set_rvalue_init (init); /* Needed by the global for write dump. */
11261126
}
11271127

1128+
/* Create a recording::memento_of_sizeof instance and add it
1129+
to this context's list of mementos.
1130+
1131+
Implements the post-error-checking part of
1132+
gcc_jit_context_new_sizeof. */
1133+
1134+
recording::rvalue *
1135+
recording::context::new_sizeof (recording::type *type)
1136+
{
1137+
recording::rvalue *result =
1138+
new memento_of_new_sizeof (this, NULL, type);
1139+
record (result);
1140+
return result;
1141+
}
1142+
11281143
/* Create a recording::memento_of_new_string_literal instance and add it
11291144
to this context's list of mementos.
11301145
@@ -5535,6 +5550,43 @@ memento_of_new_rvalue_from_const <void *>::write_reproducer (reproducer &r)
55355550

55365551
} // namespace recording
55375552

5553+
/* The implementation of class gcc::jit::recording::memento_of_new_sizeof. */
5554+
5555+
/* Implementation of pure virtual hook recording::memento::replay_into
5556+
for recording::memento_of_new_sizeof. */
5557+
5558+
void
5559+
recording::memento_of_new_sizeof::replay_into (replayer *r)
5560+
{
5561+
set_playback_obj (r->new_sizeof (m_type->playback_type ()));
5562+
}
5563+
5564+
/* Implementation of recording::memento::make_debug_string for
5565+
sizeof expressions. */
5566+
5567+
recording::string *
5568+
recording::memento_of_new_sizeof::make_debug_string ()
5569+
{
5570+
return string::from_printf (m_ctxt,
5571+
"sizeof (%s)",
5572+
m_type->get_debug_string ());
5573+
}
5574+
5575+
/* Implementation of recording::memento::write_reproducer for sizeof
5576+
expressions. */
5577+
5578+
void
5579+
recording::memento_of_new_sizeof::write_reproducer (reproducer &r)
5580+
{
5581+
const char *id = r.make_identifier (this, "rvalue");
5582+
r.write (" gcc_jit_rvalue *%s =\n"
5583+
" gcc_jit_context_new_sizeof (%s, /* gcc_jit_context *ctxt */\n"
5584+
" %s); /* gcc_jit_type *type */\n",
5585+
id,
5586+
r.get_identifier (get_context ()),
5587+
m_type->get_debug_string ());
5588+
}
5589+
55385590
/* The implementation of class gcc::jit::recording::memento_of_new_string_literal. */
55395591

55405592
/* Implementation of pure virtual hook recording::memento::replay_into

gcc/jit/jit-recording.h

+28
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ class context : public log_user
177177
new_rvalue_from_const (type *type,
178178
HOST_TYPE value);
179179

180+
rvalue *
181+
new_sizeof (type *type);
182+
180183
rvalue *
181184
new_string_literal (const char *value);
182185

@@ -1723,6 +1726,31 @@ class memento_of_new_rvalue_from_const : public rvalue
17231726
HOST_TYPE m_value;
17241727
};
17251728

1729+
class memento_of_new_sizeof : public rvalue
1730+
{
1731+
public:
1732+
memento_of_new_sizeof (context *ctxt,
1733+
location *loc,
1734+
type *type)
1735+
: rvalue (ctxt, loc, ctxt->get_type (GCC_JIT_TYPE_INT)),
1736+
m_type (type) {}
1737+
1738+
void replay_into (replayer *r) final override;
1739+
1740+
void visit_children (rvalue_visitor *) final override {}
1741+
1742+
private:
1743+
string * make_debug_string () final override;
1744+
void write_reproducer (reproducer &r) final override;
1745+
enum precedence get_precedence () const final override
1746+
{
1747+
return PRECEDENCE_PRIMARY;
1748+
}
1749+
1750+
private:
1751+
type *m_type;
1752+
};
1753+
17261754
class memento_of_new_string_literal : public rvalue
17271755
{
17281756
public:

gcc/jit/libgccjit.cc

+17
Original file line numberDiff line numberDiff line change
@@ -2128,6 +2128,23 @@ gcc_jit_context_null (gcc_jit_context *ctxt,
21282128
return gcc_jit_context_new_rvalue_from_ptr (ctxt, pointer_type, NULL);
21292129
}
21302130

2131+
/* Public entrypoint. See description in libgccjit.h.
2132+
2133+
After error-checking, the real work is done by the
2134+
gcc::jit::recording::context::new_sizeof method in
2135+
jit-recording.cc. */
2136+
2137+
gcc_jit_rvalue *
2138+
gcc_jit_context_new_sizeof (gcc_jit_context *ctxt,
2139+
gcc_jit_type *type)
2140+
{
2141+
RETURN_NULL_IF_FAIL (ctxt, NULL, NULL, "NULL context");
2142+
JIT_LOG_FUNC (ctxt->get_logger ());
2143+
2144+
return ((gcc_jit_rvalue *)ctxt
2145+
->new_sizeof (type));
2146+
}
2147+
21312148
/* Public entrypoint. See description in libgccjit.h.
21322149
21332150
After error-checking, the real work is done by the

gcc/jit/libgccjit.h

+4
Original file line numberDiff line numberDiff line change
@@ -1102,6 +1102,10 @@ extern gcc_jit_rvalue *
11021102
gcc_jit_context_null (gcc_jit_context *ctxt,
11031103
gcc_jit_type *pointer_type);
11041104

1105+
extern gcc_jit_rvalue *
1106+
gcc_jit_context_new_sizeof (gcc_jit_context *ctxt,
1107+
gcc_jit_type *type);
1108+
11051109
/* String literals. */
11061110
extern gcc_jit_rvalue *
11071111
gcc_jit_context_new_string_literal (gcc_jit_context *ctxt,

gcc/jit/libgccjit.map

+5
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,8 @@ LIBGCCJIT_ABI_34 {
331331
global:
332332
gcc_jit_type_get_restrict;
333333
} LIBGCCJIT_ABI_33;
334+
335+
LIBGCCJIT_ABI_35 {
336+
global:
337+
gcc_jit_context_new_sizeof;
338+
} LIBGCCJIT_ABI_34;

0 commit comments

Comments
 (0)