From 970e85a25c16abd6e69690d0be935e5b6854210b Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Sun, 3 Jul 2022 18:22:26 +0200 Subject: [PATCH] Add readme --- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qbe.cabal | 2 +- test/Main.hs | 6 +++++- 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..77c1dbe --- /dev/null +++ b/README.md @@ -0,0 +1,53 @@ +# qbe-hs + +[![Hackage](https://img.shields.io/hackage/v/qbe.svg)](https://hackage.haskell.org/package/qbe) +[![builds.sr.ht status](https://builds.sr.ht/~fgaz/qbe-hs/commits/master.svg)](https://builds.sr.ht/~fgaz/qbe-hs/commits/master?) + +Haskell types and prettyprinter for the [IL](https://c9x.me/compile/doc/il.html) +of the [QBE](https://c9x.me/compile/) compiler backend + +## Example + +```haskell +helloWorld :: Program +helloWorld = Program [] [helloString] [helloMain] + where + helloString = DataDef [] "str" Nothing + [ FieldExtTy Byte $ String "hello world" :| [] + , FieldExtTy Byte $ Const (CInt False 0) :| [] + ] + helloMain = FuncDef [Export] (Just $ AbiBaseTy Word) "main" + Nothing [] NoVariadic $ + Block "start" + [] + [ Call (Just ("r", AbiBaseTy Word)) (ValGlobal "puts") + Nothing + [Arg (AbiBaseTy Long) $ ValGlobal "str"] + [] + ] + (Ret $ Just $ ValConst $ CInt False 0) + :| [] +``` + +Gets rendered to + +``` +data $str = +{b "hello world", b 0} +export +function w $main () { +@start + %r =w call $puts (l $str) + ret 0 +} +``` + +## Contributing + +You can send patches to my +[public-inbox mailing list](https://lists.sr.ht/~fgaz/public-inbox) +or to any of the contacts listed at [fgaz.me/about](https://fgaz.me/about). +Or you can send a pull request to the +[GitHub mirror](https://github.com/fgaz/qbe-hs). + +Issues are tracked at https://todo.sr.ht/~fgaz/qbe-hs diff --git a/qbe.cabal b/qbe.cabal index 4168bb2..89f048f 100644 --- a/qbe.cabal +++ b/qbe.cabal @@ -19,7 +19,7 @@ copyright: 2022 Francesco Gazzetta category: Language build-type: Simple extra-doc-files: CHANGELOG.md -extra-source-files: golden/*.qbe +extra-source-files: README.md golden/*.qbe tested-with: , GHC == 8.10.7 , GHC == 9.0.2 diff --git a/test/Main.hs b/test/Main.hs index e5d7085..0691ed5 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -113,6 +113,10 @@ helloWorld = Program [] [helloString] [helloMain] Nothing [] NoVariadic $ Block "start" [] - [Call (Just ("r", AbiBaseTy Word)) (ValGlobal "puts") Nothing [Arg (AbiBaseTy Long) $ ValGlobal "str"] []] + [ Call (Just ("r", AbiBaseTy Word)) (ValGlobal "puts") + Nothing + [Arg (AbiBaseTy Long) $ ValGlobal "str"] + [] + ] (Ret $ Just $ ValConst $ CInt False 0) :| []