Added opcode functions to Instruction/Constant.Tag

This commit is contained in:
antlilja 2024-01-20 00:20:38 +01:00
parent ff76ba64d6
commit 52e8434022

View File

@ -130,6 +130,67 @@ pub const String = enum(u32) {
};
};
pub const BinaryOpcode = enum(u4) {
add = 0,
sub = 1,
mul = 2,
udiv = 3,
sdiv = 4,
urem = 5,
srem = 6,
shl = 7,
lshr = 8,
ashr = 9,
@"and" = 10,
@"or" = 11,
xor = 12,
};
pub const CastOpcode = enum(u4) {
trunc = 0,
zext = 1,
sext = 2,
fptoui = 3,
fptosi = 4,
uitofp = 5,
sitofp = 6,
fptrunc = 7,
fpext = 8,
ptrtoint = 9,
inttoptr = 10,
bitcast = 11,
addrspacecast = 12,
};
pub const CmpPredicate = enum(u6) {
fcmp_false = 0,
fcmp_oeq = 1,
fcmp_ogt = 2,
fcmp_oge = 3,
fcmp_olt = 4,
fcmp_ole = 5,
fcmp_one = 6,
fcmp_ord = 7,
fcmp_uno = 8,
fcmp_ueq = 9,
fcmp_ugt = 10,
fcmp_uge = 11,
fcmp_ult = 12,
fcmp_ule = 13,
fcmp_une = 14,
fcmp_true = 15,
icmp_eq = 32,
icmp_ne = 33,
icmp_ugt = 34,
icmp_uge = 35,
icmp_ult = 36,
icmp_ule = 37,
icmp_sgt = 38,
icmp_sge = 39,
icmp_slt = 40,
icmp_sle = 41,
};
pub const StrtabString = struct {
offset: usize,
size: usize,
@ -4125,6 +4186,143 @@ pub const Function = struct {
va_arg,
xor,
zext,
pub fn toBinaryOpcode(self: Tag) BinaryOpcode {
return switch (self) {
.add,
.@"add nsw",
.@"add nuw",
.@"add nuw nsw",
.fadd,
.@"fadd fast",
=> .add,
.sub,
.@"sub nsw",
.@"sub nuw",
.@"sub nuw nsw",
.fsub,
.@"fsub fast",
=> .sub,
.sdiv,
.@"sdiv exact",
.fdiv,
.@"fdiv fast",
=> .sdiv,
.fmul,
.@"fmul fast",
.mul,
.@"mul nsw",
.@"mul nuw",
.@"mul nuw nsw",
=> .mul,
.srem,
.frem,
.@"frem fast",
=> .srem,
.udiv,
.@"udiv exact",
=> .udiv,
.shl,
.@"shl nsw",
.@"shl nuw",
.@"shl nuw nsw",
=> .shl,
.lshr,
.@"lshr exact",
=> .lshr,
.ashr,
.@"ashr exact",
=> .ashr,
.@"and" => .@"and",
.@"or" => .@"or",
.xor => .xor,
.urem => .urem,
else => unreachable,
};
}
pub fn toCastOpcode(self: Tag) CastOpcode {
return switch (self) {
.trunc => .trunc,
.zext => .zext,
.sext => .sext,
.fptoui => .fptoui,
.fptosi => .fptosi,
.uitofp => .uitofp,
.sitofp => .sitofp,
.fptrunc => .fptrunc,
.fpext => .fpext,
.ptrtoint => .ptrtoint,
.inttoptr => .inttoptr,
.bitcast => .bitcast,
.addrspacecast => .addrspacecast,
else => unreachable,
};
}
pub fn toCmpPredicate(self: Tag) CmpPredicate {
return switch (self) {
.@"fcmp false",
.@"fcmp fast false",
=> .fcmp_false,
.@"fcmp oeq",
.@"fcmp fast oeq",
=> .fcmp_oeq,
.@"fcmp oge",
.@"fcmp fast oge",
=> .fcmp_oge,
.@"fcmp ogt",
.@"fcmp fast ogt",
=> .fcmp_ogt,
.@"fcmp ole",
.@"fcmp fast ole",
=> .fcmp_ole,
.@"fcmp olt",
.@"fcmp fast olt",
=> .fcmp_olt,
.@"fcmp one",
.@"fcmp fast one",
=> .fcmp_one,
.@"fcmp ord",
.@"fcmp fast ord",
=> .fcmp_ord,
.@"fcmp true",
.@"fcmp fast true",
=> .fcmp_true,
.@"fcmp ueq",
.@"fcmp fast ueq",
=> .fcmp_ueq,
.@"fcmp uge",
.@"fcmp fast uge",
=> .fcmp_uge,
.@"fcmp ugt",
.@"fcmp fast ugt",
=> .fcmp_ugt,
.@"fcmp ule",
.@"fcmp fast ule",
=> .fcmp_ule,
.@"fcmp ult",
.@"fcmp fast ult",
=> .fcmp_ult,
.@"fcmp une",
.@"fcmp fast une",
=> .fcmp_une,
.@"fcmp uno",
.@"fcmp fast uno",
=> .fcmp_uno,
.@"icmp eq" => .icmp_eq,
.@"icmp ne" => .icmp_ne,
.@"icmp sge" => .icmp_sge,
.@"icmp sgt" => .icmp_sgt,
.@"icmp sle" => .icmp_sle,
.@"icmp slt" => .icmp_slt,
.@"icmp uge" => .icmp_uge,
.@"icmp ugt" => .icmp_ugt,
.@"icmp ule" => .icmp_ule,
.@"icmp ult" => .icmp_ult,
else => unreachable,
};
}
};
pub const Index = enum(u32) {
@ -7239,6 +7437,49 @@ pub const Constant = enum(u32) {
@"asm sideeffect inteldialect unwind",
@"asm alignstack inteldialect unwind",
@"asm sideeffect alignstack inteldialect unwind",
pub fn toBinaryOpcode(self: Tag) BinaryOpcode {
return switch (self) {
.add,
.@"add nsw",
.@"add nuw",
=> .add,
.sub,
.@"sub nsw",
.@"sub nuw",
=> .sub,
.mul,
.@"mul nsw",
.@"mul nuw",
=> .mul,
.shl => .shl,
.lshr => .lshr,
.ashr => .ashr,
.@"and" => .@"and",
.@"or" => .@"or",
.xor => .xor,
else => unreachable,
};
}
pub fn toCastOpcode(self: Tag) CastOpcode {
return switch (self) {
.trunc => .trunc,
.zext => .zext,
.sext => .sext,
.fptoui => .fptoui,
.fptosi => .fptosi,
.uitofp => .uitofp,
.sitofp => .sitofp,
.fptrunc => .fptrunc,
.fpext => .fpext,
.ptrtoint => .ptrtoint,
.inttoptr => .inttoptr,
.bitcast => .bitcast,
.addrspacecast => .addrspacecast,
else => unreachable,
};
}
};
pub const Item = struct {