Skip to content
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

Introduce Undefined Value Graphs (UVGs) #717

Merged
merged 22 commits into from
Jan 30, 2025
Merged

Introduce Undefined Value Graphs (UVGs) #717

merged 22 commits into from
Jan 30, 2025

Conversation

Akuli
Copy link
Owner

@Akuli Akuli commented Jan 30, 2025

The purpose of UVGs is to eventually fix issues like #3, #445 and #566. This PR only adds code that builds UVGs, and doesn't use them for anything yet.

An UVG is somewhat similar to LLVM IR and the CFGs in old Jou compilers, but much simpler. Currently, it only contains three instructions:

  • set x: A value is stored to variable x.
  • use x: A value is loaded from variable x.
  • don't analyze x: Something more complicated is done with variable x. Compiler doesn't fully understand what, so it will not complain.

For example, consider the following function (taken from docs included in this PR):

import "stdlib/io.jou"

def foo(a: int) -> int:         # line 3
    x = a + 6                   # line 4
    y: int                      # line 5
    z = y                       # line 6
    printf("%d %d\n", x, y, z)  # line 7

Running jou --uvg-only file.jou prints the following UVG:

===== UVG for foo =====
block 0 (start):
    [line 3]   set a
    [line 4]   use a
    [line 4]   set x
    [line 6]   use y
    [line 6]   set z
    [line 7]   use x
    [line 7]   use y
    [line 7]   use z
    [line 7]   use return
    Return from function.

@Akuli Akuli merged commit 057f1bf into main Jan 30, 2025
38 checks passed
@Akuli Akuli deleted the uvg2 branch January 30, 2025 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant