Skip to main content

Options

Struct Options 

Source
#[non_exhaustive]
pub struct Options { pub abi: &'static Abi, pub frame_pointer: bool, pub trap_symbol: &'static str, pub gc_poll_symbol: &'static str, pub resume_symbol: &'static str, pub pow_f64_symbol: &'static str, pub pow_f32_symbol: &'static str, pub jump_table_min_cases: u32, pub jump_table_max_spread: u32, pub regalloc: Options, }
Expand description

How to compile: the platform’s C convention, frame and runtime choices, and selection and allocation settings.

The C convention (abi) serves ir-lang’s c tag and its fast tag (the backend’s own convention for code compiled together is the platform’s C convention in this release). Runtime entry points are called by name and left as relocations unless the module defines them:

SymbolCalledWith
trap_symbolfor trap and every trapping policythe OPS code (first argument); never returns
gc_poll_symbolfor a safepoint instructionnothing; a safepoint with a stack map
resume_symbolfor resumethe exception payload; never returns
pow_f64_symbolfor an f64 powthe operands’ bit patterns as two u64 integer arguments; returns the result’s bits as a u64
pow_f32_symbolfor an f32 powthe operands’ bit patterns as two u32 integer arguments; returns the result’s bits as a u32

The two pow routines must compute ir-lang’s ls_pow (OPS v2: the same bits on every tier, never a platform libm); for f32, ls_pow of both operands widened to f64, rounded once. In Rust, ir_lang::ls_pow( f64::from_bits(x), f64::from_bits(y)).to_bits(). They take bit patterns in integer registers because this release keeps floats in general-purpose registers (isa-lang 0.2 encodes no SSE).

§Examples

use backend_lang::Options;

let o = Options::sysv().with_frame_pointer(false);
assert_eq!(o.abi.name(), "sysv64");
assert!(!o.frame_pointer);
assert_eq!(Options::win64().abi.name(), "win64");

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§abi: &'static Abi

The platform’s C convention, used for the c and fast tags and for runtime calls.

§frame_pointer: bool

Whether functions keep a frame pointer (on by default). Without one, rbp is one more register for the allocator.

§trap_symbol: &'static str

The runtime’s trap handler.

§gc_poll_symbol: &'static str

The runtime’s GC poll, called by safepoint.

§resume_symbol: &'static str

The runtime’s unwinder entry, called by resume.

§pow_f64_symbol: &'static str

The runtime’s ls_pow for f64 (bit patterns in, bit pattern out).

§pow_f32_symbol: &'static str

The runtime’s ls_pow for f32 (bit patterns in, bit pattern out).

§jump_table_min_cases: u32

The fewest cases a switch needs for a jump table.

§jump_table_max_spread: u32

A jump table is used when the case values span at most this many table entries per case (3: at least a third of the entries are cases).

§regalloc: Options

Register-allocation settings.

Implementations§

Source§

impl Options

Source

pub const fn sysv() -> Options

For System V AMD64 platforms (Linux, the BSDs, macOS).

§Examples
use backend_lang::Options;

assert_eq!(Options::sysv().trap_symbol, "__lexersketch_trap");
Source

pub const fn win64() -> Options

For Windows x64.

§Examples
use backend_lang::Options;

assert_eq!(Options::win64().abi.name(), "win64");
Source

pub const fn host() -> Options

For the platform this crate is compiled for: Win64 on Windows, System V elsewhere.

§Examples
use backend_lang::Options;

let name = Options::host().abi.name();
assert!(name == "sysv64" || name == "win64");
Source

pub const fn with_abi(abi: &'static Abi) -> Options

The defaults with abi as the C convention.

§Examples
use backend_lang::Options;
use backend_lang::x86_64::WIN64;

assert_eq!(Options::with_abi(&WIN64).abi.name(), "win64");
Source

pub const fn with_frame_pointer(self, keep: bool) -> Options

Keeps or omits the frame pointer.

§Examples
use backend_lang::Options;

assert!(!Options::sysv().with_frame_pointer(false).frame_pointer);
Source

pub const fn with_runtime( self, trap: &'static str, gc_poll: &'static str, resume: &'static str, ) -> Options

Renames the runtime entry points.

§Examples
use backend_lang::Options;

let o = Options::sysv().with_runtime("my_trap", "my_poll", "my_resume");
assert_eq!(o.gc_poll_symbol, "my_poll");
Source

pub const fn with_pow_runtime( self, f64_pow: &'static str, f32_pow: &'static str, ) -> Options

Renames the runtime’s float pow routines (see Options for their contract).

§Examples
use backend_lang::Options;

let o = Options::sysv().with_pow_runtime("my_pow", "my_powf");
assert_eq!((o.pow_f64_symbol, o.pow_f32_symbol), ("my_pow", "my_powf"));
assert_eq!(Options::sysv().pow_f64_symbol, "__lexersketch_pow_f64");
Source

pub const fn with_jump_tables(self, min_cases: u32, max_spread: u32) -> Options

Sets when a switch becomes a jump table.

§Examples
use backend_lang::Options;

// Never use a jump table.
let o = Options::sysv().with_jump_tables(u32::MAX, 1);
assert_eq!(o.jump_table_min_cases, u32::MAX);
Source

pub const fn with_regalloc(self, regalloc: Options) -> Options

Sets the register-allocation settings.

§Examples
use backend_lang::{regalloc, Options};

let o = Options::sysv().with_regalloc(regalloc::Options::new().with_live_budget(1 << 20));
assert_eq!(o.regalloc.live_budget, 1 << 20);

Trait Implementations§

Source§

impl Clone for Options

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Options

Source§

impl Debug for Options

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Options

Source§

fn default() -> Options

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.