@@ -420,6 +420,55 @@ def is_included(path: Optional[str]) -> bool:
420420 exit (0 )
421421
422422
423+ def cproject_cil_source (args : argparse .Namespace ) -> NoReturn :
424+ """Outputs a textual representation of the CIL AST."""
425+
426+ #arguments
427+ tgtpath : str = args .tgtpath
428+ projectname : str = args .projectname
429+ filename : str = args .filename
430+ loglevel : str = args .loglevel
431+ logfilename : Optional [str ] = args .logfilename
432+ logfilemode : str = args .logfilemode
433+
434+ targetpath = os .path .abspath (tgtpath )
435+ projectpath = targetpath
436+ cfilename_c = os .path .basename (filename )
437+ cfilename = cfilename_c [:- 2 ]
438+ cfilepath = os .path .dirname (filename )
439+
440+ set_logging (
441+ loglevel ,
442+ targetpath ,
443+ logfilename = logfilename ,
444+ mode = logfilemode ,
445+ msg = "Command cfile mk-headerfile was invoked" )
446+
447+ if not UF .has_analysisresults_path (targetpath , projectname ):
448+ print_error (
449+ f"No analysis results found for { projectname } in { targetpath } " )
450+ exit (1 )
451+
452+ contractpath = os .path .join (targetpath , "chc_contracts" )
453+ capp = CApplication (
454+ projectpath , projectname , targetpath , contractpath )
455+
456+ if capp .has_file (filename [:- 2 ]):
457+ cfile = capp .get_file (filename [:- 2 ])
458+ else :
459+ print_error (f"File { filename } not found" )
460+ exit (1 )
461+
462+ fcilsource = cfile .cil_source ()
463+
464+ outputfilename = cfile .cfilename + ".cil.c"
465+ with open (outputfilename , "w" ) as fp :
466+ fp .write (fcilsource )
467+ print ("Cil source code written to " + outputfilename )
468+
469+ exit (0 )
470+
471+
423472def cproject_analyze_project (args : argparse .Namespace ) -> NoReturn :
424473
425474 # arguments
0 commit comments