Skip to content

Commit 586d798

Browse files
committed
libgccjit: Add a way to set the language name and the context filename
1 parent 91e90fb commit 586d798

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
@@ -1086,6 +1087,9 @@ jit_end_diagnostic (diagnostics::text_sink &,
10861087
static bool
10871088
jit_langhook_init (void)
10881089
{
1090+
if (jit_lang_name)
1091+
lang_hooks.name = jit_lang_name;
1092+
10891093
jit_gc_root = NULL_TREE;
10901094
personality_decl = NULL_TREE;
10911095
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
@@ -3319,6 +3319,11 @@ make_fake_args (vec <char *> *argvec,
33193319
ADD_ARG (get_path_c_file ());
33203320
ADD_ARG ("-fPIC");
33213321

3322+
// Explicitly set the .s file path since the user can customize the path of
3323+
// the fake C file via gcc_jit_context_set_filename.
3324+
ADD_ARG ("-o");
3325+
ADD_ARG (get_path_s_file ());
3326+
33223327
/* Handle int options: */
33233328
switch (get_int_option (GCC_JIT_INT_OPTION_OPTIMIZATION_LEVEL))
33243329
{
@@ -3886,6 +3891,10 @@ const char *
38863891
playback::context::
38873892
get_path_c_file () const
38883893
{
3894+
const char *filename = m_recording_ctxt->get_filename ();
3895+
if (filename)
3896+
return filename;
3897+
38893898
return m_tempdir->get_path_c_file ();
38903899
}
38913900

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);
@@ -437,6 +443,8 @@ class context : public log_user
437443
builtins_manager *m_builtins_manager; // lazily created
438444

439445
target_info *m_target_info;
446+
447+
char *m_filename = nullptr;
440448
};
441449

442450

gcc/jit/libgccjit.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4016,6 +4016,16 @@ gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
40164016
ctxt->set_output_ident (output_ident);
40174017
}
40184018

4019+
void
4020+
gcc_jit_context_set_filename (gcc_jit_context *ctxt, const char *filename)
4021+
{
4022+
RETURN_IF_FAIL (ctxt, NULL, NULL, "NULL context");
4023+
RETURN_IF_FAIL (filename, ctxt, NULL, "NULL filename");
4024+
JIT_LOG_FUNC (ctxt->get_logger ());
4025+
4026+
ctxt->set_filename (filename);
4027+
}
4028+
40194029
gcc_jit_target_info *
40204030
gcc_jit_context_get_target_info (gcc_jit_context *ctxt)
40214031
{
@@ -4935,3 +4945,11 @@ gcc_jit_is_lto_supported ()
49354945

49364946
return false;
49374947
}
4948+
4949+
extern const char* jit_lang_name;
4950+
4951+
void
4952+
gcc_jit_set_lang_name (const char *lang_name)
4953+
{
4954+
jit_lang_name = lang_name;
4955+
}

gcc/jit/libgccjit.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,9 @@ gcc_jit_context_set_output_ident (gcc_jit_context *ctxt,
23082308

23092309
#define LIBGCCJIT_HAVE_gcc_jit_context_set_output_ident
23102310

2311+
extern void
2312+
gcc_jit_context_set_filename (gcc_jit_context *ctxt, const char *filename);
2313+
23112314
/* Add an attribute to a variable. */
23122315
extern void
23132316
gcc_jit_lvalue_add_attribute (gcc_jit_lvalue *variable,
@@ -2335,6 +2338,9 @@ gcc_jit_rvalue_set_location (gcc_jit_rvalue *rvalue,
23352338
extern bool
23362339
gcc_jit_is_lto_supported ();
23372340

2341+
extern void
2342+
gcc_jit_set_lang_name (const char *lang_name);
2343+
23382344
#ifdef __cplusplus
23392345
}
23402346
#endif /* __cplusplus */

gcc/jit/libgccjit.map

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,3 +393,9 @@ LIBGCCJIT_ABI_46 {
393393
global:
394394
gcc_jit_is_lto_supported;
395395
} LIBGCCJIT_ABI_45;
396+
397+
LIBGCCJIT_ABI_47 {
398+
global:
399+
gcc_jit_set_lang_name;
400+
gcc_jit_context_set_filename;
401+
} LIBGCCJIT_ABI_46;

0 commit comments

Comments
 (0)