I have written the following program using pycparser and pycparserext:
from pycparser import parse_file,c_parser, c_ast, c_generator
from pycparserext.ext_c_parser import GnuCParser
content="int main() { int x = 1; int y = 0; while (y < 1000 && __VERIFIER_nondet_int()) { x = x + y; y = y + 1; } __VERIFIER_assert(x >= y); return 0;}"
text = r""" """+content
parser = GnuCParser()
ast = parser.parse(text)
generator = c_generator.CGenerator()
print str(generator.visit(ast))
When I run the code in Mac it returns the correct output. But when I run the same code in Ubuntu 16.04.3 it returns the following incorrect output (that is missing the 'main()':
int{
int x = 1;
int y = 0;
while ((y < 1000) && __VERIFIER_nondet_int())
{
x = x + y;
y = y + 1;
}
__VERIFIER_assert(x >= y);
return 0;
}
What is causing this incorrect output?
This is probably an issue with pycparserext
. Using vanilla pycparser cloned fresh from Github, I get (running from the main pycparser directory):
$ cat /tmp/2.c
int main() { int x = 1; int y = 0; while (y < 1000 && __VERIFIER_nondet_int()) { x = x + y; y = y + 1; } __VERIFIER_assert(x >= y); return 0;}
$ PYTHONPATH=. python examples/c-to-c.py /tmp/2.c
int main()
{
int x = 1;
int y = 0;
while ((y < 1000) && __VERIFIER_nondet_int())
{
x = x + y;
y = y + 1;
}
__VERIFIER_assert(x >= y);
return 0;
}
So I suggest you open an issue for pycparserext