Skip to content

theseus-rs/stratum

Repository files navigation

stratum

ci Documentation Code Coverage Latest version License Semantic Versioning

Experimental, multi-language compiler tools built around a unified intermediate representation. Stratum is designed so that several source languages can converge on a single, language-neutral High-level Intermediate Representation (HIR), after which the middle- and back-ends never need to know which language the code came from.

Pipeline

The long-term target is the full lowering chain:

Source ↔ HIR ↔ MIR (SSA + CFG) ↔ LIR (roles + layout) ↔ ASM ↔ OIR ↔ Binary

This repository currently implements the frontend convergence point and the binary end of the chain: shared infrastructure, the shared HIR, a dialect-aware C frontend that lowers into HIR, and a format-neutral Object Intermediate Representation (OIR) with symmetric read/write codecs for ELF, Mach-O, PE/COFF, WebAssembly, DWARF, CodeView, and PDB/MSF. The OIR crate is stratum_oir in ir/oir/; format codecs live under be/object/, and stratum_object_driver in be/object/driver/ provides magic-byte sniffing plus read/write dispatch. The frontend accepts C89/C90, C99, C11, C17/C18, and C23 modes; the C89/C99 surface has the most complete structure-preserving HIR coverage, while selected C11/C23 constructs are parsed and carried through the current representation. The intermediate MIR / LIR / ASM stages are intentionally deferred.

   C source
      |
      v
+-------------+   pp-tokens   +------------------+   pp-tokens
|  c-lexer    | ------------> |  c-preprocessor  | ------------+
+-------------+               +------------------+             |
                                                               v
                                                     +------------------+  tokens
                                                     | finalize (parser)|
                                                     +------------------+
                                                               |
                                                               v
                                +----------+   C AST   +------------------+
                                |  c-ast   | <-------- |     c-parser     |
                                +----+-----+           +------------------+
                                     |
                         +-----------+-----------+
                         |                       |
                         v                       v
                   +-------------+          +----------+
                   | c-sema      |          | c-bridge |
                   | diagnostics |          +----+-----+
                   +-------------+               |  HirBridge
                                                 v
                                          +-------------+
                                          |     hir     |  (language-neutral)
                                          +-------------+

The binary end mirrors the frontend: source/HIR provenance and emitted code converge on the format-neutral Object Intermediate Representation (OIR). Object containers are symmetric codecs behind a single OirBridge trait (read parses bytes into an ObjectModule, write serializes an ObjectModule back to bytes); debug codecs adapt the DebugInfo embedded in OIR. The stratum_object_driver sniffs magic bytes and dispatches to the matching object codec.

   HIR / Source provenance                emitted code + target facts
  (FunctionRecord, LineRecord)        (sections, symbols, relocations,
              |                         segments, imports/exports, entry)
              |                                       |
              +-------------------+   +---------------+
                                  v   v
                          +-----------------------+
                          |          oir          |  format-neutral model
                          | ObjectModule + arenas |  + OirBridge trait
                          +-----------+-----------+
                                      |
                   object codecs use OirBridge; debug codecs use DebugInfo adapters
                                      |
   +---------------+---------------+--+------------+---------------+-------------+-------+
   v               v               v               v               v             v       v
+-------+      +--------+      +-------+       +--------+      +-------+    +----------+ +-----+
|  elf  |      | macho  |      |  pe   |       |  wasm  |      | dwarf |    | codeview | | pdb |
+---+---+      +---+----+      +---+---+       +---+----+      +---+---+    +-----+----+ +--+--+
    |              |               |               |               |              |        |
 ELF32/64      32/64-bit       PE32/PE32+      standard +    .debug_* DIEs    C13 line +  MSF7
 LE/BE         load cmds       data dirs       custom name   + line program   symbol      streams
 e_machine     ad-hoc sign     imports/exp     wasm32-wasi   (provenance)     subsecs     + RSDS id
    |              |               |               |
    +--------------+------+--------+---------------+
                          v
              +-----------------------+
              | stratum_object_driver |  magic-byte sniff + read/write dispatch
              +-----------------------+

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

About

Experimental language tools

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages