Skip to content

Empty Basic Blocks #17

@nwtgck

Description

@nwtgck

Hi, developers of llvm-hs-quote.

Environment

llvm-hs-quote: 1497273
stack solver: lts-10.3 (this is the same as llvm-hs-quote)

Proposal

Allow library users to use $bbs with empty [BasicBlock].

My concern

module11 [bBlock] has no error in the following code. However, module11 [] has a runtime error.

module11 :: [AST.Global.BasicBlock] -> AST.Module
module11 basicBlocks = [Quote.LLVM.llmod|
  define void @myfunc(i32 %a, i32 %b) {
    $bbs:basicBlocks
    ret void
  }
|]

runtime error message

Pattern match failure in do expression at ...

To avoid the empty-list problem, I should write the following. In the code, betterModule11 [] has no error, but it is redundant.

betterModule11 :: [AST.Global.BasicBlock] -> AST.Module
betterModule11 basicBlocks =
  if Prelude.null basicBlocks
    then
      [Quote.LLVM.llmod|
        define void @myfunc(i32 %a, i32 %b) {
          ret void
        }
      |]
    else
      [Quote.LLVM.llmod|
        define void @myfunc(i32 %a, i32 %b) {
          $bbs:basicBlocks
          ret void
        }
      |]

The code is just an example. In actual program using this library, allowing empty list is more convenient. I was wondering whether you allow to us use $bbs with empty [BasicBlock].

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