From bd9648d960b8b61b4152f630a188e50416242ab0 Mon Sep 17 00:00:00 2001 From: abdul124 Date: Fri, 30 Aug 2024 14:22:27 +0800 Subject: [PATCH] language: sync exception ids and names --- artiq/coredevice/exceptions.py | 23 +++++++++++++++- artiq/language/embedding_map.py | 49 +++++++++++++++++++-------------- 2 files changed, 50 insertions(+), 22 deletions(-) diff --git a/artiq/coredevice/exceptions.py b/artiq/coredevice/exceptions.py index 9a7c2e598..16b0fb533 100644 --- a/artiq/coredevice/exceptions.py +++ b/artiq/coredevice/exceptions.py @@ -1,6 +1,27 @@ +import builtins +from numpy.linalg import LinAlgError from artiq.language.core import nac3, UnwrapNoneError -from builtins import ZeroDivisionError, ValueError, IndexError, RuntimeError, AssertionError +""" +This file provides class definition for all the exceptions declared in `EmbeddingMap` in `artiq.language.embedding_map` + +For Python builtin exceptions, use the `builtins` module +For ARTIQ specific exceptions, inherit from `Exception` class +""" + +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 @nac3 class RTIOUnderflow(Exception): diff --git a/artiq/language/embedding_map.py b/artiq/language/embedding_map.py index 14833b730..11739e0b1 100644 --- a/artiq/language/embedding_map.py +++ b/artiq/language/embedding_map.py @@ -7,27 +7,34 @@ class EmbeddingMap: self.function_map = {} self.attributes_writeback = [] - # preallocate exception names - # must be kept in sync with EXCEPTION_ID_LOOKUP in artiq/firmware/ksupport/eh_artiq.rs, - # and src/runtime/src/eh_artiq.rs (Zynq) - self.preallocate_runtime_exception_names(["RuntimeError", - "RTIOUnderflow", - "RTIOOverflow", - "RTIODestinationUnreachable", - "DMAError", - "I2CError", - "CacheError", - "SPIError", - "0:ZeroDivisionError", - "0:IndexError", - "0:ValueError", - "0:RuntimeError", - "0:AssertionError", - "0:KeyError", - "0:NotImplementedError", - "0:OverflowError", - "0:IOError", - "0:UnwrapNoneError"]) + # Keep this list of exceptions in sync with `EXCEPTION_ID_LOOKUP` in `artiq::firmware::ksupport::eh_artiq` + # The exceptions declared here must be defined in `artiq.coredevice.exceptions` + # Verify synchronization by running the test cases in `artiq.test.coredevice.test_exceptions` + self.preallocate_runtime_exception_names([ + "RTIOUnderflow", + "RTIOOverflow", + "RTIODestinationUnreachable", + "DMAError", + "I2CError", + "CacheError", + "SPIError", + "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", + "0:LinAlgError", + "UnwrapNoneError", + ]) def preallocate_runtime_exception_names(self, names): for i, name in enumerate(names):