-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grant Wuerker
committed
Dec 20, 2022
1 parent
25218d4
commit a76549b
Showing
7 changed files
with
356 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ use crate::{ | |
}, | ||
}; | ||
|
||
// here | ||
pub fn lower_function( | ||
db: &dyn CodegenDb, | ||
ctx: &mut Context, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use super::context::Context; | ||
use fe_analyzer::namespace::items::FunctionId; | ||
use yultsur::{yul, *}; | ||
use crate::{ | ||
db::CodegenDb, | ||
}; | ||
|
||
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_constants = context.resolve_constant_dependency(db); | ||
let dep_functions: Vec<_> = context | ||
.resolve_function_dependency(db) | ||
.into_iter() | ||
.map(yul::Statement::FunctionDefinition) | ||
.collect(); | ||
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 = expression! {[test_func_name]()}; | ||
|
||
let code = code! { | ||
[dep_functions...] | ||
[runtime_funcs...] | ||
}; | ||
|
||
let name = identifier! { test }; | ||
let object = yul::Object { | ||
name, | ||
code, | ||
objects: vec![], | ||
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.