caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] Using Frontc
@ 2005-11-20  8:44 Zhu Ping
  2005-11-20 12:37 ` Matthieu Dubuget
  0 siblings, 1 reply; 7+ messages in thread
From: Zhu Ping @ 2005-11-20  8:44 UTC (permalink / raw)
  To: Anil Madhavapeddy; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2205 bytes --]

Dear Madhavapeddy:

I used FrontC because I hope the parsing result w.r.t a C source code is represented in OCaml code.

I installed CIT and linked my main program with the library released in CIL.

My main program (main.ml) now is:

  open Frontc
  (* -------------------------------------- Test case for sample1.wh --------------------------------------*)
  let parse_result = Frontc.parse "/home/sand/zhuping/sample1.c"; 

The main program is successfully compiled without linking by executing: ocamlc -c -I /home/sand/cil/obj/x86_LINUX  main.ml

But an error occurs when I linked the related object codes together:  

ocamlc -o main -I /home/sand/cil/obj/x86_LINUX/ pretty.cmo trace.cmo errormsg.cmo cabs.cmo cabsvisit.cmo escape.cmo cprint.cmo patch.cmo frontc.cmo main.cmo

"Error while linking /home/sand/cil/obj/x86_LINUX/patch.cmo: Reference to undefined global 'Unix' "

I looked into the patch.ml code and found this piece of code where 'Unix' is referenced:
let gettime () : float = (Unix.times ()).Unix.tms_utime


Can anybody help me to solve this problem? 

Thank you very much for your help:)


----- Original Message ----- 
From: "Anil Madhavapeddy" <anil@recoil.org>
To: "Zhu Ping" <zhuping@comp.nus.edu.sg>
Cc: <caml-list@yquem.inria.fr>
Sent: Friday, November 18, 2005 5:52 PM
Subject: Re: [Caml-list] Using Frontc


> On Fri, Nov 18, 2005 at 05:22:37PM +0800, Zhu Ping wrote:
>> 
>> I'm using Frontc, which is one of the libraries released in
>> CDK, to parse C source code.
> (snip)
>> 
>> There are no source implementation/interface files with respect to
>> the corresponding files listed above.
>> 
>> Can anybody help to to solve this problem? Thank you very much for
>> your help:)
> 
> You haven't said if you must get FrontC to work, or can use any C
> parser.  If you dont mind using another package, CIL from Berkeley
> is written in OCaml and is actively developed (and very very good).
> 
> You can find more details at http://manju.cs.berkeley.edu/cil/
> 
> -- 
> Anil Madhavapeddy                                 http://anil.recoil.org
> University of Cambridge                          http://www.cl.cam.ac.uk
>

[-- Attachment #2: Type: text/html, Size: 4047 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Using Frontc
  2005-11-20  8:44 [Caml-list] Using Frontc Zhu Ping
@ 2005-11-20 12:37 ` Matthieu Dubuget
  2005-11-21  8:41   ` Zhu Ping
  0 siblings, 1 reply; 7+ messages in thread
From: Matthieu Dubuget @ 2005-11-20 12:37 UTC (permalink / raw)
  To: Zhu Ping; +Cc: Anil Madhavapeddy, caml-list


> ocamlc -o main -I /home/sand/cil/obj/x86_LINUX/ pretty.cmo trace.cmo
> errormsg.cmo cabs.cmo cabsvisit.cmo escape.cmo cprint.cmo patch.cmo
> frontc.cmo main.cmo
> "Error while linking /home/sand/cil/obj/x86_LINUX/patch.cmo: Reference
> to undefined global 'Unix' "

Try this :
ocamlc -o main -I /home/sand/cil/obj/x86_LINUX/ unix .cma pretty.cmo
trace.cmo errormsg.cmo cabs.cmo cabsvisit.cmo escape.cmo cprint.cmo
patch.cmo frontc.cmo main.cmo

Salutations

Matthieu


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Using Frontc
  2005-11-20 12:37 ` Matthieu Dubuget
@ 2005-11-21  8:41   ` Zhu Ping
  2005-11-21  9:54     ` Gerd Stolpmann
  0 siblings, 1 reply; 7+ messages in thread
From: Zhu Ping @ 2005-11-21  8:41 UTC (permalink / raw)
  To: matthieu.dubuget; +Cc: Anil Madhavapeddy, caml-list

