[restructured] moved more types and exceptions to riscemu.types

assembly-parser-rework
Anton Lydike 3 years ago
parent bc26ed3a02
commit cc3df91fd1

@ -14,7 +14,7 @@ from .config import RunConfig
from .MMU import MMU from .MMU import MMU
from .colors import FMT_CPU, FMT_NONE from .colors import FMT_CPU, FMT_NONE
from .debug import launch_debug_session from .debug import launch_debug_session
from .exceptions import RiscemuBaseException, LaunchDebuggerException from .types.exceptions import RiscemuBaseException, LaunchDebuggerException
from .syscall import SyscallInterface, get_syscall_symbols from .syscall import SyscallInterface, get_syscall_symbols
from .types import CPU, ProgramLoader, Int32, BinaryDataMemorySection from .types import CPU, ProgramLoader, Int32, BinaryDataMemorySection
from .parser import AssemblyFileLoader from .parser import AssemblyFileLoader

@ -7,10 +7,10 @@ SPDX-License-Identifier: MIT
from typing import Dict, List, Optional, Union from typing import Dict, List, Optional, Union
from .colors import * from .colors import *
from .exceptions import InvalidAllocationException, MemoryAccessException
from .helpers import align_addr from .helpers import align_addr
from .types import Instruction, MemorySection, MemoryFlags, T_AbsoluteAddress, \ from .types import Instruction, MemorySection, MemoryFlags, T_AbsoluteAddress, \
Program, InstructionContext, Int32 Program, InstructionContext, Int32
from .types.exceptions import InvalidAllocationException, MemoryAccessException
class MMU: class MMU:

@ -8,7 +8,7 @@ This package aims at providing an all-round usable RISC-V emulator and debugger
It contains everything needed to run assembly files, so you don't need any custom compilers or toolchains It contains everything needed to run assembly files, so you don't need any custom compilers or toolchains
""" """
from .exceptions import RiscemuBaseException, LaunchDebuggerException, InvalidSyscallException, LinkerException, \ from .types.exceptions import RiscemuBaseException, LaunchDebuggerException, InvalidSyscallException, LinkerException, \
ParseException, NumberFormatException, InvalidRegisterException, MemoryAccessException, OutOfMemoryException ParseException, NumberFormatException, InvalidRegisterException, MemoryAccessException, OutOfMemoryException
from .instructions import * from .instructions import *

@ -3,7 +3,7 @@ from typing import List
from typing import Optional, Tuple, Union from typing import Optional, Tuple, Union
from .colors import FMT_PARSE, FMT_NONE from .colors import FMT_PARSE, FMT_NONE
from .exceptions import ParseException, ASSERT_LEN from riscemu.types.exceptions import ParseException, ASSERT_LEN
from .helpers import parse_numeric_argument, align_addr, get_section_base_name from .helpers import parse_numeric_argument, align_addr, get_section_base_name
from .tokenizer import Token from .tokenizer import Token
from .types import Program, T_RelativeAddress, InstructionContext, Instruction, BinaryDataMemorySection, InstructionMemorySection from .types import Program, T_RelativeAddress, InstructionContext, Instruction, BinaryDataMemorySection, InstructionMemorySection

