{"id":15400828,"url":"https://github.com/dannypsnl/racket-llvm","last_synced_at":"2025-04-15T22:31:12.511Z","repository":{"id":62424325,"uuid":"437798207","full_name":"dannypsnl/racket-llvm","owner":"dannypsnl","description":"racket llvm C-API bindings","archived":false,"fork":false,"pushed_at":"2024-12-10T13:03:30.000Z","size":480,"stargazers_count":17,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-29T03:42:34.776Z","etag":null,"topics":["compiler","llvm"],"latest_commit_sha":null,"homepage":"https://pkgs.racket-lang.org/package/racket-llvm","language":"Racket","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dannypsnl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-13T08:47:23.000Z","updated_at":"2024-09-17T15:28:05.000Z","dependencies_parsed_at":"2022-11-01T18:01:03.344Z","dependency_job_id":null,"html_url":"https://github.com/dannypsnl/racket-llvm","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/dannypsnl%2Fracket-llvm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dannypsnl%2Fracket-llvm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dannypsnl%2Fracket-llvm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dannypsnl%2Fracket-llvm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dannypsnl","download_url":"https://codeload.github.com/dannypsnl/racket-llvm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249166007,"owners_count":21223361,"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","llvm"],"created_at":"2024-10-01T15:55:05.833Z","updated_at":"2025-04-15T22:31:11.829Z","avatar_url":"https://github.com/dannypsnl.png","language":"Racket","funding_links":[],"categories":[],"sub_categories":[],"readme":"racket-llvm\n=============\n\n\u003e **Warning**\n\u003e LLVM is a big project, that's quite normal to find some missing functions/definitions in this project. Thus, you can use `define-llvm` to get missing functions, and we will give you a big thanks if you would like to port them back to the project by pull requests! To get full definitions in LLVM, look at [LLVM C-API](https://llvm.org/doxygen/dir_db1e4f1ef1b4536ff54becd23c94e664.html) for reference.\n\nA racket to LLVM C-API bindings.\n\n### Installation\n\n```shell\nraco pkg install --auto racket-llvm\n```\n\n### Usage\n\nEnsure you have `llvm-config` installed and can invoke it. You might need following command.\n\n```shell\n# export homebrew installed llvm binaries\nexport PATH=\"/opt/homebrew/opt/llvm/bin:$PATH\"\n```\n\n##### Dependencies\n\nAdd `\"racket-llvm\"` into `info.rkt`\n\n```racket\n(define deps '(\"base\" \"racket-llvm\"))\n```\n\n##### Example\n\nThe following one shows how to use **Execution Engine** to run a LLVM function and view the result.\n\n```racket\n; create module, the basic unit in LLVM IR\n(define mod (llvm-module \"test_mod\"))\n; create builder, all instructions will be created by this\n(define builder (llvm-builder-create))\n\n; add function into module\n(define sum (llvm-add-function mod \"sum\" (llvm-function-type (llvm-int32-type) (list (llvm-int32-type) (llvm-int32-type)))))\n; create basic block for function\n(define entry (llvm-append-basic-block sum))\n; shift builder insertion point to the end of the basic block\n(llvm-builder-position-at-end builder entry)\n; build `%3 = add i32 %0, %1`\n; build `ret i32 %3`\n(llvm-build-ret builder (llvm-build-add builder (llvm-get-param sum 0) (llvm-get-param sum 1)))\n\n; verify the module\n(llvm-module-verify mod)\n; print and check the content of the module\n(displayln (llvm-module-\u003estring mod))\n\n; create execution engine based on module\n(define eng (llvm-create-execution-engine-for-module mod))\n; link to mcjit\n(llvm-link-in-mcjit)\n\n; ask two integers\n(define (ask-integer)\n  (printf \"enter integer: \")\n  (read))\n(define-values (x y) (values (ask-integer) (ask-integer)))\n\n; use engine to run the function(engine will search it in the module)\n(define res (llvm-run-function eng sum\n                               (list (llvm-create-generic-value-of-int (llvm-int32-type) x #f)\n                                     (llvm-create-generic-value-of-int (llvm-int32-type) y #f))))\n; show result\n(printf \"JIT result: ~a\\n\" (llvm-generic-value-\u003eint res #f))\n```\n\n### Develop\n\nHere is an example to show how can one define a new llvm function binding via `define-llvm`.\n\n```racket\n;; our standard is converting from CamlCase to kebab-case identifier\n(define-llvm llvm-build-struct-gep2\n  ;; here is a complicated version of `_fun`, the first wrapped list are parameters\n  (_fun (builder ty pointer index [name \"\"]) ::\n        ;; the followings are type for parameters\n        (builder : _LLVMBuilderRef)\n        (ty : _LLVMTypeRef)\n        (pointer : _LLVMValueRef)\n        (index : _int)\n        (name : _string)\n        ;; final, the return type\n        -\u003e _LLVMValueRef)\n  ;; `LLVMBuildStructGEP2` is the name of function in C side\n  #:c-id LLVMBuildStructGEP2)\n```\n\nAnd you can get llvm functions list from [LLVM C-API](https://llvm.org/doxygen/dir_db1e4f1ef1b4536ff54becd23c94e664.html). To get more about the FFI in racket, reference to its [document](https://docs.racket-lang.org/foreign/index.html#%28tech._ffi%29).\n\n### Reference\n\n- [llvm doxygen](https://llvm.org/doxygen/)\n- [How to get started with the LLVM C API](https://www.pauladamsmith.com/blog/2015/01/how-to-get-started-with-llvm-c-api.html)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannypsnl%2Fracket-llvm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdannypsnl%2Fracket-llvm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdannypsnl%2Fracket-llvm/lists"}