Skip to content
Snippets Groups Projects
Commit 75945fff authored by Basile Desloges's avatar Basile Desloges
Browse files

[eacsl] Update code printer to support `__fc_vla_alloc()` and `__fc_vla_free()`

parent b07b339c
No related branches found
No related tags found
No related merge requests found
...@@ -205,13 +205,43 @@ let change_printer = ...@@ -205,13 +205,43 @@ let change_printer =
let module Printer_class(X: Printer.PrinterClass) = struct let module Printer_class(X: Printer.PrinterClass) = struct
class printer = object class printer = object
inherit X.printer as super inherit X.printer as super
method !varinfo fmt vi = method !varinfo fmt vi =
if vi.Cil_types.vghost || vi.Cil_types.vstorage <> Cil_types.Extern if Functions.Libc.is_vla_alloc_name vi.Cil_types.vname then
then (* Replace VLA allocation with calls to [__builtin_alloca] *)
super#varinfo fmt vi Format.fprintf fmt "%s" Functions.Libc.actual_alloca
else else if (not vi.vghost) && vi.vstorage == Cil_types.Extern then
(* Replace calls to Frama-C builtins with calls to their original
version from the libc *)
let s = Str.replace_first r "" vi.Cil_types.vname in let s = Str.replace_first r "" vi.Cil_types.vname in
Format.fprintf fmt "%s" s Format.fprintf fmt "%s" s
else
(* Otherwise use the original printer *)
super#varinfo fmt vi
method !instr fmt i =
match i with
| Call(_, fct, _, _) when Functions.Libc.is_vla_free fct ->
(* Nothing to print: VLA deallocation is done automatically when
leaving the scope *)
Format.fprintf fmt "/* ";
super#instr fmt i;
Format.fprintf fmt " */"
| _ ->
super#instr fmt i
method !global fmt g =
let is_vla_builtin vi =
Functions.Libc.is_vla_alloc_name vi.Cil_types.vname ||
Functions.Libc.is_vla_free_name vi.Cil_types.vname
in
match g with
| GFunDecl (_, vi, _) when is_vla_builtin vi ->
(* Nothing to print: the VLA builtins don't have an original libc
version. *)
()
| _ ->
super#global fmt g
end end
end in end in
Printer.update_printer (module Printer_class: Printer.PrinterExtension) Printer.update_printer (module Printer_class: Printer.PrinterExtension)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment