Control Flow Abstraction Generatorのロゴ

Control Flow Abstraction Generator

コミュニティ
ArabelaTso
control-flow-abstraction-generator

Generate abstract Control Flow Graph (CFG) representations of programs showing loops, branches, and function calls for static analysis or verification. Use when users need to: (1) Visualize program control flow structure, (2) Generate CFGs for static analysis tools, (3) Create control flow abstractions for formal verification, (4) Analyze program paths and reachability, (5) Document program structure. Supports both function-level (intraprocedural) and program-level (interprocedural) analysis with multiple output formats (textual, DOT/Graphviz, JSON).

概要

公開者ArabelaTso
リポジトリSkills-4-SE
スキル名control-flow-abstraction-generator
スター
258
フォーク
25
同梱ファイル
1
ライセンスApache-2.0
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 1個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    ArabelaTsoがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Control Flow Abstraction Generator」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/control-flow-abstraction-generator
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ArabelaTso/Skills-4-SE.git /tmp/Skills-4-SE
mkdir -p .claude/skills
cp -r /tmp/Skills-4-SE/skills/control-flow-abstraction-generator .claude/skills/control-flow-abstraction-generator
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでControl Flow Abstraction Generatorを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にControl Flow Abstraction Generatorを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Control Flow Abstraction Generatorは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

Control Flow Abstraction Generator

Generate abstract Control Flow Graph representations of programs.

Overview

This skill analyzes program code and generates Control Flow Graphs (CFGs) that abstract the program's control flow structure. CFGs show how execution flows through the program via nodes (statements, conditions) and edges (control transfers), making them suitable for static analysis, formal verification, and program understanding.

How to Use

Provide:

  1. Program code: Function or program to analyze
  2. Analysis scope: Function-level or program-level
  3. Output format (optional): Textual, DOT, JSON, or multiple

The skill will generate:

  • CFG with nodes and edges
  • Node types (entry, exit, statement, condition, merge)
  • Edge types (sequential, true/false branches, back edges, calls)
  • Optional: DOT format for visualization, JSON for tool integration

CFG Generation Workflow

Step 1: Parse Program Structure

Identify program constructs:

  • Sequential statements: Assignments, expressions, declarations
  • Conditional statements: if-then-else, switch-case
  • Loop statements: while, for, do-while
  • Function calls: Direct calls, recursive calls
  • Control transfers: break, continue, return, goto
  • Exception handling: try-catch-finally

Step 2: Create CFG Nodes

Generate nodes for each construct:

Entry Node: Function/program start

  • Label: ENTRY or function name
  • Type: entry
  • Successors: First statement

Exit Node: Function/program end

  • Label: EXIT or return
  • Type: exit
  • Predecessors: All return points

Statement Node: Regular statement

  • Label: Statement text or line number
  • Type: statement
  • Represents: Assignment, call, expression

Condition Node: Branch decision

  • Label: Boolean expression
  • Type: condition
  • Successors: True branch, false branch

Merge Node: Branch join point

  • Label: MERGE or empty
  • Type: merge
  • Predecessors: Multiple branches

Step 3: Create CFG Edges

Connect nodes with appropriate edges:

Sequential Edge: Normal flow

  • From: Statement/node
  • To: Next statement/node
  • Label: None or →

True Edge: Condition true branch

  • From: Condition node
  • To: True branch first statement
  • Label: T or true

False Edge: Condition false branch

  • From: Condition node
  • To: False branch first statement
  • Label: F or false

Back Edge: Loop iteration

  • From: Loop body end
  • To: Loop header
  • Label: ↶ or back

Call Edge: Function invocation (interprocedural)

  • From: Call site
  • To: Called function entry
  • Label: ⇒ or call

Return Edge: Function return (interprocedural)

  • From: Called function exit
  • To: Call site return point
  • Label: ⇐ or return

Step 4: Handle Special Constructs

Loops: Create back edges from body to header

Break: Create edge from break statement to loop exit

Continue: Create back edge from continue to loop header

Return: Create edge from return to EXIT node

Exceptions: Create exception edges from try block to catch handlers

Step 5: Generate Output

Produce CFG in requested format(s):

  • Textual representation
  • DOT format for Graphviz
  • JSON for tool integration

Example: Simple Conditional

Code:

python
def max_value(x, y):
    if x > y:
        result = x
    else:
        result = y
    return result

CFG (Textual):

Node 1 (ENTRY):
  Label: max_value
  Successors: [2]

Node 2 (x > y):
  Type: condition
  Predecessors: [1]
  Successors: [3 (true), 4 (false)]

Node 3 (result = x):
  Type: statement
  Predecessors: [2]
  Successors: [5]

Node 4 (result = y):
  Type: statement
  Predecessors: [2]
  Successors: [5]

Node 5 (MERGE):
  Type: merge
  Predecessors: [3, 4]
  Successors: [6]

Node 6 (return result):
  Type: statement
  Predecessors: [5]
  Successors: [7]

Node 7 (EXIT):
  Predecessors: [6]

CFG (Visual):

    ENTRY
      ↓
   [x > y]
    ↓   ↓
   T↓   ↓F
    ↓   ↓
[result=x] [result=y]
    ↓       ↓
    └→MERGE←┘
        ↓
  [return result]
        ↓
      EXIT

CFG (DOT):

dot
digraph CFG {
  node [shape=box];

  n1 [label="ENTRY", shape=ellipse];
  n2 [label="x > y", shape=diamond];
  n3 [label="result = x"];
  n4 [label="result = y"];
  n5 [label="MERGE", shape=circle];
  n6 [label="return result"];
  n7 [label="EXIT", shape=ellipse];

  n1 -> n2;
  n2 -> n3 [label="T", color=green];
  n2 -> n4 [label="F", color=red];
  n3 -> n5;
  n4 -> n5;
  n5 -> n6;
  n6 -> n7;
}

Example: While Loop

Code:

python
def sum_to_n(n):
    sum = 0
    i = 0
    while i < n:
        sum += i
        i += 1
    return sum

CFG (Visual):

    ENTRY
      ↓
   [sum = 0]
      ↓
   [i = 0]
      ↓
      ┌─────────┐
      ↓         ↑
   [i < n]      ↑ (back edge)
    ↓   ↓       ↑
   T↓   ↓F      ↑
    ↓   ↓       ↑
[sum += i]      ↑
      ↓         ↑
  [i += 1]──────┘
      ↓F
[return sum]
      ↓
    EXIT

Key Features:

  • Loop header: [i < n]
  • Back edge: From [i += 1] to [i < n]
  • Exit edge: False branch from condition to return

CFG (Textual):

Node 1 (ENTRY)
  → Node 2

Node 2 (sum = 0)
  → Node 3

Node 3 (i = 0)
  → Node 4

Node 4 (i < n) [LOOP HEADER]
  →T Node 5
  →F Node 7

Node 5 (sum += i)
  → Node 6

Node 6 (i += 1)
  → Node 4 [BACK EDGE]

Node 7 (return sum)
  → Node 8

Node 8 (EXIT)

Example: Nested Control Flow

Code:

python
def process(arr, threshold):
    result = []
    for item in arr:
        if item > threshold:
            result.append(item * 2)
        else:
            if item < 0:
                continue
            result.append(item)
    return result

CFG (Visual):

ENTRY
  ↓
[result = []]
  ↓
[i = 0]
  ↓
  ┌──────────────────────┐
  ↓                      ↑
[i < len(arr)]           ↑
  ↓T                     ↑
[item = arr[i]]          ↑
  ↓                      ↑
[item > threshold]       ↑
  ↓T            ↓F       ↑
[result.append  [item<0] ↑
 (item*2)]        ↓T     ↑
  ↓               └──────┘ (continue)
  ↓              ↓F
  ↓         [result.append(item)]
  ↓               ↓
  └──→MERGE←──────┘
       ↓
   [i += 1]───────┘
       ↓F
  [return result]
       ↓
     EXIT

Key Features:

  • Outer loop: for loop over array
  • Inner conditional: if-else with nested if
  • Continue statement: back edge to loop header
  • Multiple merge points

Example: Function Calls (Interprocedural)

Code:

python
def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n-1)

def compute(x):
    result = factorial(x)
    return result + 1

Intraprocedural CFG (factorial only):

factorial:ENTRY
      ↓
   [n <= 1]
    ↓     ↓
   T↓     ↓F
    ↓     ↓
[return 1] [call factorial(n-1)]
    ↓           ↓
    ↓      [return n * result]
    ↓           ↓
    └──→EXIT←───┘

Interprocedural CFG (with call edges):

compute:ENTRY
      ↓
