forked from argotorg/fe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.rs
More file actions
70 lines (64 loc) · 1.92 KB
/
Copy pathtest.rs
File metadata and controls
70 lines (64 loc) · 1.92 KB
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
use super::context::Context;
use crate::db::CodegenDb;
use fe_analyzer::namespace::items::FunctionId;
use yultsur::{yul, *};
pub fn lower_test(db: &dyn CodegenDb, test: FunctionId) -> yul::Object {
let mut context = Context::default();
let test = db.mir_lowered_func_signature(test);
context.function_dependency.insert(test);
let dep_functions: Vec<_> = context
.resolve_function_dependency(db)
.into_iter()
.map(yul::Statement::FunctionDefinition)
.collect();
let dep_constants = context.resolve_constant_dependency(db);
let dep_contracts = context.resolve_contract_dependency(db);
let runtime_funcs: Vec<_> = context
.runtime
.collect_definitions()
.into_iter()
.map(yul::Statement::FunctionDefinition)
.collect();
let test_func_name = identifier! { (db.codegen_function_symbol_name(test)) };
let call = function_call_statement! {[test_func_name]()};
let code = code! {
[dep_functions...]
[runtime_funcs...]
[call]
(stop())
};
let name = identifier! { test };
let object = yul::Object {
name,
code,
objects: dep_contracts,
data: dep_constants,
};
normalize_object(object)
}
fn normalize_object(obj: yul::Object) -> yul::Object {
let data = obj
.data
.into_iter()
.map(|data| yul::Data {
name: data.name,
value: data
.value
.replace('\\', "\\\\\\\\")
.replace('\n', "\\\\n")
.replace('"', "\\\\\"")
.replace('\r', "\\\\r")
.replace('\t', "\\\\t"),
})
.collect::<Vec<_>>();
yul::Object {
name: obj.name,
code: obj.code,
objects: obj
.objects
.into_iter()
.map(normalize_object)
.collect::<Vec<_>>(),
data,
}
}