Use external linkage for global async variables

This commit is contained in:
jeltz 2020-12-26 04:28:39 +01:00
parent 74f5e9a2e8
commit e536ec17d6
Signed by: jeltz
GPG key ID: 800882B66C0C3326
3 changed files with 17 additions and 3 deletions

View file

@ -13,12 +13,21 @@ let filter_async_objs cd =
| None -> false)
cd.cd_objs
let async_global_objs_defs cd =
let async_global_objs_vars cd =
List.map
(fun od ->
let name = async_global_var_name od in
let ty = Cty_id (qn_append od.o_class "_async") in
Cvardef (name, ty))
name, ty)
(filter_async_objs cd)
let async_global_objs_defs cd =
List.map
(fun (name, ty) -> Cvardef (name, ty))
(async_global_objs_vars cd)
let async_global_objs_decls cd =
List.map
(fun (name, ty) -> Cdecl_extern (name, ty))
(async_global_objs_vars cd)

View file

@ -143,6 +143,7 @@ type cdecl =
(** C function declaration. *)
| Cdecl_constant of string * cty * cexpr
(** C constant declaration (alias, name)*)
| Cdecl_extern of string * cty
(** C function definitions *)
type cfundef = {
@ -353,6 +354,9 @@ let pp_cdecl fmt cdecl = match cdecl with
| Cdecl_constant (n, cty, ce) ->
fprintf fmt "@[<v>static const %a = %a;@ @]@\n"
pp_vardecl (n, cty) pp_cconst_expr ce
| Cdecl_extern (n, cty) ->
fprintf fmt "@[<v>extern %a;@ @]@\n"
pp_vardecl (n, cty)
let pp_cdef fmt cdef = match cdef with
| Cfundef cfd ->

View file

@ -947,6 +947,7 @@ let cdefs_and_cdecls_of_class_def cd =
let out_struct_decl = out_decl_of_class_def cd in
let async_struct_decl = async_decl_of_class_def cd in
let objs = async_global_objs_defs cd in
let objs_decls = async_global_objs_decls cd in
let step = fun_def_of_step_fun cd.cd_name cd.cd_objs cd.cd_mems
cd.cd_objs step_m in
(* TODO(Arduino): let the user choose the backend they want *)
@ -973,7 +974,7 @@ let cdefs_and_cdecls_of_class_def cd =
let decls = List.map cdecl_of_cfundef defs in
memory_struct_decl @ in_struct_decl @ out_struct_decl @ async_struct_decl
@ decls, objs @ defs
@ objs_decls @ decls, objs @ defs
(** {2 Type translation} *)