dynasm/
lib.rs

1// utility
2extern crate lazy_static;
3extern crate bitflags;
4extern crate byteorder;
5
6use std::collections::HashMap;
7
8/// Module with common infrastructure across assemblers
9mod common;
10/// Module with architecture-specific assembler implementations
11pub mod arch;
12/// Module contaning the implementation of directives
13mod directive;
14
15pub use common::{Const, Expr, Ident, Number, NumericRepr, JumpOffset, Size, Stmt, Value};
16pub use directive::{Directive, MalformedDirectiveError};
17
18/// output from parsing a full dynasm invocation. target represents the first dynasm argument, being the assembler
19/// variable being used. stmts contains an abstract representation of the statements to be generated from this dynasm
20/// invocation.
21struct Dynasm {
22    target: Box<dyn arch::Arch>,
23    stmts: Vec<common::Stmt>
24}
25
26/// As dynasm_opmap takes no args it doesn't parse to anything
27// TODO: opmaps
28struct DynasmOpmap {
29    pub arch: String
30}
31
32/// This struct contains all non-parsing state that dynasm! requires while parsing and compiling
33pub struct State<'a> {
34    pub stmts: &'a mut Vec<common::Stmt>,
35    pub target: &'a str,
36    pub file_data: &'a mut DynasmData,
37}
38
39pub struct DynasmData {
40    pub current_arch: Box<dyn arch::Arch>,
41    pub aliases: HashMap<String, String>,
42}
43
44impl DynasmData {
45    /// Create data with the current default architecture (target dependent).
46    pub fn new() -> DynasmData {
47        DynasmData {
48            current_arch:
49                arch::from_str(arch::CURRENT_ARCH).expect("Default architecture is invalid"),
50            aliases: HashMap::new(),
51        }
52    }
53}