Skip to content

context: Add macro wrapped #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions data_prep/project_context/context_introspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,31 @@ def _get_function_implementation(self) -> str:

return function_source

def _get_macro_block(self) -> list[str]:
"""Queries FI to check macro block around this function."""
project = self._benchmark.project
if not self._benchmark.function_dict:
return []

source = self._benchmark.function_dict.get('function_filename', '')
start = self._benchmark.function_dict.get('source_line_begin', 0)
end = self._benchmark.function_dict.get('source_end_begin', 99999)
macro_block = introspector.query_introspector_macro_block(
project, source, start, end)

results = set()
for macro in macro_block:
conditions = macro.get('conditions', [])
for condition in conditions:
cond_type = condition.get('type')
cond_detail = condition.get('condition')
if not cond_type or not cond_detail:
continue

results.add(f'#{cond_type} {cond_detail}')

return list(results)

def _get_xrefs_to_function(self) -> list[str]:
"""Queries FI for function being fuzzed."""
project = self._benchmark.project
Expand All @@ -177,13 +202,15 @@ def _get_xrefs_to_function(self) -> list[str]:
def get_context_info(self) -> dict:
"""Retrieves contextual information and stores them in a dictionary."""
xrefs = self._get_xrefs_to_function()
macro = self._get_macro_block()
func_source = self._get_function_implementation()
files = self._get_files_to_include()
decl = self._get_embeddable_declaration()
header = self.get_prefixed_header_file()

context_info = {
'xrefs': xrefs,
'macro_block': macro,
'func_source': func_source,
'files': files,
'decl': decl,
Expand Down
1 change: 1 addition & 0 deletions llm_toolkit/prompt_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def format_context(self, context_info: dict) -> str:
must_insert=context_info['decl'],
func_source=context_info['func_source'],
xrefs='\n'.join(context_info['xrefs']),
macro='\n'.join(context_info['macro_block']),
include_statement=context_info['header'],
)

Expand Down
9 changes: 9 additions & 0 deletions prompts/template_xml/context.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,12 @@ Here is the source code for functions which reference the function being tested:
{{ xrefs }}
</code>
{% endif %}
{% if macro %}

Here are all the macro conditions wrapped around or present in the target functions:
<code>
{{ macro }}
</code>
{% endif %}