Scan and print sections - prepare for SymbolTable
This commit is contained in:
parent
59472a3f31
commit
2ab4e8b155
|
@ -7,17 +7,32 @@ pub fn scan<F: FnMut() -> Option<String>>(mut next_line: F) -> Result<MemoryMap,
|
|||
const SECTION_IDENTIFIER:&'static str = "Sections:";
|
||||
const SYMBOL_TABLE_IDENTIFIER:&'static str = "SYMBOL TABLE:";
|
||||
|
||||
while let Some(line) = next_line() {
|
||||
if line == SECTION_IDENTIFIER {
|
||||
scan_sections(&mut next_line)?;
|
||||
}
|
||||
let mut memory_map = MemoryMap::default();
|
||||
|
||||
if line == SYMBOL_TABLE_IDENTIFIER {}
|
||||
while let Some(mut line) = next_line() {
|
||||
loop {
|
||||
// loop so we pick-up changes of line
|
||||
if line == SECTION_IDENTIFIER {
|
||||
line = scan_sections(&mut next_line, &mut memory_map.sections)?;
|
||||
continue;
|
||||
}
|
||||
|
||||
if line == SYMBOL_TABLE_IDENTIFIER {
|
||||
// Process Symbol table here
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Print them off for now!
|
||||
for section in memory_map.sections {
|
||||
println!("Name: {}", section.name);
|
||||
}
|
||||
Err(Error::not_implemented("scan"))
|
||||
}
|
||||
|
||||
fn scan_sections<F: FnMut() -> Option<String>>(next_line: &mut F) -> Result<Vec<Section>, Error> {
|
||||
fn scan_sections<F: FnMut() -> Option<String>>(next_line: &mut F, sections: &mut Vec<Section>) -> Result<String, Error> {
|
||||
while let Some(_) = next_line() {
|
||||
// We read every other line
|
||||
let line = next_line().ok_or(Error::from_str("Failed skipping section line"))?;
|
||||
|
@ -27,15 +42,15 @@ fn scan_sections<F: FnMut() -> Option<String>>(next_line: &mut F) -> Result<Vec<
|
|||
let size = split_line_radix(&mut split_line, 16, "Section Size")?;
|
||||
let adr = split_line_radix(&mut split_line, 16, "Section Address")?;
|
||||
|
||||
println!("\"{}\" @0x{:X} -> 0x{:X}", name, adr, (adr + size));
|
||||
sections.push(Section::new(name.to_string(), adr, size as usize));
|
||||
}
|
||||
|
||||
else {
|
||||
return Err(Error::from_str("<No proper return value yet>"));
|
||||
return Ok(line);
|
||||
}
|
||||
}
|
||||
|
||||
Err(Error::not_implemented("scan"))
|
||||
Err(Error::not_implemented("Failed obtaining complete section"))
|
||||
}
|
||||
|
||||
fn split_line_radix<'a>(split_line: &mut std::str::SplitWhitespace<'a>, radix: u32, value_name: &str) -> Result<u64, Error> {
|
||||
|
|
Loading…
Reference in New Issue