Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
edg-l committed Oct 14, 2024
1 parent 5451f28 commit 802dad2
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 19 deletions.
2 changes: 2 additions & 0 deletions src/bin/utils/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ pub fn run_tests(
) -> anyhow::Result<TestsSummary> {
let native_context = NativeContext::new();

dbg!("compiling");
// Compile the sierra program into a MLIR module.
let native_module = native_context.compile(&sierra_program, false).unwrap();
dbg!("compiled");

let native_executor: Box<dyn Fn(_, _, _, &mut StubSyscallHandler) -> _> = match args.run_mode {
RunMode::Aot => {
Expand Down
14 changes: 9 additions & 5 deletions src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -926,12 +926,12 @@ fn compile_func(
),
(
Identifier::new(context, "linkage"),
Attribute::parse(context, "#llvm.linkage<internal>").unwrap(),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
(
Identifier::new(context, "CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
// (
// Identifier::new(context, "CConv"),
// Attribute::parse(context, "#llvm.cconv<tailcc>").unwrap(),
// ),
],
Location::fused(
context,
Expand Down Expand Up @@ -1393,6 +1393,10 @@ fn generate_entry_point_wrapper<'c>(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<internal>").unwrap(),
),
(
Identifier::new(context, "llvm.CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
(
Identifier::new(context, "llvm.emit_c_interface"),
Attribute::unit(context),
Expand Down
8 changes: 6 additions & 2 deletions src/metadata/drop_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ impl DropOverridesMeta {
&[
(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
StringAttribute::new(context, "public").into(),
),
(
Identifier::new(context, "llvm.CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<internal>").unwrap(),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
],
Location::unknown(context),
Expand Down
8 changes: 6 additions & 2 deletions src/metadata/dup_overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,15 @@ impl DupOverridesMeta {
&[
(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
StringAttribute::new(context, "public").into(),
),
(
Identifier::new(context, "llvm.CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<internal>").unwrap(),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
],
Location::unknown(context),
Expand Down
60 changes: 60 additions & 0 deletions src/metadata/runtime_bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
],
Location::unknown(context),
));
Expand Down Expand Up @@ -195,6 +199,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -243,6 +251,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -291,6 +303,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -334,6 +350,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -386,6 +406,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -441,6 +465,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -495,6 +523,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -548,6 +580,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -613,6 +649,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -675,6 +715,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -732,6 +776,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -791,6 +839,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -844,6 +896,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down Expand Up @@ -904,6 +960,10 @@ impl RuntimeBindingsMeta {
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "private").into(),
),
(
Identifier::new(context, "llvm.will_return"),
Attribute::unit(context),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<external>").unwrap(),
Expand Down
32 changes: 29 additions & 3 deletions src/types/felt252_dict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use melior::{
dialect::{func, llvm, ods},
ir::{
attribute::{FlatSymbolRefAttribute, StringAttribute, TypeAttribute},
Block, Location, Module, Region, Type,
Attribute, Block, Identifier, Location, Module, Region, Type,
},
Context,
};
Expand Down Expand Up @@ -126,7 +126,20 @@ fn build_dup<'ctx>(
false,
)),
region,
&[],
&[
(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "public").into(),
),
(
Identifier::new(context, "CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
(
Identifier::new(context, "linkage"),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
],
location,
));
}
Expand Down Expand Up @@ -191,7 +204,20 @@ fn build_drop<'ctx>(
false,
)),
region,
&[],
&[
(
Identifier::new(context, "sym_visibility"),
StringAttribute::new(context, "public").into(),
),
(
Identifier::new(context, "llvm.CConv"),
Attribute::parse(context, "#llvm.cconv<fastcc>").unwrap(),
),
(
Identifier::new(context, "llvm.linkage"),
Attribute::parse(context, "#llvm.linkage<private>").unwrap(),
),
],
location,
));

Expand Down
7 changes: 0 additions & 7 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,13 +292,6 @@ pub fn run_pass_manager(context: &Context, module: &mut Module) -> Result<(), Er
pass_manager.add_pass(pass::transform::create_canonicalizer());
pass_manager.add_pass(pass::conversion::create_scf_to_control_flow()); // needed because to_llvm doesn't include it.
pass_manager.add_pass(pass::conversion::create_to_llvm());
pass_manager.add_pass(pass::transform::create_cse());
pass_manager.add_pass(pass::transform::create_sccp());
pass_manager.add_pass(pass::transform::create_control_flow_sink());
pass_manager.add_pass(pass::transform::create_loop_invariant_code_motion());
pass_manager.add_pass(pass::transform::create_inliner());
pass_manager.add_pass(pass::transform::create_topological_sort());
pass_manager.add_pass(pass::transform::create_canonicalizer());
pass_manager.run(module)
}

Expand Down

0 comments on commit 802dad2

Please sign in to comment.