authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-18 22:32:07-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-07-20 12:19:16-07:00
log44fe9c52e15deb1a1ea82760c5f4204d50fb0e9f
tree65041a2a3db328604b685d81b21cb2060a020007
parent934ebbe900dcc770d7761a87ae35beaf1c5a6797

stage2: wasm backend: update to latest naming convention


1 files changed, 58 insertions(+), 56 deletions(-)

src/codegen/wasm.zig+58-56
......@@ -792,43 +792,45 @@ pub const Context = struct {
792792 fn genInst(self: *Context, inst: Air.Inst.Index) !WValue {
793793 const air_tags = self.air.instructions.items(.tag);
794794 return switch (air_tags[inst]) {
795 .add => self.genBinOp(inst, .add),
796 .alloc => self.genAlloc(inst),
797 .arg => self.genArg(inst),
798 .bit_and => self.genBinOp(inst, .@"and"),
799 .bitcast => self.genBitcast(inst),
800 .bit_or => self.genBinOp(inst, .@"or"),
801 .block => self.genBlock(inst),
802 .bool_and => self.genBinOp(inst, .@"and"),
803 .bool_or => self.genBinOp(inst, .@"or"),
804 .breakpoint => self.genBreakpoint(inst),
805 .br => self.genBr(inst),
806 .call => self.genCall(inst),
807 .cmp_eq => self.genCmp(inst, .eq),
808 .cmp_gte => self.genCmp(inst, .gte),
809 .cmp_gt => self.genCmp(inst, .gt),
810 .cmp_lte => self.genCmp(inst, .lte),
811 .cmp_lt => self.genCmp(inst, .lt),
812 .cmp_neq => self.genCmp(inst, .neq),
813 .cond_br => self.genCondBr(inst),
795 .add => self.airBinOp(inst, .add),
796 .sub => self.airBinOp(inst, .sub),
797 .mul => self.airBinOp(inst, .mul),
798 .div => self.airBinOp(inst, .div),
799 .bit_and => self.airBinOp(inst, .@"and"),
800 .bit_or => self.airBinOp(inst, .@"or"),
801 .bool_and => self.airBinOp(inst, .@"and"),
802 .bool_or => self.airBinOp(inst, .@"or"),
803 .xor => self.airBinOp(inst, .xor),
804
805 .cmp_eq => self.airCmp(inst, .eq),
806 .cmp_gte => self.airCmp(inst, .gte),
807 .cmp_gt => self.airCmp(inst, .gt),
808 .cmp_lte => self.airCmp(inst, .lte),
809 .cmp_lt => self.airCmp(inst, .lt),
810 .cmp_neq => self.airCmp(inst, .neq),
811
812 .alloc => self.airAlloc(inst),
813 .arg => self.airArg(inst),
814 .bitcast => self.airBitcast(inst),
815 .block => self.airBlock(inst),
816 .breakpoint => self.airBreakpoint(inst),
817 .br => self.airBr(inst),
818 .call => self.airCall(inst),
819 .cond_br => self.airCondBr(inst),
814820 .constant => unreachable,
815821 .dbg_stmt => WValue.none,
816 .div => self.genBinOp(inst, .div),
817 .is_err => self.genIsErr(inst, .i32_ne),
818 .is_non_err => self.genIsErr(inst, .i32_eq),
819 .load => self.genLoad(inst),
820 .loop => self.genLoop(inst),
821 .mul => self.genBinOp(inst, .mul),
822 .not => self.genNot(inst),
823 .ret => self.genRet(inst),
824 .store => self.genStore(inst),
825 .struct_field_ptr => self.genStructFieldPtr(inst),
826 .sub => self.genBinOp(inst, .sub),
827 .switch_br => self.genSwitchBr(inst),
828 .unreach => self.genUnreachable(inst),
829 .unwrap_errunion_payload => self.genUnwrapErrUnionPayload(inst),
830 .wrap_errunion_payload => self.genWrapErrUnionPayload(inst),
831 .xor => self.genBinOp(inst, .xor),
822 .is_err => self.airIsErr(inst, .i32_ne),
823 .is_non_err => self.airIsErr(inst, .i32_eq),
824 .load => self.airLoad(inst),
825 .loop => self.airLoop(inst),
826 .not => self.airNot(inst),
827 .ret => self.airRet(inst),
828 .store => self.airStore(inst),
829 .struct_field_ptr => self.airStructFieldPtr(inst),
830 .switch_br => self.airSwitchBr(inst),
831 .unreach => self.airUnreachable(inst),
832 .unwrap_errunion_payload => self.airUnwrapErrUnionPayload(inst),
833 .wrap_errunion_payload => self.airWrapErrUnionPayload(inst),
832834 else => |tag| self.fail("TODO: Implement wasm inst: {s}", .{@tagName(tag)}),
833835 };
834836 }
......@@ -840,7 +842,7 @@ pub const Context = struct {
840842 }
841843 }
842844
843 fn genRet(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
845 fn airRet(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
844846 const un_op = self.air.instructions.items(.data)[inst].un_op;
845847 const operand = self.resolveInst(un_op);
846848 try self.emitWValue(operand);
......@@ -848,7 +850,7 @@ pub const Context = struct {
848850 return .none;
849851 }
850852
851 fn genCall(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
853 fn airCall(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
852854 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
853855 const extra = self.air.extraData(Air.Call, pl_op.payload);
854856 const args = self.air.extra[extra.end..][0..extra.data.args_len];
......@@ -882,12 +884,12 @@ pub const Context = struct {
882884 return .none;
883885 }
884886
885 fn genAlloc(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
887 fn airAlloc(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
886888 const elem_type = self.air.typeOfIndex(inst).elemType();
887889 return self.allocLocal(elem_type);
888890 }
889891
890 fn genStore(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
892 fn airStore(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
891893 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
892894 const writer = self.code.writer();
893895
......@@ -926,19 +928,19 @@ pub const Context = struct {
926928 return .none;
927929 }
928930
929 fn genLoad(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
931 fn airLoad(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
930932 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
931933 return self.resolveInst(ty_op.operand);
932934 }
933935
934 fn genArg(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
936 fn airArg(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
935937 _ = inst;
936938 // arguments share the index with locals
937939 defer self.local_index += 1;
938940 return WValue{ .local = self.local_index };
939941 }
940942
941 fn genBinOp(self: *Context, inst: Air.Inst.Index, op: Op) InnerError!WValue {
943 fn airBinOp(self: *Context, inst: Air.Inst.Index, op: Op) InnerError!WValue {
942944 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
943945 const lhs = self.resolveInst(bin_op.lhs);
944946 const rhs = self.resolveInst(bin_op.rhs);
......@@ -1074,7 +1076,7 @@ pub const Context = struct {
10741076 }
10751077 }
10761078
1077 fn genBlock(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1079 fn airBlock(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
10781080 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
10791081 const block_ty = try self.genBlockType(self.air.getRefType(ty_pl.ty));
10801082 const extra = self.air.extraData(Air.Block, ty_pl.payload);
......@@ -1108,7 +1110,7 @@ pub const Context = struct {
11081110 self.block_depth -= 1;
11091111 }
11101112
1111 fn genLoop(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1113 fn airLoop(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
11121114 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
11131115 const loop = self.air.extraData(Air.Block, ty_pl.payload);
11141116 const body = self.air.extra[loop.end..][0..loop.data.body_len];
......@@ -1127,7 +1129,7 @@ pub const Context = struct {
11271129 return .none;
11281130 }
11291131
1130 fn genCondBr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1132 fn airCondBr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
11311133 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
11321134 const condition = self.resolveInst(pl_op.operand);
11331135 const extra = self.air.extraData(Air.CondBr, pl_op.payload);
......@@ -1166,7 +1168,7 @@ pub const Context = struct {
11661168 return .none;
11671169 }
11681170
1169 fn genCmp(self: *Context, inst: Air.Inst.Index, op: std.math.CompareOperator) InnerError!WValue {
1171 fn airCmp(self: *Context, inst: Air.Inst.Index, op: std.math.CompareOperator) InnerError!WValue {
11701172 // save offset, so potential conditions can insert blocks in front of
11711173 // the comparison that we can later jump back to
11721174 const offset = self.code.items.len;
......@@ -1202,7 +1204,7 @@ pub const Context = struct {
12021204 return WValue{ .code_offset = offset };
12031205 }
12041206
1205 fn genBr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1207 fn airBr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
12061208 const br = self.air.instructions.items(.data)[inst].br;
12071209
12081210 // if operand has codegen bits we should break with a value
......@@ -1220,7 +1222,7 @@ pub const Context = struct {
12201222 return .none;
12211223 }
12221224
1223 fn genNot(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1225 fn airNot(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
12241226 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
12251227 const offset = self.code.items.len;
12261228
......@@ -1238,7 +1240,7 @@ pub const Context = struct {
12381240 return WValue{ .code_offset = offset };
12391241 }
12401242
1241 fn genBreakpoint(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1243 fn airBreakpoint(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
12421244 _ = self;
12431245 _ = inst;
12441246 // unsupported by wasm itself. Can be implemented once we support DWARF
......@@ -1246,18 +1248,18 @@ pub const Context = struct {
12461248 return .none;
12471249 }
12481250
1249 fn genUnreachable(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1251 fn airUnreachable(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
12501252 _ = inst;
12511253 try self.code.append(wasm.opcode(.@"unreachable"));
12521254 return .none;
12531255 }
12541256
1255 fn genBitcast(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1257 fn airBitcast(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
12561258 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
12571259 return self.resolveInst(ty_op.operand);
12581260 }
12591261
1260 fn genStructFieldPtr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1262 fn airStructFieldPtr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
12611263 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
12621264 const extra = self.air.extraData(Air.StructField, ty_pl.payload);
12631265 const struct_ptr = self.resolveInst(extra.data.struct_ptr);
......@@ -1265,7 +1267,7 @@ pub const Context = struct {
12651267 return WValue{ .local = struct_ptr.multi_value.index + @intCast(u32, extra.data.field_index) };
12661268 }
12671269
1268 fn genSwitchBr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1270 fn airSwitchBr(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
12691271 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
12701272 const extra = self.air.extraData(Air.SwitchBr, pl_op.payload);
12711273 const cases = self.air.extra[extra.end..][0..extra.data.cases_len];
......@@ -1319,7 +1321,7 @@ pub const Context = struct {
13191321 return .none;
13201322 }
13211323
1322 fn genIsErr(self: *Context, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!WValue {
1324 fn airIsErr(self: *Context, inst: Air.Inst.Index, opcode: wasm.Opcode) InnerError!WValue {
13231325 const un_op = self.air.instructions.items(.data)[inst].un_op;
13241326 const operand = self.resolveInst(un_op);
13251327 const offset = self.code.items.len;
......@@ -1336,7 +1338,7 @@ pub const Context = struct {
13361338 return WValue{ .code_offset = offset };
13371339 }
13381340
1339 fn genUnwrapErrUnionPayload(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1341 fn airUnwrapErrUnionPayload(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
13401342 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
13411343 const operand = self.resolveInst(ty_op.operand);
13421344 // The index of multi_value contains the error code. To get the initial index of the payload we get
......@@ -1346,7 +1348,7 @@ pub const Context = struct {
13461348 return WValue{ .local = operand.multi_value.index + 1 };
13471349 }
13481350
1349 fn genWrapErrUnionPayload(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
1351 fn airWrapErrUnionPayload(self: *Context, inst: Air.Inst.Index) InnerError!WValue {
13501352 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
13511353 return self.resolveInst(ty_op.operand);
13521354 }