pr 60
This commit is contained in:
@@ -18,4 +18,9 @@ pub mod abi;
|
||||
pub mod readwrite;
|
||||
pub mod asm;
|
||||
pub mod disasm;
|
||||
pub mod v0;
|
||||
|
||||
mod model;
|
||||
mod module_linker;
|
||||
|
||||
pub use model::*;
|
||||
pub use module_linker::*;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod linker;
|
||||
|
||||
use crate::abi::SourceSpan;
|
||||
use crate::opcode::OpCode;
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
use crate::opcode::OpCode;
|
||||
use crate::v0::{BytecodeModule, ConstantPoolEntry, DebugInfo, FunctionMeta};
|
||||
use crate::{BytecodeModule, ConstantPoolEntry, DebugInfo, FunctionMeta};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@@ -8,7 +8,7 @@ pub enum LinkError {
|
||||
DuplicateExport(String),
|
||||
}
|
||||
|
||||
pub struct Linker;
|
||||
pub struct ModuleLinker;
|
||||
|
||||
/// Internal representation for linking process
|
||||
#[derive(Debug)]
|
||||
@@ -20,7 +20,7 @@ pub struct LinkedProgram {
|
||||
pub exports: HashMap<String, u32>,
|
||||
}
|
||||
|
||||
impl Linker {
|
||||
impl ModuleLinker {
|
||||
pub fn link(modules: &[BytecodeModule]) -> Result<LinkedProgram, LinkError> {
|
||||
let mut combined_code = Vec::new();
|
||||
let mut combined_functions = Vec::new();
|
||||
@@ -159,7 +159,7 @@ impl Linker {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::opcode::OpCode;
|
||||
use crate::v0::{BytecodeModule, Export, FunctionMeta, Import};
|
||||
use crate::{BytecodeModule, Export, FunctionMeta, Import};
|
||||
|
||||
#[test]
|
||||
fn test_linker_basic() {
|
||||
@@ -202,7 +202,7 @@ mod tests {
|
||||
imports: vec![],
|
||||
};
|
||||
|
||||
let result = Linker::link(&[m1, m2]).unwrap();
|
||||
let result = ModuleLinker::link(&[m1, m2]).unwrap();
|
||||
|
||||
assert_eq!(result.functions.len(), 2);
|
||||
// 'foo' is func 0, 'bar' is func 1
|
||||
@@ -225,7 +225,7 @@ mod tests {
|
||||
exports: vec![],
|
||||
imports: vec![Import { symbol: "missing".to_string(), relocation_pcs: vec![] }],
|
||||
};
|
||||
let result = Linker::link(&[m1]);
|
||||
let result = ModuleLinker::link(&[m1]);
|
||||
assert_eq!(result.unwrap_err(), LinkError::UnresolvedSymbol("missing".to_string()));
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ mod tests {
|
||||
imports: vec![],
|
||||
};
|
||||
let m2 = m1.clone();
|
||||
let result = Linker::link(&[m1, m2]);
|
||||
let result = ModuleLinker::link(&[m1, m2]);
|
||||
assert_eq!(result.unwrap_err(), LinkError::DuplicateExport("dup".to_string()));
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ mod tests {
|
||||
imports: vec![],
|
||||
};
|
||||
|
||||
let result = Linker::link(&[m1, m2]).unwrap();
|
||||
let result = ModuleLinker::link(&[m1, m2]).unwrap();
|
||||
|
||||
assert_eq!(result.constant_pool.len(), 2);
|
||||
assert_eq!(result.constant_pool[0], ConstantPoolEntry::Int32(42));
|
||||
Reference in New Issue
Block a user