[PATCH] D95924: [Example][NFC} Add testcase for BrainF HelloWorld

Andrzej Warzynski via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 02:43:38 PST 2021


awarzynski added a comment.

In D95924#2584281 <https://reviews.llvm.org/D95924#2584281>, @t.p.northover wrote:

> This worked for me:
>
>   [
>   ; RUN: BrainF %s -o - | llvm-dis | FileCheck --check-prefix=CHECK %s
>   ; RUN: BrainF %s -o - | lli 2>&1 | FileCheck --check-prefix=EXEC %s
>   ]
>
> Though it seems there's extra output from the CHECK lines too. It might actually be better to put the BF code in its own completely separate file (this is usually put in an `Inputs` subdirectory and referred to as `%p/Inputs/helloworld.bf` instead of the test name `%s`).

I believe that this is what we want here:

  [
  RUN: BrainF %s -o - | llvm-dis | FileCheck --check-prefix=CHECK %s
  RUN: BrainF %s -o - | lli 2>&1 | FileCheck --check-prefix=EXEC %s
  
  CHECK-LABEL:      define void @brainf() {
  CHECK-NEXT:      brainf:
  CHECK-NEXT:        %malloccall = tail call i8* @malloc(i32 mul (i32 ptrtoint (i8* getelementptr (i8, i8* null, i32 1) to i32), i32 65536))
  CHECK-NEXT:        call void @llvm.memset.p0i8.i32(i8* %malloccall, i8 0, i32 65536, i1 false)
  CHECK-NEXT:        %head = getelementptr i8, i8* %malloccall, i32 32768
  CHECK-NEXT:        %tape = load i8, i8* %head, align 1
  CHECK:             store i8 %tape2, i8* %head, align 1
  CHECK:             br label %brainf3
  CHECK:           brainf1:                                          ; preds = %brainf55
  CHECK-NEXT:        tail call void @free(i8* %malloccall)
  CHECK-NEXT:        ret void
  CHECK:       }
  CHECK-LABEL:      define i32 @main(i32 %argc, i8** %argv) {
  CHECK-NEXT:      main.0:
  CHECK-NEXT:        call void @brainf()
  CHECK-NEXT:        ret i32 0
  CHECK:       }
  
  EXEC: Hello World!
  ]
  
  ++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.

Basically, the first loop is completely ignored and can be used for input for LIT/FileCheck. This solution is inspired by the HelloWorld <https://en.wikipedia.org/wiki/Brainfuck#Hello_World!> eample from Wikipedia. Note that there is no need to use `;` or `#`, that's ignored by `BrainF` anyway.

Other points:

- I would rename the test file as e.g.` HelloWorld.bf` as this is not an LLVM IR file (so `*.ll` is a bit confusing)
- Could you add a comment that explains what that BF examples does?
- I'm using LLVM 11 and get slightly different IR (e.g. labels). It's probably worth using more regex here and focusing on the key bits a bit more.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95924/new/

https://reviews.llvm.org/D95924



More information about the llvm-commits mailing list