[call factorial(x)] ⇒ factorial:ENTRY
      ↓                     ↓
      ↓                [n <= 1]
      ↓                  ↓   ↓
      ↓                 ...  ...
      ↓                     ↓
[result = ...] ⇐ factorial:EXIT
      ↓
[return result + 1]
      ↓
compute:EXIT

Key Features:

  • Call edge: From call site to callee entry
  • Return edge: From callee exit to call site
  • Recursive call: Edge back to same function

Output Formats

Textual Format

Human-readable node and edge listing:

Node <id> (<label>):
  Type: <type>
  Predecessors: [<ids>]
  Successors: [<ids>]

DOT Format (Graphviz)

Graph visualization format:

dot
digraph CFG {
  node [shape=box];
  n1 [label="...", shape=...];
  n1 -> n2 [label="...", color=...];
}

Generate PNG/SVG with: dot -Tpng cfg.dot -o cfg.png

JSON Format

Machine-readable for tool integration:

json
{
  "nodes": [
    {"id": 1, "label": "...", "type": "..."}
  ],
  "edges": [
    {"from": 1, "to": 2, "type": "..."}
  ]
}

Analysis Levels

Function-Level (Intraprocedural)

Scope: Single function Nodes: Statements within function Edges: Control flow within function Calls: Treated as single statement nodes

Use cases:

  • Function-level analysis
  • Loop detection
  • Path analysis within function

Program-Level (Interprocedural)

Scope: Multiple functions Nodes: Statements across all functions Edges: Control flow + call/return edges Calls: Explicit call and return edges

Use cases:

  • Whole-program analysis
  • Call graph construction
  • Interprocedural dataflow

CFG Properties

Dominance

Node A dominates node B if every path from ENTRY to B passes through A.

Uses: Loop header identification, optimization

Post-Dominance

Node A post-dominates node B if every path from B to EXIT passes through A.

Uses: Control dependence, merge point identification

Reachability

Node B is reachable from node A if there exists a path from A to B.

Uses: Dead code detection, path analysis

Strongly Connected Components

Maximal set of nodes where every node is reachable from every other.

Uses: Loop detection, cycle analysis

Common Patterns

Sequential Statements

Pattern: Linear flow See: cfg_patterns.md

If-Then-Else

Pattern: Diamond shape with merge See: cfg_patterns.md

While Loop

Pattern: Back edge from body to header See: cfg_patterns.md

Break/Continue

Pattern: Direct edges to exit/header See: cfg_patterns.md

Try-Catch

Pattern: Exception edges to handlers See: cfg_patterns.md

References

Detailed CFG construction patterns:

  • cfg_patterns.md: Comprehensive patterns for all control flow constructs with examples

Load this reference when:

  • Need detailed patterns for specific constructs
  • Working with complex nested structures
  • Want to see all output format examples
  • Need CFG property definitions

Tips

  1. Start with entry/exit: Always create ENTRY and EXIT nodes first
  2. Handle loops carefully: Identify loop headers and create back edges
  3. Merge branches: Create explicit merge nodes after conditionals
  4. Label edges clearly: Use T/F for branches, mark back edges
  5. Consider scope: Choose function-level or program-level based on use case
  6. Visualize complex CFGs: Use DOT format for large graphs
  7. Validate structure: Check that all nodes are reachable from ENTRY
  8. Document assumptions: Note how you handle language-specific constructs

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「Control Flow Abstraction Generator」では何ができますか?

Generate abstract Control Flow Graph (CFG) representations of programs showing loops, branches, and function calls for static analysis or verification. Use when users need to: (1) Visualize program control flow structure, (2) Generate CFGs for static analysis tools, (3) Create control flow abstractions for formal verification, (4) Analyze program paths and reachability, (5) Document program structure. Supports both function-level (intraprocedural) and program-level (interprocedural) analysis with multiple output formats (textual, DOT/Graphviz, JSON).

TypingMindでControl Flow Abstraction Generatorを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Control Flow Abstraction Generatorはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにControl Flow Abstraction Generatorをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/ArabelaTso/Skills-4-SE/tree/main/skills/control-flow-abstraction-generatorを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Control Flow Abstraction Generatorを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Control Flow Abstraction Generatorで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもControl Flow Abstraction Generatorを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Control Flow Abstraction Generator」は無料ですか?

はい。ArabelaTsoがApache-2.0ライセンスのもとでGitHubに公開しています。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