3

I just started developing a frama-c plugin that is doing some kind of alias analysis. I'm using the Dataflow.Backwards analysis and now I have to go through the different assignment statements and collect some stuff about the lvalues.

Does frama-c provide me with 3-address code? Do I have some guarantees about the shape of the lvalue (or any memory access)? I mean, sth like in soot or wala that there is at most one field access, s.t., for a->b->c, there would be a temp variable like tmp=a->b; tmp->c;? I checked the manuals, but I couldn't find anything related to this.

Martin Schäf
  • 365
  • 1
  • 12

2 Answers2

2

No, there is no such normalization in Frama-C. If you really need it, you can first use a visitor in order to normalize the code so that it suits the requirements of your plug-in. It'd go like that:

class normalize prj: Visitor.frama_c_visitor =
object
  inherit Visitor.frama_c_copy prj

  method vinstr i =
    match i with
      | Set (lv,e) -> ...
      ....
end

let analyze () = ...

let run () =
  let my_prj = File.create_project_from_visitor "my_project" (fun prj -> new normalize prj) in
  Project.on my_prj analyze ()
Virgile
  • 9,724
  • 18
  • 42
  • Too bad. Didn't CIL provide at least some simplification back then? Looking at your sample code, the run() method is not writing stuff back, right? is there a way to write a plugin that actually transforms the code (like this cfg simplification plugin you have)? – Martin Schäf Mar 22 '13 at 17:53
  • The command File.create_project_from_visitor creates a new AST with the modifications that you perform in the class normalize. The original AST is left untouched. In Frama-C, mutating an AST is strongly discouraged. – byako Mar 22 '13 at 20:43
1

The following module from Cil does probably what you want: http://www.cs.berkeley.edu/~necula/cil/ext.html#toc26. Be aware that the type of the resulting AST is the standard Cil one. You won't be getting any help from the OCaml compiler as to which constructs can be present in the simplified AST, and which ones cannot.

Note also that this module has not been ported to Frama-C so far. You will need some minor adaptation to make it work within Frama-C.

byako
  • 3,372
  • 2
  • 21
  • 36