[pypy-svn] r68710 - in pypy/branch/msvc-asmgcroot/pypy/translator/c: gcc gcc/test/msvc src
afa at codespeak.net
afa at codespeak.net
Thu Oct 22 13:13:23 CEST 2009
Author: afa
Date: Thu Oct 22 13:13:22 2009
New Revision: 68710
Modified:
pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/instruction.py
pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/test/msvc/track0.s
pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/test/msvc/track8.s
pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/trackgcroot.py
pypy/branch/msvc-asmgcroot/pypy/translator/c/src/mem.h
Log:
More progress: generate usable tables in assembler,
and really track saved registers...
The call shapes seem to be correct now
Modified: pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/instruction.py
==============================================================================
--- pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/instruction.py (original)
+++ pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/instruction.py Thu Oct 22 13:13:22 2009
@@ -1,24 +1,15 @@
-CALLEE_SAVE_REGISTERS_NOEBP = ['%ebx', '%esi', '%edi']
-CALLEE_SAVE_REGISTERS = CALLEE_SAVE_REGISTERS_NOEBP + ['%ebp']
-
LOC_NOWHERE = 0
LOC_REG = 1
LOC_EBP_BASED = 2
LOC_ESP_BASED = 3
LOC_MASK = 0x03
-REG2LOC = {}
-for _i, _reg in enumerate(CALLEE_SAVE_REGISTERS):
- REG2LOC[_reg] = LOC_REG | (_i<<2)
- REG2LOC[_reg[1:]] = LOC_REG | (_i<<2)
-
def frameloc(base, offset):
assert base in (LOC_EBP_BASED, LOC_ESP_BASED)
assert offset % 4 == 0
return base | offset
-
class SomeNewValue(object):
pass
somenewvalue = SomeNewValue()
@@ -84,9 +75,9 @@
class InsnFunctionStart(Insn):
framesize = 0
previous_insns = ()
- def __init__(self):
+ def __init__(self, registers):
self.arguments = {}
- for reg in CALLEE_SAVE_REGISTERS:
+ for reg in registers:
self.arguments[reg] = somenewvalue
def source_of(self, localvar, tag):
@@ -160,6 +151,9 @@
class InsnRet(InsnStop):
framesize = 0
+ def __init__(self, registers):
+ self.registers = registers
+
def requestgcroots(self, tracker):
# no need to track the value of these registers in the caller
# function if we are the main(), or if we are flagged as a
@@ -167,7 +161,7 @@
if tracker.is_stack_bottom:
return {}
else:
- return dict(zip(CALLEE_SAVE_REGISTERS, CALLEE_SAVE_REGISTERS))
+ return dict(zip(self.registers, self.registers))
class InsnCall(Insn):
_args_ = ['lineno', 'gcroots']
Modified: pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/test/msvc/track0.s
==============================================================================
--- pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/test/msvc/track0.s (original)
+++ pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/test/msvc/track0.s Thu Oct 22 13:13:22 2009
@@ -64,7 +64,7 @@
jl SHORT $LN15 at pypy_g_ll_@139
$LN14 at pypy_g_ll_@139:
call _RPyAbort
- ;; expected {24(%esp) | %ebx, %esi, %edi, %ebp | 32(%esp)}
+ ;; expected {24(%esp) | 12(%esp), 4(%esp), (%esp), 8(%esp) | 32(%esp)}
$LN15 at pypy_g_ll_@139:
; 1529 : l_v420 = l_v419;
@@ -76,7 +76,7 @@
test ebx, ebx
jne SHORT $LN16 at pypy_g_ll_@139
call _RPyAbort
- ;; expected {24(%esp) | %ebx, %esi, %edi, %ebp | 32(%esp)}
+ ;; expected {24(%esp) | 12(%esp), 4(%esp), (%esp), 8(%esp) | 32(%esp)}
$LN16 at pypy_g_ll_@139:
; 1531 : OP_INT_ADD(l_v402, l_v421, l_v422);
@@ -106,7 +106,7 @@
push edi
call _pypy_g_mallocstr__Signed
- ;; expected {28(%esp) | %ebx, %esi, %edi, %ebp | 36(%esp)}
+ ;; expected {28(%esp) | 16(%esp), 8(%esp), 4(%esp), 12(%esp) | 36(%esp)}
; 1486 : l_v405 = (void*)l_items_2;
@@ -182,7 +182,7 @@
jl SHORT $LN10 at pypy_g_ll_@139
$LN9 at pypy_g_ll_@139:
call _RPyAbort
- ;; expected {24(%esp) | %ebx, %esi, %edi, %ebp | }
+ ;; expected {24(%esp) | 12(%esp), 4(%esp), (%esp), 8(%esp) | }
$LN10 at pypy_g_ll_@139:
; 1517 : l_v413 = l_v412;
@@ -194,7 +194,7 @@
test edi, edi
jne SHORT $LN11 at pypy_g_ll_@139
call _RPyAbort
- ;; expected {24(%esp) | %ebx, %esi, %edi, %ebp | }
+ ;; expected {24(%esp) | 12(%esp), 4(%esp), (%esp), 8(%esp) | }
$LN11 at pypy_g_ll_@139:
mov edi, DWORD PTR [edi+8]
@@ -207,7 +207,7 @@
jl SHORT $LN13 at pypy_g_ll_@139
$LN12 at pypy_g_ll_@139:
call _RPyAbort
- ;; expected {24(%esp) | %ebx, %esi, %edi, %ebp | }
+ ;; expected {24(%esp) | 12(%esp), 4(%esp), (%esp), 8(%esp) | }
$LN13 at pypy_g_ll_@139:
; 1520 : pypy_g_copy_string_contents__rpy_stringPtr_rpy_stringPt(l_v415, l_result_2, 0L, l_res_index_0, l_v414);
@@ -235,7 +235,7 @@
$block0$80678:
$block1$80679:
call _memcpy
- ;; expected {36(%esp) | %ebx, %esi, %edi, %ebp | }
+ ;; expected {36(%esp) | 24(%esp), 16(%esp), 12(%esp), 20(%esp) | }
add esp, 12 ; 0000000cH
; 1521 : OP_INT_ADD(l_res_index_0, l_v414, l_v417);
Modified: pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/test/msvc/track8.s
==============================================================================
--- pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/test/msvc/track8.s (original)
+++ pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/test/msvc/track8.s Thu Oct 22 13:13:22 2009
@@ -94,7 +94,7 @@
jle SHORT $LN17 at pypy_g_foo
$LN16 at pypy_g_foo:
call _LL_stack_too_big_slowpath
- ;; expected {24(%esp) | %ebx, %esi, %edi, %ebp | %ebx, %edi, %ebp, 44(%esp), 48(%esp), 52(%esp)}
+ ;; expected {24(%esp) | 12(%esp), (%esp), 4(%esp), 8(%esp) | %ebx, %edi, %ebp, 44(%esp), 48(%esp), 52(%esp)}
test eax, eax
jne $LN71 at pypy_g_foo
$LN17 at pypy_g_foo:
@@ -147,7 +147,7 @@
push OFFSET _pypy_g_pypy_rpython_memory_gc_semispace_SemiSpaceGC
$block11$34394:
call _pypy_g_SemiSpaceGC_obtain_free_space
- ;; expected {32(%esp) | %ebx, %esi, %edi, %ebp | %ebx, %edi, %ebp, 52(%esp), 56(%esp), 60(%esp)}
+ ;; expected {32(%esp) | 20(%esp), 8(%esp), 12(%esp), 16(%esp) | %ebx, %edi, %ebp, 52(%esp), 56(%esp), 60(%esp)}
add esp, 8
; 1192 : l_v425 = RPyField((&pypy_g_ExcData), ed_exc_type);
@@ -293,7 +293,7 @@
$block7$34426:
mov DWORD PTR [esi+4], OFFSET _pypy_g_src8_A_vtable
call _pypy_g_foo
- ;; expected {52(%esp) | %ebx, %esi, %edi, %ebp | %ebx, %esi, %edi, %ebp, 72(%esp), 76(%esp), 80(%esp)}
+ ;; expected {52(%esp) | 40(%esp), 28(%esp), 32(%esp), 36(%esp) | %ebx, %esi, %edi, %ebp, 72(%esp), 76(%esp), 80(%esp)}
add esp, 28 ; 0000001cH
; 1125 : l_v376 = (void*)l_a2_1;
@@ -389,7 +389,7 @@
push eax
$block8$34437:
call _pypy_g_foo
- ;; expected {52(%esp) | %ebx, %esi, %edi, %ebp | %ebx, %edi, %ebp, 72(%esp), 76(%esp), 80(%esp)}
+ ;; expected {52(%esp) | 40(%esp), 28(%esp), 32(%esp), 36(%esp) | %ebx, %edi, %ebp, 72(%esp), 76(%esp), 80(%esp)}
add esp, 28 ; 0000001cH
; 1156 : l_v401 = (void*)l_a2_1;
Modified: pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/trackgcroot.py
==============================================================================
--- pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/trackgcroot.py (original)
+++ pypy/branch/msvc-asmgcroot/pypy/translator/c/gcc/trackgcroot.py Thu Oct 22 13:13:22 2009
@@ -34,7 +34,6 @@
r_jmp_source = re.compile(r"\d*[(](%[\w]+)[,)]")
r_jmptable_item = re.compile(r"\t.long\t"+LABEL+"(-\"[A-Za-z0-9$]+\")?\s*$")
r_jmptable_end = re.compile(r"\t.text|\t.section\s+.text|\t\.align|"+LABEL)
-r_bottom_marker = re.compile(r"\t/[*] GC_STACK_BOTTOM [*]/")
class FunctionGcRootTracker(object):
skip = 0
@@ -91,7 +90,7 @@
shape = [retaddr]
# the first gcroots are always the ones corresponding to
# the callee-saved registers
- for reg in CALLEE_SAVE_REGISTERS:
+ for reg in self.CALLEE_SAVE_REGISTERS:
shape.append(LOC_NOWHERE)
gcroots = []
for localvar, tag in insn.gcroots.items():
@@ -99,17 +98,17 @@
loc = localvar.getlocation(insn.framesize,
self.uses_frame_pointer)
else:
- assert localvar in REG2LOC, "%s: %s" % (self.funcname,
- localvar)
- loc = REG2LOC[localvar]
+ assert localvar in self.REG2LOC, "%s: %s" % (self.funcname,
+ localvar)
+ loc = self.REG2LOC[localvar]
assert isinstance(loc, int)
if tag is None:
gcroots.append(loc)
else:
- regindex = CALLEE_SAVE_REGISTERS.index(tag)
+ regindex = self.CALLEE_SAVE_REGISTERS.index(tag)
shape[1 + regindex] = loc
if LOC_NOWHERE in shape and not self.is_stack_bottom:
- reg = CALLEE_SAVE_REGISTERS[shape.index(LOC_NOWHERE) - 1]
+ reg = self.CALLEE_SAVE_REGISTERS[shape.index(LOC_NOWHERE) - 1]
raise AssertionError("cannot track where register %s is saved"
% (reg,))
gcroots.sort()
@@ -139,7 +138,7 @@
lst.append(previnsn)
def parse_instructions(self):
- self.insns = [InsnFunctionStart()]
+ self.insns = [InsnFunctionStart(self.CALLEE_SAVE_REGISTERS)]
ignore_insns = False
for lineno, line in enumerate(self.lines):
if lineno < self.skip:
@@ -147,7 +146,10 @@
self.currentlineno = lineno
insn = []
match = r_insn.match(line)
- if match:
+
+ if self.r_bottom_marker.match(line):
+ self.is_stack_bottom = True
+ elif match:
if not ignore_insns:
opname = match.group(1)
try:
@@ -159,8 +161,6 @@
insn = meth(line)
elif self.r_gcroot_marker.match(line):
insn = self._visit_gcroot_marker(line)
- elif r_bottom_marker.match(line):
- self.is_stack_bottom = True
elif line == '\t/* ignore_in_trackgcroot */\n':
ignore_insns = True
elif line == '\t/* end_ignore_in_trackgcroot */\n':
@@ -176,7 +176,7 @@
else:
self.append_instruction(insn)
- del self.currentlineno
+ del self.currentlineno
@classmethod
def find_missing_visit_method(cls, opname):
@@ -524,7 +524,7 @@
return self._visit_epilogue() + self._visit_pop(self.EBP)
def visit_ret(self, line):
- return InsnRet()
+ return InsnRet(self.CALLEE_SAVE_REGISTERS)
def visit_jmp(self, line):
tablelabels = []
@@ -579,7 +579,7 @@
if self.r_unaryinsn_star.match(line):
# that looks like an indirect tail-call.
# tail-calls are equivalent to RET for us
- return InsnRet()
+ return InsnRet(self.CALLEE_SAVE_REGISTERS)
try:
self.conditional_jump(line)
except KeyError:
@@ -588,7 +588,7 @@
target = match.group(1)
assert not target.startswith('.')
# tail-calls are equivalent to RET for us
- return InsnRet()
+ return InsnRet(self.CALLEE_SAVE_REGISTERS)
return InsnStop()
def register_jump_to(self, label):
@@ -669,6 +669,9 @@
ESP = '%esp'
EBP = '%ebp'
EAX = '%eax'
+ CALLEE_SAVE_REGISTERS = ['%ebx', '%esi', '%edi', '%ebp']
+ REG2LOC = dict((_reg, LOC_REG | (_i<<2))
+ for _i, _reg in enumerate(CALLEE_SAVE_REGISTERS))
OPERAND = r'(?:[-\w$%+.:@"]+(?:[(][\w%,]+[)])?|[(][\w%,]+[)])'
LABEL = r'([a-zA-Z_$.][a-zA-Z0-9_$@.]*)'
TOP_OF_STACK = '0(%esp)'
@@ -679,10 +682,12 @@
LOCALVARFP = LOCALVAR + r"|-?\d*[(]%ebp[)]"
r_localvarnofp = re.compile(LOCALVAR)
r_localvarfp = re.compile(LOCALVARFP)
- r_gcroot_marker = re.compile(r"\t/[*] GCROOT ("+LOCALVARFP+") [*]/")
r_localvar_esp = re.compile(r"(\d*)[(]%esp[)]")
r_localvar_ebp = re.compile(r"(-?\d*)[(]%ebp[)]")
+ r_gcroot_marker = re.compile(r"\t/[*] GCROOT ("+LOCALVARFP+") [*]/")
+ r_bottom_marker = re.compile(r"\t/[*] GC_STACK_BOTTOM [*]/")
+
def __init__(self, lines, filetag=0):
match = self.r_functionstart.match(lines[0])
funcname = match.group(1)
@@ -718,6 +723,9 @@
ESP = 'esp'
EBP = 'ebp'
EAX = 'eax'
+ CALLEE_SAVE_REGISTERS = ['ebx', 'esi', 'edi', 'ebp']
+ REG2LOC = dict((_reg, LOC_REG | (_i<<2))
+ for _i, _reg in enumerate(CALLEE_SAVE_REGISTERS))
TOP_OF_STACK = 'DWORD PTR [esp]'
OPERAND = r'(?:(:?WORD|DWORD|BYTE) PTR |OFFSET )?[_\w?:@$]*(?:[-+0-9]+)?(:?\[[-+*\w0-9]+\])?'
@@ -728,14 +736,16 @@
r_functionend = re.compile(LABEL+r"\s+ENDP\s*$")
r_symboldefine = re.compile(r"([_a-z0-9]+\$) = ([-0-9]+)\s*;.+\n")
- LOCALVAR = r"eax|edx|ecx|ebx|esi|edi|ebp|DWORD PTR [-+]?\d*\[esp[-+]\d+\]"
+ LOCALVAR = r"eax|edx|ecx|ebx|esi|edi|ebp|DWORD PTR [-+]?\d*\[esp[-+]?\d*\]"
LOCALVARFP = LOCALVAR + r"|DWORD PTR -?\d*\[ebp\]"
r_localvarnofp = re.compile(LOCALVAR)
r_localvarfp = re.compile(LOCALVARFP)
- r_gcroot_marker = re.compile(r";.+ = pypy_asm_gcroot\(")
r_localvar_esp = re.compile(r"DWORD PTR ([-+]?\d+)?\[esp([-+]?\d+)?\]")
r_localvar_ebp = re.compile(r"DWORD PTR ([-+]?\d+)?\[ebp([-+]?\d+)?\]")
+ r_gcroot_marker = re.compile(r";.+ = pypy_asm_gcroot\(")
+ r_bottom_marker = re.compile(r"\tcall\t_pypy_asm_stack_bottom\s*")
+
@classmethod
def init_regexp(cls):
super(MsvcFunctionGcRootTracker, cls).init_regexp()
@@ -1096,8 +1106,6 @@
mingw32='\t.text',
msvc='_TEXT\tSEGMENT')
- _globl('__gcrootanchor')
-
_globl('pypy_asm_stackwalk')
_variant(elf='.type pypy_asm_stackwalk, @function',
darwin='',
@@ -1160,12 +1168,13 @@
_comment("A circular doubly-linked list of all")
_comment("the ASM_FRAMEDATAs currently alive")
if self.format == 'msvc':
- print >> output, '%s:' % _globalname("__gcrootanchor")
- print >> output, '\tDD FLAT:___gcrootanchor ; prev'
+ _globl('__gcrootanchor')
+ print >> output, '%s\tDD FLAT:___gcrootanchor ; prev' % _globalname("__gcrootanchor")
print >> output, '\tDD FLAT:___gcrootanchor ; next'
else:
print >> output, '\t.data'
print >> output, '\t.align\t4'
+ _globl('__gcrootanchor')
_label('__gcrootanchor')
print >> output, """\
.long\t__gcrootanchor /* prev */
@@ -1174,7 +1183,7 @@
_globl('__gcmapstart')
if self.format == 'msvc':
- print >> output, '%s:' % _globalname('__gcmapstart')
+ print >> output, '%s' % _globalname('__gcmapstart'),
else:
_label('__gcmapstart')
for label, state, is_range in self.gcmaptable:
@@ -1202,7 +1211,10 @@
print >> output, '\t.long\t%d' % (n,)
_globl('__gcmapend')
- _label('__gcmapend')
+ if self.format == 'msvc':
+ print >> output, '%s DD ?' % _globalname('__gcmapend')
+ else:
+ _label('__gcmapend')
_variant(elf='.section\t.rodata',
darwin='.const',
mingw32='',
@@ -1210,7 +1222,7 @@
_globl('__gccallshapes')
if self.format == 'msvc':
- print >> output, '%s:' % _globalname('__gccallshapes')
+ print >> output, _globalname('__gccallshapes'),
else:
_label('__gccallshapes')
output.writelines(shapelines)
@@ -1272,7 +1284,7 @@
elif kind == LOC_REG:
reg = loc >> 2
assert 0 <= reg <= 3
- return CALLEE_SAVE_REGISTERS[reg]
+ return ElfFunctionGcRootTracker.CALLEE_SAVE_REGISTERS[reg]
else:
if kind == LOC_EBP_BASED:
result = '(%ebp)'
Modified: pypy/branch/msvc-asmgcroot/pypy/translator/c/src/mem.h
==============================================================================
--- pypy/branch/msvc-asmgcroot/pypy/translator/c/src/mem.h (original)
+++ pypy/branch/msvc-asmgcroot/pypy/translator/c/src/mem.h Thu Oct 22 13:13:22 2009
@@ -47,7 +47,7 @@
return _r1;
}
#define pypy_asm_keepalive(v) __asm { }
-#define pypy_asm_stack_bottom() /* GC_STACK_BOTTOM */
+static __declspec(noinline) void* pypy_asm_stack_bottom() { }
#endif
More information about the Pypy-commit
mailing list