Skip to content

Commit

Permalink
core: frontend: cpp: cache report generation (#2094)
Browse files Browse the repository at this point in the history
* core: frontend: cpp: cache report generation

Signed-off-by: David Korczynski <david@adalogics.com>

* nit

Signed-off-by: David Korczynski <david@adalogics.com>

---------

Signed-off-by: David Korczynski <david@adalogics.com>
  • Loading branch information
DavidKorczynski authored Feb 14, 2025
1 parent 5530e98 commit 80010f6
Showing 1 changed file with 49 additions and 40 deletions.
89 changes: 49 additions & 40 deletions src/fuzz_introspector/frontends/frontend_cpp.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from tree_sitter import Language, Node

import os
import copy
import logging

from fuzz_introspector.frontends import datatypes
Expand Down Expand Up @@ -614,6 +615,7 @@ class CppProject(datatypes.Project[CppSourceCodeFile]):

def __init__(self, source_code_files: list[CppSourceCodeFile]):
super().__init__(source_code_files)
self.internal_func_list: list[dict[str, Any]] = []

def generate_report(self,
entry_function: str = '',
Expand Down Expand Up @@ -643,46 +645,53 @@ def generate_report(self,
self.all_functions.append(func)

# Process all project functions
func_list = []
for func in self.all_functions:
logger.debug('Iterating %s', func.name)
logger.debug('Extracing callsites')
func.extract_callsites(self)
logger.debug('Done extracting callsites')
func_dict: dict[str, Any] = {}
func_dict['functionName'] = func.name
func_dict['functionSourceFile'] = func.parent_source.source_file
func_dict['functionLinenumber'] = func.start_line
func_dict['functionLinenumberEnd'] = func.end_line
func_dict['linkageType'] = ''
func_dict['func_position'] = {
'start': func.start_line,
'end': func.end_line
}
func_dict['CyclomaticComplexity'] = func.complexity
func_dict['EdgeCount'] = func_dict['CyclomaticComplexity']
func_dict['ICount'] = func.icount
func_dict['argNames'] = func.arg_names
func_dict['argTypes'] = func.arg_types
func_dict['argCount'] = len(func_dict['argTypes'])
func_dict['returnType'] = func.return_type
func_dict['BranchProfiles'] = []
func_dict['Callsites'] = func.detailed_callsites
logger.debug('Calculating function uses')
func_dict['functionUses'] = self.calculate_function_uses(func.name)
logger.debug('Getting function depth')
func_dict['functionDepth'] = self.calculate_function_depth(func)
func_dict['constantsTouched'] = []
func_dict['BBCount'] = 0
func_dict['signature'] = func.sig
callsites = func.base_callsites
reached = set()
for cs_dst, _ in callsites:
reached.add(cs_dst)
func_dict['functionsReached'] = list(reached)

logger.debug('Done')
func_list.append(func_dict)
if not self.internal_func_list:
func_list = []
for func in self.all_functions:
logger.debug('Iterating %s', func.name)
logger.debug('Extracing callsites')
func.extract_callsites(self)
logger.debug('Done extracting callsites')
func_dict: dict[str, Any] = {}
func_dict['functionName'] = func.name
func_dict[
'functionSourceFile'] = func.parent_source.source_file
func_dict['functionLinenumber'] = func.start_line
func_dict['functionLinenumberEnd'] = func.end_line
func_dict['linkageType'] = ''
func_dict['func_position'] = {
'start': func.start_line,
'end': func.end_line
}
func_dict['CyclomaticComplexity'] = func.complexity
func_dict['EdgeCount'] = func_dict['CyclomaticComplexity']
func_dict['ICount'] = func.icount
func_dict['argNames'] = func.arg_names
func_dict['argTypes'] = func.arg_types
func_dict['argCount'] = len(func_dict['argTypes'])
func_dict['returnType'] = func.return_type
func_dict['BranchProfiles'] = []
func_dict['Callsites'] = func.detailed_callsites
logger.debug('Calculating function uses')
func_dict['functionUses'] = self.calculate_function_uses(
func.name)
logger.debug('Getting function depth')
func_dict['functionDepth'] = self.calculate_function_depth(
func)
func_dict['constantsTouched'] = []
func_dict['BBCount'] = 0
func_dict['signature'] = func.sig
callsites = func.base_callsites
reached = set()
for cs_dst, _ in callsites:
reached.add(cs_dst)
func_dict['functionsReached'] = list(reached)

logger.debug('Done')
func_list.append(func_dict)
self.internal_func_list = copy.deepcopy(func_list)
else:
func_list = copy.deepcopy(self.internal_func_list)

if func_list:
self.report['All functions'] = {}
Expand Down

0 comments on commit 80010f6

Please sign in to comment.