assembler: apply clippy lints
This commit is contained in:
@@ -11,8 +11,14 @@ pub struct AssemblerContext {
|
|||||||
pub module_registry: RwLock<ModuleRegistry>,
|
pub module_registry: RwLock<ModuleRegistry>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for AssemblerContext {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AssemblerContext {
|
impl AssemblerContext {
|
||||||
pub fn new() -> Self {
|
#[must_use] pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
symbol_table: RwLock::new(SymbolTable::new()),
|
symbol_table: RwLock::new(SymbolTable::new()),
|
||||||
module_registry: RwLock::new(ModuleRegistry::new()),
|
module_registry: RwLock::new(ModuleRegistry::new()),
|
||||||
|
|||||||
@@ -15,22 +15,21 @@ use crate::model::module_registry::ModuleRegistry;
|
|||||||
pub struct ModuleId(Uuid);
|
pub struct ModuleId(Uuid);
|
||||||
|
|
||||||
impl ModuleId {
|
impl ModuleId {
|
||||||
pub fn from_module(module: Module) -> Self {
|
#[must_use]
|
||||||
|
pub const fn from_module(module: &Module) -> Self {
|
||||||
module.id
|
module.id
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to get the [`Module`] from a [`ModuleId`].
|
/// Convenience method to get the [`Module`] from a [`ModuleId`].
|
||||||
|
#[must_use]
|
||||||
pub fn to_module<'m>(&self, registry: &'m ModuleRegistry) -> Option<&'m Module> {
|
pub fn to_module<'m>(&self, registry: &'m ModuleRegistry) -> Option<&'m Module> {
|
||||||
registry.get(self)
|
registry.get(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to get the [`Module`] name from a [`ModuleId`].
|
/// Convenience method to get the [`Module`] name from a [`ModuleId`].
|
||||||
pub fn to_module_name<'m>(self, registry: &'m ModuleRegistry) -> Option<&'m str> {
|
#[must_use]
|
||||||
if let Some(module) = self.to_module(®istry) {
|
pub fn to_module_name(self, registry: &ModuleRegistry) -> Option<&str> {
|
||||||
Some(module.name.as_str())
|
self.to_module(registry).map(|module| module.name.as_str())
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,15 +10,21 @@ pub struct ModuleRegistry {
|
|||||||
modules: HashMap<ModuleId, Module>,
|
modules: HashMap<ModuleId, Module>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for ModuleRegistry {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ModuleRegistry {
|
impl ModuleRegistry {
|
||||||
pub fn new() -> Self {
|
#[must_use] pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
modules: HashMap::new(),
|
modules: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets a [`Module`] by ID.
|
/// Gets a [`Module`] by ID.
|
||||||
pub fn get(&self, module_id: &ModuleId) -> Option<&Module> {
|
#[must_use] pub fn get(&self, module_id: &ModuleId) -> Option<&Module> {
|
||||||
self.modules.get(module_id)
|
self.modules.get(module_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,23 +16,28 @@ impl From<Symbol> for SymbolId {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for SymbolId {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl SymbolId {
|
impl SymbolId {
|
||||||
|
#[must_use]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self(Uuid::new_v4())
|
Self(Uuid::new_v4())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to get the [`Module`] from a [`ModuleId`].
|
/// Convenience method to get the [`Module`] from a [`ModuleId`].
|
||||||
|
#[must_use]
|
||||||
pub fn to_module<'s>(&self, registry: &'s SymbolTable) -> Option<&'s Symbol> {
|
pub fn to_module<'s>(&self, registry: &'s SymbolTable) -> Option<&'s Symbol> {
|
||||||
registry.get(self)
|
registry.get(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience method to get the [`Module`] name from a [`ModuleId`].
|
/// Convenience method to get the [`Module`] name from a [`ModuleId`].
|
||||||
pub fn to_module_name<'m>(self, registry: &'m SymbolTable) -> Option<&'m str> {
|
#[must_use]
|
||||||
if let Some(module) = self.to_module(®istry) {
|
pub fn to_module_name(self, registry: &SymbolTable) -> Option<&str> {
|
||||||
Some(module.name.as_str())
|
self.to_module(registry).map(|module| module.name.as_str())
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,6 +87,7 @@ pub struct Symbol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Symbol {
|
impl Symbol {
|
||||||
|
#[must_use]
|
||||||
pub fn new(
|
pub fn new(
|
||||||
name: String,
|
name: String,
|
||||||
module_id: ModuleId,
|
module_id: ModuleId,
|
||||||
@@ -123,6 +129,7 @@ impl Symbol {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns whether a [`Symbol`] depends on `symbol_id`.
|
/// Returns whether a [`Symbol`] depends on `symbol_id`.
|
||||||
|
#[must_use]
|
||||||
pub fn depends_on(&self, symbol_id: &SymbolId) -> bool {
|
pub fn depends_on(&self, symbol_id: &SymbolId) -> bool {
|
||||||
self.dependencies.contains(symbol_id)
|
self.dependencies.contains(symbol_id)
|
||||||
}
|
}
|
||||||
@@ -140,14 +147,14 @@ impl Symbol {
|
|||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
/// The visibility of the symbol in different object files.
|
/// The visibility of the symbol in different object files.
|
||||||
pub enum Visibility {
|
pub enum Visibility {
|
||||||
/// STB_PUBLIC under the ELF spec. Visible in all other object files. Shall be used
|
/// `STB_PUBLIC` under the ELF spec. Visible in all other object files. Shall be used
|
||||||
/// for labels. Remember labels are namespaced in different files so they won't clash
|
/// for labels. Remember labels are namespaced in different files so they won't clash
|
||||||
/// with one another.
|
/// with one another.
|
||||||
Public,
|
Public,
|
||||||
/// Only visible within this object file. STB_LOCAL under ELF spec. Shall be used for
|
/// Only visible within this object file. `STB_LOCAL` under ELF spec. Shall be used
|
||||||
/// data definitions unless they are marked public.
|
/// for data definitions unless they are marked public.
|
||||||
Local,
|
Local,
|
||||||
/// STB_WEAK under the ELF spec. Potentially unused.
|
/// `STB_WEAK` under the ELF spec. Potentially unused.
|
||||||
Weak,
|
Weak,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,19 +63,19 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the [`Symbol`] by its [`SymbolId`].
|
/// Gets the [`Symbol`] by its [`SymbolId`].
|
||||||
pub fn get(&self, id: &SymbolId) -> Option<&Symbol> {
|
#[must_use] pub fn get(&self, id: &SymbolId) -> Option<&Symbol> {
|
||||||
self.symbols.get(id)
|
self.symbols.get(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the [`Symbol`] by its name.
|
/// Gets the [`Symbol`] by its name.
|
||||||
pub fn get_by_name(&self, name: &str) -> Option<&Symbol> {
|
#[must_use] pub fn get_by_name(&self, name: &str) -> Option<&Symbol> {
|
||||||
self.name_to_id
|
self.name_to_id
|
||||||
.get(name)
|
.get(name)
|
||||||
.and_then(|id| self.symbols.get(id))
|
.and_then(|id| self.symbols.get(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all [`Symbol`]s in a module.
|
/// Gets all [`Symbol`]s in a module.
|
||||||
pub fn get_module_symbols(&self, module_id: &ModuleId) -> Vec<&Symbol> {
|
#[must_use] pub fn get_module_symbols(&self, module_id: &ModuleId) -> Vec<&Symbol> {
|
||||||
self.module_symbols
|
self.module_symbols
|
||||||
.get(module_id)
|
.get(module_id)
|
||||||
.map(|ids| ids.iter().filter_map(|id| self.symbols.get(id)).collect())
|
.map(|ids| ids.iter().filter_map(|id| self.symbols.get(id)).collect())
|
||||||
@@ -83,7 +83,7 @@ impl SymbolTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Gets all the public symbols.
|
/// Gets all the public symbols.
|
||||||
pub fn get_public_symbols(&self) -> Vec<&Symbol> {
|
#[must_use] pub fn get_public_symbols(&self) -> Vec<&Symbol> {
|
||||||
self.symbols
|
self.symbols
|
||||||
.values()
|
.values()
|
||||||
.filter(|sym| matches!(sym.visibility, Visibility::Public))
|
.filter(|sym| matches!(sym.visibility, Visibility::Public))
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use crate::emulator::{
|
|||||||
ui::interface::Component,
|
ui::interface::Component,
|
||||||
};
|
};
|
||||||
|
|
||||||
use assembler::prelude::*;
|
// use assembler::prelude::*;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Editor {
|
pub struct Editor {
|
||||||
|
|||||||
Reference in New Issue
Block a user