Skip to content

Commit 6c00b2a

Browse files
committed
Add gcc_jit_global_set_readonly
1 parent c87e106 commit 6c00b2a

File tree

7 files changed

+50
-11
lines changed

7 files changed

+50
-11
lines changed

gcc/jit/jit-playback.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,8 @@ global_new_decl (location *loc,
622622
enum gcc_jit_global_kind kind,
623623
type *type,
624624
const char *name,
625-
enum global_var_flags flags)
625+
enum global_var_flags flags,
626+
bool readonly)
626627
{
627628
gcc_assert (type);
628629
gcc_assert (name);
@@ -661,7 +662,7 @@ global_new_decl (location *loc,
661662
break;
662663
}
663664

664-
if (TYPE_READONLY (type_tree))
665+
if (TYPE_READONLY (type_tree) || readonly)
665666
TREE_READONLY (inner) = 1;
666667

667668
if (loc)
@@ -689,10 +690,11 @@ new_global (location *loc,
689690
enum gcc_jit_global_kind kind,
690691
type *type,
691692
const char *name,
692-
enum global_var_flags flags)
693+
enum global_var_flags flags,
694+
bool readonly)
693695
{
694696
tree inner =
695-
global_new_decl (loc, kind, type, name, flags);
697+
global_new_decl (loc, kind, type, name, flags, readonly);
696698

697699
return global_finalize_lvalue (inner);
698700
}
@@ -837,9 +839,10 @@ new_global_initialized (location *loc,
837839
size_t initializer_num_elem,
838840
const void *initializer,
839841
const char *name,
840-
enum global_var_flags flags)
842+
enum global_var_flags flags,
843+
bool readonly)
841844
{
842-
tree inner = global_new_decl (loc, kind, type, name, flags);
845+
tree inner = global_new_decl (loc, kind, type, name, flags, readonly);
843846

844847
vec<constructor_elt, va_gc> *constructor_elements = NULL;
845848

gcc/jit/jit-playback.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ class context : public log_user
113113
enum gcc_jit_global_kind kind,
114114
type *type,
115115
const char *name,
116-
enum global_var_flags flags);
116+
enum global_var_flags flags,
117+
bool readonly);
117118

118119
lvalue *
119120
new_global_initialized (location *loc,
@@ -123,7 +124,8 @@ class context : public log_user
123124
size_t initializer_num_elem,
124125
const void *initializer,
125126
const char *name,
126-
enum global_var_flags flags);
127+
enum global_var_flags flags,
128+
bool readonly);
127129

128130
rvalue *
129131
new_ctor (location *log,
@@ -325,7 +327,8 @@ class context : public log_user
325327
enum gcc_jit_global_kind kind,
326328
type *type,
327329
const char *name,
328-
enum global_var_flags flags);
330+
enum global_var_flags flags,
331+
bool readonly);
329332
lvalue *
330333
global_finalize_lvalue (tree inner);
331334

gcc/jit/jit-recording.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4955,12 +4955,14 @@ recording::global::replay_into (replayer *r)
49554955
/ m_type->dereference ()->get_size (),
49564956
m_initializer,
49574957
playback_string (m_name),
4958-
m_flags)
4958+
m_flags,
4959+
m_readonly)
49594960
: r->new_global (playback_location (r, m_loc),
49604961
m_kind,
49614962
m_type->playback_type (),
49624963
playback_string (m_name),
4963-
m_flags);
4964+
m_flags,
4965+
m_readonly);
49644966

49654967
if (m_tls_model != GCC_JIT_TLS_MODEL_NONE)
49664968
global->set_tls_model (recording::tls_models[m_tls_model]);

gcc/jit/jit-recording.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1303,6 +1303,11 @@ class lvalue : public rvalue
13031303
rvalue *
13041304
as_rvalue () { return this; }
13051305

1306+
void set_readonly ()
1307+
{
1308+
m_readonly = true;
1309+
}
1310+
13061311
const char *access_as_rvalue (reproducer &r) OVERRIDE;
13071312
virtual const char *access_as_lvalue (reproducer &r);
13081313
virtual bool is_global () const { return false; }
@@ -1317,6 +1322,7 @@ class lvalue : public rvalue
13171322
string *m_reg_name;
13181323
enum gcc_jit_tls_model m_tls_model;
13191324
unsigned m_alignment;
1325+
bool m_readonly = false;
13201326
};
13211327

13221328
class param : public lvalue

gcc/jit/libgccjit.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,6 +1898,23 @@ gcc_jit_global_set_initializer (gcc_jit_lvalue *global,
18981898
return global;
18991899
}
19001900

1901+
/* Public entrypoint. See description in libgccjit.h.
1902+
1903+
After error-checking, the real work is done by the
1904+
gcc::jit::recording::global::set_readonly method, in
1905+
jit-recording.cc. */
1906+
1907+
extern void
1908+
gcc_jit_global_set_readonly (gcc_jit_lvalue *global)
1909+
{
1910+
RETURN_IF_FAIL (global, NULL, NULL, "NULL global");
1911+
RETURN_IF_FAIL_PRINTF1 (global->is_global (), NULL, NULL,
1912+
"lvalue \"%s\" not a global",
1913+
global->get_debug_string ());
1914+
1915+
global->set_readonly ();
1916+
}
1917+
19011918
/* Public entrypoint. See description in libgccjit.h.
19021919
19031920
After error-checking, this calls the trivial

gcc/jit/libgccjit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,9 @@ gcc_jit_global_set_initializer (gcc_jit_lvalue *global,
10441044
const void *blob,
10451045
size_t num_bytes);
10461046

1047+
extern void
1048+
gcc_jit_global_set_readonly (gcc_jit_lvalue *global);
1049+
10471050
/* Upcasting. */
10481051
extern gcc_jit_object *
10491052
gcc_jit_lvalue_as_object (gcc_jit_lvalue *lvalue);

gcc/jit/libgccjit.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,8 @@ LIBGCCJIT_ABI_28 {
293293
global:
294294
gcc_jit_context_convert_vector;
295295
} LIBGCCJIT_ABI_27;
296+
297+
LIBGCCJIT_ABI_29 {
298+
global:
299+
gcc_jit_global_set_readonly;
300+
} LIBGCCJIT_ABI_28;

0 commit comments

Comments
 (0)