1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
pub mod asm;
pub mod diagn;
pub mod expr;
pub mod syntax;
pub mod util;

#[cfg(test)]
pub mod test;

#[cfg(any(test, target_arch="wasm32"))]
pub mod driver;

#[cfg(target_arch="wasm32")]
pub mod webasm;


/// Convenience function to assemble a given string.
/// 
/// The code cannot access external files through
/// `#include` or `incbin()`.
/// 
/// Returns the generated bytes of the assembled binary
/// if successful, together with the report containing
/// any errors or warnings that were encountered.
pub fn assemble_str_to_binary(
	src: &str)
	-> (Option<Vec<u8>>, diagn::Report)
{
	let virtual_filename = "str";

	let mut report = diagn::Report::new();
	let mut fileserver = util::FileServerMock::new();
	fileserver.add(virtual_filename, src.clone());

	let opts = asm::AssemblyOptions::new();

	let assembly = asm::assemble(
		&mut report,
		&opts,
		&mut fileserver,
		&[virtual_filename]);
	
	(assembly.output.map(|o| o.format_binary()), report)
}