I have successfully compiled my main program by executing the following two 
commands sequentially:
$ ocamlc -c -I /home/sand/cil/obj/x86_LINUX  main.ml
$ ocamlc -o main -custom /home/sand/cil/obj/x86_LINUX/perfcount.o 
/usr/lib/ocaml/unix.cma /usr/lib/ocaml/str.cma -I 
/home/sand/cil/obj/x86_LINUX/ pretty.cmo trace.cmo errormsg.cmo cabs.cmo 
cabsvisit.cmo escape.cmo cprint.cmo patch.cmo stats.cmo lexerhack.cmo 
machdep.cmo clexer.cmo cparser.cmo inthash.cmo util.cmo clist.cmo 
cilversion.cmo alpha.cmo cil.cmo cilutil.cmo cabs2cil.cmo frontc.cmo 
main.cmo

But you can't see anything by just typing "./main"



To print the value of "parse_result" defined in my main.ml, I first build my 
toplevel interpretator by executing:
$ ocamlmktop -o mytoplevel -custom /home/sand/cil/obj/x86_LINUX/perfcount.o 
/usr/lib/ocaml/unix.cma /usr/lib/ocaml/str.cma -I 
/home/sand/cil/obj/x86_LINUX/ pretty.cmo trace.cmo errormsg.cmo cabs.cmo 
cabsvisit.cmo escape.cmo cprint.cmo patch.cmo stats.cmo lexerhack.cmo 
machdep.cmo clexer.cmo cparser.cmo inthash.cmo util.cmo clist.cmo 
cilversion.cmo alpha.cmo cil.cmo cilutil.cmo cabs2cil.cmo frontc.cmo 
main.cmo

Then in this new toplevel the value of "parse_result" is propoerly displayed

You can refer to the book "Developing Applications With Objective Caml" 
(page 322) to know more details about building a new toplevel interpretator 
which can use an external C function in the toplevel interactive loop.


The pity now is the CIL format seems too complicated for me. I like the data 
structure defined in an earlier version of FrontC 
(http://casse.hugues.free.fr/projects/frontc.html) better:). However I still 
have problems in compiling FrontC sources downloaded from the site 
http://casse.hugues.free.fr/projects/frontc.html. Did anyone successfully 
install FrontC in Linux/Unix?



Anyway, thank you all for your help:)


----- Original Message ----- 
From: "Matthieu Dubuget" <matthieu.dubuget@laposte.net>
To: "Zhu Ping" <zhuping@comp.nus.edu.sg>
Cc: "Anil Madhavapeddy" <anil@recoil.org>; <caml-list@yquem.inria.fr>
Sent: Sunday, November 20, 2005 8:37 PM
Subject: Re: [Caml-list] Using Frontc


>
>> ocamlc -o main -I /home/sand/cil/obj/x86_LINUX/ pretty.cmo trace.cmo
>> errormsg.cmo cabs.cmo cabsvisit.cmo escape.cmo cprint.cmo patch.cmo
>> frontc.cmo main.cmo
>> "Error while linking /home/sand/cil/obj/x86_LINUX/patch.cmo: Reference
>> to undefined global 'Unix' "
>
> Try this :
> ocamlc -o main -I /home/sand/cil/obj/x86_LINUX/ unix .cma pretty.cmo
> trace.cmo errormsg.cmo cabs.cmo cabsvisit.cmo escape.cmo cprint.cmo
> patch.cmo frontc.cmo main.cmo
>
> Salutations
>
> Matthieu
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Using Frontc
  2005-11-21  8:41   ` Zhu Ping
@ 2005-11-21  9:54     ` Gerd Stolpmann
  2005-11-24  6:12       ` Zhu Ping
  0 siblings, 1 reply; 7+ messages in thread
From: Gerd Stolpmann @ 2005-11-21  9:54 UTC (permalink / raw)
  To: Zhu Ping; +Cc: matthieu.dubuget, caml-list, Anil Madhavapeddy

> The pity now is the CIL format seems too complicated for me. I like the
> data
> structure defined in an earlier version of FrontC
> (http://casse.hugues.free.fr/projects/frontc.html) better:). However I
> still
> have problems in compiling FrontC sources downloaded from the site
> http://casse.hugues.free.fr/projects/frontc.html. Did anyone successfully
> install FrontC in Linux/Unix?

FrontC is available in GODI, http://godi.ocaml-programming.de. This is
probably the simplest way to install it. Furthermore, this also simplifies
using libraries, as GODI supports findlib for all libraries, i.e. you just
say

ocamlfind ocamlc -package frontc -c your_module.ml

and get rid of the .cma nightmare.

Gerd

> ----- Original Message -----
> From: "Matthieu Dubuget" <matthieu.dubuget@laposte.net>
> To: "Zhu Ping" <zhuping@comp.nus.edu.sg>
> Cc: "Anil Madhavapeddy" <anil@recoil.org>; <caml-list@yquem.inria.fr>
> Sent: Sunday, November 20, 2005 8:37 PM
> Subject: Re: [Caml-list] Using Frontc
>
>
>>
>>> ocamlc -o main -I /home/sand/cil/obj/x86_LINUX/ pretty.cmo trace.cmo
>>> errormsg.cmo cabs.cmo cabsvisit.cmo escape.cmo cprint.cmo patch.cmo
>>> frontc.cmo main.cmo
>>> "Error while linking /home/sand/cil/obj/x86_LINUX/patch.cmo: Reference
>>> to undefined global 'Unix' "
>>
>> Try this :
>> ocamlc -o main -I /home/sand/cil/obj/x86_LINUX/ unix .cma pretty.cmo
>> trace.cmo errormsg.cmo cabs.cmo cabsvisit.cmo escape.cmo cprint.cmo
>> patch.cmo frontc.cmo main.cmo
>>
>> Salutations
>>
>> Matthieu
>>
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
>


------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
gerd@gerd-stolpmann.de          http://www.gerd-stolpmann.de
------------------------------------------------------------



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Using Frontc
  2005-11-21  9:54     ` Gerd Stolpmann
