1

I'm using CIL to process C programs using the pthread library. I have to process user-defined and non-pthread functions differently from pthread functions. Can I have a type definition which looks something like:

type PThreadFun = "pthread_create" | "pthread_join" | ...;;

so that I first pattern-match on the function name and then send it to either

processFunction (fn_name: string)

or

processPThreadFun (fn_name: PThreadFun)
svick
  • 236,525
  • 50
  • 385
  • 514
user34812
  • 513
  • 1
  • 4
  • 15

1 Answers1

4

You can have sum types in OCaml, they are called variants. But their values are not strings. You could declare

type pthreadfun_t = Pthread_create | Pthread_join (* etc *);

Then you'll need some code processing the CIL representation to find such pthreadfun_t values.

BTW, you might be interested by MELT, which is a domain specific language to extend the GCC compiler. MELT works on the internal GCC representations, notably Gimple. It is not Ocaml or CIL based, but it is a GCC plugin giving you a powerful Lisp-like domain specific language with powerful pattern-matching, including ability to match Gimple-s, Tree-s, strings, etc...

nlucaroni
  • 47,556
  • 6
  • 64
  • 86
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547