1 # SPDX-License-Identifier: LGPL-3-or-later
2 # Copyright (C) 2020 Michael Nolan <mtnolan2640@gmail.com>
3 # Copyright (C) 2020 Luke Kenneth Casson Leighton <lkcl@lkcl.net>
10 def get_assembled_instruction(instruction
, bigendian
=False):
12 endian_fmt
= "elf64-big"
15 endian_fmt
= "elf64-little"
17 with tempfile
.NamedTemporaryFile(suffix
=".o") as outfile
:
18 args
= ["powerpc64-linux-gnu-as",
22 p
= subprocess
.Popen(args
, stdin
=subprocess
.PIPE
)
23 p
.communicate(instruction
.encode('utf-8'))
26 with tempfile
.NamedTemporaryFile(suffix
=".bin") as binfile
:
27 args
= ["powerpc64-linux-gnu-objcopy",
32 subprocess
.check_output(args
)
33 binary
= struct
.unpack('>i', binfile
.read(4))[0]