Skip to content

Commit 0137524

Browse files
committed
Add gcc_jit_global_set_readonly
1 parent f1b57c7 commit 0137524

File tree

7 files changed

+51
-11
lines changed

7 files changed

+51
-11
lines changed

gcc/jit/jit-playback.cc

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,8 @@ global_new_decl (location *loc,
615615
enum gcc_jit_global_kind kind,
616616
type *type,
617617
const char *name,
618-
enum global_var_flags flags)
618+
enum global_var_flags flags,
619+
bool readonly)
619620
{
620621
gcc_assert (type);
621622
gcc_assert (name);
@@ -654,7 +655,7 @@ global_new_decl (location *loc,
654655
break;
655656
}
656657

657-
if (TYPE_READONLY (type_tree))
658+
if (TYPE_READONLY (type_tree) || readonly)
658659
TREE_READONLY (inner) = 1;
659660

660661
if (loc)
@@ -682,10 +683,11 @@ new_global (location *loc,
682683
enum gcc_jit_global_kind kind,
683684
type *type,
684685
const char *name,
685-
enum global_var_flags flags)
686+
enum global_var_flags flags,
687+
bool readonly)
686688
{
687689
tree inner =
688-
global_new_decl (loc, kind, type, name, flags);
690+
global_new_decl (loc, kind, type, name, flags, readonly);
689691

690692
return global_finalize_lvalue (inner);
691693
}
@@ -830,9 +832,10 @@ new_global_initialized (location *loc,
830832
size_t initializer_num_elem,
831833
const void *initializer,
832834
const char *name,
833-
enum global_var_flags flags)
835+
enum global_var_flags flags,
836+
bool readonly)
834837
{
835-
tree inner = global_new_decl (loc, kind, type, name, flags);
838+
tree inner = global_new_decl (loc, kind, type, name, flags, readonly);
836839

837840
vec<constructor_elt, va_gc> *constructor_elements = NULL;
838841

gcc/jit/jit-playback.h

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

117118
lvalue *
118119
new_global_initialized (location *loc,
@@ -122,7 +123,8 @@ class context : public log_user
122123
size_t initializer_num_elem,
123124
const void *initializer,
124125
const char *name,
125-
enum global_var_flags flags);
126+
enum global_var_flags flags,
127+
bool readonly);
126128

127129
rvalue *
128130
new_ctor (location *log,
@@ -312,7 +314,8 @@ class context : public log_user
312314
enum gcc_jit_global_kind kind,
313315
type *type,
314316
const char *name,
315-
enum global_var_flags flags);
317+
enum global_var_flags flags,
318+
bool readonly);
316319
lvalue *
317320
global_finalize_lvalue (tree inner);
318321

gcc/jit/jit-recording.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4857,12 +4857,14 @@ recording::global::replay_into (replayer *r)
48574857
/ m_type->dereference ()->get_size (),
48584858
m_initializer,
48594859
playback_string (m_name),
4860-
m_flags)
4860+
m_flags,
4861+
m_readonly)
48614862
: r->new_global (playback_location (r, m_loc),
48624863
m_kind,
48634864
m_type->playback_type (),
48644865
playback_string (m_name),
4865-
m_flags);
4866+
m_flags,
4867+
m_readonly);
48664868

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

gcc/jit/jit-recording.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,12 @@ class lvalue : public rvalue
12131213
as_rvalue () { return this; }
12141214

12151215
const char *access_as_rvalue (reproducer &r) override;
1216+
1217+
void set_readonly ()
1218+
{
1219+
m_readonly = true;
1220+
}
1221+
12161222
virtual const char *access_as_lvalue (reproducer &r);
12171223
virtual bool is_global () const { return false; }
12181224
void set_tls_model (enum gcc_jit_tls_model model);
@@ -1226,6 +1232,7 @@ class lvalue : public rvalue
12261232
string *m_reg_name;
12271233
enum gcc_jit_tls_model m_tls_model;
12281234
unsigned m_alignment;
1235+
bool m_readonly = false;
12291236
};
12301237

12311238
class param : public lvalue

gcc/jit/libgccjit.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,6 +1868,23 @@ gcc_jit_global_set_initializer (gcc_jit_lvalue *global,
18681868
return global;
18691869
}
18701870

1871+
/* Public entrypoint. See description in libgccjit.h.
1872+
1873+
After error-checking, the real work is done by the
1874+
gcc::jit::recording::global::set_readonly method, in
1875+
jit-recording.cc. */
1876+
1877+
extern void
1878+
gcc_jit_global_set_readonly (gcc_jit_lvalue *global)
1879+
{
1880+
RETURN_IF_FAIL (global, NULL, NULL, "NULL global");
1881+
RETURN_IF_FAIL_PRINTF1 (global->is_global (), NULL, NULL,
1882+
"lvalue \"%s\" not a global",
1883+
global->get_debug_string ());
1884+
1885+
global->set_readonly ();
1886+
}
1887+
18711888
/* Public entrypoint. See description in libgccjit.h.
18721889
18731890
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
@@ -1036,6 +1036,9 @@ gcc_jit_global_set_initializer (gcc_jit_lvalue *global,
10361036
const void *blob,
10371037
size_t num_bytes);
10381038

1039+
extern void
1040+
gcc_jit_global_set_readonly (gcc_jit_lvalue *global);
1041+
10391042
/* Upcasting. */
10401043
extern gcc_jit_object *
10411044
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
@@ -286,3 +286,8 @@ LIBGCCJIT_ABI_27 {
286286
global:
287287
gcc_jit_context_convert_vector;
288288
} LIBGCCJIT_ABI_26;
289+
290+
LIBGCCJIT_ABI_28 {
291+
global:
292+
gcc_jit_global_set_readonly;
293+
} LIBGCCJIT_ABI_27;

0 commit comments

Comments
 (0)