Add a stack_check instruction.

This instruction loads a stack limit from a global variable and compares
it to the stack pointer, trapping if the stack has grown beyond the
limit.

Also add a expand_flags transform group containing legalization patterns
for ISAs with CPU flags.

Fixes #234.
This commit is contained in:
Jakob Stoklund Olesen
2018-02-12 13:50:22 -08:00
parent a73fcb2691
commit 3ccc3f4f9b
8 changed files with 107 additions and 13 deletions

View File

@@ -567,6 +567,21 @@ copy_special = Instruction(
ins=(src, dst),
other_side_effects=True)
GV = Operand(
'GV', entities.global_var, doc=r"""
Global variable containing the stack limit.
""")
stack_check = Instruction(
'stack_check', r"""
Check for stack overflow.
Read the stack limit from ``GV`` and compare it to the stack pointer. If
the stack pointer has reached or exceeded the limit, generate a trap with a
``stk_ovf`` code.
""",
ins=GV, can_trap=True)
StackOffset = Operand('Offset', imm64, 'Offset from current stack pointer')
adjust_sp_imm = Instruction(
'adjust_sp_imm', r"""