assembler: great leap forwards (more like the Cultural Revolution)

This commit is contained in:
2025-06-25 03:26:50 +01:00
parent ce76820b6d
commit 9232f2ccab
10 changed files with 172 additions and 1 deletions
+69
View File
@@ -0,0 +1,69 @@
//! This module contains the definitions for a Symbol.
use uuid::Uuid;
/// A symbol is a named reference that may be resolved later to an address by a linker.
pub struct Symbol {
/// Stored cheaply instead of the name. Shall be stored in the symbol table under
/// this key.
pub id: Uuid,
pub visibility: Visibility,
pub symbol_type: SymbolType,
/// The id of the module the symbol is defined in.
module_id: Uuid,
/// Whether or not the symbol requires relocating.
pub needs_relocation: bool,
/// A list of the symbol's dependencies.
///
/// e.g.
///
/// ```dsa
/// main:
/// call another_func
///
/// another_func:
/// // Code goes here
/// ret
/// ```
///
/// Where `main` depends on `another_func`.
pub dependencies: Vec<Uuid>,
}
impl Symbol {
pub fn new(
id: Uuid,
visibility: Visibility,
symbol_type: SymbolType,
module_id: Uuid,
) -> Self {
Self {
id,
visibility,
symbol_type,
module_id,
}
}
}
#[derive(Debug, Copy, Clone)]
/// The visibility of the symbol in different object files.
pub enum Visibility {
/// 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
/// with one another.
Public,
/// Only visible within this object file. STB_LOCAL under ELF spec. Shall be used for
/// data definitions unless they are marked public.
Local,
/// STB_WEAK under the ELF spec. Potentially unused.
Weak,
}
pub enum SymbolType {
Function,
Label,
}