dynasm\arch\aarch64/
mod.rs

1use syn::parse;
2use proc_macro_error2::emit_error;
3
4mod ast;
5mod parser;
6mod matching;
7mod compiler;
8mod aarch64data;
9mod encoding_helpers;
10mod debug;
11
12use crate::State;
13use crate::common::{Size, Stmt, Jump};
14use crate::arch::Arch;
15use self::aarch64data::Relocation;
16
17#[cfg(feature = "dynasm_opmap")]
18pub use debug::create_opmap;
19#[cfg(feature = "dynasm_extract")]
20pub use debug::extract_opmap;
21
22struct Context<'a, 'b: 'a> {
23    pub state: &'a mut State<'b>
24}
25
26#[derive(Clone, Debug, Default)]
27pub struct ArchAarch64 {
28
29}
30
31impl Arch for ArchAarch64 {
32    fn set_features(&mut self, features: &[syn::Ident]) {
33        if let Some(feature) = features.first() {
34            emit_error!(feature, "Arch aarch64 has no known features");
35        }
36    }
37
38    fn handle_static_reloc(&self, stmts: &mut Vec<Stmt>, reloc: Jump, size: Size) {
39        let span = reloc.span();
40
41        let relocation = match size {
42            Size::BYTE => Relocation::LITERAL8,
43            Size::B_2 => Relocation::LITERAL16,
44            Size::B_4 => Relocation::LITERAL32,
45            Size::B_8 => Relocation::LITERAL64,
46            _ => {
47                emit_error!(span, "Relocation of unsupported size for the current target architecture");
48                return;
49            }
50        };
51
52        stmts.push(Stmt::Const(0, size));
53        stmts.push(reloc.encode(size.in_bytes(), size.in_bytes(), &[relocation.to_id()]));
54    }
55
56    fn default_align(&self) -> u8 {
57        0
58    }
59
60    fn compile_instruction(&self, state: &mut State, input: parse::ParseStream) -> parse::Result<()> {
61        let mut ctx = Context {
62            state
63        };
64
65        let (instruction, args) = parser::parse_instruction(&mut ctx, input)?;
66        let span = instruction.span;
67
68        let match_data = match matching::match_instruction(&mut ctx, &instruction, args) {
69            Err(None) => return Ok(()),
70            Err(Some(e)) => {
71                emit_error!(span, e);
72                return Ok(())
73            }
74            Ok(m) => m
75        };
76
77        match compiler::compile_instruction(&mut ctx, match_data) {
78            Err(None) => return Ok(()),
79            Err(Some(e)) => {
80                emit_error!(span, e);
81                return Ok(())
82            }
83            Ok(()) => ()
84        }
85
86        Ok(())
87    }
88}