Skip to content

Commit c8add0c

Browse files
committed
Add support for setting the comment ident
1 parent 8f9ff06 commit c8add0c

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed

gcc/jit/jit-playback.cc

+7
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,13 @@ get_type (enum gcc_jit_types type_)
324324
return new type (type_node);
325325
}
326326

327+
void
328+
playback::context::
329+
set_output_ident (const char* ident)
330+
{
331+
targetm.asm_out.output_ident (ident);
332+
}
333+
327334
/* Construct a playback::type instance (wrapping a tree) for the given
328335
array type. */
329336

gcc/jit/jit-playback.h

+3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ class context : public log_user
7878
type *
7979
get_type (enum gcc_jit_types type);
8080

81+
void
82+
set_output_ident (const char* ident);
83+
8184
type *
8285
new_array_type (location *loc,
8386
type *element_type,

gcc/jit/jit-recording.cc

+51
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,13 @@ recording::context::set_str_option (enum gcc_jit_str_option opt,
14561456
log_str_option (opt);
14571457
}
14581458

1459+
void
1460+
recording::context::set_output_ident (const char *ident)
1461+
{
1462+
recording::output_ident *memento = new output_ident (this, ident);
1463+
record (memento);
1464+
}
1465+
14591466
/* Set the given integer option for this context, or add an error if
14601467
it's not recognized.
14611468
@@ -2314,6 +2321,50 @@ recording::string::write_reproducer (reproducer &)
23142321
/* Empty. */
23152322
}
23162323

2324+
/* The implementation of class gcc::jit::recording::output_ident. */
2325+
2326+
/* Constructor for gcc::jit::recording::output_ident, allocating a
2327+
copy of the given text using new char[]. */
2328+
2329+
recording::output_ident::output_ident (context *ctxt, const char *ident)
2330+
: memento (ctxt)
2331+
{
2332+
m_ident = ident ? xstrdup (ident) : NULL;
2333+
}
2334+
2335+
/* Destructor for gcc::jit::recording::output_ident. */
2336+
2337+
recording::output_ident::~output_ident ()
2338+
{
2339+
delete[] m_ident;
2340+
}
2341+
2342+
/* Implementation of pure virtual hook recording::memento::replay_into
2343+
for recording::output_ident. */
2344+
2345+
void
2346+
recording::output_ident::replay_into (replayer *r)
2347+
{
2348+
r->set_output_ident (m_ident);
2349+
}
2350+
2351+
/* Implementation of recording::memento::make_debug_string for output_ident. */
2352+
2353+
recording::string *
2354+
recording::output_ident::make_debug_string ()
2355+
{
2356+
return m_ctxt->new_string (m_ident);
2357+
}
2358+
2359+
/* Implementation of recording::memento::write_reproducer for output_ident. */
2360+
2361+
void
2362+
recording::output_ident::write_reproducer (reproducer &)
2363+
{
2364+
/* TODO */
2365+
}
2366+
2367+
23172368
/* The implementation of class gcc::jit::recording::location. */
23182369

23192370
/* Implementation of recording::memento::replay_into for locations.

gcc/jit/jit-recording.h

+22
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,9 @@ class context : public log_user
255255
set_str_option (enum gcc_jit_str_option opt,
256256
const char *value);
257257

258+
void
259+
set_output_ident (const char *output_ident);
260+
258261
void
259262
set_int_option (enum gcc_jit_int_option opt,
260263
int value);
@@ -497,6 +500,25 @@ class string : public memento
497500
bool m_escaped;
498501
};
499502

503+
class output_ident : public memento
504+
{
505+
public:
506+
output_ident (context *ctxt, const char *text);
507+
~output_ident ();
508+
509+
void replay_into (replayer *) final override;
510+
511+
output_ident (const output_ident&) = delete;
512+
output_ident& operator= (const output_ident&) = delete;
513+
514+
private:
515+
string * make_debug_string () final override;
516+
void write_reproducer (reproducer &r) final override;
517+
518+
private:
519+
const char *m_ident;
520+
};
521+
500522
class location : public memento
501523
{
502524
public:

gcc/jit/libgccjit.cc

+15
Original file line numberDiff line numberDiff line change
@@ -3919,6 +3919,21 @@ gcc_jit_context_get_target_info (gcc_jit_context *ctxt)
39193919
return (gcc_jit_target_info*) jit_get_target_info ();
39203920
}
39213921

3922+
/* Public entrypoint. See description in libgccjit.h.
3923+
3924+
After error-checking, the real work is done by the
3925+
gcc::jit::recording::context::set_str_option method in
3926+
jit-recording.cc. */
3927+
3928+
void
3929+
gcc_jit_context_set_output_ident (gcc_jit_context *ctxt, const char* output_ident)
3930+
{
3931+
RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
3932+
JIT_LOG_FUNC (ctxt->get_logger ());
3933+
3934+
ctxt->set_output_ident (output_ident);
3935+
}
3936+
39223937
void
39233938
gcc_jit_target_info_release (gcc_jit_target_info *info)
39243939
{

gcc/jit/libgccjit.h

+3
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,9 @@ gcc_jit_lvalue_add_string_attribute (gcc_jit_lvalue *variable,
21452145
extern gcc_jit_target_info *
21462146
gcc_jit_context_get_target_info (gcc_jit_context *ctxt);
21472147

2148+
extern void
2149+
gcc_jit_context_set_output_ident (gcc_jit_context *ctxt, const char* output_ident);
2150+
21482151
extern void
21492152
gcc_jit_target_info_release (gcc_jit_target_info *info);
21502153

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_context_new_sizeof;
333333
} LIBGCCJIT_ABI_33;
334+
335+
LIBGCCJIT_ABI_35 {
336+
global:
337+
gcc_jit_context_set_output_ident;
338+
} LIBGCCJIT_ABI_34;

0 commit comments

Comments
 (0)