libsel4/tools: use condition element

Signed-off-by: matt rice <ratmice@gmail.com>
This commit is contained in:
matt rice
2022-03-02 07:40:31 -08:00
committed by Gerwin Klein
parent e863cbe987
commit 311d4a0a34
4 changed files with 40 additions and 1 deletions

View File

@@ -8,4 +8,27 @@
# This file allows the the libsel4 tools directory to be imported as
# a python module.
# The following import of `loader` avoids a python module loading error
# When this is used as a module in manual/tools/libsel4_tools.
# Traceback (most recent call last):
# File "/path/to/syscall_stub_gen.py", line 46, in <module>
# from condition import condition_to_cpp
# ModuleNotFoundError: No module named 'condition'
#
# Imports for modules differ from imports for scripts
# Such that when run as a script in tools/ it includes the current
# directory in the search path. But not when imported as a module.
# Importing `loader` will add the current directory to the search path.
#
# It exists as a module so that autopep8 will not reorder the
# code on code formatting. So that the path modification
# needed before import syscall_stub_gen occurs after the import.
#
# Upgrading autopep8 to 1.5.4 would offer an alternate solution:
# fmt: off
# path modification code
# imports.
# fmt: on
from . import loader
from . import condition
from . import syscall_stub_gen

1
libsel4/tools/condition.py Symbolic link
View File

@@ -0,0 +1 @@
../../tools/condition.py

View File

@@ -0,0 +1,14 @@
# Copyright 2022, seL4 Project a Series of LF Projects, LLC
#
# SPDX-License-Identifier: BSD-2-Clause or GPL-2.0-only
import os
import sys
import pathlib
# Add the parent module to the sys.path, do so in this __init__.py
# so that the code producing the side-effect can occur after import
# statements. Otherwise autopep8 would want to reformat this code
# so the side-effect occurs after all import statements.
sys.path.append(str(pathlib.Path(os.path.dirname(os.path.realpath(__file__))).parent))

View File

@@ -43,6 +43,7 @@ import xml.dom.minidom
from argparse import ArgumentParser
import sys
from functools import reduce
from condition import condition_to_cpp
# Number of bits in a standard word
WORD_SIZE_BITS_ARCH = {
@@ -847,7 +848,7 @@ def parse_xml_file(input_file, valid_types):
for method in interface.getElementsByTagName("method"):
method_name = method.getAttribute("name")
method_id = method.getAttribute("id")
method_condition = method.getAttribute("condition")
method_condition = condition_to_cpp(method.getElementsByTagName("condition"))
method_manual_name = method.getAttribute("manual_name") or method_name
method_manual_label = method.getAttribute("manual_label")