@ 2005-11-24  6:12       ` Zhu Ping
  2005-11-24 10:25         ` skaller
  0 siblings, 1 reply; 7+ messages in thread
From: Zhu Ping @ 2005-11-24  6:12 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: matthieu.dubuget, caml-list, Anil Madhavapeddy

Dear Gerd Stolpmann

Thank you very much for recommending GODI. I have successfully installed
GODI, compiled and linked my code with the FrontC library.

My main program *main.ml* is as following:
open Frontc
let parse_result = Frontc.parse_file "/home/dreamer/code/sample1.c" stdout;;

The sample C code sample1.c is:
int main(int base, int expon)
{
int accum = 1;
while (expon > 0) {
accum = base * accum;
expon = expon - 1;
}
return(accum);
}


I performed the compilation and linking by executing the following two
commands:
ocamlc -c -I /opt/godi/lib/ocaml/pkg-lib/FrontC main.ml
ocamlc -o main /opt/godi/lib/ocaml/std-lib/unix.cma -I
/opt/godi/lib/ocaml/pkg-lib/FrontC frontc.cma main.cmo

To display the parsing result explicitly I built my toplevel:
ocamlmktop -o mytoplevel /opt/godi/lib/ocaml/std-lib/unix.cma -I
/opt/godi/lib/ocaml/pkg-lib/FrontC frontc.cma
./mytoplevel
#directory "/home/dreamer/code/";;
#directory "/opt/godi/lib/ocaml/pkg-lib/FrontC/";;
#use "main.ml";;

The output is:

/home/dreamer/code/sample1.c[1] Invalid symbol: int main(int base, int
expon)
/home/dreamer/code/sample1.c[2] Invalid symbol: {
/home/dreamer/code/sample1.c[3] Invalid symbol: int accum = 1;
/home/dreamer/code/sample1.c[4] Invalid symbol: while (expon > 0) {
/home/dreamer/code/sample1.c[5] Invalid symbol: accum = base * accum;
/home/dreamer/code/sample1.c[6] Invalid symbol: expon = expon - 1;
/home/dreamer/code/sample1.c[7] Invalid symbol: }
/home/dreamer/code/sample1.c[8] Invalid symbol: return(accum);
/home/dreamer/code/sample1.c[9] Invalid symbol: }
val parse_result : Frontc.parsing_result =
PARSING_OK
[Cabs.FUNDEF
((Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
("main",
Cabs.PROTO
(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN),
[(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
("base", Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), [], Cabs.NOTHING));
(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
("expon", Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), [],
Cabs.NOTHING))],
false),
[], Cabs.NOTHING)),
([Cabs.DECDEF
(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
[("accum", Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), [],
Cabs.CONSTANT (Cabs.CONST_INT "1"))])],
Cabs.SEQUENCE
(Cabs.WHILE
(Cabs.BINARY (Cabs.GT, Cabs.VARIABLE "expon",
Cabs.CONSTANT (Cabs.CONST_INT "0")),
Cabs.BLOCK
([],
Cabs.SEQUENCE
(Cabs.COMPUTATION
(Cabs.BINARY (Cabs.ASSIGN, Cabs.VARIABLE "accum",
Cabs.BINARY (Cabs.MUL, Cabs.VARIABLE "base",
Cabs.VARIABLE "accum"))),
Cabs.COMPUTATION
(Cabs.BINARY (Cabs.ASSIGN, Cabs.VARIABLE "expon",
Cabs.BINARY (Cabs.SUB, Cabs.VARIABLE "expon",
Cabs.CONSTANT (Cabs.CONST_INT "1"))))))),
Cabs.RETURN (Cabs.VARIABLE "accum"))))]


