Ejemplo n.º 1
0
    def __init__(
        self,
        cgDoc,
        implementationsByTemplateName,
        outputStream=sys.stdout,
        moduleNodesByName=None,
        parallelRegionData=None,
        symbolAnalysisByRoutineNameAndSymbolName=None,
        symbolsByModuleNameAndSymbolName=None,
        symbolsByRoutineNameAndSymbolName=None
    ):
        super(H90toF90Converter, self).__init__(
            cgDoc,
            moduleNodesByName=moduleNodesByName,
            parallelRegionData=parallelRegionData,
            implementationsByTemplateName=implementationsByTemplateName
        )
        self.outputStream = outputStream
        self.currSubroutineImplementationNeedsToBeCommented = False
        self.currParallelIterators = []
        self.currRoutine = None
        self.currRegion = None
        self.currParallelRegion = None
        self.currModule = None
        self.currCallee = None
        self.codeSanitizer = FortranCodeSanitizer()
        self.currParallelRegionRelationNode = None
        self.currParallelRegionTemplateNode = None
        self.prepareLineCalledForCurrentLine = False
        self.preparedBy = None
        try:
            if symbolAnalysisByRoutineNameAndSymbolName != None:
                self.symbolAnalysisByRoutineNameAndSymbolName = symbolAnalysisByRoutineNameAndSymbolName
            else:
                symbolAnalyzer = SymbolDependencyAnalyzer(self.cgDoc)
                self.symbolAnalysisByRoutineNameAndSymbolName = symbolAnalyzer.getSymbolAnalysisByRoutine()
            if symbolsByModuleNameAndSymbolName != None:
                self.symbolsByModuleNameAndSymbolName = symbolsByModuleNameAndSymbolName
            else:
                self.symbolsByModuleNameAndSymbolName = getSymbolsByModuleNameAndSymbolName(self.cgDoc, self.moduleNodesByName, self.symbolAnalysisByRoutineNameAndSymbolName)

            if symbolsByRoutineNameAndSymbolName != None:
                self.symbolsByRoutineNameAndSymbolName = symbolsByRoutineNameAndSymbolName
            else:
                self.symbolsByRoutineNameAndSymbolName = getSymbolsByRoutineNameAndSymbolName(
                    self.cgDoc,
                    self.routineNodesByProcName,
                    self.parallelRegionTemplatesByProcName,
                    self.symbolAnalysisByRoutineNameAndSymbolName
                )
        except UsageError as e:
            logging.error('Error: %s' %(str(e)), extra={"hfLineNo":currLineNo, "hfFile":currFile})
            sys.exit(1)
        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            logging.critical('Error when initializing h90 conversion: %s' %(str(e)), extra={"hfLineNo":currLineNo, "hfFile":currFile})
            logging.info(traceback.format_exc())
            sys.exit(1)
Ejemplo n.º 2
0
    def __init__(self,
                 cgDoc,
                 implementationsByTemplateName,
                 outputStream=sys.stdout,
                 moduleNodesByName=None,
                 parallelRegionData=None,
                 symbolAnalysisByRoutineNameAndSymbolName=None,
                 symbolsByModuleNameAndSymbolName=None,
                 symbolsByRoutineNameAndSymbolName=None):
        super(H90toF90Converter, self).__init__(
            cgDoc,
            moduleNodesByName=moduleNodesByName,
            parallelRegionData=parallelRegionData,
            implementationsByTemplateName=implementationsByTemplateName)
        self.outputStream = outputStream
        self.currSubroutineImplementationNeedsToBeCommented = False
        self.currParallelIterators = []
        self.currRoutine = None
        self.currRegion = None
        self.currParallelRegion = None
        self.currModule = None
        self.currCallee = None
        self.codeSanitizer = FortranCodeSanitizer()
        self.currParallelRegionRelationNode = None
        self.currParallelRegionTemplateNode = None
        self.prepareLineCalledForCurrentLine = False
        self.preparedBy = None
        try:
            if symbolAnalysisByRoutineNameAndSymbolName != None:
                self.symbolAnalysisByRoutineNameAndSymbolName = symbolAnalysisByRoutineNameAndSymbolName
            else:
                symbolAnalyzer = SymbolDependencyAnalyzer(self.cgDoc)
                self.symbolAnalysisByRoutineNameAndSymbolName = symbolAnalyzer.getSymbolAnalysisByRoutine(
                )
            if symbolsByModuleNameAndSymbolName != None:
                self.symbolsByModuleNameAndSymbolName = symbolsByModuleNameAndSymbolName
            else:
                self.symbolsByModuleNameAndSymbolName = getSymbolsByModuleNameAndSymbolName(
                    self.cgDoc, self.moduleNodesByName,
                    self.symbolAnalysisByRoutineNameAndSymbolName)

            if symbolsByRoutineNameAndSymbolName != None:
                self.symbolsByRoutineNameAndSymbolName = symbolsByRoutineNameAndSymbolName
            else:
                self.symbolsByRoutineNameAndSymbolName = getSymbolsByRoutineNameAndSymbolName(
                    self.cgDoc, self.routineNodesByProcName,
                    self.parallelRegionTemplatesByProcName,
                    self.symbolAnalysisByRoutineNameAndSymbolName)
        except UsageError as e:
            logging.error('Error: %s' % (str(e)),
                          extra={
                              "hfLineNo": currLineNo,
                              "hfFile": currFile
                          })
            sys.exit(1)
        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            logging.critical('Error when initializing h90 conversion: %s' %
                             (str(e)),
                             extra={
                                 "hfLineNo": currLineNo,
                                 "hfFile": currFile
                             })
            logging.info(traceback.format_exc())
            sys.exit(1)
