cfd16-assembler 0.7.3

An assembler backend for the CFD-16 ISA.
Documentation
//! A library which implements an assembler backend for the CFD-16
//! instruction set architecture.

#![warn(missing_docs)]

use std::{fs, path::PathBuf};

mod elf;

mod error;
use error::{AssemErrorKind, AssemblerError};

mod parse;
use parse::{BinFormat, Program};

mod text;

#[allow(missing_docs)]
pub mod prelude;

#[cfg(test)]
mod tests;

/// Assembles the contents of the file `srcfile` into properly encoded
/// CFD-16 machine code. The `format` variable indicates the file type
/// in which the resulting program is encoded.
pub fn assemble(srcfile: PathBuf, format: BinFormat) -> Result<Vec<u8>, AssemblerError> {
    let source = match fs::read_to_string(&srcfile) {
        Ok(s) => s,
        Err(_) => return Err(AssemblerError::new(None, AssemErrorKind::FileRead(srcfile))),
    };

    let filestr = srcfile.display().to_string();
    let mut prog = Program::from_source(source, format, filestr)?;

    prog.resolve_symbols()?;
    prog.encode()
}