@@ -516,6 +516,16 @@ const char* fn_attribute_to_string(gcc_jit_fn_attribute attr)
516516 return NULL ;
517517}
518518
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+
519529/* Construct a playback::function instance. */
520530
521531playback::function *
@@ -652,7 +662,8 @@ global_new_decl (location *loc,
652662 type *type,
653663 const char *name,
654664 enum global_var_flags flags,
655- bool readonly)
665+ bool readonly,
666+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
656667{
657668 gcc_assert (type);
658669 gcc_assert (name);
@@ -697,9 +708,27 @@ global_new_decl (location *loc,
697708 if (loc)
698709 set_tree_location (inner, loc);
699710
711+ set_variable_attribute (attributes, inner);
712+
700713 return inner;
701714}
702715
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+
703732/* In use by new_global and new_global_initialized. */
704733
705734playback::lvalue *
@@ -720,10 +749,11 @@ new_global (location *loc,
720749 type *type,
721750 const char *name,
722751 enum global_var_flags flags,
723- bool readonly)
752+ bool readonly,
753+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
724754{
725755 tree inner =
726- global_new_decl (loc, kind, type, name, flags, readonly);
756+ global_new_decl (loc, kind, type, name, flags, readonly, attributes );
727757
728758 return global_finalize_lvalue (inner);
729759}
@@ -869,9 +899,10 @@ new_global_initialized (location *loc,
869899 const void *initializer,
870900 const char *name,
871901 enum global_var_flags flags,
872- bool readonly)
902+ bool readonly,
903+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
873904{
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 );
875906
876907 vec<constructor_elt, va_gc> *constructor_elements = NULL ;
877908
@@ -2033,7 +2064,8 @@ playback::lvalue *
20332064playback::function::
20342065new_local (location *loc,
20352066 type *type,
2036- const char *name)
2067+ const char *name,
2068+ const std::vector<std::pair<gcc_jit_variable_attribute, std::string>> &attributes)
20372069{
20382070 gcc_assert (type);
20392071 gcc_assert (name);
@@ -2046,6 +2078,8 @@ new_local (location *loc,
20462078 DECL_CHAIN (inner) = BIND_EXPR_VARS (m_inner_bind_expr);
20472079 BIND_EXPR_VARS (m_inner_bind_expr) = inner;
20482080
2081+ set_variable_attribute (attributes, inner);
2082+
20492083 if (loc)
20502084 set_tree_location (inner, loc);
20512085 return new lvalue (m_ctxt, inner);
0 commit comments