{"id":13994104,"url":"https://github.com/eliben/pykaleidoscope","last_synced_at":"2025-06-26T07:34:36.480Z","repository":{"id":26419561,"uuid":"29869822","full_name":"eliben/pykaleidoscope","owner":"eliben","description":"Implementation of the LLVM tutorial in Python using llvmlite","archived":false,"fork":false,"pushed_at":"2025-01-25T15:27:42.000Z","size":94,"stargazers_count":313,"open_issues_count":1,"forks_count":36,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-06-24T00:05:06.921Z","etag":null,"topics":["compiler","jit","llvm","llvmlite"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eliben.png","metadata":{"files":{"readme":"README.rst","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":"2015-01-26T16:26:46.000Z","updated_at":"2025-06-17T00:19:19.000Z","dependencies_parsed_at":"2022-07-16T00:16:13.305Z","dependency_job_id":null,"html_url":"https://github.com/eliben/pykaleidoscope","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eliben/pykaleidoscope","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fpykaleidoscope","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fpykaleidoscope/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fpykaleidoscope/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fpykaleidoscope/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eliben","download_url":"https://codeload.github.com/eliben/pykaleidoscope/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliben%2Fpykaleidoscope/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262022950,"owners_count":23246423,"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","jit","llvm","llvmlite"],"created_at":"2024-08-09T14:02:42.547Z","updated_at":"2025-06-26T07:34:36.455Z","avatar_url":"https://github.com/eliben.png","language":"Python","funding_links":[],"categories":["Python","Starchart"],"sub_categories":[],"readme":"Pykaleidoscope\n==============\n\nWhat is this?\n-------------\n\nLLVM comes with a `great tutorial \u003chttp://llvm.org/docs/tutorial/\u003e`_ that builds\na compiler for a simple language called Kaleidoscope. The compiler parses\nKaleidoscope into an AST, from which LLVM code is then generated using the LLVM\nIR building APIs. Once we have LLVM IR, it can be JITed to generate machine code\nand run it. In other words, convert your language into LLVM IR and leave the\nrest to LLVM itself (including world-class optimizations).\n\nThe tutorial is presented in several \"chapters\" that start with a simple lexer\nand build up the language step by step.\n\nThis repository contains a chapter-by-chapter translation of the LLVM tutorial\ninto Python, using the `llvmlite \u003chttps://github.com/numba/llvmlite\u003e`_ package\nthat exposes LLVM to Python.\n\nThis repository is fairly complete - the whole Kaleidoscope language is\nimplemented. The only thing missing is Chapter 9 - Adding Debug Information,\nbecause ``llvmlite`` does not yet support convenient emission of debug info.\n\nHow to use this code\n--------------------\n\nGo through the `LLVM tutorial \u003chttp://llvm.org/docs/tutorial/\u003e`_. The files in\nthis repository are named after tutorial chapters and roughly correspond to the\nC++ code presented in the tutorial. In each source file, the ``__main__``\nsection of code in the bottom is a small sample of usage, and there are also\nunit tests that check a variety of cases.\n\nTesting\n-------\n\nSome of the files have unit test classes in them. To run all unit tests::\n\n    $ python3.4 -m unittest discover -p \"*.py\"\n\nVersion of LLVM, Python and llvmlite\n------------------------------------\n\nLast tested with Python 3.4, LLVM 3.8 and top-of-tree ``llvmlite``.\n\nSetting up llvmlite\n-------------------\n\nBack in January 2015 I wrote a `blog post about setting up llvmlite\n\u003chttp://eli.thegreenplace.net/2015/building-and-using-llvmlite-a-basic-example\u003e`_,\nbut as often happens in LLVM-land, things have changed and it may no longer\nwork.\n\nThe easiest way to use llvmlite right now is to download a binary release. If\nyou can do that, save yourself the trouble and go do that. No need to read any\nfurther :-)\n\nIf you insist to build llvmlite on your own, you'll need LLVM. The easiest way\nto get LLVM is to grab a binary release from http://llvm.org/releases/. Be sure\nto grab a release that llvmlite works with (llvmlite has a correspondence of\nversions with the LLVMs supported).\n\nWhen building llvmlite you'll have to pass in some flags to the ``Makefile``\nthat gets invoked by the Python setup process:\n\n.. sourcecode:: shell\n\n  $ CXX_FLTO_FLAGS= LD_FLTO_FLAGS= \\\n    CXX=\u003cpath/to/clang++\u003e LLVM_CONFIG=\u003cpath/to/llvm-config\u003e \\\n    python3.4 setup.py build\n\nWhere ``path/to`` points to the binaries within the ``bin`` directory of the\nuntarred LLVM binary release. The reasons for this complication are:\n\n1. Recent versions of Clang are built with themselves (bootstrapped), and\n   ``llvm-config`` may have some compiler flags gcc doesn't support, so\n   compiling with gcc won't work. We therefore use the same compiler that\n   LLVM/Clang was built with to build llvmlite.\n2. Clang binary builds don't support LTO, and llvmlite's ``Makefile`` passes\n   ``-flto`` when compiling. The ``*_FLTO_FLAGS`` settings are made to avoid\n   that.\n\nNote that these directions work at the time of writing (last updated: Nov 21,\n2016) and may change with new versions of LLVM and/or llvmlite. I'll try to keep\nup but feel free to open issues if anything needs to be done differently.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliben%2Fpykaleidoscope","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feliben%2Fpykaleidoscope","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliben%2Fpykaleidoscope/lists"}