| ... | @@ -1275,7 +1275,7 @@ fn airCall(o: *Object, inst: Air.Inst.Index) !CValue { | ... | @@ -1275,7 +1275,7 @@ fn airCall(o: *Object, inst: Air.Inst.Index) !CValue { |
| 1275 | fn airDbgStmt(o: *Object, inst: Air.Inst.Index) !CValue { | 1275 | fn airDbgStmt(o: *Object, inst: Air.Inst.Index) !CValue { |
| 1276 | const dbg_stmt = o.air.instructions.items(.data)[inst].dbg_stmt; | 1276 | const dbg_stmt = o.air.instructions.items(.data)[inst].dbg_stmt; |
| 1277 | const writer = o.writer(); | 1277 | const writer = o.writer(); |
| 1278 | try writer.print("#line {d}\n", .{dbg_stmt.line}); | 1278 | try writer.print("#line {d}\n", .{dbg_stmt.line + 1}); |
| 1279 | return CValue.none; | 1279 | return CValue.none; |
| 1280 | } | 1280 | } |
| 1281 | | 1281 | |
| ... | @@ -1403,35 +1403,41 @@ fn airSwitchBr(o: *Object, inst: Air.Inst.Index) !CValue { | ... | @@ -1403,35 +1403,41 @@ fn airSwitchBr(o: *Object, inst: Air.Inst.Index) !CValue { |
| 1403 | const pl_op = o.air.instructions.items(.data)[inst].pl_op; | 1403 | const pl_op = o.air.instructions.items(.data)[inst].pl_op; |
| 1404 | const condition = try o.resolveInst(pl_op.operand); | 1404 | const condition = try o.resolveInst(pl_op.operand); |
| 1405 | const condition_ty = o.air.typeOf(pl_op.operand); | 1405 | const condition_ty = o.air.typeOf(pl_op.operand); |
| | 1406 | const switch_br = o.air.extraData(Air.SwitchBr, pl_op.payload); |
| 1406 | const writer = o.writer(); | 1407 | const writer = o.writer(); |
| 1407 | | 1408 | |
| 1408 | try writer.writeAll("switch ("); | 1409 | try writer.writeAll("switch ("); |
| 1409 | try o.writeCValue(writer, condition); | 1410 | try o.writeCValue(writer, condition); |
| 1410 | try writer.writeAll(") {\n"); | 1411 | try writer.writeAll(") {"); |
| 1411 | o.indent_writer.pushIndent(); | 1412 | o.indent_writer.pushIndent(); |
| 1412 | | 1413 | |
| 1413 | // Need to rework Sema so that multiple cases are represented rather than | 1414 | var extra_index: usize = switch_br.end; |
| 1414 | // getting branching logic inside the else, this way we get multiple case | 1415 | var case_i: u32 = 0; |
| 1415 | // labels here rather than logic in the default case. | 1416 | while (case_i < switch_br.data.cases_len) : (case_i += 1) { |
| 1416 | _ = condition_ty; | 1417 | const case = o.air.extraData(Air.SwitchBr.Case, extra_index); |
| 1417 | return o.dg.fail("TODO implement switch in C backend", .{}); | 1418 | const items = @bitCast([]const Air.Inst.Ref, o.air.extra[case.end..][0..case.data.items_len]); |
| 1418 | | 1419 | const case_body = o.air.extra[case.end + items.len ..][0..case.data.body_len]; |
| 1419 | //for (inst.cases) |case| { | 1420 | extra_index = case.end + case.data.items_len + case_body.len; |
| 1420 | // try writer.writeAll("case "); | 1421 | |
| 1421 | // try o.dg.renderValue(writer, condition_ty, case.item); | 1422 | for (items) |item| { |
| 1422 | // try writer.writeAll(": "); | 1423 | try o.indent_writer.insertNewline(); |
| 1423 | // // the case body must be noreturn so we don't need to insert a break | 1424 | try writer.writeAll("case "); |
| 1424 | // try genBody(o, case.body); | 1425 | try o.dg.renderValue(writer, condition_ty, o.air.value(item).?); |
| 1425 | // try o.indent_writer.insertNewline(); | 1426 | try writer.writeAll(": "); |
| 1426 | //} | 1427 | } |
| 1427 | | 1428 | // The case body must be noreturn so we don't need to insert a break. |
| 1428 | //try writer.writeAll("default: "); | 1429 | try genBody(o, case_body); |
| 1429 | //try genBody(o, inst.else_body); | 1430 | } |
| 1430 | //try o.indent_writer.insertNewline(); | 1431 | |
| 1431 | | 1432 | const else_body = o.air.extra[extra_index..][0..switch_br.data.else_body_len]; |
| 1432 | //o.indent_writer.popIndent(); | 1433 | try o.indent_writer.insertNewline(); |
| 1433 | //try writer.writeAll("}\n"); | 1434 | try writer.writeAll("default: "); |
| 1434 | //return CValue.none; | 1435 | try genBody(o, else_body); |
| | 1436 | try o.indent_writer.insertNewline(); |
| | 1437 | |
| | 1438 | o.indent_writer.popIndent(); |
| | 1439 | try writer.writeAll("}\n"); |
| | 1440 | return CValue.none; |
| 1435 | } | 1441 | } |
| 1436 | | 1442 | |
| 1437 | fn airAsm(o: *Object, inst: Air.Inst.Index) !CValue { | 1443 | fn airAsm(o: *Object, inst: Air.Inst.Index) !CValue { |