{"id":20128702,"url":"https://github.com/llvm-hs/llvm-hs-pretty","last_synced_at":"2025-04-09T17:25:54.889Z","repository":{"id":18920302,"uuid":"85577252","full_name":"llvm-hs/llvm-hs-pretty","owner":"llvm-hs","description":"Pretty printer for LLVM AST to Textual IR","archived":false,"fork":false,"pushed_at":"2022-04-24T23:23:08.000Z","size":190,"stargazers_count":68,"open_issues_count":7,"forks_count":39,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T14:07:17.461Z","etag":null,"topics":["code-generation","haskell-bindings","llvm","llvm-ast","llvm-hs","llvm-ir","pretty-printer"],"latest_commit_sha":null,"homepage":"","language":"LLVM","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/llvm-hs.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-20T13:01:32.000Z","updated_at":"2024-11-29T00:56:51.000Z","dependencies_parsed_at":"2022-08-07T09:01:01.672Z","dependency_job_id":null,"html_url":"https://github.com/llvm-hs/llvm-hs-pretty","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llvm-hs%2Fllvm-hs-pretty","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llvm-hs%2Fllvm-hs-pretty/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llvm-hs%2Fllvm-hs-pretty/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/llvm-hs%2Fllvm-hs-pretty/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/llvm-hs","download_url":"https://codeload.github.com/llvm-hs/llvm-hs-pretty/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248076025,"owners_count":21043692,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generation","haskell-bindings","llvm","llvm-ast","llvm-hs","llvm-ir","pretty-printer"],"created_at":"2024-11-13T20:28:51.214Z","updated_at":"2025-04-09T17:25:54.865Z","avatar_url":"https://github.com/llvm-hs.png","language":"LLVM","funding_links":[],"categories":[],"sub_categories":[],"readme":"llvm-hs-pretty\n--------------\n\n[![Build Status](https://travis-ci.org/llvm-hs/llvm-hs-pretty.svg)](https://travis-ci.org/llvm-hs/llvm-hs-pretty)\n[![Hackage](https://img.shields.io/hackage/v/llvm-hs-pretty.svg)](https://hackage.haskell.org/package/llvm-hs-pretty)\n\nA pretty printer for ``llvm-hs-pure``. Goal is to be able to pretty print a\nsufficiently large subset of the LLVM AST from pure Haskell without having to go\nthrough the C++ API.\n\n\u003e **Note**: It is possible to construct llvm-hs-pure ASTs that are invalid ASTs\n\u003e and as such there is no meaningful way to print them. Always run the LLVM\n\u003e verifier on your AST to test it is sound. If you encounter incomplete pattern\n\u003e matches using this library you likely have constructed invalid IR.\n\nUsage\n-----\n\nThere is a single function ``ppllvm`` that maps a LLVM.AST.Module to a Text.\n\n```haskell\nimport LLVM.AST\nimport LLVM.Pretty (ppllvm)\n\nppllvm :: Module -\u003e Text\n```\n\nIndividual LLVM elements (constants, instructions) can be printed using the\nthe polymorphic ``ppll`` function for any LLVM structure that implements the\n``PP`` typeclass.\n\nTests\n-----\n\n```bash\n# This is only necessary for running the test suite\nsudo apt-get install llvm-9-dev\n```\n\nThe test suite currently consists of round tripping a LLVM IR from correct IR\noutputted by the llc toolchain, parsing into llvm-hs AST and then printing it\nback out and comparing it with the original textual form to see if the pretty\nprinter faithfully preserves the structure. The sample modules are in\n``tests/``.\n\nUsing stack:\n\n```bash\n$ stack build\n$ stack test\n```\n\nUsing cabal:\n\n```bash\n$ cabal run\n$ cabal run -- tests/simple.ll\n```\n\nIf you're using Nix then:\n\n```bash\n$ nix-shell\n$ cabal run\n```\n\nExample\n-------\n\nTo try out the standalone example run:\n\n```bash\n$ stack repl\n$ :load Example.hs\nmain\n```\n\nConsider the basic example LLVM module.\n\n```llvm\n; ModuleID = 'example-llvm-module'\n\ndefine i8 @f(i8 %x){\nentry:\n  ret i8 %x\n}\n```\n\nUsing the LLVM.AST we construct the type and feed it to the pretty\nprinter.\n\n```haskell\nmodule Standalone where\n\n-- Pretty Printer\nimport LLVM.Pretty (ppllvm)\n\n-- AST\nimport qualified LLVM.AST as AST\nimport qualified LLVM.AST.Linkage as Linkage\nimport qualified LLVM.AST.Visibility as Visibility\nimport qualified LLVM.AST.CallingConvention as Convention\n\nimport Data.Text.Lazy.IO as TIO\n\nastModule :: AST.Module\nastModule = AST.Module\n    { AST.moduleName         = \"example-llvm-module\"\n    , AST.moduleDataLayout   = Nothing\n    , AST.moduleTargetTriple = Nothing\n    , AST.moduleDefinitions  =\n        [ AST.GlobalDefinition\n            (AST.Function\n                Linkage.External\n                Visibility.Default\n                Nothing\n                Convention.C\n                []\n                (AST.IntegerType 8)\n                (AST.Name \"f\")\n                ([AST.Parameter (AST.IntegerType 8) (AST.Name \"x\") []], False)\n                []\n                Nothing\n                Nothing\n                0\n                Nothing\n                Nothing\n                [ AST.BasicBlock\n                    (AST.Name \"entry\")\n                    []\n                    (AST.Do\n                        (AST.Ret\n                            (Just\n                                (AST.LocalReference\n                                    (AST.IntegerType 8)\n                                    (AST.Name \"x\")\n                                )\n                            )\n                            []\n                        )\n                    )\n                ]\n            )\n        ]\n    }\n\nmain :: IO ()\nmain = TIO.putStrLn (ppllvm astModule)\n```\n\nLicense\n-------\n\nReleased under the MIT License.\n\nCopyright (c) 2014-2020, Stephen Diehl\nCopyright (c) 2015 Cedric Shock\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllvm-hs%2Fllvm-hs-pretty","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fllvm-hs%2Fllvm-hs-pretty","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fllvm-hs%2Fllvm-hs-pretty/lists"}