@ -7,8 +7,8 @@ SPDX-License-Identifier: MIT
from math import log10, ceil from math import log10, ceil
from typing import Iterable, Iterator, TypeVar, Generic, List, Optional from typing import Iterable, Iterator, TypeVar, Generic, List, Optional
from .exceptions import * from .types.exceptions import *
import types from .types import Int32, UInt32
def align_addr(addr: int, to_bytes: int = 8) -> int: def align_addr(addr: int, to_bytes: int = 8) -> int:
@ -55,10 +55,10 @@ def format_bytes(byte_arr: bytearray, fmt: str, group: int = 1, highlight: int =
return highlight_in_list(['0x{}'.format(ch.hex()) for ch in chunks], highlight) return highlight_in_list(['0x{}'.format(ch.hex()) for ch in chunks], highlight)
if fmt == 'int': if fmt == 'int':
spc = str(ceil(log10(2 ** (group * 8 - 1))) + 1) spc = str(ceil(log10(2 ** (group * 8 - 1))) + 1)
return highlight_in_list([('{:0' + spc + 'd}').format(types.Int32(ch)) for ch in chunks], highlight) return highlight_in_list([('{:0' + spc + 'd}').format(Int32(ch)) for ch in chunks], highlight)
if fmt == 'uint': if fmt == 'uint':
spc = str(ceil(log10(2 ** (group * 8)))) spc = str(ceil(log10(2 ** (group * 8))))
return highlight_in_list([('{:0' + spc + 'd}').format(types.UInt32(ch)) for ch in chunks], return highlight_in_list([('{:0' + spc + 'd}').format(UInt32(ch)) for ch in chunks],
highlight) highlight)
if fmt == 'ascii': if fmt == 'ascii':
return "".join(repr(chr(b))[1:-1] for b in byte_arr) return "".join(repr(chr(b))[1:-1] for b in byte_arr)

@ -1,5 +1,5 @@
from .instruction_set import InstructionSet, Instruction from .instruction_set import InstructionSet, Instruction
from ..exceptions import INS_NOT_IMPLEMENTED from riscemu.types.exceptions import INS_NOT_IMPLEMENTED
from ..types import Int32, UInt32 from ..types import Int32, UInt32

@ -8,8 +8,7 @@ from .instruction_set import *
from ..CPU import UserModeCPU from ..CPU import UserModeCPU
from ..colors import FMT_DEBUG, FMT_NONE from ..colors import FMT_DEBUG, FMT_NONE
from ..debug import launch_debug_session from riscemu.types.exceptions import LaunchDebuggerException
from ..exceptions import LaunchDebuggerException
from ..syscall import Syscall from ..syscall import Syscall
from ..types import Instruction, Int32, UInt32 from ..types import Instruction, Int32, UInt32

@ -5,7 +5,7 @@ SPDX-License-Identifier: MIT
""" """
from .instruction_set import * from .instruction_set import *
from ..exceptions import INS_NOT_IMPLEMENTED from riscemu.types.exceptions import INS_NOT_IMPLEMENTED
class RV32M(InstructionSet): class RV32M(InstructionSet):

@ -8,7 +8,7 @@ from typing import Tuple, Callable, Dict
from abc import ABC from abc import ABC
from ..CPU import CPU from ..CPU import CPU
from ..exceptions import ASSERT_LEN, ASSERT_IN from riscemu.types.exceptions import ASSERT_LEN, ASSERT_IN
from ..types import Instruction, Int32, UInt32 from ..types import Instruction, Int32, UInt32

@ -8,10 +8,10 @@ from typing import Dict, Tuple, Iterable, Callable, List
from .assembler import MemorySectionType, ParseContext, AssemblerDirectives from .assembler import MemorySectionType, ParseContext, AssemblerDirectives
from .colors import FMT_PARSE from .colors import FMT_PARSE
from .exceptions import ParseException
from .helpers import Peekable from .helpers import Peekable
from .tokenizer import Token, TokenType, tokenize from .tokenizer import Token, TokenType, tokenize
from .types import Program, T_ParserOpts, ProgramLoader, SimpleInstruction from .types import Program, T_ParserOpts, ProgramLoader, SimpleInstruction
from .types.exceptions import ParseException
def parse_instruction(token: Token, args: Tuple[str], context: ParseContext): def parse_instruction(token: Token, args: Tuple[str], context: ParseContext):

@ -5,7 +5,7 @@ SPDX-License-Identifier: MIT
""" """
from ..instructions.RV32I import * from ..instructions.RV32I import *
from ..exceptions import INS_NOT_IMPLEMENTED from riscemu.types.exceptions import INS_NOT_IMPLEMENTED
from .Exceptions import * from .Exceptions import *
from .privmodes import PrivModes from .privmodes import PrivModes
from ..colors import FMT_CPU, FMT_NONE from ..colors import FMT_CPU, FMT_NONE

@ -7,10 +7,10 @@ SPDX-License-Identifier: MIT
import re import re
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum, auto from enum import Enum, auto
from typing import List, Iterable, Optional from typing import List, Iterable
from riscemu.decoder import RISCV_REGS
from .exceptions import ParseException from riscemu.decoder import RISCV_REGS
from riscemu.types.exceptions import ParseException
LINE_COMMENT_STARTERS = ('#', ';', '//') LINE_COMMENT_STARTERS = ('#', ';', '//')
WHITESPACE_PATTERN = re.compile(r'\s+') WHITESPACE_PATTERN = re.compile(r'\s+')

@ -10,6 +10,7 @@ T_ParserOpts = Dict[str, any]
NUMBER_SYMBOL_PATTERN = re.compile(r'^\d+[fb]$') NUMBER_SYMBOL_PATTERN = re.compile(r'^\d+[fb]$')
# base classes
from .flags import MemoryFlags from .flags import MemoryFlags
from .int32 import UInt32, Int32 from .int32 import UInt32, Int32
from .instruction import Instruction from .instruction import Instruction
@ -22,5 +23,7 @@ from .simple_instruction import SimpleInstruction
from .instruction_memory_section import InstructionMemorySection from .instruction_memory_section import InstructionMemorySection
from .binary_data_memory_section import BinaryDataMemorySection from .binary_data_memory_section import BinaryDataMemorySection
# exceptions
from .exceptions import ParseException, NumberFormatException, MemoryAccessException, OutOfMemoryException, \
LinkerException, LaunchDebuggerException, RiscemuBaseException, InvalidRegisterException, \
InvalidAllocationException, InvalidSyscallException, UnimplementedInstruction

@ -1,5 +1,5 @@
from . import MemorySection, InstructionContext, MemoryFlags, T_RelativeAddress, Instruction from . import MemorySection, InstructionContext, MemoryFlags, T_RelativeAddress, Instruction
from ..exceptions import MemoryAccessException from ..types.exceptions import MemoryAccessException
class BinaryDataMemorySection(MemorySection): class BinaryDataMemorySection(MemorySection):

@ -5,11 +5,11 @@ SPDX-License-Identifier: MIT
""" """
from abc import abstractmethod from abc import abstractmethod
from .colors import * from ..colors import *
import typing import typing
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
from .types import Instruction from . import Instruction
class RiscemuBaseException(BaseException): class RiscemuBaseException(BaseException):

@ -1,7 +1,7 @@
from collections import defaultdict from collections import defaultdict
from typing import Dict, List, Optional from typing import Dict, List, Optional
from ..exceptions import ParseException from .exceptions import ParseException
from ..types import T_AbsoluteAddress, T_RelativeAddress, NUMBER_SYMBOL_PATTERN from ..types import T_AbsoluteAddress, T_RelativeAddress, NUMBER_SYMBOL_PATTERN

Loading…
Cancel
Save