Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to pretty print functions #12

Closed
jaseemabid opened this issue Jun 9, 2017 · 5 comments
Closed

Unable to pretty print functions #12

jaseemabid opened this issue Jun 9, 2017 · 5 comments

Comments

@jaseemabid
Copy link

@jaseemabid jaseemabid commented Jun 9, 2017

Found this module failing with a pattern match error even though I can compile it just fine.

*** Exception: src/LLVM/Pretty.hs:485:7-66: Irrefutable pattern failed for pattern functionType@(FunctionType {..})
Module
{ moduleName = "calc"
, moduleSourceFileName = "<string>"
, moduleDataLayout = Nothing
, moduleTargetTriple = Nothing
, moduleDefinitions =
      [ GlobalDefinition
            (Function
             { linkage = External
             , visibility = Default
             , dllStorageClass = Nothing
             , callingConvention = C
             , returnAttributes = []
             , returnType = IntegerType {typeBits = 64}
             , name = Name "a"
             , parameters =
                   ( [Parameter (IntegerType {typeBits = 64}) (Name "x") []]
                   , False)
             , functionAttributes = []
             , section = Nothing
             , comdat = Nothing
             , alignment = 0
             , garbageCollectorName = Nothing
             , prefix = Nothing
             , basicBlocks =
                   [ BasicBlock
                         (Name "entry")
                         []
                         (Do
                              (Ret
                               { returnOperand =
                                     Just
                                         (LocalReference
                                              (IntegerType {typeBits = 64})
                                              (Name "x"))
                               , metadata' = []
                               }))
                   ]
             , personalityFunction = Nothing
             })
      , GlobalDefinition
            (Function
             { linkage = External
             , visibility = Default
             , dllStorageClass = Nothing
             , callingConvention = C
             , returnAttributes = []
             , returnType = IntegerType {typeBits = 64}
             , name = Name "main"
             , parameters =
                   ( [Parameter (IntegerType {typeBits = 64}) (Name "argv") []]
                   , False)
             , functionAttributes = []
             , section = Nothing
             , comdat = Nothing
             , alignment = 0
             , garbageCollectorName = Nothing
             , prefix = Nothing
             , basicBlocks =
                   [ BasicBlock
                         (Name "entry")
                         [ UnName 0 :=
                           Call
                           { tailCallKind = Nothing
                           , callingConvention = C
                           , returnAttributes = []
                           , function =
                                 Right
                                     (ConstantOperand
                                          (GlobalReference
                                               (IntegerType {typeBits = 64})
                                               (Name "a")))
                           , arguments =
                                 [ ( ConstantOperand
                                         (Int
                                          {integerBits = 64, integerValue = 4})
                                   , [])
                                 ]
                           , functionAttributes = []
                           , metadata = []
                           }
                         ]
                         (Do
                              (Ret
                               { returnOperand =
                                     Just
                                         (LocalReference
                                              (IntegerType {typeBits = 64})
                                              (UnName 0))
                               , metadata' = []
                               }))
                   ]
             , personalityFunction = Nothing
             })
      ]
}
@sdiehl
Copy link
Member

@sdiehl sdiehl commented Jun 11, 2017

Run the AST through the C++ bindings to verify that it's well-formed. It seems like it's trying to call something that isn't a function.

@jaseemabid
Copy link
Author

@jaseemabid jaseemabid commented Jun 13, 2017

@sdiehl So I'm mainly using this library to print malformed ASTs (which is also why I'm running into way too many troubles). The LLVM.AST.Module exposed by llvm-hs library is not type safe and often I ended up creating malformed modules. I'm using this library to figure out what went wrong in the intermediate module.

What should this library do with respect to malformed ASTs? Do a best approach to not crash or just error out?

@sdiehl
Copy link
Member

@sdiehl sdiehl commented Jun 14, 2017

I would strongly advise you not to depend on the stability of this library at the moment. The reason it's not on Hackage at the moment is that we're still actively working on it I don't consider it done or stable.

@sdiehl
Copy link
Member

@sdiehl sdiehl commented Jun 14, 2017

If you're constructing malformed ASTs this library isn't going to be able to produce semantically meaningful pretty-printed IR because there is no mapping (nor could there be). Run your ASTs through the verifier pass and LLVM should be able to tell you the line number and instruction in your IR where the problem is.

If you're adventurous there is a typed AST prototype llvm-hs-typed that can possibly prevent malformed LLVM by construction. But mapping between the LLVM type system and Haskell type system is complex and this library is still very early as well.

@sdiehl
Copy link
Member

@sdiehl sdiehl commented Jun 25, 2017

Going to close this issue as "won't fix". The ability to print malformed IR isn't on the roadmap this project.

@sdiehl sdiehl closed this Jun 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants