Debian Codegraph @

rpython/jit/backend/arm/test/gen.py

raw symbols SCIP
1 import os
2 from rpython.tool.udir import udir
3 import tempfile
4 from rpython.jit.backend.arm.test.support import AS
5
6 class ASMInstruction(object):
7
8 asm_opts = '-mfpu=neon -mcpu=cortex-a8 -march=armv7-a'
9 body = """.section .text
10 .arm
11 _start: .global _start
12 .global main
13 b main
14 main:
15 .ascii "START"
16 %s
17 .ascii "END"
18 """
19 begin_tag = 'START'
20 end_tag = 'END'
21 base_name = 'test_%d.asm'
22 index = 0
23
24 def __init__(self, instr):
25 self.instr = instr
26 self.file = udir.join(self.base_name % self.index)
27 while self.file.check():
28 self.index += 1
29 self.file = udir.join(self.base_name % self.index)
30
31 def encode(self):
32 f = open("%s/a.out" % (udir),'rb')
33 data = f.read()
34 #f.close()
35 i = data.find(self.begin_tag)
36 assert i>=0
37 j = data.find(self.end_tag, i)
38 assert j>=0
39 as_code = data[i+len(self.begin_tag):j]
40 return as_code
41
42
43
44 def assemble(self, *args):
45 res = self.body % (self.instr)
46 self.file.write(res)
47 os.system("%s --fatal-warnings %s %s -o %s/a.out" % (AS, self.asm_opts, self.file, udir))
48
49 #def __del__(self):
50 # self.file.close()
51
52 def assemble(instr):
53 a = ASMInstruction(instr)
54 a.assemble(instr)
55 return a.encode()