Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: [Caml-list] Using Frontc
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Zhu Ping <zhuping@c...>
Subject: Re: [Caml-list] Using Frontc
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
>