Add is_call and is_return instruction attributes.

This commit is contained in:
Jakob Stoklund Olesen
2017-03-08 14:48:50 -08:00
parent 7a45aeebeb
commit 58756e5d34
3 changed files with 23 additions and 31 deletions

View File

@@ -288,31 +288,13 @@ def gen_opcodes(groups, fmt):
fmt.line()
with fmt.indented('impl Opcode {', '}'):
attrs = [
{
'name': 'is_branch',
'comment': 'True for all branch instructions.'
},
{
'name': 'is_terminator',
'comment': 'True for instructions that terminate EBB.'
},
{
'name': 'can_trap',
'comment': 'True if instruction could trap.'
}
]
for attr in attrs:
if attr != attrs[0]:
fmt.line()
fmt.doc_comment(attr['comment'])
for attr in sorted(Instruction.ATTRIBS.keys()):
fmt.doc_comment(Instruction.ATTRIBS[attr])
with fmt.indented('pub fn {}(self) -> bool {{'
.format(attr['name']), '}'):
.format(attr), '}'):
with fmt.indented('match self {', '}'):
for i in instrs:
if getattr(i, attr['name']):
if getattr(i, attr):
fmt.format(
'Opcode::{} => true,',
i.camel_name, i.name)