Allocating Heap with Cranelift

This page summarizes the projects mentioned and recommended in the original post on /r/rust

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • cranelift-jit-demo

    JIT compiler and runtime for a toy language, using Cranelift

  • I'm working on a small stack-based programming language. I'm currently at a stage where I'm trying to compile it using Cranelift. Altrough the Cranelift documentation is extensive, I'm lacking a broader picture on how to approach some things like heap-allocations and stack-management. The only example project I found are cranelift-jit-demo and this wonderful post.

  • wasmtime

    A fast and secure runtime for WebAssembly

  • So, does someone know how to allocate memory on the heap using Cranelift? I've seen instructions like heap_addr, heap_load and heap_store so there should be some way (altrough I don't understand why we can't use the normal load and store here..). create_heap would be my best guess, but it takes a HeapData which confuses me. Dafuq is an index_type, HeapStyle and offset_guard_size? How do I get a GlobalValue for it? How do I free it? Or maybe I should just use C's malloc/free instead... On the other hand direct support for heaps seems to be removed? Sigh. I'm confused.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • stack2ssa

    Simple implementation of stack to SSA IR lowering

  • And I need heap-allocations anyway for storing larger objects. Thx for the stack2ssa tip, found thisand it seems interesting..

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts