forked from M-Labs/artiq
1
0
Fork 0

sync exception names and ids

This commit is contained in:
abdul124 2024-08-19 11:43:26 +08:00 committed by Sébastien Bourdeauducq
parent 0eddd2bbaa
commit 33d5002f39
8 changed files with 76 additions and 39 deletions

View File

@ -88,18 +88,32 @@ class EmbeddingMap:
self.subkernel_message_map[msg_type.name] = msg_id self.subkernel_message_map[msg_type.name] = msg_id
self.object_reverse_map[obj_id] = msg_id self.object_reverse_map[obj_id] = msg_id
self.preallocate_runtime_exception_names(["RuntimeError", # Keep this list of exceptions in sync with `EXCEPTION_ID_LOOKUP` in `artiq.firmware.ksupport.eh_artiq``
"RTIOUnderflow", # The exceptions declared here should be defined in `artiq.coredeive.exceptions``
"RTIOOverflow", # Without sync, test cases in artiq.test.coredevice.test_exceptions would fail
"RTIODestinationUnreachable", self.preallocate_runtime_exception_names([
"DMAError", "RTIOUnderflow",
"I2CError", "RTIOOverflow",
"CacheError", "RTIODestinationUnreachable",
"SPIError", "DMAError",
"0:ZeroDivisionError", "I2CError",
"0:IndexError", "CacheError",
"UnwrapNoneError", "SPIError",
"SubkernelError"]) "SubkernelError",
"0:AssertionError",
"0:AttributeError",
"0:IndexError",
"0:IOError",
"0:KeyError",
"0:NotImplementedError",
"0:OverflowError",
"0:RuntimeError",
"0:TimeoutError",
"0:TypeError",
"0:ValueError",
"0:ZeroDivisionError"
])
def preallocate_runtime_exception_names(self, names): def preallocate_runtime_exception_names(self, names):
for i, name in enumerate(names): for i, name in enumerate(names):

View File

@ -6,12 +6,26 @@ import os
from artiq import __artiq_dir__ as artiq_dir from artiq import __artiq_dir__ as artiq_dir
from artiq.coredevice.runtime import source_loader from artiq.coredevice.runtime import source_loader
"""
This file should provide class definition for all the exceptions declared in `EmbeddingMap` in artiq.compiler.embedding
For python builtin exceptions, use the `builtins` module
For artiq specific exceptions, inherit from `Exception` class
"""
ZeroDivisionError = builtins.ZeroDivisionError
ValueError = builtins.ValueError
IndexError = builtins.IndexError
RuntimeError = builtins.RuntimeError
AssertionError = builtins.AssertionError AssertionError = builtins.AssertionError
AttributeError = builtins.AttributeError
IndexError = builtins.IndexError
IOError = builtins.IOError
KeyError = builtins.KeyError
NotImplementedError = builtins.NotImplementedError
OverflowError = builtins.OverflowError
RuntimeError = builtins.RuntimeError
TimeoutError = builtins.TimeoutError
TypeError = builtins.TypeError
ValueError = builtins.ValueError
ZeroDivisionError = builtins.ZeroDivisionError
OSError = builtins.OSError
class CoreException: class CoreException:
@ -157,13 +171,13 @@ class SubkernelError(Exception):
class ClockFailure(Exception): class ClockFailure(Exception):
"""Raised when RTIO PLL has lost lock.""" """Raised when RTIO PLL has lost lock."""
artiq_builtin = True
class I2CError(Exception): class I2CError(Exception):
"""Raised when a I2C transaction fails.""" """Raised when a I2C transaction fails."""
pass artiq_builtin = True
class SPIError(Exception): class SPIError(Exception):
"""Raised when a SPI transaction fails.""" """Raised when a SPI transaction fails."""
pass artiq_builtin = True

View File

@ -328,19 +328,28 @@ extern fn stop_fn(_version: c_int,
} }
} }
static EXCEPTION_ID_LOOKUP: [(&str, u32); 12] = [ // Must be kept in sync with `artq.compiler.embedding`
("RuntimeError", 0), static EXCEPTION_ID_LOOKUP: [(&str, u32); 20] = [
("RTIOUnderflow", 1), ("RTIOUnderflow", 0),
("RTIOOverflow", 2), ("RTIOOverflow", 1),
("RTIODestinationUnreachable", 3), ("RTIODestinationUnreachable", 2),
("DMAError", 4), ("DMAError", 3),
("I2CError", 5), ("I2CError", 4),
("CacheError", 6), ("CacheError", 5),
("SPIError", 7), ("SPIError", 6),
("ZeroDivisionError", 8), ("SubkernelError", 7),
("IndexError", 9), ("AssertionError", 8),
("UnwrapNoneError", 10), ("AttributeError", 9),
("SubkernelError", 11) ("IndexError", 10),
("IOError", 11),
("KeyError", 12),
("NotImplementedError", 13),
("OverflowError", 14),
("RuntimeError", 15),
("TimeoutError", 16),
("TypeError", 17),
("ValueError", 18),
("ZeroDivisionError", 19),
]; ];
pub fn get_exception_id(name: &str) -> u32 { pub fn get_exception_id(name: &str) -> u32 {

View File

@ -8,7 +8,7 @@ def catch(f):
except Exception as e: except Exception as e:
print(e) print(e)
# CHECK-L: 8(0, 0, 0) # CHECK-L: 19(0, 0, 0)
catch(lambda: 1/0) catch(lambda: 1/0)
# CHECK-L: 9(10, 1, 0) # CHECK-L: 10(10, 1, 0)
catch(lambda: [1.0][10]) catch(lambda: [1.0][10])

View File

@ -10,7 +10,7 @@ def catch(f):
except IndexError as ie: except IndexError as ie:
print(ie) print(ie)
# CHECK-L: 8(0, 0, 0) # CHECK-L: 19(0, 0, 0)
catch(lambda: 1/0) catch(lambda: 1/0)
# CHECK-L: 9(10, 1, 0) # CHECK-L: 10(10, 1, 0)
catch(lambda: [1.0][10]) catch(lambda: [1.0][10])

View File

@ -3,7 +3,7 @@
# REQUIRES: exceptions # REQUIRES: exceptions
def f(): def f():
# CHECK-L: Uncaught 8 # CHECK-L: Uncaught 19
# CHECK-L: at input.py:${LINE:+1}: # CHECK-L: at input.py:${LINE:+1}:
1/0 1/0

View File

@ -9,7 +9,7 @@ def g():
try: try:
f() f()
except Exception as e: except Exception as e:
# CHECK-L: Uncaught 8 # CHECK-L: Uncaught 19
# CHECK-L: at input.py:${LINE:+1}: # CHECK-L: at input.py:${LINE:+1}:
raise e raise e

View File

@ -2,6 +2,6 @@
# RUN: OutputCheck %s --file-to-check=%t # RUN: OutputCheck %s --file-to-check=%t
# REQUIRES: exceptions # REQUIRES: exceptions
# CHECK-L: Uncaught 8: cannot divide by zero (0, 0, 0) # CHECK-L: Uncaught 19: cannot divide by zero (0, 0, 0)
# CHECK-L: at input.py:${LINE:+1}: # CHECK-L: at input.py:${LINE:+1}:
1/0 1/0