Skip to content

Commit c2c288e

Browse files
committed
Add macro wrapped info in function context
Signed-off-by: Arthur Chan <[email protected]>
1 parent 83bd929 commit c2c288e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

data_prep/project_context/context_introspector.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,28 @@ def _get_function_implementation(self) -> str:
162162

163163
return function_source
164164

165+
def _get_macro_block(self) -> list[str]:
166+
"""Queries FI to check macro block around this function."""
167+
project = self._benchmark.project
168+
source = self._benchmark.function_dict.get('function_filename', '')
169+
start = self._benchmark.function_dict.get('source_line_begin', 0)
170+
end = self._benchmark.function_dict.get('source_end_begin', 99999)
171+
macro_block = introspector.query_introspector_macro_block(
172+
project, source, start, end)
173+
174+
results = set()
175+
for macro in macro_block:
176+
conditions = macro.get('conditions', [])
177+
for condition in conditions:
178+
cond_type = condition.get('type')
179+
cond_detail = condition.get('condition')
180+
if not cond_type or not cond_detail:
181+
continue
182+
183+
results.add(f'#{cond_type} {cond_detail}')
184+
185+
return list(results)
186+
165187
def _get_xrefs_to_function(self) -> list[str]:
166188
"""Queries FI for function being fuzzed."""
167189
project = self._benchmark.project
@@ -177,13 +199,15 @@ def _get_xrefs_to_function(self) -> list[str]:
177199
def get_context_info(self) -> dict:
178200
"""Retrieves contextual information and stores them in a dictionary."""
179201
xrefs = self._get_xrefs_to_function()
202+
macro = self._get_macro_block()
180203
func_source = self._get_function_implementation()
181204
files = self._get_files_to_include()
182205
decl = self._get_embeddable_declaration()
183206
header = self.get_prefixed_header_file()
184207

185208
context_info = {
186209
'xrefs': xrefs,
210+
'macro_block': macro,
187211
'func_source': func_source,
188212
'files': files,
189213
'decl': decl,

llm_toolkit/prompt_builder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def format_context(self, context_info: dict) -> str:
203203
must_insert=context_info['decl'],
204204
func_source=context_info['func_source'],
205205
xrefs='\n'.join(context_info['xrefs']),
206+
macro='\n'.join(context_info['macro']),
206207
include_statement=context_info['header'],
207208
)
208209

prompts/template_xml/context.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ Here is the source code of the function being tested:
2020
{% endif %}
2121
{% if xrefs %}
2222

23+
Here are all the macro conditions wrapped around or present in the target functions:
24+
<code>
25+
{{ macro }}
26+
</code>
27+
2328
Here is the source code for functions which reference the function being tested:
2429
<code>
2530
{{ xrefs }}

0 commit comments

Comments
 (0)