Skip to content

Commit

Permalink
Move internal testing stuff from c-to-c example into utils/internal
Browse files Browse the repository at this point in the history
  • Loading branch information
eliben committed Apr 15, 2020
1 parent d97ca61 commit 7b893b8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 31 deletions.
32 changes: 1 addition & 31 deletions examples/c-to-c.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@

# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
#
sys.path.extend(['.', '..'])

from pycparser import parse_file, c_parser, c_generator
from pycparser import parse_file, c_generator


def translate_to_c(filename):
Expand All @@ -26,36 +25,7 @@ def translate_to_c(filename):
print(generator.visit(ast))


def _zz_test_translate():
# internal use
src = r'''
void f(char * restrict joe){}
int main(void)
{
unsigned int long k = 4;
int p = - - k;
return 0;
}
'''
parser = c_parser.CParser()
ast = parser.parse(src)
ast.show()
generator = c_generator.CGenerator()

print(generator.visit(ast))

# tracing the generator for debugging
#~ import trace
#~ tr = trace.Trace(countcallers=1)
#~ tr.runfunc(generator.visit, ast)
#~ tr.results().write_results()


#------------------------------------------------------------------------------
if __name__ == "__main__":
#_zz_test_translate()
if len(sys.argv) > 1:
translate_to_c(sys.argv[1])
else:
Expand Down
27 changes: 27 additions & 0 deletions utils/internal/zz-ctoc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import print_function
from pycparser import parse_file, c_parser, c_generator

if __name__ == '__main__':
src = r'''
void f(char * restrict joe){}
int main(void)
{
unsigned int long k = 4;
int p = - - k;
return 0;
}
'''
parser = c_parser.CParser()
ast = parser.parse(src)
ast.show()
generator = c_generator.CGenerator()

print(generator.visit(ast))

# tracing the generator for debugging
#~ import trace
#~ tr = trace.Trace(countcallers=1)
#~ tr.runfunc(generator.visit, ast)
#~ tr.results().write_results()

0 comments on commit 7b893b8

Please sign in to comment.