@@ -522,6 +522,16 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
522
522
return NULL ;
523
523
}
524
524
525
+ const char * variable_attribute_to_string (gcc_jit_variable_attribute attr)
526
+ {
527
+ switch (attr)
528
+ {
529
+ case GCC_JIT_VARIABLE_ATTRIBUTE_VISIBILITY:
530
+ return " visibility" ;
531
+ }
532
+ return NULL ;
533
+ }
534
+
525
535
/* Construct a playback::function instance. */
526
536
527
537
playback::function *
@@ -674,7 +684,8 @@ global_new_decl (location *loc,
674
684
type *type,
675
685
const char *name,
676
686
enum global_var_flags flags,
677
- bool readonly)
687
+ bool readonly,
688
+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
678
689
{
679
690
gcc_assert (type);
680
691
gcc_assert (name);
@@ -719,9 +730,27 @@ global_new_decl (location *loc,
719
730
if (loc)
720
731
set_tree_location (inner, loc);
721
732
733
+ set_variable_attribute (attributes, inner);
734
+
722
735
return inner;
723
736
}
724
737
738
+ void
739
+ playback::
740
+ set_variable_attribute (const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes, tree decl)
741
+ {
742
+ for (auto attr: attributes)
743
+ {
744
+ gcc_jit_variable_attribute& name = std::get<0 >(attr);
745
+ std::string& value = std::get<1 >(attr);
746
+ tree attribute_value = build_tree_list (NULL_TREE, ::build_string (value.length () + 1 , value.c_str ()));
747
+ tree ident = get_identifier (variable_attribute_to_string (name));
748
+
749
+ DECL_ATTRIBUTES (decl) =
750
+ tree_cons (ident, attribute_value, DECL_ATTRIBUTES (decl));
751
+ }
752
+ }
753
+
725
754
/* In use by new_global and new_global_initialized. */
726
755
727
756
playback::lvalue *
@@ -742,10 +771,11 @@ new_global (location *loc,
742
771
type *type,
743
772
const char *name,
744
773
enum global_var_flags flags,
745
- bool readonly)
774
+ bool readonly,
775
+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
746
776
{
747
777
tree inner =
748
- global_new_decl (loc, kind, type, name, flags, readonly);
778
+ global_new_decl (loc, kind, type, name, flags, readonly, attributes );
749
779
750
780
return global_finalize_lvalue (inner);
751
781
}
@@ -891,9 +921,10 @@ new_global_initialized (location *loc,
891
921
const void *initializer,
892
922
const char *name,
893
923
enum global_var_flags flags,
894
- bool readonly)
924
+ bool readonly,
925
+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
895
926
{
896
- tree inner = global_new_decl (loc, kind, type, name, flags, readonly);
927
+ tree inner = global_new_decl (loc, kind, type, name, flags, readonly, attributes );
897
928
898
929
vec<constructor_elt, va_gc> *constructor_elements = NULL ;
899
930
@@ -2072,7 +2103,8 @@ playback::lvalue *
2072
2103
playback::function::
2073
2104
new_local (location *loc,
2074
2105
type *type,
2075
- const char *name)
2106
+ const char *name,
2107
+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
2076
2108
{
2077
2109
gcc_assert (type);
2078
2110
gcc_assert (name);
@@ -2085,6 +2117,8 @@ new_local (location *loc,
2085
2117
DECL_CHAIN (inner) = BIND_EXPR_VARS (m_inner_bind_expr);
2086
2118
BIND_EXPR_VARS (m_inner_bind_expr) = inner;
2087
2119
2120
+ set_variable_attribute (attributes, inner);
2121
+
2088
2122
if (loc)
2089
2123
set_tree_location (inner, loc);
2090
2124
return new lvalue (m_ctxt, inner);
0 commit comments