sway_ir/
lib.rs

1//! Sway-IR is a library providing an intermediate representation for the
2//! [Sway](https://github.com/FuelLabs/sway) compiler pipeline.
3//!
4//! It is inspired heavily by [LLVM](https://llvm.org/docs/LangRef.html) although it aims to remain
5//! a much simpler system, providing only that which is required by Sway to target the Fuel virtual
6//! machine.  It takes the form of a
7//! [static single assignment](https://en.wikipedia.org/wiki/Static_single_assignment_form) graph
8//! and is designed primarily to allow executable code optimization transforms powerful, yet remain
9//! relatively simple.
10//!
11//! The core data type is [`Context`] which contains all the IR state in an entity-component style
12//! system.  A [`Context`] contains one or more [`Module`]s, which in turn contain one or more
13//! [`Function`]s. [`Function`]s have a set of arguments, contain a collection of local variables
14//! and one or more [`Block`]s.  [`Block`]s contain lists of [`Instruction`]s and may be joined as a
15//! graph to represent program control flow.
16//!
17//! Other important data types are [`Value`], [`Type`] and [`Constant`].  Function arguments, local
18//! variables, instructions and constants are all [`Value`]s.
19//!
20//! The optimization passes are found in the [optimize] module.
21//!
22//! # Note:
23//!
24//! Most of the public data types used in this library are in fact wrappers around a handle into
25//! the context.  The context uses the
26//! [slotmap](https://github.com/orlp/slotmap) crate to maintain an entity
27//! component system, or ECS.
28//!
29//! The nature of SSA is that it represents a graph of modules, functions, basic blocks and
30//! instructions, which in Rust could be represented using references, [`Box`]es or [`std::rc::Rc`]
31//! pointers.  But the nature of optimization passes are to transform these graphs into generally
32//! smaller or at least somehow more efficient versions of themselves, and so to avoid a lot of
33//! copying and the interior mutability problem Sway-IR uses the ECS.  Each handle implements
34//! [`Copy`] and so is cheap to pass around by value, making changes to the ECS context simpler in
35//! terms of satisfying the Rust borrow checker.
36
37// For now it's easiest to just export absolutely everything to core_lang, we can refine the public
38// API when it's closer to finished.
39
40pub mod analysis;
41pub use analysis::*;
42pub mod asm;
43pub use asm::*;
44pub mod block;
45pub use block::*;
46pub mod constant;
47pub use constant::*;
48pub mod context;
49pub use context::*;
50pub mod error;
51pub use error::*;
52pub mod function;
53pub use function::*;
54pub mod instruction;
55pub use instruction::*;
56pub mod irtype;
57pub use irtype::*;
58pub mod metadata;
59pub use metadata::*;
60pub mod module;
61pub use module::*;
62pub mod optimize;
63pub use optimize::*;
64pub mod parser;
65pub use parser::*;
66pub mod variable;
67pub use variable::*;
68pub mod pass_manager;
69pub use pass_manager::*;
70pub mod pretty;
71pub use pretty::*;
72pub mod printer;
73pub use printer::*;
74pub mod value;
75pub use value::*;
76pub mod verify;
77pub use verify::*;