Skip to content

Instantly share code, notes, and snippets.

@retpolanne
Created November 12, 2024 01:40
Show Gist options
  • Save retpolanne/3e2326b0290d68308ff7074e98b9e2f0 to your computer and use it in GitHub Desktop.
Save retpolanne/3e2326b0290d68308ff7074e98b9e2f0 to your computer and use it in GitHub Desktop.
Generate control-flow graph from source code using ollama and graphviz
#!/usr/bin/env sh
# Usage
# ./gen-dot-llm.sh filename.java Function
temp_jpg=$(mktemp)
full_prompt=$(mktemp)
prompt="generate a control-flow graph from the following code in dot language.
Consider only the function $2. Output only the raw dot code without any other words.
Do not format as markdown."
code="$(cat $1)"
echo "$prompt" >> $full_prompt
echo "$code" >> $full_prompt
ollama run qwen2.5-coder < $full_prompt | dot -Tjpg > /tmp/dot.jpg
echo "Saved graph in /tmp/dot.jpg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment