File tree Expand file tree Collapse file tree
shellblocks/compiler_archs Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ from enum import Enum
12from shellblocks .compiler_archs .mips import CompilerArchMIPSBE , CompilerArchMIPSLE
3+ from shellblocks .compiler_arch import CompilerArch
4+
5+
6+ class CompilerArchOption (Enum ):
7+ MIPSBE = "mipsbe"
8+ MIPSLE = "mipsle"
9+
10+
11+ def compiler_arch_to_object (arch : CompilerArchOption ) -> CompilerArch :
12+ if arch == CompilerArchOption .MIPSBE :
13+ return CompilerArchMIPSBE ()
14+ elif arch == CompilerArchOption .MIPSLE :
15+ return CompilerArchMIPSLE ()
16+
17+ raise NotImplementedError ()
218
319
420__all__ = [
Original file line number Diff line number Diff line change 44
55from pathlib import Path
66
7+ from unicorn import (
8+ Uc ,
9+ UC_ARCH_MIPS ,
10+ UC_MODE_32 ,
11+ UC_MODE_BIG_ENDIAN ,
12+ UC_MODE_LITTLE_ENDIAN ,
13+ )
14+
15+
16+ from shellblocks .test_arch_helper import MIPSHelper
17+
18+ from shellblocks .compiler_archs import CompilerArchOption , compiler_arch_to_object
19+
20+
21+ def pytest_addoption (parser ):
22+ choices = [e .value for e in CompilerArchOption ]
23+
24+ parser .addoption (
25+ "--compiler-arch" ,
26+ type = str ,
27+ choices = choices ,
28+ default = CompilerArchOption .MIPSBE .value ,
29+ help = "The architecture to compile to"
30+ )
31+
32+
33+ @pytest .fixture
34+ def compiler_arch_option (request ):
35+ return CompilerArchOption (request .config .getoption ("--compiler-arch" ))
36+
37+
38+ @pytest .fixture
39+ def compiler_arch (compiler_arch_option ):
40+ return compiler_arch_to_object (compiler_arch_option )
41+
42+
43+ @pytest .fixture
44+ def arch_helper (compiler_arch_option ):
45+ if compiler_arch_option in [CompilerArchOption .MIPSBE , CompilerArchOption .MIPSLE ]:
46+ return MIPSHelper (compiler_arch_option )
47+ else :
48+ raise NotImplementedError ("Arch unimplemented error!" )
49+
50+
51+ @pytest .fixture
52+ def get_mu (compiler_arch_option ):
53+ def get_mu_instance ():
54+ if CompilerArchOption .MIPSBE == compiler_arch_option :
55+ return Uc (UC_ARCH_MIPS , UC_MODE_32 | UC_MODE_BIG_ENDIAN )
56+ elif CompilerArchOption .MIPSLE == compiler_arch_option :
57+ return Uc (UC_ARCH_MIPS , UC_MODE_32 | UC_MODE_LITTLE_ENDIAN )
58+ else :
59+ raise NotImplementedError ("Arch unimplemented error!" )
60+
61+ return get_mu_instance
62+
763
864@pytest .fixture (scope = 'function' )
965def temp_dir_path ():
You can’t perform that action at this time.
0 commit comments