-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathjoern_parse
executable file
·46 lines (36 loc) · 1.54 KB
/
joern_parse
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python2
import argparse
import sourceutils.codeTree.create as codeTreeCreate
import sourceutils.csvASTs.create as csvASTCreate
import sourceutils.pythonASTs.create as pythonASTCreate
import sourceutils.pythonCFGs.create as pythonCFGCreate
class CLI():
def __init__(self):
self.initializeOptParser()
self.parseCommandLine()
def initializeOptParser(self):
self.argParser = argparse.ArgumentParser(description = "Parses source code and creates abstract syntax trees for all source files and control flow graphs for all functions.")
self.argParser.add_argument("sourcedir", help="directory containing the source code to parse")
self.argParser.add_argument("--output-dir", help="output directory")
def parseCommandLine(self):
self.args = self.argParser.parse_args()
def codeDirToOutputDir(self, codeDir):
outputDir = codeDir
if codeDir[-1] == '/':
outputDir = outputDir[:-1]
outputDir = '.' + outputDir.split('/')[-1]
return outputDir
def run(self):
codeDir = self.args.sourcedir
if self.args.output_dir != None:
outputDir = self.args.output_dir
else:
outputDir = self.codeDirToOutputDir(codeDir)
print 'Parsing code in: %s' % (codeDir)
codeTreeCreate.main(codeDir)
csvASTCreate.main(outputDir)
pythonASTCreate.main(outputDir)
pythonCFGCreate.main(outputDir)
if __name__ == '__main__':
cli = CLI()
cli.run()