Beispiel #1
0
    def __init__(self, clang_driver=None):
        common.RepresentationBuilder.__init__(self)

        if clang_driver:
            self.__clang_driver = clang_driver
        else:
            self.__clang_driver = ClangDriver(
                ClangDriver.ProgrammingLanguage.C,
                ClangDriver.OptimizationLevel.O3,
                [],
                ["-Wall"],
            )
        self.__extractor = LLVMIRExtractor(self.__clang_driver)
Beispiel #2
0
def clang_extractor_fixture():
    clang_driver = ClangDriver(
        ClangDriver.ProgrammingLanguage.C,
        ClangDriver.OptimizationLevel.O0,
        [],
        ["-Wall"],
    )
    clang_extractor = ClangExtractor(clang_driver)
    return clang_extractor
Beispiel #3
0
class SyntaxSeqBuilder(common.RepresentationBuilder):
    def __init__(self, clang_driver=None):
        common.RepresentationBuilder.__init__(self)

        if clang_driver:
            self.__clang_driver = clang_driver
        else:
            self.__clang_driver = ClangDriver(
                ClangDriver.ProgrammingLanguage.C,
                ClangDriver.OptimizationLevel.O3,
                [],
                ["-Wall"],
            )
        self.__extractor = ClangExtractor(self.__clang_driver)

    def string_to_info(self, src, additional_include_dir=None):
        if additional_include_dir:
            self.__clang_driver.addIncludeDir(additional_include_dir,
                                              ClangDriver.IncludeDirType.User)
        info = self.__extractor.SeqFromString(src)
        if additional_include_dir:
            self.__clang_driver.removeIncludeDir(
                additional_include_dir, ClangDriver.IncludeDirType.User)

        return info

    def info_to_representation(self,
                               info,
                               visitor=SyntaxTokenkindVariableVisitor):
        vis = visitor()
        info.accept(vis)

        for token in vis.S:
            if token not in self._tokens:
                self._tokens[token] = 1
            self._tokens[token] += 1

        return common.Sequence(vis.S, self.get_tokens())
Beispiel #4
0
class LLVMGraphBuilder(common.RepresentationBuilder):
    def __init__(self, clang_driver=None):
        common.RepresentationBuilder.__init__(self)

        if clang_driver:
            self.__clang_driver = clang_driver
        else:
            self.__clang_driver = ClangDriver(
                ClangDriver.ProgrammingLanguage.C,
                ClangDriver.OptimizationLevel.O3,
                [],
                ["-Wall"],
            )
        self.__extractor = LLVMIRExtractor(self.__clang_driver)

    def string_to_info(self, src, additional_include_dir=None):
        if additional_include_dir:
            self.__clang_driver.addIncludeDir(additional_include_dir,
                                              ClangDriver.IncludeDirType.User)
        info = self.__extractor.GraphFromString(src)
        if additional_include_dir:
            self.__clang_driver.removeIncludeDir(
                additional_include_dir, ClangDriver.IncludeDirType.User)

        return info

    def info_to_representation(self, info, visitor=LLVMCDFGVisitor):
        vis = visitor()
        info.accept(vis)

        for (n, data) in vis.G.nodes(data=True):
            attr = data["attr"]
            if attr not in self._tokens:
                self._tokens[attr] = 1
            self._tokens[attr] += 1

        return common.Graph(vis.G, self.get_tokens(), vis.edge_types)