Skip to content

Comments

Fix bug preventing access to formal parameters in addition to variables#9

Open
heksterb wants to merge 1 commit intoPacktPublishing:masterfrom
heksterb:fix-parameter-access
Open

Fix bug preventing access to formal parameters in addition to variables#9
heksterb wants to merge 1 commit intoPacktPublishing:masterfrom
heksterb:fix-parameter-access

Conversation

@heksterb
Copy link

@heksterb heksterb commented Apr 1, 2022

The code as provided is missing some parts that deal with accessing parameters (as opposed to variables). To demonstrate, run

$ ./build/tools/driver/tinylang --emit-llvm examples/Gcd.mod

and view the generated examples/Gcd.ll. Note specifically the while.cond block does not have instructions for the two assignments to parameters a and b. Before my changes:

while.cond:                                       ; preds = %while.body, %after.if
  %1 = icmp ne i64 %b, 0
  br i1 %1, label %while.body, label %after.while

With my changes:

while.cond:                                       ; preds = %while.body, %after.if
  %1 = phi i64 [ %2, %while.body ], [ %a, %after.if ]
  %2 = phi i64 [ %4, %while.body ], [ %b, %after.if ]
  %3 = icmp ne i64 %2, 0
  br i1 %3, label %while.body, label %after.while

Also verified with a test program that the generated function produces the correct numerical result.

Copy link

@OrchidRock OrchidRock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CR Ok!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants