added Opcode flags methods

generate `is_branch`, `is_terminator`, `can_trap` methods for `enum
Opcode`.
This commit is contained in:
Dominik Inführ
2016-12-01 00:11:06 +01:00
committed by Jakob Stoklund Olesen
parent 19ac05577c
commit 93aa2b456e
3 changed files with 30 additions and 10 deletions

View File

@@ -271,6 +271,22 @@ def gen_opcodes(groups, fmt):
fmt.line(i.camel_name + ',')
fmt.line()
with fmt.indented('impl Opcode {', '}'):
attrs = ['is_branch', 'is_terminator', 'can_trap']
for attr in attrs:
if attr != attrs[0]:
fmt.line()
with fmt.indented('fn {}(self) -> bool {{'
.format(attr), '}'):
with fmt.indented('match self {', '}'):
for i in instrs:
if getattr(i, attr):
fmt.format('Opcode::{} => true,', i.camel_name, i.name)
fmt.line('_ => false')
# Generate a private opcode_format table.
with fmt.indented(
'const OPCODE_FORMAT: [InstructionFormat; {}] = ['