Skip to content

Commit 2829eed

Browse files
committed
libgccjit: Add a way to set the language name and the context filename
1 parent ab85833 commit 2829eed

File tree

7 files changed

+66
-0
lines changed

7 files changed

+66
-0
lines changed

gcc/jit/dummy-frontend.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ static const scoped_attribute_specs *const jit_attribute_table[] =
246246
};
247247

248248
char* jit_personality_func_name = NULL;
249+
const char* jit_lang_name = NULL;
249250
static tree personality_decl;
250251

251252
/* FIXME: This is a hack to preserve trees that we create from the
@@ -1087,6 +1088,9 @@ jit_end_diagnostic (diagnostics::text_sink &,
10871088
static bool
10881089
jit_langhook_init (void)
10891090
{
1091+
if (jit_lang_name)
1092+
lang_hooks.name = jit_lang_name;
1093+
10901094
jit_gc_root = NULL_TREE;
10911095
personality_decl = NULL_TREE;
10921096
gcc_assert (gcc::jit::active_playback_ctxt);

gcc/jit/jit-playback.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3324,6 +3324,11 @@ make_fake_args (vec <char *> *argvec,
33243324
ADD_ARG (get_path_c_file ());
33253325
ADD_ARG ("-fPIC");
33263326

3327+
// Explicitly set the .s file path since the user can customize the path of
3328+
// the fake C file via gcc_jit_context_set_filename.
3329+
ADD_ARG ("-o");
3330+
ADD_ARG (get_path_s_file ());
3331+
33273332
/* Handle int options: */
33283333
switch (get_int_option (GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL))
33293334
{
@@ -3891,6 +3896,10 @@ const char *
38913896
playback::context::
38923897
get_path_c_file () const
38933898
{
3899+
const char *filename = m_recording_ctxt->get_filename ();
3900+
if (filename)
3901+
return filename;
3902+
38943903
return m_tempdir->get_path_c_file ();
38953904
}
38963905

gcc/jit/jit-recording.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ recording::context::~context ()
638638
if (m_owns_last_error_str)
639639
if (m_last_error_str != m_first_error_str)
640640
free (m_last_error_str);
641+
642+
if (m_filename)
643+
free (m_filename);
641644
}
642645

643646
/* Add the given mememto to the list of those tracked by this
@@ -1495,6 +1498,18 @@ recording::context::new_case (recording::rvalue *min_value,
14951498
return result;
14961499
}
14971500

1501+
const char *
1502+
recording::context::get_filename ()
1503+
{
1504+
return m_filename;
1505+
}
1506+
1507+
void
1508+
recording::context::set_filename (const char *filename)
1509+
{
1510+
m_filename = xstrdup(filename);
1511+
}
1512+
14981513
/* Set the given string option for this context, or add an error if
14991514
it's not recognized.
15001515

gcc/jit/jit-recording.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ class context : public log_user
262262
rvalue *max_value,
263263
block *block);
264264

265+
const char *
266+
get_filename ();
267+
268+
void
269+
set_filename (const char *filename);
270+
265271
void
266272
set_str_option (enum gcc_jit_str_option opt,
267273
const char *value);
@@ -445,6 +451,8 @@ class context : public log_user
445451
builtins_manager *m_builtins_manager; // lazily created
446452

447453
target_info *m_target_info;
454+
455+
char *m_filename = nullptr;
448456
};
449457

450458

gcc/jit/libgccjit.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4026,6 +4026,16 @@ gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
40264026
ctxt->set_output_ident (output_ident);
40274027
}
40284028

4029+
void
4030+
gcc_jit_context_set_filename (gcc_jit_context *ctxt, const char *filename)
4031+
{
4032+
RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
4033+
RETURN_IF_FAIL (filename, ctxt, NULL, "NULL filename");
4034+
JIT_LOG_FUNC (ctxt->get_logger ());
4035+
4036+
ctxt->set_filename (filename);
4037+
}
4038+
40294039
gcc_jit_target_info *
40304040
gcc_jit_context_get_target_info (gcc_jit_context *ctxt)
40314041
{
@@ -4953,3 +4963,11 @@ gcc_jit_is_lto_supported ()
49534963

49544964
return false;
49554965
}
4966+
4967+
extern const char* jit_lang_name;
4968+
4969+
void
4970+
gcc_jit_set_lang_name (const char *lang_name)
4971+
{
4972+
jit_lang_name = lang_name;
4973+
}

gcc/jit/libgccjit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,9 @@ gcc_jit_context_set_abort_on_unsupported_target_builtin (gcc_jit_context *ctxt);
23282328

23292329
#define LIBGCCJIT_HAVE_gcc_jit_context_set_abort_on_unsupported_target_builtin
23302330

2331+
extern void
2332+
gcc_jit_context_set_filename (gcc_jit_context *ctxt, const char *filename);
2333+
23312334
/* Add an attribute to a variable. */
23322335
extern void
23332336
gcc_jit_lvalue_add_attribute (gcc_jit_lvalue *variable,
@@ -2355,6 +2358,9 @@ gcc_jit_rvalue_set_location (gcc_jit_rvalue *rvalue,
23552358
extern bool
23562359
gcc_jit_is_lto_supported ();
23572360

2361+
extern void
2362+
gcc_jit_set_lang_name (const char *lang_name);
2363+
23582364
#ifdef __cplusplus
23592365
}
23602366
#endif /* __cplusplus */

gcc/jit/libgccjit.map

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,9 @@ LIBGCCJIT_ABI_48 {
403403
global:
404404
gcc_jit_is_lto_supported;
405405
} LIBGCCJIT_ABI_47;
406+
407+
LIBGCCJIT_ABI_49 {
408+
global:
409+
gcc_jit_set_lang_name;
410+
gcc_jit_context_set_filename;
411+
} LIBGCCJIT_ABI_48;

0 commit comments

Comments
 (0)