I’m working on the LLVM parsing + typechecking.
The following situation arises

define i32 @mult(i32 %i, i32 %j) #0 {
  %1 = alloca i32, align 4 
  %2 = alloca i32, align 4
  store i32 %i, i32* %1, align 4
  store i32 %j, i32* %2, align 4
  ret i32 %i
  %3 = load i32* %1, align 4
  %4 = load i32* %2, align 4
  %5 = mul nsw i32 %3, %4
  ret i32 %5
}

Which ideally should be parsed as:

Function([
    Block(
        [instructions]
    ),
    Block(
        [instructions]
    )
])

I would now like to import my local definitions from block 1 into block 2, but because they are defined in subsequent scope in the block, this is not possible.

The current hacky (and only known) solution is to move the block into the list of instructions of the previous block during desugaring, such that it is in the subsequent scope.

This is ofcourse unwieldy because all my functions that recurse on instructions should now be VERY careful to treat the last entry appropriately.
Or, I have to suger this again after the namebinding stage.

Submitted by Arjen on 2 May 2014 at 13:44

On 2 May 2014 at 14:14 Guido Wachsmuth commented:

Another solution might be to not have blocks before name analysis. In this case, ret ... would just be another instruction, and a function would have only a list of instructions. You can then introduce the blocks after name analysis.


On 2 May 2014 at 14:19 Arjen commented:

Yes, that might be a more sensible solution.

Log in to post comments