Ejemplo n.º 3
0
#   note: We do this, since for simplicity reasons, the declaration parser relies on the symbol names that
#   have been declared in @domainDependant directives. Since these directives come *after* the declaration,
#   we need this pass
# cgDoc = getClonedDocument(cgDoc)
for fileNum, fileInDir in enumerate(filesInDir):
    parser = H90XMLSymbolDeclarationExtractor(
        cgDoc, implementationsByTemplateName=implementationsByTemplateName)
    parser.processFile(fileInDir)
    logging.debug("Symbol declarations extracted for " + fileInDir + "")
    printProgressIndicator(sys.stderr, fileInDir, fileNum + 1, len(filesInDir),
                           "Symbol parsing, excluding imports")
progressIndicatorReset(sys.stderr)

#   build up symbol table indexed by module name
moduleNodesByNameWithoutImplicitImports = getModuleNodesByName(cgDoc)
symbolAnalyzer = SymbolDependencyAnalyzer(cgDoc)
symbolAnalysisByRoutineNameAndSymbolNameWithoutImplicitImports = symbolAnalyzer.getSymbolAnalysisByRoutine(
)
symbolsByModuleNameAndSymbolNameWithoutImplicitImports = getSymbolsByModuleNameAndSymbolName(
    ImmutableDOMDocument(cgDoc),
    moduleNodesByNameWithoutImplicitImports,
    symbolAnalysisByRoutineNameAndSymbolName=
    symbolAnalysisByRoutineNameAndSymbolNameWithoutImplicitImports)

#   parse the symbols again, this time know about all informations in the sourced modules in import
#   -> update the callgraph document with this information.
for fileNum, fileInDir in enumerate(filesInDir):
    parser = H90XMLSymbolDeclarationExtractor(
        cgDoc,
        symbolsByModuleNameAndSymbolNameWithoutImplicitImports,
        implementationsByTemplateName=implementationsByTemplateName)
#   parse the @domainDependant symbol declarations flags in all h90 files
#   -> update the callgraph document with this information.
#   note: We do this, since for simplicity reasons, the declaration parser relies on the symbol names that
#   have been declared in @domainDependant directives. Since these directives come *after* the declaration,
#   we need this pass
# cgDoc = getClonedDocument(cgDoc)
for fileNum, fileInDir in enumerate(filesInDir):
	parser = H90XMLSymbolDeclarationExtractor(cgDoc, implementationsByTemplateName=implementationsByTemplateName)
	parser.processFile(fileInDir)
	logging.debug("Symbol declarations extracted for " + fileInDir + "")
	printProgressIndicator(sys.stderr, fileInDir, fileNum + 1, len(filesInDir), "Symbol parsing, excluding imports")
progressIndicatorReset(sys.stderr)

#   build up symbol table indexed by module name
moduleNodesByNameWithoutImplicitImports = getModuleNodesByName(cgDoc)
symbolAnalyzer = SymbolDependencyAnalyzer(cgDoc)
symbolAnalysisByRoutineNameAndSymbolNameWithoutImplicitImports = symbolAnalyzer.getSymbolAnalysisByRoutine()
symbolsByModuleNameAndSymbolNameWithoutImplicitImports = getSymbolsByModuleNameAndSymbolName(
	ImmutableDOMDocument(cgDoc),
	moduleNodesByNameWithoutImplicitImports,
	symbolAnalysisByRoutineNameAndSymbolName=symbolAnalysisByRoutineNameAndSymbolNameWithoutImplicitImports
)

#   parse the symbols again, this time know about all informations in the sourced modules in import
#   -> update the callgraph document with this information.
for fileNum, fileInDir in enumerate(filesInDir):
	parser = H90XMLSymbolDeclarationExtractor(
		cgDoc,
		symbolsByModuleNameAndSymbolNameWithoutImplicitImports,
		implementationsByTemplateName=implementationsByTemplateName
	)
Ejemplo n.º 5
0
    def __init__(self,
                 cgDoc,
                 implementationsByTemplateName,
                 moduleNodesByName=None,
                 parallelRegionData=None,
                 symbolAnalysisByRoutineNameAndSymbolName=None,
                 symbolsByModuleNameAndSymbolName=None,
                 symbolsByRoutineNameAndSymbolName=None,
                 globalParallelDomainNames={}):
        super(ApplicationModelGenerator, self).__init__(
            cgDoc,
            moduleNodesByName=moduleNodesByName,
            parallelRegionData=parallelRegionData,
            implementationsByTemplateName=implementationsByTemplateName)
        self.globalParallelDomainNames = globalParallelDomainNames
        self.currSubroutineImplementationNeedsToBeCommented = False
        self.currParallelIterators = []
        self.currRoutine = None
        self.currRegion = None
        self.currParallelRegion = None
        self.currModule = None
        self.currCallee = None
        self.currParallelRegionRelationNode = None
        self.currParallelRegionTemplateNode = None
        self.prepareLineCalledForCurrentLine = False
        self.preparedBy = None
        self.modulesInFile = []
        self.prefix = ""
        self.appendixByModuleName = {}
        self.lastModuleName = None
        try:
            if symbolAnalysisByRoutineNameAndSymbolName != None:
                self.symbolAnalysisByRoutineNameAndSymbolName = symbolAnalysisByRoutineNameAndSymbolName
            else:
                symbolAnalyzer = SymbolDependencyAnalyzer(self.cgDoc)
                self.symbolAnalysisByRoutineNameAndSymbolName = symbolAnalyzer.getSymbolAnalysisByRoutine(
                )
            if symbolsByModuleNameAndSymbolName != None:
                self.symbolsByModuleNameAndSymbolName = symbolsByModuleNameAndSymbolName
            else:
                self.symbolsByModuleNameAndSymbolName = getSymbolsByModuleNameAndSymbolName(
                    self.cgDoc, self.moduleNodesByName,
                    self.symbolAnalysisByRoutineNameAndSymbolName)
            addGlobalParallelDomainNames(
                sum([
                    index.values() for index in
                    self.symbolsByModuleNameAndSymbolName.values()
                ], []), globalParallelDomainNames)

            if symbolsByRoutineNameAndSymbolName != None:
                self.symbolsByRoutineNameAndSymbolName = symbolsByRoutineNameAndSymbolName
            else:
                self.symbolsByRoutineNameAndSymbolName = getSymbolsByRoutineNameAndSymbolName(
                    self.cgDoc, self.routineNodesByProcName,
                    self.parallelRegionTemplatesByProcName,
                    self.symbolAnalysisByRoutineNameAndSymbolName)
            addGlobalParallelDomainNames(
                sum([
                    index.values() for index in
                    self.symbolsByRoutineNameAndSymbolName.values()
                ], []), globalParallelDomainNames)

        except UsageError as e:
            logging.error('%s' % (str(e)),
                          extra={
                              "hfLineNo": currLineNo,
                              "hfFile": currFile
                          })
            sys.exit(1)
        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            logging.critical('Error when initializing h90 conversion: %s' %
                             (str(e)),
                             extra={
                                 "hfLineNo": currLineNo,
                                 "hfFile": currFile
                             })
            logging.info(traceback.format_exc())
            sys.exit(1)
            # [ #labels
            # 	"<TD>%s</TD>" %("</TD><TD>".join([
            # 		"<FONT POINT-SIZE='%s'>%s</FONT>" %(smallFontSize, entry) for entry in ["local", "s.name", "s.module"] #
            # 	]))
            # ] +
            symbolRows  #symbols
        ))


#read in working xml
srcFile = openFile(str(options.source), 'r')
data = srcFile.read()
srcFile.close()
doc = parseString(data)

analyzer = SymbolDependencyAnalyzer(doc)
if options.debug:
    print "=== calls by calleename ==="
    prettyprint(analyzer.callsByCalleeName)
    print "=== calls by callsByCallerName ==="
    prettyprint(analyzer.callsByCallerName)
    print "=== callGraphEdgesByCallerName ==="
    prettyprint(analyzer.callGraphEdgesByCallerName)
    print "=== routines by name ==="
    prettyprint(analyzer.routinesByName)

