Skip to content

Repository files navigation

Graphical C Code Generator

Wire a flowchart. Get real C99.

A visual block editor that turns graphs into compilable C — then builds and runs them in the same window. Built for teaching, exploration, and anyone who thinks better in diagrams than in blank .c files.

Repository: github.com/ViezTrinker/Graphical-C-Code-Generator

Graphical C Code Generator editor showing a prime-number flowchart

Prime number detector as a flowchart — blocks, wires, properties, minimap.

Generated C source with Build and Run panes

Generate → Build → Run: C source, gcc log, and live Program Output in one place.


Why this exists

Most “visual coding” tools hide the language. This one exposes C:

  • You place blocks (control flow, data, I/O, files, memory, structs, functions, …)
  • You connect amber control and blue data wires
  • Generate C validates the graph, writes build_out/<name>.c, and can run clang-format
  • Build / Run use gcc and stream stdin/stdout in the bottom panes

Open an example, press Generate, and you can see exactly how the graph maps to C.


Features at a glance

Area What you get
Editor Collapsible palette (drag & drop), resize handle, per-block fill/text color presets, snap/align, tidy, Ortho wires, minimap, multi-select, undo/redo, copy/paste, Light/Dark theme, caret editing
Typing Named types (Hero, FILE*, bool, …), live green/red wire preview, wire reconnect, property dropdowns
Functions Typed FunctionDef params, Call arity preview, Create Matching FunctionDef, Call↔FunctionDef validation
Types & memory Struct / Enum / Typedef decls, Struct Literal, Address Of, Deref Get/Set, Malloc/Free
Feedback Live Compiler issues + canvas Error/Warning outlines; hover tooltips
Comments Per-block comment/* … */ in generated C when set
Safety Autosave / crash recovery (.cgen.tmp)
Output Doxygen \file / \brief, optional clang-format, in-app source view
CLI Headless --codegen with optional --compile / --run

Quick start (Windows)

.\scripts\build.ps1
.\build\c_code_generator.exe

Then Openexamples/prime_number_detector.cgenGenerate CBuildRun.

Or stay in the terminal:

"7" | .\build\c_code_generator.exe --codegen examples\prime_number_detector.cgen --run

--codegen writes C only. Add --compile for gcc, or --run to compile and execute.

Requirements & other ways to build

Requirements

  • CMake 3.20+
  • A C++17 compiler (Visual Studio 2022/2026, or MinGW g++)
  • Network on the first configure/build (to download SFML unless already cached)
  • gcc on PATH for in-app Build / Run
  • Optional: clang-format on PATH when Document clangFormat=1
Dependency How it is provided
nlohmann_json Vendored in third_party/nlohmann/json.hpp
SFML 3 Auto-downloaded into third_party/sfml by scripts/build.ps1, or via CMake FetchContent

No vcpkg / manual SFML install is required.

Visual Studio

Double-click OpenInVisualStudio.bat in the repo root (finds the latest VS install and opens this folder as a CMake project).

Or manually: File → Open → Folder…, pick x64-Debug or x64-Release, then Build (first configure may download SFML).

Manual CMake

cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release
cmake --build build

Unit tests

git submodule update --init --recursive
cmake --build build --target cgen_unit_tests
ctest --test-dir build --output-on-failure

Disable tests with -DCGEN_BUILD_TESTS=OFF if needed.


Example projects

Feature primers

Short graphs that teach one IR feature.

File Shows Expected output
ex_struct_literal.cgen Struct Literal point = (3, 7)
ex_multi_arg_call.cgen Multi-arg Call add3(10, 20, 12) = 42
ex_address_of.cgen Address Of + Hero* hero.hp after bump = 11
ex_malloc_free.cgen Malloc / Free pBuf[0] = 42
.\build\c_code_generator.exe --codegen examples\ex_struct_literal.cgen --run
.\build\c_code_generator.exe --codegen examples\ex_multi_arg_call.cgen --run
.\build\c_code_generator.exe --codegen examples\ex_address_of.cgen --run
.\build\c_code_generator.exe --codegen examples\ex_malloc_free.cgen --run

Larger demos

Example Idea
add_two_integers.cgen Tiny starter: a + b → print
prime_number_detector.cgen Interactive prime check (screenshots above)
live_clock.cgen Local time + Sleep loop
password_generator.cgen Shuffle a typed password policy
tic_tac_toe.cgen You vs AI, file history
dungeon_log.cgen Full-featured adventure showcase
# Add two integers
.\build\c_code_generator.exe --codegen examples\add_two_integers.cgen --run

# Prime detector
"8" | .\build\c_code_generator.exe --codegen examples\prime_number_detector.cgen --run

# Live clock (Ctrl+C to stop)
.\build\c_code_generator.exe --codegen examples\live_clock.cgen --run

# Password generator (total, digits, specials, uppers)
"16`n3`n2`n3" | .\build\c_code_generator.exe --codegen examples\password_generator.cgen --run

# Tic Tac Toe / Dungeon Log — interactive in the GUI, or pipe stdin for CLI
.\build\c_code_generator.exe --codegen examples\tic_tac_toe.cgen --run

Dungeon Log covers nearly every block family (structs, multi-arg Call, Address Of, Malloc/Free, files, time). Snapshot: examples/build_out/dungeon_log.c.


Using the editor

  • Drag blocks from the left palette onto the canvas (filter by name; Esc cancels a drag)
  • Select a block and drag the bottom-right handle to resize, or edit width / height in Properties
  • Style blocks with fillColor / textColor presets (use Custom + *ColorCustom hex for exact colors)
  • Wire preview turns green/red for type compatibility; drag an Out to reconnect; drop on a wired In to replace
  • Ortho (or Document orthogonalWires) draws elbow wires for dense graphs
  • Validation: live Compiler issues + red/yellow canvas outlines (click an issue to jump); Generate still writes C
  • Snap / AlignL / AlignT / Tidy (Ctrl+L); Fit / Fit Sel; canvas minimap
  • Theme toggles Light / Dark UI; preference is remembered
  • Property fields have a blinking caret (Left/Right/Home/End); dropdowns for type, op, access, function, …
  • Clear selection for Document fileDescription / clangFormat / orthogonalWires
  • Per-block comment/* … */ in generated C when non-empty
  • Call: arity subtitle on canvas; right-click → Create Matching FunctionDef
  • FunctionDef: typed params + Param ports; double-click to collapse the body
  • Generate C: validates, writes .c, optional clang-format, shows source (Esc closes)
  • Build / Run / Stop: gcc in Compiler; stdin via Program Output (caret editing)
  • Autosave while dirty (~30 s); crash-recovery prompt on next start; temps cleared after Save / New / Open
  • ? / F1 for in-app help · projects save as .cgen (CGEN 1 + JSON)

Project layout

Path Role
include/, src/ Application code
tests/ GoogleTest (cgen_unit_tests)
examples/ Sample .cgen projects
docs/ Architecture notes + screenshots
scripts/build.ps1 One-shot fetch + build
third_party/ Vendored JSON, GoogleTest submodule, local SFML (gitignored after download)
build_out/ Generated C and executables

How the code is structured: docs/README.md.


License & status

This project is licensed under the MIT License. Releases are tagged as V_x.y.z.R.

About

Visual SFML flowchart editor that generates, validates, and runs C99

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages