authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-01-20 00:20:38+01:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2024-02-21 16:24:59+01:00
log52e843402224e43141a63e406432643b4304b507
treeb9d4a51d9508841a7e96a6da7bb73997b6498b96
parentff76ba64d63f8a82a22cda65aee2aa6e9e69ca75

Added opcode functions to Instruction/Constant.Tag


1 files changed, 241 insertions(+), 0 deletions(-)

src/codegen/llvm/Builder.zig+241
...@@ -130,6 +130,67 @@ pub const String = enum(u32) {...@@ -130,6 +130,67 @@ pub const String = enum(u32) {
130 };130 };
131};131};
132132
133pub const BinaryOpcode = enum(u4) {
134 add = 0,
135 sub = 1,
136 mul = 2,
137 udiv = 3,
138 sdiv = 4,
139 urem = 5,
140 srem = 6,
141 shl = 7,
142 lshr = 8,
143 ashr = 9,
144 @"and" = 10,
145 @"or" = 11,
146 xor = 12,
147};
148
149pub const CastOpcode = enum(u4) {
150 trunc = 0,
151 zext = 1,
152 sext = 2,
153 fptoui = 3,
154 fptosi = 4,
155 uitofp = 5,
156 sitofp = 6,
157 fptrunc = 7,
158 fpext = 8,
159 ptrtoint = 9,
160 inttoptr = 10,
161 bitcast = 11,
162 addrspacecast = 12,
163};
164
165pub const CmpPredicate = enum(u6) {
166 fcmp_false = 0,
167 fcmp_oeq = 1,
168 fcmp_ogt = 2,
169 fcmp_oge = 3,
170 fcmp_olt = 4,
171 fcmp_ole = 5,
172 fcmp_one = 6,
173 fcmp_ord = 7,
174 fcmp_uno = 8,
175 fcmp_ueq = 9,
176 fcmp_ugt = 10,
177 fcmp_uge = 11,
178 fcmp_ult = 12,
179 fcmp_ule = 13,
180 fcmp_une = 14,
181 fcmp_true = 15,
182 icmp_eq = 32,
183 icmp_ne = 33,
184 icmp_ugt = 34,
185 icmp_uge = 35,
186 icmp_ult = 36,
187 icmp_ule = 37,
188 icmp_sgt = 38,
189 icmp_sge = 39,
190 icmp_slt = 40,
191 icmp_sle = 41,
192};
193
133pub const StrtabString = struct {194pub const StrtabString = struct {
134 offset: usize,195 offset: usize,
135 size: usize,196 size: usize,
...@@ -4125,6 +4186,143 @@ pub const Function = struct {...@@ -4125,6 +4186,143 @@ pub const Function = struct {
4125 va_arg,4186 va_arg,
4126 xor,4187 xor,
4127 zext,4188 zext,
4189
4190 pub fn toBinaryOpcode(self: Tag) BinaryOpcode {
4191 return switch (self) {
4192 .add,
4193 .@"add nsw",
4194 .@"add nuw",
4195 .@"add nuw nsw",
4196 .fadd,
4197 .@"fadd fast",
4198 => .add,
4199 .sub,
4200 .@"sub nsw",
4201 .@"sub nuw",
4202 .@"sub nuw nsw",
4203 .fsub,
4204 .@"fsub fast",
4205 => .sub,
4206 .sdiv,
4207 .@"sdiv exact",
4208 .fdiv,
4209 .@"fdiv fast",
4210 => .sdiv,
4211 .fmul,
4212 .@"fmul fast",
4213 .mul,
4214 .@"mul nsw",
4215 .@"mul nuw",
4216 .@"mul nuw nsw",
4217 => .mul,
4218 .srem,
4219 .frem,
4220 .@"frem fast",
4221 => .srem,
4222 .udiv,
4223 .@"udiv exact",
4224 => .udiv,
4225 .shl,
4226 .@"shl nsw",
4227 .@"shl nuw",
4228 .@"shl nuw nsw",
4229 => .shl,
4230 .lshr,
4231 .@"lshr exact",
4232 => .lshr,
4233 .ashr,
4234 .@"ashr exact",
4235 => .ashr,
4236 .@"and" => .@"and",
4237 .@"or" => .@"or",
4238 .xor => .xor,
4239 .urem => .urem,
4240 else => unreachable,
4241 };
4242 }
4243
4244 pub fn toCastOpcode(self: Tag) CastOpcode {
4245 return switch (self) {
4246 .trunc => .trunc,
4247 .zext => .zext,
4248 .sext => .sext,
4249 .fptoui => .fptoui,
4250 .fptosi => .fptosi,
4251 .uitofp => .uitofp,
4252 .sitofp => .sitofp,
4253 .fptrunc => .fptrunc,
4254 .fpext => .fpext,
4255 .ptrtoint => .ptrtoint,
4256 .inttoptr => .inttoptr,
4257 .bitcast => .bitcast,
4258 .addrspacecast => .addrspacecast,
4259 else => unreachable,
4260 };
4261 }
4262
4263 pub fn toCmpPredicate(self: Tag) CmpPredicate {
4264 return switch (self) {
4265 .@"fcmp false",
4266 .@"fcmp fast false",
4267 => .fcmp_false,
4268 .@"fcmp oeq",
4269 .@"fcmp fast oeq",
4270 => .fcmp_oeq,
4271 .@"fcmp oge",
4272 .@"fcmp fast oge",
4273 => .fcmp_oge,
4274 .@"fcmp ogt",
4275 .@"fcmp fast ogt",
4276 => .fcmp_ogt,
4277 .@"fcmp ole",
4278 .@"fcmp fast ole",
4279 => .fcmp_ole,
4280 .@"fcmp olt",
4281 .@"fcmp fast olt",
4282 => .fcmp_olt,
4283 .@"fcmp one",
4284 .@"fcmp fast one",
4285 => .fcmp_one,
4286 .@"fcmp ord",
4287 .@"fcmp fast ord",
4288 => .fcmp_ord,
4289 .@"fcmp true",
4290 .@"fcmp fast true",
4291 => .fcmp_true,
4292 .@"fcmp ueq",
4293 .@"fcmp fast ueq",
4294 => .fcmp_ueq,
4295 .@"fcmp uge",
4296 .@"fcmp fast uge",
4297 => .fcmp_uge,
4298 .@"fcmp ugt",
4299 .@"fcmp fast ugt",
4300 => .fcmp_ugt,
4301 .@"fcmp ule",
4302 .@"fcmp fast ule",
4303 => .fcmp_ule,
4304 .@"fcmp ult",
4305 .@"fcmp fast ult",
4306 => .fcmp_ult,
4307 .@"fcmp une",
4308 .@"fcmp fast une",
4309 => .fcmp_une,
4310 .@"fcmp uno",
4311 .@"fcmp fast uno",
4312 => .fcmp_uno,
4313 .@"icmp eq" => .icmp_eq,
4314 .@"icmp ne" => .icmp_ne,
4315 .@"icmp sge" => .icmp_sge,
4316 .@"icmp sgt" => .icmp_sgt,
4317 .@"icmp sle" => .icmp_sle,
4318 .@"icmp slt" => .icmp_slt,
4319 .@"icmp uge" => .icmp_uge,
4320 .@"icmp ugt" => .icmp_ugt,
4321 .@"icmp ule" => .icmp_ule,
4322 .@"icmp ult" => .icmp_ult,
4323 else => unreachable,
4324 };
4325 }
4128 };4326 };
41294327
4130 pub const Index = enum(u32) {4328 pub const Index = enum(u32) {
...@@ -7239,6 +7437,49 @@ pub const Constant = enum(u32) {...@@ -7239,6 +7437,49 @@ pub const Constant = enum(u32) {
7239 @"asm sideeffect inteldialect unwind",7437 @"asm sideeffect inteldialect unwind",
7240 @"asm alignstack inteldialect unwind",7438 @"asm alignstack inteldialect unwind",
7241 @"asm sideeffect alignstack inteldialect unwind",7439 @"asm sideeffect alignstack inteldialect unwind",
7440
7441 pub fn toBinaryOpcode(self: Tag) BinaryOpcode {
7442 return switch (self) {
7443 .add,
7444 .@"add nsw",
7445 .@"add nuw",
7446 => .add,
7447 .sub,
7448 .@"sub nsw",
7449 .@"sub nuw",
7450 => .sub,
7451 .mul,
7452 .@"mul nsw",
7453 .@"mul nuw",
7454 => .mul,
7455 .shl => .shl,
7456 .lshr => .lshr,
7457 .ashr => .ashr,
7458 .@"and" => .@"and",
7459 .@"or" => .@"or",
7460 .xor => .xor,
7461 else => unreachable,
7462 };
7463 }
7464
7465 pub fn toCastOpcode(self: Tag) CastOpcode {
7466 return switch (self) {
7467 .trunc => .trunc,
7468 .zext => .zext,
7469 .sext => .sext,
7470 .fptoui => .fptoui,
7471 .fptosi => .fptosi,
7472 .uitofp => .uitofp,
7473 .sitofp => .sitofp,
7474 .fptrunc => .fptrunc,
7475 .fpext => .fpext,
7476 .ptrtoint => .ptrtoint,
7477 .inttoptr => .inttoptr,
7478 .bitcast => .bitcast,
7479 .addrspacecast => .addrspacecast,
7480 else => unreachable,
7481 };
7482 }
7242 };7483 };
72437484
7244 pub const Item = struct {7485 pub const Item = struct {