diff --git a/src/compiler/backend.cpp b/src/compiler/backend.cpp index 67a1314..2d990c7 100644 --- a/src/compiler/backend.cpp +++ b/src/compiler/backend.cpp @@ -119,32 +119,32 @@ namespace backend { // Stage 7, jump fix auto mod = DeviceModule(ctx); - // p.measure("Jump Fix", [&] { - // auto old_instr = std::move(instr); - - // int err = futhark_entry_backend_fix_jumps( - // ctx, - // &instr, - // &mod.func_id, - // &mod.func_start, - // &mod.func_size, - // instr, - // functab - // ); - // if(err) - // throw futhark::Error(ctx); - // }); - - // // Stage 8, postprocess - // p.measure("postprocess", [&] { - // int err = futhark_entry_backend_postprocess( - // ctx, - // &mod.instructions, - // instr - // ); - // if(err) - // throw futhark::Error(ctx); - // }); + p.measure("Jump Fix", [&] { + auto old_instr = std::move(instr); + + int err = futhark_entry_backend_fix_jumps( + ctx, + &instr, + &mod.func_id, + &mod.func_start, + &mod.func_size, + old_instr, + functab + ); + if(err) + throw futhark::Error(ctx); + }); + + // Stage 8, postprocess + p.measure("postprocess", [&] { + int err = futhark_entry_backend_postprocess( + ctx, + &mod.instructions, + instr + ); + if(err) + throw futhark::Error(ctx); + }); return mod; } diff --git a/src/compiler/bridge.fut b/src/compiler/bridge.fut index 5618088..3a351ba 100644 --- a/src/compiler/bridge.fut +++ b/src/compiler/bridge.fut @@ -18,6 +18,7 @@ type front_node_data_type = u32 let NODE_TYPE_LOOKUP = mk_production_array node_type_invalid [ (production_fn_decl_list, node_type_statement_list), (production_fn_decl, node_type_func_decl), + (production_fn_decl_dummy, node_type_func_decl_dummy), (production_stat_while, node_type_while_stat), (production_stat_if, node_type_if_stat), (production_stat_expr, node_type_expr_stat), diff --git a/src/compiler/frontend.cpp b/src/compiler/frontend.cpp index 23f7b8c..f5da853 100644 --- a/src/compiler/frontend.cpp +++ b/src/compiler/frontend.cpp @@ -335,7 +335,7 @@ namespace frontend { p.measure("check convergence", [&]{ bool valid; - int err = futhark_entry_frontend_check_convergence(ctx, &valid, node_types, parents, prev_siblings, data_types); + int err = futhark_entry_frontend_check_convergence(ctx, &valid, node_types, parents, prev_siblings); if (err) throw futhark::Error(ctx); if (!valid) diff --git a/src/compiler/frontend.fut b/src/compiler/frontend.fut index 0705590..c70174f 100644 --- a/src/compiler/frontend.fut +++ b/src/compiler/frontend.fut @@ -132,8 +132,8 @@ entry resolve_data_types [n] (node_types: [n]production.t) (parents: [n]i32) (pr entry check_return_types [n] (node_types: [n]production.t) (parents: [n]i32) (data_types: [n]data_type): bool = check_return_types node_types parents data_types -entry check_convergence [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32) (data_types: [n]data_type): bool = - check_return_paths node_types parents prev_siblings data_types +entry check_convergence [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32): bool = + check_return_paths node_types parents prev_siblings entry build_ast [n] (node_types: *[n]production.t) diff --git a/src/compiler/main.fut b/src/compiler/main.fut index af46a67..a9e4254 100644 --- a/src/compiler/main.fut +++ b/src/compiler/main.fut @@ -97,8 +97,8 @@ entry frontend_resolve_data_types [n] (node_types: [n]production.t) (parents: [n entry frontend_check_return_types [n] (node_types: [n]production.t) (parents: [n]i32) (data_types: [n]data_type): bool = frontend.check_return_types node_types parents data_types -entry frontend_check_convergence [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32) (data_types: [n]data_type): bool = - frontend.check_convergence node_types parents prev_siblings data_types +entry frontend_check_convergence [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32): bool = + frontend.check_convergence node_types parents prev_siblings entry frontend_build_ast [n] (node_types: *[n]production.t) diff --git a/src/compiler/parser/pareas.g b/src/compiler/parser/pareas.g index 0aa90e8..470b968 100644 --- a/src/compiler/parser/pareas.g +++ b/src/compiler/parser/pareas.g @@ -3,7 +3,9 @@ start -> fn_decl_list; fn_decl_list -> fn_decl fn_decl_list; fn_decl_list [fn_decl_list_end] -> ; -fn_decl -> 'fn' expr compound_stat; +fn_decl -> 'fn' fn_decl_dummy expr compound_stat; + +fn_decl_dummy -> ; type [type_int] -> 'int'; type [type_float] -> 'float'; diff --git a/src/compiler/passes/check_return_paths.fut b/src/compiler/passes/check_return_paths.fut index a863543..b535dc4 100644 --- a/src/compiler/passes/check_return_paths.fut +++ b/src/compiler/passes/check_return_paths.fut @@ -52,7 +52,7 @@ local let iter [n] (expr: [n]bool_expr_node): [n]bool_expr_node = -- | As type resolving works by first computing a type that is valid for the expression if the program is valid, -- we cannot also check whether all paths in a function return a value, as this would require picking the child with the -- right value when analysing an `if_else` node. Instead, this check is performed separately in this pass. -let check_return_paths [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32) (data_types: [n]data_type.t) = +let check_return_paths [n] (node_types: [n]production.t) (parents: [n]i32) (prev_siblings: [n]i32): bool = -- The children of each node are going to be its first child and its sibling, so compute those. let next_siblings = invert prev_siblings let first_childs = @@ -71,7 +71,7 @@ let check_return_paths [n] (node_types: [n]production.t) (parents: [n]i32) (prev else if node_types[parent] == production_stat_if_else && nty == production_stat_list && next_sibling != -1 then #and -- Cannot guarantee these types returning, so return false from these. else if node_types[parent] == production_stat_if || node_types[parent] == production_stat_while then #false - else if nty == production_fn_decl then #true + else if nty == production_fn_decl then #and -- The return type of a void function maps to true as these don't need to end every path with a return statement. else if nty == production_type_void && node_types[parent] == production_fn_decl then #true else #or)