@@ -522,6 +522,16 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
522522 return NULL ;
523523}
524524
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+
525535/* Construct a playback::function instance. */
526536
527537playback::function *
@@ -674,7 +684,8 @@ global_new_decl (location *loc,
674684 type *type,
675685 const char *name,
676686 enum global_var_flags flags,
677- bool readonly)
687+ bool readonly,
688+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
678689{
679690 gcc_assert (type);
680691 gcc_assert (name);
@@ -719,9 +730,27 @@ global_new_decl (location *loc,
719730 if (loc)
720731 set_tree_location (inner, loc);
721732
733+ set_variable_attribute (attributes, inner);
734+
722735 return inner;
723736}
724737
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+
725754/* In use by new_global and new_global_initialized. */
726755
727756playback::lvalue *
@@ -742,10 +771,11 @@ new_global (location *loc,
742771 type *type,
743772 const char *name,
744773 enum global_var_flags flags,
745- bool readonly)
774+ bool readonly,
775+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
746776{
747777 tree inner =
748- global_new_decl (loc, kind, type, name, flags, readonly);
778+ global_new_decl (loc, kind, type, name, flags, readonly, attributes );
749779
750780 return global_finalize_lvalue (inner);
751781}
@@ -891,9 +921,10 @@ new_global_initialized (location *loc,
891921 const void *initializer,
892922 const char *name,
893923 enum global_var_flags flags,
894- bool readonly)
924+ bool readonly,
925+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
895926{
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 );
897928
898929 vec<constructor_elt, va_gc> *constructor_elements = NULL ;
899930
@@ -2072,7 +2103,8 @@ playback::lvalue *
20722103playback::function::
20732104new_local (location *loc,
20742105 type *type,
2075- const char *name)
2106+ const char *name,
2107+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
20762108{
20772109 gcc_assert (type);
20782110 gcc_assert (name);
@@ -2085,6 +2117,8 @@ new_local (location *loc,
20852117 DECL_CHAIN (inner) = BIND_EXPR_VARS (m_inner_bind_expr);
20862118 BIND_EXPR_VARS (m_inner_bind_expr) = inner;
20872119
2120+ set_variable_attribute (attributes, inner);
2121+
20882122 if (loc)
20892123 set_tree_location (inner, loc);
20902124 return new lvalue (m_ctxt, inner);
0 commit comments