refactor(ir): use u64 directly instead of spans for instructions
This commit is contained in:
parent
3e3f1aca7a
commit
5464ba6aa8
3 changed files with 10 additions and 46 deletions
|
@ -6,10 +6,8 @@
|
|||
//!
|
||||
//! Instead, this module offers an alternative way to refer to specific instances:
|
||||
//!
|
||||
//! - [`Instruction`]s are referred to as their **byte [`Span`]s** in the source code,
|
||||
//! so effectively where they are written in the source code.
|
||||
//! (Or if coming from [`crate::semi_human::GraphIr`],
|
||||
//! it's just a fictional number floating in space.)
|
||||
//! - [`Instruction`]s are effectively just a number floating in space,
|
||||
//! incremented each time a new instruction is referred to.
|
||||
//! - [`Socket`]s contain
|
||||
//! - what [`Instruction`] they belong to
|
||||
//! - which index they occupy on it
|
||||
|
@ -19,22 +17,12 @@
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::Span;
|
||||
|
||||
/// One specific instruction, and where it is found in code.
|
||||
/// One specific instruction.
|
||||
///
|
||||
/// It does **not** contain what kind of instruction this is.
|
||||
/// Refer to [`crate::instruction::Kind`] for this instead.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
pub struct Instruction(pub(super) Span);
|
||||
|
||||
impl Instruction {
|
||||
/// Where this instruction is written down.
|
||||
#[must_use]
|
||||
pub fn span(&self) -> &Span {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
pub struct Instruction(pub(super) u64);
|
||||
|
||||
/// On an **instruction**, accepts incoming data.
|
||||
///
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::{num::NonZeroUsize, ops::RangeInclusive};
|
||||
use std::num::NonZeroUsize;
|
||||
|
||||
use instruction::SocketCount;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -268,26 +268,6 @@ impl<'ir> Instruction<'ir> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Some part referred to in source code.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
|
||||
pub struct Span {
|
||||
// would love to use an actual [`std::ops::RangeInclusive`], but those don't implement
|
||||
// `PartialOrd` and `Ord` unfortunately
|
||||
/// At which byte this span starts, inclusively.
|
||||
pub from: usize,
|
||||
/// At which byte this span ends, inclusively.
|
||||
pub to: usize,
|
||||
}
|
||||
|
||||
impl From<RangeInclusive<usize>> for Span {
|
||||
fn from(range: RangeInclusive<usize>) -> Self {
|
||||
Self {
|
||||
from: *range.start(),
|
||||
to: *range.end(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Constructs an [`id::Socket`] a bit more tersely.
|
||||
fn socket(id: &id::Instruction, idx: u16) -> id::Socket {
|
||||
id::Socket {
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{id, instruction, Map, Set, Span};
|
||||
use crate::{id, instruction, Map, Set};
|
||||
|
||||
/// Semi-human-{read,writ}able [`crate::GraphIr`] with far less useful types.
|
||||
///
|
||||
|
@ -19,8 +19,7 @@ use crate::{id, instruction, Map, Set, Span};
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
|
||||
pub struct GraphIr {
|
||||
/// See [`crate::GraphIr::instructions`], just that a simple number is used for the ID instead
|
||||
/// of a proper span.
|
||||
pub(crate) instructions: Map<usize, instruction::Kind>,
|
||||
pub(crate) instructions: Map<u64, instruction::Kind>,
|
||||
/// See [`crate::GraphIr::edges`], the forward edges.
|
||||
/// RON wants you to type the set as if it were a list.
|
||||
pub(crate) edges: Map<Socket, Set<Socket>>,
|
||||
|
@ -29,17 +28,14 @@ pub struct GraphIr {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
|
||||
pub struct Socket {
|
||||
/// ID of the instruction this socket is on.
|
||||
pub(crate) on: usize,
|
||||
pub(crate) on: u64,
|
||||
pub(crate) idx: u16,
|
||||
}
|
||||
|
||||
impl From<Socket> for id::Socket {
|
||||
fn from(source: Socket) -> Self {
|
||||
Self {
|
||||
belongs_to: (id::Instruction(Span {
|
||||
from: source.on,
|
||||
to: source.on,
|
||||
})),
|
||||
belongs_to: id::Instruction(source.on),
|
||||
idx: id::SocketIdx(source.idx),
|
||||
}
|
||||
}
|
||||
|
@ -52,7 +48,7 @@ impl From<GraphIr> for crate::GraphIr {
|
|||
instructions: source
|
||||
.instructions
|
||||
.into_iter()
|
||||
.map(|(id, kind)| (id::Instruction(Span { from: id, to: id }), kind))
|
||||
.map(|(id, kind)| (id::Instruction(id), kind))
|
||||
.collect(),
|
||||
edges: type_edges(source.edges),
|
||||
rev_edges: reverse_and_type_edges(edges),
|
||||
|
|
Loading…
Reference in a new issue