| ... | @@ -2068,20 +2068,20 @@ fn walkInstruction( | ... | @@ -2068,20 +2068,20 @@ fn walkInstruction( |
| 2068 | | 2068 | |
| 2069 | return result; | 2069 | return result; |
| 2070 | }, | 2070 | }, |
| 2071 | // .func_extended => { | 2071 | .func_fancy => { |
| 2072 | // const type_slot_index = self.types.items.len; | 2072 | const type_slot_index = self.types.items.len; |
| 2073 | // try self.types.append(self.arena, .{ .Unanalyzed = .{} }); | 2073 | try self.types.append(self.arena, .{ .Unanalyzed = .{} }); |
| 2074 | | 2074 | |
| 2075 | // const result = self.analyzeFunctionExtended( | 2075 | const result = self.analyzeFancyFunction( |
| 2076 | // file, | 2076 | file, |
| 2077 | // parent_scope, | 2077 | parent_scope, |
| 2078 | // inst_index, | 2078 | inst_index, |
| 2079 | // self_ast_node_index, | 2079 | self_ast_node_index, |
| 2080 | // type_slot_index, | 2080 | type_slot_index, |
| 2081 | // ); | 2081 | ); |
| 2082 | | 2082 | |
| 2083 | // return result; | 2083 | return result; |
| 2084 | // }, | 2084 | }, |
| 2085 | .extended => { | 2085 | .extended => { |
| 2086 | const extended = data[inst_index].extended; | 2086 | const extended = data[inst_index].extended; |
| 2087 | switch (extended.opcode) { | 2087 | switch (extended.opcode) { |
| ... | @@ -3129,7 +3129,7 @@ fn tryResolveRefPath( | ... | @@ -3129,7 +3129,7 @@ fn tryResolveRefPath( |
| 3129 | // that said, we might want to store it elsewhere and reclaim memory asap | 3129 | // that said, we might want to store it elsewhere and reclaim memory asap |
| 3130 | } | 3130 | } |
| 3131 | } | 3131 | } |
| 3132 | fn analyzeFunctionExtended( | 3132 | fn analyzeFancyFunction( |
| 3133 | self: *Autodoc, | 3133 | self: *Autodoc, |
| 3134 | file: *File, | 3134 | file: *File, |
| 3135 | scope: *Scope, | 3135 | scope: *Scope, |
| ... | @@ -3204,19 +3204,10 @@ fn analyzeFunctionExtended( | ... | @@ -3204,19 +3204,10 @@ fn analyzeFunctionExtended( |
| 3204 | } | 3204 | } |
| 3205 | } | 3205 | } |
| 3206 | | 3206 | |
| 3207 | // ret | | |
| 3208 | const ret_type_ref = blk: { | | |
| 3209 | const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; | | |
| 3210 | const break_operand = data[last_instr_index].@"break".operand; | | |
| 3211 | const wr = try self.walkRef(file, scope, break_operand, false); | | |
| 3212 | | | |
| 3213 | break :blk wr; | | |
| 3214 | }; | | |
| 3215 | | | |
| 3216 | self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items; | 3207 | self.ast_nodes.items[self_ast_node_index].fields = param_ast_indexes.items; |
| 3217 | | 3208 | |
| 3218 | const inst_data = data[inst_index].pl_node; | 3209 | const inst_data = data[inst_index].pl_node; |
| 3219 | const extra = file.zir.extraData(Zir.Inst.ExtendedFunc, inst_data.payload_index); | 3210 | const extra = file.zir.extraData(Zir.Inst.FuncFancy, inst_data.payload_index); |
| 3220 | | 3211 | |
| 3221 | var extra_index: usize = extra.end; | 3212 | var extra_index: usize = extra.end; |
| 3222 | | 3213 | |
| ... | @@ -3226,25 +3217,96 @@ fn analyzeFunctionExtended( | ... | @@ -3226,25 +3217,96 @@ fn analyzeFunctionExtended( |
| 3226 | extra_index += 1; | 3217 | extra_index += 1; |
| 3227 | } | 3218 | } |
| 3228 | | 3219 | |
| 3229 | var cc_index: ?usize = null; | | |
| 3230 | var align_index: ?usize = null; | 3220 | var align_index: ?usize = null; |
| 3231 | if (extra.data.bits.has_cc) { | 3221 | if (extra.data.bits.has_align_ref) { |
| | 3222 | const align_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| | 3223 | align_index = self.exprs.items.len; |
| | 3224 | _ = try self.walkRef(file, scope, align_ref, false); |
| | 3225 | extra_index += 1; |
| | 3226 | } else if (extra.data.bits.has_align_body) { |
| | 3227 | const align_body_len = file.zir.extra[extra_index]; |
| | 3228 | extra_index += 1; |
| | 3229 | const align_body = file.zir.extra[extra_index .. extra_index + align_body_len]; |
| | 3230 | _ = align_body; |
| | 3231 | // TODO: analyze the block (or bail with a comptimeExpr) |
| | 3232 | extra_index += align_body_len; |
| | 3233 | } else { |
| | 3234 | // default alignment |
| | 3235 | } |
| | 3236 | |
| | 3237 | var addrspace_index: ?usize = null; |
| | 3238 | if (extra.data.bits.has_addrspace_ref) { |
| | 3239 | const addrspace_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| | 3240 | addrspace_index = self.exprs.items.len; |
| | 3241 | _ = try self.walkRef(file, scope, addrspace_ref, false); |
| | 3242 | extra_index += 1; |
| | 3243 | } else if (extra.data.bits.has_addrspace_body) { |
| | 3244 | const addrspace_body_len = file.zir.extra[extra_index]; |
| | 3245 | extra_index += 1; |
| | 3246 | const addrspace_body = file.zir.extra[extra_index .. extra_index + addrspace_body_len]; |
| | 3247 | _ = addrspace_body; |
| | 3248 | // TODO: analyze the block (or bail with a comptimeExpr) |
| | 3249 | extra_index += addrspace_body_len; |
| | 3250 | } else { |
| | 3251 | // default alignment |
| | 3252 | } |
| | 3253 | |
| | 3254 | var section_index: ?usize = null; |
| | 3255 | if (extra.data.bits.has_section_ref) { |
| | 3256 | const section_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| | 3257 | section_index = self.exprs.items.len; |
| | 3258 | _ = try self.walkRef(file, scope, section_ref, false); |
| | 3259 | extra_index += 1; |
| | 3260 | } else if (extra.data.bits.has_section_body) { |
| | 3261 | const section_body_len = file.zir.extra[extra_index]; |
| | 3262 | extra_index += 1; |
| | 3263 | const section_body = file.zir.extra[extra_index .. extra_index + section_body_len]; |
| | 3264 | _ = section_body; |
| | 3265 | // TODO: analyze the block (or bail with a comptimeExpr) |
| | 3266 | extra_index += section_body_len; |
| | 3267 | } else { |
| | 3268 | // default alignment |
| | 3269 | } |
| | 3270 | |
| | 3271 | var cc_index: ?usize = null; |
| | 3272 | if (extra.data.bits.has_cc_ref) { |
| 3232 | const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); | 3273 | const cc_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); |
| 3233 | cc_index = self.exprs.items.len; | 3274 | cc_index = self.exprs.items.len; |
| 3234 | _ = try self.walkRef(file, scope, cc_ref, false); | 3275 | _ = try self.walkRef(file, scope, cc_ref, false); |
| 3235 | extra_index += 1; | 3276 | extra_index += 1; |
| | 3277 | } else if (extra.data.bits.has_cc_body) { |
| | 3278 | const cc_body_len = file.zir.extra[extra_index]; |
| | 3279 | extra_index += 1; |
| | 3280 | const cc_body = file.zir.extra[extra_index .. extra_index + cc_body_len]; |
| | 3281 | _ = cc_body; |
| | 3282 | // TODO: analyze the block (or bail with a comptimeExpr) |
| | 3283 | extra_index += cc_body_len; |
| | 3284 | } else { |
| | 3285 | // auto calling convention |
| 3236 | } | 3286 | } |
| 3237 | | 3287 | |
| 3238 | if (extra.data.bits.has_align) { | 3288 | // ret |
| 3239 | const align_ref = @intToEnum(Zir.Inst.Ref, file.zir.extra[extra_index]); | 3289 | const ret_type_ref: DocData.Expr = switch (fn_info.ret_ty_body.len) { |
| 3240 | align_index = self.exprs.items.len; | 3290 | 0 => switch (fn_info.ret_ty_ref) { |
| 3241 | _ = try self.walkRef(file, scope, align_ref, false); | 3291 | .none => DocData.Expr{ .void = .{} }, |
| 3242 | } | 3292 | else => blk: { |
| | 3293 | const ref = fn_info.ret_ty_ref; |
| | 3294 | const wr = try self.walkRef(file, scope, ref, false); |
| | 3295 | break :blk wr.expr; |
| | 3296 | }, |
| | 3297 | }, |
| | 3298 | else => blk: { |
| | 3299 | const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; |
| | 3300 | const break_operand = data[last_instr_index].@"break".operand; |
| | 3301 | const wr = try self.walkRef(file, scope, break_operand, false); |
| | 3302 | break :blk wr.expr; |
| | 3303 | }, |
| | 3304 | }; |
| 3243 | | 3305 | |
| 3244 | // TODO: a complete version of this will probably need a scope | 3306 | // TODO: a complete version of this will probably need a scope |
| 3245 | // in order to evaluate correctly closures around funcion | 3307 | // in order to evaluate correctly closures around funcion |
| 3246 | // parameters etc. | 3308 | // parameters etc. |
| 3247 | const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) { | 3309 | const generic_ret: ?DocData.Expr = switch (ret_type_ref) { |
| 3248 | .type => |t| blk: { | 3310 | .type => |t| blk: { |
| 3249 | if (fn_info.body.len == 0) break :blk null; | 3311 | if (fn_info.body.len == 0) break :blk null; |
| 3250 | if (t == @enumToInt(Ref.type_type)) { | 3312 | if (t == @enumToInt(Ref.type_type)) { |
| ... | @@ -3265,11 +3327,11 @@ fn analyzeFunctionExtended( | ... | @@ -3265,11 +3327,11 @@ fn analyzeFunctionExtended( |
| 3265 | .name = "todo_name func", | 3327 | .name = "todo_name func", |
| 3266 | .src = self_ast_node_index, | 3328 | .src = self_ast_node_index, |
| 3267 | .params = param_type_refs.items, | 3329 | .params = param_type_refs.items, |
| 3268 | .ret = ret_type_ref.expr, | 3330 | .ret = ret_type_ref, |
| 3269 | .generic_ret = generic_ret, | 3331 | .generic_ret = generic_ret, |
| 3270 | .is_extern = extra.data.bits.is_extern, | 3332 | .is_extern = extra.data.bits.is_extern, |
| 3271 | .has_cc = extra.data.bits.has_cc, | 3333 | .has_cc = cc_index != null, |
| 3272 | .has_align = extra.data.bits.has_align, | 3334 | .has_align = align_index != null, |
| 3273 | .has_lib_name = extra.data.bits.has_lib_name, | 3335 | .has_lib_name = extra.data.bits.has_lib_name, |
| 3274 | .lib_name = lib_name, | 3336 | .lib_name = lib_name, |
| 3275 | .is_inferred_error = extra.data.bits.is_inferred_error, | 3337 | .is_inferred_error = extra.data.bits.is_inferred_error, |
| ... | @@ -3359,19 +3421,28 @@ fn analyzeFunction( | ... | @@ -3359,19 +3421,28 @@ fn analyzeFunction( |
| 3359 | } | 3421 | } |
| 3360 | | 3422 | |
| 3361 | // ret | 3423 | // ret |
| 3362 | const ret_type_ref = blk: { | 3424 | const ret_type_ref: DocData.Expr = switch (fn_info.ret_ty_body.len) { |
| 3363 | // const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; | 3425 | 0 => switch (fn_info.ret_ty_ref) { |
| 3364 | // const break_operand = data[last_instr_index].@"break".operand; | 3426 | .none => DocData.Expr{ .void = .{} }, |
| 3365 | // const wr = try self.walkRef(file, scope, break_operand, false); | 3427 | else => blk: { |
| 3366 | const wr = try self.walkRef(file, scope, fn_info.ret_ty_ref, false); | 3428 | const ref = fn_info.ret_ty_ref; |
| 3367 | | 3429 | const wr = try self.walkRef(file, scope, ref, false); |
| 3368 | break :blk wr; | 3430 | break :blk wr.expr; |
| | 3431 | }, |
| | 3432 | }, |
| | 3433 | else => blk: { |
| | 3434 | //const last_instr_index = fn_info.ret_ty_body[fn_info.ret_ty_body.len - 1]; |
| | 3435 | //const break_operand = data[last_instr_index].@"break".operand; |
| | 3436 | //const wr = try self.walkRef(file, scope, break_operand, false); |
| | 3437 | const wr = try self.walkRef(file, scope, fn_info.ret_ty_ref, false); |
| | 3438 | break :blk wr.expr; |
| | 3439 | }, |
| 3369 | }; | 3440 | }; |
| 3370 | | 3441 | |
| 3371 | // TODO: a complete version of this will probably need a scope | 3442 | // TODO: a complete version of this will probably need a scope |
| 3372 | // in order to evaluate correctly closures around funcion | 3443 | // in order to evaluate correctly closures around funcion |
| 3373 | // parameters etc. | 3444 | // parameters etc. |
| 3374 | const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) { | 3445 | const generic_ret: ?DocData.Expr = switch (ret_type_ref) { |
| 3375 | .type => |t| blk: { | 3446 | .type => |t| blk: { |
| 3376 | if (fn_info.body.len == 0) break :blk null; | 3447 | if (fn_info.body.len == 0) break :blk null; |
| 3377 | if (t == @enumToInt(Ref.type_type)) { | 3448 | if (t == @enumToInt(Ref.type_type)) { |
| ... | @@ -3393,7 +3464,7 @@ fn analyzeFunction( | ... | @@ -3393,7 +3464,7 @@ fn analyzeFunction( |
| 3393 | .name = "todo_name func", | 3464 | .name = "todo_name func", |
| 3394 | .src = self_ast_node_index, | 3465 | .src = self_ast_node_index, |
| 3395 | .params = param_type_refs.items, | 3466 | .params = param_type_refs.items, |
| 3396 | .ret = ret_type_ref.expr, | 3467 | .ret = ret_type_ref, |
| 3397 | .generic_ret = generic_ret, | 3468 | .generic_ret = generic_ret, |
| 3398 | }, | 3469 | }, |
| 3399 | }; | 3470 | }; |