Skip to content

Commit

Permalink
dr: Simplify repeated == chains with matches!
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Nov 26, 2021
1 parent eb1c607 commit c30dcc8
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions autogen/src/dr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,13 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
// LiteralInteger is replaced by LiteralInt32.
// IdResult and IdResultType are not stored as operands in `dr`.
!(element.starts_with("Pair")
|| *element == "LiteralContextDependentNumber"
|| *element == "LiteralInteger"
|| *element == "IdResult"
|| *element == "IdResultType")
|| matches!(
*element,
"LiteralContextDependentNumber"
| "LiteralInteger"
| "IdResult"
| "IdResultType"
))
})
.map(as_ident)
.collect();
Expand Down Expand Up @@ -774,25 +777,22 @@ pub fn gen_dr_builder_normal_insts(grammar: &structs::Grammar) -> TokenStream {
// Generate build methods for all normal instructions (instructions must be
// in some block).
let elements = grammar.instructions.iter().filter(|inst| {
let skip =
inst.class == Some(Type) ||
inst.class == Some(Constant) ||
inst.class == Some(ExtensionDecl) ||
(inst.class == Some(FunctionStruct) && inst.opname != "OpFunctionCall") ||
inst.class == Some(Debug) ||
inst.class == Some(Annotation) ||
is_terminator_instruction(inst) ||
let skip = matches!(
inst.class,
Some(Type | Constant | ExtensionDecl | Debug | Annotation | ModeSetting | Exclude)
) || matches!(
inst.opname.as_str(),
// Labels should not be inserted but attached instead.
inst.opname == "OpLabel" ||
inst.class == Some(ModeSetting) ||
inst.class == Some(Exclude) ||
inst.opname == "OpTypeForwardPointer" ||
inst.opname == "OpTypePointer" ||
inst.opname == "OpTypeOpaque" ||
inst.opname == "OpUndef" ||
inst.opname == "OpVariable" ||
inst.opname == "OpSamplerImageAddressingModeNV" ||
inst.opname.starts_with("OpType");
"OpLabel"
| "OpTypeForwardPointer"
| "OpTypePointer"
| "OpTypeOpaque"
| "OpUndef"
| "OpVariable"
| "OpSamplerImageAddressingModeNV"
) || (inst.class == Some(FunctionStruct) && inst.opname != "OpFunctionCall")
|| is_terminator_instruction(inst)
|| inst.opname.starts_with("OpType");
!skip
}).map(|inst| {
let params = get_param_list(&inst.operands, true, kinds);
Expand Down

0 comments on commit c30dcc8

Please sign in to comment.