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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//use indexmap::IndexMap;
//use std::rc::Rc;
//
//use proc_macro2::Ident;
//use quote::format_ident;
//
//use super::{from_sleigh, snake_case, SLEIGH_IDENT};
//
//pub struct Functions {
// macros: IndexMap<*const sleigh_rs::PcodeMacro, PcodeMacro>,
// functions: IndexMap<*const sleigh_rs::UserFunction, UserFunction>,
//}
//
//impl Functions {
// pub fn new(sleigh: &sleigh_rs::Sleigh) -> Self {
// let macros = sleigh
// .pcode_macros()
// .map(PcodeMacro::new)
// .map(|fuck| (Rc::as_ptr(&fuck.sleigh), fuck))
// .collect();
// let functions = sleigh
// .user_functions()
// .map(UserFunction::new)
// .map(|function| (Rc::as_ptr(&function.sleigh), function))
// .collect();
// Self { macros, functions }
// }
//}
//
//const MACRO_PREFIX: [&str; 2] = [SLEIGH_IDENT, "macro"];
//struct PcodeMacro {
// ident: Ident,
// sleigh: Rc<sleigh_rs::PcodeMacro>,
//}
//impl PcodeMacro {
// pub fn new(sleigh: Rc<sleigh_rs::PcodeMacro>) -> Self {
// let ident = MACRO_PREFIX.into_iter().chain(from_sleigh(&sleigh.name));
// let ident = format_ident!("{}", &snake_case(ident));
// Self { ident, sleigh }
// }
//}
//
//const USER_FUNCTION_PREFIX: [&str; 3] = [SLEIGH_IDENT, "user", "function"];
//struct UserFunction {
// ident: Ident,
// sleigh: Rc<sleigh_rs::UserFunction>,
//}
//impl UserFunction {
// pub fn new(sleigh: Rc<sleigh_rs::UserFunction>) -> Self {
// let ident = USER_FUNCTION_PREFIX
// .into_iter()
// .chain(from_sleigh(&sleigh.name));
// let ident = format_ident!("{}", &snake_case(ident));
// Self { ident, sleigh }
// }
//}
//struct PcodeMacroBuilder<'a, 'b> {
// builder: &'a mut Builder<'b>,
// pcode_macro: &'a PcodeMacro,
// params: IndexMap<Rc<str>, Ident>,
// vars: IndexMap<Rc<str>, Ident>,
//}
//
//impl<'a, 'b> PcodeMacroBuilder<'a, 'b> {
// pub fn new(
// builder: &'a mut Builder<'b>,
// pcode_macro: &'a PcodeMacro,
// ) -> Self {
// Self {
// builder,
// pcode_macro,
// params: IndexMap::new(),
// vars: IndexMap::new(),
// }
// }
// pub fn impl_function(&mut self) -> TokenStream {
// let pcode_macros = self.builder.pcode_macros.insert(IndexMap::new());
// let function_name = Rc::clone(&self.pcode_macro.name);
// let function_ident = pcode_macros
// .entry(Rc::clone(&function_name))
// .or_insert(format_ident!("macro_{}", *function_name))
// .clone();
// let params = self.pcode_macro.params.borrow();
// self.params = params
// .keys()
// .map(|name| (Rc::clone(name), format_ident!("{}", **name)))
// .collect();
// let body = self.impl_body();
// let params = self.params.values();
// let ident = &self.builder.space_struct().ident;
// quote! {
// impl #ident {
// fn #function_ident(&mut self, #(#params : usize),*) {
// #body
// }
// }
// }
// }
//
// pub fn impl_body(&mut self) -> TokenStream {
// let execution = self.pcode_macro.execution.borrow();
//
// self.vars = execution
// .vars
// .values()
// .map(|var| (Rc::clone(&var.name), format_ident!("{}", *var.name)))
// .collect();
// let vars = execution.vars.values().map(|var| {
// let var = self.vars.get(&var.name).unwrap();
// quote! {
// let #var;
// }
// });
//
// let entry_next = &execution.entry_block.next.borrow();
// let entry_next = entry_next
// .as_ref()
// .map(|x| {
// let next = x.name.as_ref().unwrap();
// quote! {todo!{#next};}
// })
// .unwrap_or(quote! {todo!("Return");});
// let entry_statements = execution.entry_block.statements.borrow();
// let entry_statements = entry_statements.iter().map(|st| {
// use sleigh_rs::parser::semantic::execution::Statement::*;
// match st {
// Delayslot(x) => quote! {todo!("delayslot({})", #x);},
// Export(_) => quote! {todo!("export");},
// CpuBranch(_) => quote! {todo!("cpubranch");},
// LocalGoto(_) => quote! {todo!("localgoto");},
// Call(_) => quote! {todo!("call");},
// Build(_) => unreachable!(),
// Declare(x) => {
// let var = self.vars.get(&x.name).unwrap();
// let var_type = todo!();
// quote! {let #var: #var_type;}
// }
// Assignment(_) => quote! {todo!();},
// }
// });
// quote! {
// #(#vars)*
// #(#entry_statements)*
// #entry_next
// }
// }
//}
//
//pub fn do_the_thing<'a, 'b>(
// builder: &'a mut Builder<'b>,
// pcode_macro: &'a PcodeMacro,
//) -> TokenStream {
// let mut builder = PcodeMacroBuilder::new(builder, pcode_macro);
// builder.impl_function()
//}