Why the parsing result is correct in the presence of lexing errors?

Thank you very much for your help:)



Gerd Stolpmann wrote:

>>The pity now is the CIL format seems too complicated for me. I like the data structure defined in an earlier version of FrontC
>>(http://casse.hugues.free.fr/projects/frontc.html) better:). However I still have problems in compiling FrontC sources downloaded from the site
>>http://casse.hugues.free.fr/projects/frontc.html. Did anyone successfullyinstall FrontC in Linux/Unix?
>>    
>>
>FrontC is available in GODI, http://godi.ocaml-programming.de. This is probably the simplest way to install it. Furthermore, this also simplifies
>using libraries, as GODI supports findlib for all libraries, i.e. you just say
>
>ocamlfind ocamlc -package frontc -c your_module.ml
>
>and get rid of the .cma nightmare.
>
>Gerd
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Using Frontc
  2005-11-24  6:12       ` Zhu Ping
@ 2005-11-24 10:25         ` skaller
  0 siblings, 0 replies; 7+ messages in thread
From: skaller @ 2005-11-24 10:25 UTC (permalink / raw)
  To: Zhu Ping; +Cc: Gerd Stolpmann, matthieu.dubuget, caml-list, Anil Madhavapeddy

On Thu, 2005-11-24 at 14:12 +0800, Zhu Ping wrote:

> 
> /home/dreamer/code/sample1.c[1] Invalid symbol: int main(int base, int
> expon)
> /home/dreamer/code/sample1.c[2] Invalid symbol: {

Spurious CR by any chance? Only one error per line here.
Weird though, it should handle it.

Anyhow the reason it works is simple enough: the parser
is called 'initial' and here is the rule in question:
|    _        {E.parse_error
      "Invalid symbol"
     (Lexing.lexeme_start lexbuf)
    (Lexing.lexeme_end lexbuf);
   initial lexbuf}


so you can see it emits a diagnostic .. and then continues
by recursively calling itself again .. ignoring the error.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Using Frontc
  2005-11-18  9:22 Zhu Ping
@ 2005-11-18  9:52 ` Anil Madhavapeddy
  0 siblings, 0 replies; 7+ messages in thread
From: Anil Madhavapeddy @ 2005-11-18  9:52 UTC (permalink / raw)
  To: Zhu Ping; +Cc: caml-list

On Fri, Nov 18, 2005 at 05:22:37PM +0800, Zhu Ping wrote:
> 
> I'm using Frontc, which is one of the libraries released in
> CDK, to parse C source code.
(snip)
> 
> There are no source implementation/interface files with respect to
> the corresponding files listed above.
> 
> Can anybody help to to solve this problem? Thank you very much for
> your help:)

You haven't said if you must get FrontC to work, or can use any C
parser.  If you dont mind using another package, CIL from Berkeley
is written in OCaml and is actively developed (and very very good).

You can find more details at http://manju.cs.berkeley.edu/cil/

-- 
Anil Madhavapeddy                                 http://anil.recoil.org
University of Cambridge                          http://www.cl.cam.ac.uk


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-11-24 10:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-20  8:44 [Caml-list] Using Frontc Zhu Ping
2005-11-20 12:37 ` Matthieu Dubuget
2005-11-21  8:41   ` Zhu Ping
2005-11-21  9:54     ` Gerd Stolpmann
2005-11-24  6:12       ` Zhu Ping
2005-11-24 10:25         ` skaller
  -- strict thread matches above, loose matches on Subject: below --
2005-11-18  9:22 Zhu Ping
2005-11-18  9:52 ` [Caml-list] " Anil Madhavapeddy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).