@@ -516,6 +516,16 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
516
516
return NULL ;
517
517
}
518
518
519
+ const char * variable_attribute_to_string (gcc_jit_variable_attribute attr)
520
+ {
521
+ switch (attr)
522
+ {
523
+ case GCC_JIT_VARIABLE_ATTRIBUTE_VISIBILITY:
524
+ return " visibility" ;
525
+ }
526
+ return NULL ;
527
+ }
528
+
519
529
/* Construct a playback::function instance. */
520
530
521
531
playback::function *
@@ -652,7 +662,8 @@ global_new_decl (location *loc,
652
662
type *type,
653
663
const char *name,
654
664
enum global_var_flags flags,
655
- bool readonly)
665
+ bool readonly,
666
+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
656
667
{
657
668
gcc_assert (type);
658
669
gcc_assert (name);
@@ -697,9 +708,27 @@ global_new_decl (location *loc,
697
708
if (loc)
698
709
set_tree_location (inner, loc);
699
710
711
+ set_variable_attribute (attributes, inner);
712
+
700
713
return inner;
701
714
}
702
715
716
+ void
717
+ playback::
718
+ set_variable_attribute (const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes, tree decl)
719
+ {
720
+ for (auto attr: attributes)
721
+ {
722
+ gcc_jit_variable_attribute& name = std::get<0 >(attr);
723
+ std::string& value = std::get<1 >(attr);
724
+ tree attribute_value = build_tree_list (NULL_TREE, ::build_string (value.length () + 1 , value.c_str ()));
725
+ tree ident = get_identifier (variable_attribute_to_string (name));
726
+
727
+ DECL_ATTRIBUTES (decl) =
728
+ tree_cons (ident, attribute_value, DECL_ATTRIBUTES (decl));
729
+ }
730
+ }
731
+
703
732
/* In use by new_global and new_global_initialized. */
704
733
705
734
playback::lvalue *
@@ -720,10 +749,11 @@ new_global (location *loc,
720
749
type *type,
721
750
const char *name,
722
751
enum global_var_flags flags,
723
- bool readonly)
752
+ bool readonly,
753
+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
724
754
{
725
755
tree inner =
726
- global_new_decl (loc, kind, type, name, flags, readonly);
756
+ global_new_decl (loc, kind, type, name, flags, readonly, attributes );
727
757
728
758
return global_finalize_lvalue (inner);
729
759
}
@@ -869,9 +899,10 @@ new_global_initialized (location *loc,
869
899
const void *initializer,
870
900
const char *name,
871
901
enum global_var_flags flags,
872
- bool readonly)
902
+ bool readonly,
903
+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
873
904
{
874
- tree inner = global_new_decl (loc, kind, type, name, flags, readonly);
905
+ tree inner = global_new_decl (loc, kind, type, name, flags, readonly, attributes );
875
906
876
907
vec<constructor_elt, va_gc> *constructor_elements = NULL ;
877
908
@@ -2033,7 +2064,8 @@ playback::lvalue *
2033
2064
playback::function::
2034
2065
new_local (location *loc,
2035
2066
type *type,
2036
- const char *name)
2067
+ const char *name,
2068
+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
2037
2069
{
2038
2070
gcc_assert (type);
2039
2071
gcc_assert (name);
@@ -2046,6 +2078,8 @@ new_local (location *loc,
2046
2078
DECL_CHAIN (inner) = BIND_EXPR_VARS (m_inner_bind_expr);
2047
2079
BIND_EXPR_VARS (m_inner_bind_expr) = inner;
2048
2080
2081
+ set_variable_attribute (attributes, inner);
2082
+
2049
2083
if (loc)
2050
2084
set_tree_location (inner, loc);
2051
2085
return new lvalue (m_ctxt, inner);
0 commit comments