analysis = None
if options.symbolGraphRootRoutine:
    analysis = analyzer.getSymbolAnalysisByRoutine(
        options.symbolGraphRootRoutine)
elif options.allSymbols:
            # 	"<TD>%s</TD>" %("</TD><TD>".join([
            # 		"<FONT POINT-SIZE='%s'>%s</FONT>" %(smallFontSize, entry) for entry in ["local", "s.name", "s.module"] #
            # 	]))
            # ] +
            symbolRows  # symbols
        )
    )


# read in working xml
srcFile = openFile(str(options.source), "r")
data = srcFile.read()
srcFile.close()
doc = parseString(data)

analyzer = SymbolDependencyAnalyzer(doc)
if options.debug:
    print "=== calls by calleename ==="
    prettyprint(analyzer.callsByCalleeName)
    print "=== calls by callsByCallerName ==="
    prettyprint(analyzer.callsByCallerName)
    print "=== callGraphEdgesByCallerName ==="
    prettyprint(analyzer.callGraphEdgesByCallerName)
    print "=== routines by name ==="
    prettyprint(analyzer.routinesByName)

analysis = None
if options.symbolGraphRootRoutine:
    analysis = analyzer.getSymbolAnalysisByRoutine(options.symbolGraphRootRoutine)
elif options.allSymbols:
    analysis = analyzer.getSymbolAnalysisByRoutine()
Ejemplo n.º 8
0
    def __init__(
        self,
        cgDoc,
        implementationsByTemplateName,
        moduleNodesByName=None,
        parallelRegionData=None,
        symbolAnalysisByRoutineNameAndSymbolName=None,
        symbolsByModuleNameAndSymbolName=None,
        symbolsByRoutineNameAndSymbolName=None,
        globalParallelDomainNames={}
    ):
        super(ApplicationModelGenerator, self).__init__(
            cgDoc,
            moduleNodesByName=moduleNodesByName,
            parallelRegionData=parallelRegionData,
            implementationsByTemplateName=implementationsByTemplateName
        )
        self.globalParallelDomainNames = globalParallelDomainNames
        self.currSubroutineImplementationNeedsToBeCommented = False
        self.currParallelIterators = []
        self.currRoutine = None
        self.currRegion = None
        self.currParallelRegion = None
        self.currModule = None
        self.currCallee = None
        self.currParallelRegionRelationNode = None
        self.currParallelRegionTemplateNode = None
        self.prepareLineCalledForCurrentLine = False
        self.preparedBy = None
        self.modulesInFile = []
        self.prefix = ""
        self.appendixByModuleName = {}
        self.lastModuleName = None
        try:
            if symbolAnalysisByRoutineNameAndSymbolName != None:
                self.symbolAnalysisByRoutineNameAndSymbolName = symbolAnalysisByRoutineNameAndSymbolName
            else:
                symbolAnalyzer = SymbolDependencyAnalyzer(self.cgDoc)
                self.symbolAnalysisByRoutineNameAndSymbolName = symbolAnalyzer.getSymbolAnalysisByRoutine()
            if symbolsByModuleNameAndSymbolName != None:
                self.symbolsByModuleNameAndSymbolName = symbolsByModuleNameAndSymbolName
            else:
                self.symbolsByModuleNameAndSymbolName = getSymbolsByModuleNameAndSymbolName(self.cgDoc, self.moduleNodesByName, self.symbolAnalysisByRoutineNameAndSymbolName)
            addGlobalParallelDomainNames(
                sum([index.values() for index in self.symbolsByModuleNameAndSymbolName.values()], []),
                globalParallelDomainNames
            )

            if symbolsByRoutineNameAndSymbolName != None:
                self.symbolsByRoutineNameAndSymbolName = symbolsByRoutineNameAndSymbolName
            else:
                self.symbolsByRoutineNameAndSymbolName = getSymbolsByRoutineNameAndSymbolName(
                    self.cgDoc,
                    self.routineNodesByProcName,
                    self.parallelRegionTemplatesByProcName,
                    self.symbolAnalysisByRoutineNameAndSymbolName
                )
            addGlobalParallelDomainNames(
                sum([index.values() for index in self.symbolsByRoutineNameAndSymbolName.values()], []),
                globalParallelDomainNames
            )

        except UsageError as e:
            logging.error('%s' %(str(e)), extra={"hfLineNo":currLineNo, "hfFile":currFile})
            sys.exit(1)
        except Exception as e:
            exc_type, exc_obj, exc_tb = sys.exc_info()
            fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
            logging.critical('Error when initializing h90 conversion: %s' %(str(e)), extra={"hfLineNo":currLineNo, "hfFile":currFile})
            logging.info(traceback.format_exc())
            sys.exit(1)