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
45
46
47
48
49
50
51
52
53
// utility
extern crate lazy_static;
extern crate bitflags;
extern crate byteorder;

use std::collections::HashMap;

/// Module with common infrastructure across assemblers
mod common;
/// Module with architecture-specific assembler implementations
pub mod arch;
/// Module contaning the implementation of directives
mod directive;

pub use common::{Const, Expr, Ident, Number, NumericRepr, JumpOffset, Size, Stmt, Value};
pub use directive::{Directive, MalformedDirectiveError};

/// output from parsing a full dynasm invocation. target represents the first dynasm argument, being the assembler
/// variable being used. stmts contains an abstract representation of the statements to be generated from this dynasm
/// invocation.
struct Dynasm {
    target: Box<dyn arch::Arch>,
    stmts: Vec<common::Stmt>
}

/// As dynasm_opmap takes no args it doesn't parse to anything
// TODO: opmaps
struct DynasmOpmap {
    pub arch: String
}

/// This struct contains all non-parsing state that dynasm! requires while parsing and compiling
pub struct State<'a> {
    pub stmts: &'a mut Vec<common::Stmt>,
    pub target: &'a str,
    pub file_data: &'a mut DynasmData,
}

pub struct DynasmData {
    pub current_arch: Box<dyn arch::Arch>,
    pub aliases: HashMap<String, String>,
}

impl DynasmData {
    /// Create data with the current default architecture (target dependent).
    pub fn new() -> DynasmData {
        DynasmData {
            current_arch:
                arch::from_str(arch::CURRENT_ARCH).expect("Default architecture is invalid"),
            aliases: HashMap::new(),
        }
    }
}