{"id":13546514,"url":"https://github.com/sam46/Paskell","last_synced_at":"2025-04-02T18:30:57.267Z","repository":{"id":45163946,"uuid":"140153941","full_name":"sam46/Paskell","owner":"sam46","description":"A Pascal to LLVM compiler in Haskell ","archived":false,"fork":false,"pushed_at":"2019-11-01T22:14:37.000Z","size":443,"stargazers_count":126,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-03T14:35:56.343Z","etag":null,"topics":["compiler","haskell","llvm","llvm-hs","parsec","pascal"],"latest_commit_sha":null,"homepage":"","language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sam46.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-07-08T09:23:24.000Z","updated_at":"2024-08-10T00:33:05.000Z","dependencies_parsed_at":"2022-08-26T10:11:13.731Z","dependency_job_id":null,"html_url":"https://github.com/sam46/Paskell","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam46%2FPaskell","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam46%2FPaskell/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam46%2FPaskell/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sam46%2FPaskell/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sam46","download_url":"https://codeload.github.com/sam46/Paskell/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246869698,"owners_count":20847177,"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":["compiler","haskell","llvm","llvm-hs","parsec","pascal"],"created_at":"2024-08-01T12:00:39.240Z","updated_at":"2025-04-02T18:30:57.025Z","avatar_url":"https://github.com/sam46.png","language":"Haskell","readme":"# Paskell\n[![Build Status](https://travis-ci.org/sam46/Paskell.svg?branch=master)](https://travis-ci.org/sam46/Paskell)\nA (reduced) Pascal compiler in Haskell that compiles to LLVM\n\n- [Paskell](#paskell)\n    + [Features](#features)\n    + [Progress](#progress)\n    + [Usage](#usage)\n    + [Demo](#demo)\n    + [Building](#building)\n        * [With docker](#with-docker)\n        * [Without docker](#without-docker)\n    + [Tests](#tests)\n    + [Implementation](#implementation)\n    + [TODO](#todo)\n    + [Contributions](#contributions)\n    + [References](#references)\n  \n### Features   \n- Declarations: var, type (aliases)\n- Types: integer, boolean, string, char, real\n- Control Flow: if, while, for    \n- Functions/Procedures \n- Pass by reference\n- Basic Typecasting\n- Nested Functions/Procedures (Not finished yet) \n- I/O: Write/Writeln\n\n### Progress  \n- [x] Lexing/Parsing \n- [x] Semantic Analysis/Type-Checking\n- [x] Type-Annotated IR AST\n- [x] IR pretty-printer\n- [x] LLVM Code generation \n\n### Usage\nOnce the executable is built, it can be used to compile Pascal source files to llvm-ir, or internal IR used by the compiler:  \n\n  `paskell -c src`      compile to llvm-ir  \n  `paskell -c src dest` compile to llvm-ir and save in dest  \n  `paskell -ir src`     produce internal IR   \n  `paskell -x src`      execute pascal source. Equivalent to \n                        `paskell -c src | lli`  \n  `paskell -h`          (for help)  \n  \n### Demo:\nThe compiler is complemented with the `llvm` utilities \n```\n$ paskell -c fib.pas fib.ll\n```\n\n Since the output is llvm-ir, we can leverage the many tools LLVM provide to:\n - execute it using the llvm interpreter  \n    `$ lli fib.ll`\n - convert it to bitcode llvm assembly (.bc)  \n    `$ llvm-as fib.ll -o fib.bc`\n - optimize the code using various settings, for example  \n    `$ opt -mem2reg fib.bc` \n - translate it to a native assembly executable of a specific architecture (x86, ARM, etc)  \n   `$ llc -march=x86-64 fib.bc -o fib.s`\n - link many modules into one program \n\n### Building\n\n##### With docker\n```\n$ make bash\n```\nto build the compiler and launch a shell session where the compiler and llvm utitlies are in `$PATH` and ready out-of-the-box.\n\n###### Alternatively\n```\n$ make build\n```\nwill build the same image tagged `paskell`\nwhich can be used with `docker run` and volumes.\nFor example:\n```\n$ docker run -v /path/to/original_file.pas:/path/to/file.pas paskell paskell -c /path/to/file.pas\n```\n\n##### Without docker\nYou need to have llvm installed\n```\n$ sudo apt-get install llvm-5.0\n```\n`lli` should be in `$PATH` to be able to execute Pascal programs\n\nThen, you can use Cabal or Stack.  \nTo build using Cabal:\n\n```\n$ cd Paskell/\n$ cabal install -j\n```\nthis will install all dependencies and produce an executable in \n`dist/build/Paskell/`\n  \nYou can also build using Stack.\n\n### Tests\n```\n$ make test\n```\nto run the test suite using docker.\n\n### Implementation\nThis is a 4-pass compiler:  \n\n**pass 1**: lex/parsing  \n**pass 2**: type checking  \n**pass 3**: constructing IR: type-annotation, type resolution, (future: identifier-renaming, nested-function extraction)  \n**pass 4**: code generation  \n  \n### TODO\n- finish nested functions/procedures:  \n  this only requires pulling nested functions to global scope  \n  and renaming them during the type-annotation pass\n- constants: trivial to implement\n- Read/Readln IO statements\n- records\n- arrays\n- case statements\n- forward declaration\n  \n### Contributions    \nBug reports, added features, etc are welcome  \n\n### References\n- [Language grammar](http://courses.washington.edu/css448/zander/Project/grammar.pdf)\n- Stephen Diehl's Haskell [llvm-tutorial](http://www.stephendiehl.com/llvm/)\n","funding_links":[],"categories":["Haskell"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsam46%2FPaskell","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsam46%2FPaskell","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsam46%2FPaskell/lists"}