Skip to content

Consider adding extra newline after blocks #45

Open
@jdreaver

Description

@jdreaver

Hello! I'm really excited you all have built this project. It is much nicer to debug LLVM IR issues in my compiler when I can see it printed, versus when I make a mistake and just see a segfault from the C++ LLVM library 😄

I noticed that when I print my LLVM IR using moduleLLVMAssembly, I get wonderful newlines after each block:

; ModuleID = 'amy-module'
source_filename = "<string>"

define i64 @main() {
entry:
  %0 = call i64 @fib(i64 10)
  ret i64 %0
}

define private i64 @fib(i64 %x) {
entry:
  switch i64 %x, label %case.default.0 [
    i64 0, label %case.0.0
    i64 1, label %case.1.0
  ]

case.default.0:                                   ; preds = %entry
  %0 = sub i64 %x, 1
  %1 = call i64 @fib(i64 %0)
  %2 = sub i64 %x, 2
  %3 = call i64 @fib(i64 %2)
  %4 = add i64 %1, %3
  br label %case.end.0

case.0.0:                                         ; preds = %entry
  br label %case.end.0

case.1.0:                                         ; preds = %entry
  br label %case.end.0

case.end.0:                                       ; preds = %case.1.0, %case.0.0, %case.default.0
  %end.0 = phi i64 [ %4, %case.default.0 ], [ 0, %case.0.0 ], [ 1, %case.1.0 ]
  ret i64 %end.0
}

When I use llvm-hs-pretty, those newlines are gone:

; ModuleID = 'amy-module'


define external ccc i64 @main(){
entry:
  %0 = call ccc i64 @fib(i64 10)
  ret i64 %0
}

define private ccc i64 @fib(i64 %x){
entry:
  switch i64 %x, label %case.default.0 [i64 0, label %case.0.0 i64 1, label %case.1.0]
case.default.0:
  %1 = sub i64 %x, 1
  %2 = call ccc i64 @fib(i64 %1)
  %3 = sub i64 %x, 2
  %4 = call ccc i64 @fib(i64 %3)
  %5 = add i64 %2, %4
  br label %case.end.0
case.0.0:
  br label %case.end.0
case.1.0:
  br label %case.end.0
case.end.0:
  %end.0 = phi i64 [%5, %case.default.0], [0, %case.0.0], [1, %case.1.0]
  ret i64 %end.0
}

Do you think those newlines are nice enough to add to llvm-hs-pretty? If not, feel free to close this issue. I'm mostly just popping in with a suggestion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions