[pypy-svn] r16234 - in pypy/dist/pypy/translator/llvm2: . module
ericvrp at codespeak.net
ericvrp at codespeak.net
Mon Aug 22 21:35:09 CEST 2005
Author: ericvrp
Date: Mon Aug 22 21:35:07 2005
New Revision: 16234
Modified:
pypy/dist/pypy/translator/llvm2/codewriter.py
pypy/dist/pypy/translator/llvm2/genllvm.py
pypy/dist/pypy/translator/llvm2/module/extfunction.py
pypy/dist/pypy/translator/llvm2/module/ll_math.py
pypy/dist/pypy/translator/llvm2/module/ll_os.py
pypy/dist/pypy/translator/llvm2/module/ll_time.py
pypy/dist/pypy/translator/llvm2/module/support.py
pypy/dist/pypy/translator/llvm2/opwriter.py
pypy/dist/pypy/translator/llvm2/structnode.py
pypy/dist/pypy/translator/llvm2/varsize.py
Log:
* another step toward 64bit support
Modified: pypy/dist/pypy/translator/llvm2/codewriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/codewriter.py (original)
+++ pypy/dist/pypy/translator/llvm2/codewriter.py Mon Aug 22 21:35:07 2005
@@ -8,10 +8,12 @@
DEFAULT_CCONV = 'fastcc' #or 'ccc'
class CodeWriter(object):
- def __init__(self, f, show_line_number=False):
+ def __init__(self, f, word, uword, show_line_number=False):
self.f = f
self.show_line_numbers = show_line_number
self.n_lines = 0
+ self.word = word
+ self.uword = uword
def append(self, line):
self.n_lines += 1
@@ -145,13 +147,16 @@
else:
cnt = ""
postfix = ('', '_atomic')[atomic]
- self.indent("%%malloc.Size%(cnt)s = getelementptr %(type_)s* null, uint %(size)s" % locals())
- self.indent("%%malloc.SizeU%(cnt)s = cast %(type_)s* %%malloc.Size%(cnt)s to uint" % locals())
- self.indent("%%malloc.Ptr%(cnt)s = call %(cconv)s sbyte* %%gc_malloc%(postfix)s(uint %%malloc.SizeU%(cnt)s)" % locals())
+ word = self.word
+ uword = self.uword
+ self.indent("%%malloc.Size%(cnt)s = getelementptr %(type_)s* null, %(uword)s %(size)s" % locals())
+ self.indent("%%malloc.SizeU%(cnt)s = cast %(type_)s* %%malloc.Size%(cnt)s to %(uword)s" % locals())
+ self.indent("%%malloc.Ptr%(cnt)s = call %(cconv)s sbyte* %%gc_malloc%(postfix)s(%(uword)s %%malloc.SizeU%(cnt)s)" % locals())
self.indent("%(targetvar)s = cast sbyte* %%malloc.Ptr%(cnt)s to %(type_)s*" % locals())
def getelementptr(self, targetvar, type, typevar, *indices):
- res = "%(targetvar)s = getelementptr %(type)s %(typevar)s, int 0, " % locals()
+ word = self.word
+ res = "%(targetvar)s = getelementptr %(type)s %(typevar)s, %(word)s 0, " % locals()
res += ", ".join(["%s %s" % (t, i) for t, i in indices])
self.indent(res)
@@ -163,7 +168,8 @@
"%(valuetype)s* %(ptr)s" % locals())
def debugcomment(self, tempname, len, tmpname):
- res = "%s = tail call ccc int (sbyte*, ...)* %%printf("
- res += "sbyte* getelementptr ([%s x sbyte]* %s, int 0, int 0) )"
+ word = self.word
+ res = "%s = tail call ccc %(word)s (sbyte*, ...)* %%printf(" % locals()
+ res += "sbyte* getelementptr ([%s x sbyte]* %s, %(word)s 0, %(word)s 0) )" % locals()
res = res % (tmpname, len, tmpname)
self.indent(res)
Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py Mon Aug 22 21:35:07 2005
@@ -67,7 +67,10 @@
assert False
return decls
-
+
+ def replace_with_machine_words(self, s):
+ return s.replace('UINT',self.db.get_machine_uword()).replace('INT',self.db.get_machine_word())
+
def gen_llvm_source(self, func=None):
if self.debug: print 'gen_llvm_source begin) ' + time.ctime()
if func is None:
@@ -106,7 +109,7 @@
function_count[func.func_name] = 1
filename = udir.join(func.func_name + postfix).new(ext='.ll')
f = open(str(filename),'w')
- codewriter = CodeWriter(f)
+ codewriter = CodeWriter(f, self.db.get_machine_word(), self.db.get_machine_uword())
comment = codewriter.comment
nl = codewriter.newline
@@ -142,7 +145,7 @@
if self.debug: print 'gen_llvm_source extdeclarations) ' + time.ctime()
nl(); comment("Function Prototypes") ; nl()
- for extdecl in extdeclarations.split('\n'):
+ for extdecl in self.replace_with_machine_words(extdeclarations).split('\n'):
codewriter.append(extdecl)
if self.debug: print 'gen_llvm_source self._debug_prototype) ' + time.ctime()
@@ -160,7 +163,7 @@
gc_funcs = gc_boehm
else:
gc_funcs = gc_disabled
- for gc_func in gc_funcs.split('\n'):
+ for gc_func in self.replace_with_machine_words(gc_funcs).split('\n'):
codewriter.append(gc_func)
if self.debug: print 'gen_llvm_source typ_decl.writeimpl) ' + time.ctime()
@@ -215,7 +218,7 @@
codewriter.comment('XXX: Error: ' + msg)
#raise Exception('primitive function %s has no implementation' %(dep,))
continue
- for extfunc in llvm_code.split('\n'):
+ for extfunc in self.replace_with_machine_words(llvm_code).split('\n'):
codewriter.append(extfunc)
depdone[dep] = True
Modified: pypy/dist/pypy/translator/llvm2/module/extfunction.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/extfunction.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/extfunction.py Mon Aug 22 21:35:07 2005
@@ -1,35 +1,37 @@
extdeclarations = """;rpython stuff
;gc-type dependent mallocs
-declare fastcc sbyte* %gc_malloc(uint)
-declare fastcc sbyte* %gc_malloc_atomic(uint)
+declare fastcc sbyte* %gc_malloc(UINT)
+declare fastcc sbyte* %gc_malloc_atomic(UINT)
;exception handling globals
%last_exception_type = global %RPYTHON_EXCEPTION_VTABLE* null
%last_exception_value = global %RPYTHON_EXCEPTION* null
"""
-gc_boehm = """declare ccc sbyte* %GC_malloc(uint)
-declare ccc sbyte* %GC_malloc_atomic(uint)
+gc_boehm = """declare ccc sbyte* %GC_malloc(UINT)
+declare ccc sbyte* %GC_malloc_atomic(UINT)
-internal fastcc sbyte* %gc_malloc(uint %n) {
- %ptr = call ccc sbyte* %GC_malloc(uint %n)
+internal fastcc sbyte* %gc_malloc(UINT %n) {
+ %ptr = call ccc sbyte* %GC_malloc(UINT %n)
ret sbyte* %ptr
}
-internal fastcc sbyte* %gc_malloc_atomic(uint %n) {
- %ptr = call ccc sbyte* %GC_malloc_atomic(uint %n)
+internal fastcc sbyte* %gc_malloc_atomic(UINT %n) {
+ %ptr = call ccc sbyte* %GC_malloc_atomic(UINT %n)
ret sbyte* %ptr
}
"""
-gc_disabled = """internal fastcc sbyte* %gc_malloc(uint %n) {
- %ptr = malloc sbyte, uint %n
+gc_disabled = """internal fastcc sbyte* %gc_malloc(UINT %n) {
+ %nn = cast UINT %n to uint
+ %ptr = malloc sbyte, uint %nn
ret sbyte* %ptr
}
-internal fastcc sbyte* %gc_malloc_atomic(uint %n) {
- %ptr = malloc sbyte, uint %n
+internal fastcc sbyte* %gc_malloc_atomic(UINT %n) {
+ %nn = cast UINT %n to uint
+ %ptr = malloc sbyte, uint %nn
ret sbyte* %ptr
}
"""
Modified: pypy/dist/pypy/translator/llvm2/module/ll_math.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_math.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_math.py Mon Aug 22 21:35:07 2005
@@ -62,7 +62,7 @@
""")
extfunctions["%ll_math_ldexp"] = (("%__debug",), """
-internal fastcc double %ll_math_ldexp(double %x, int %y) {
+internal fastcc double %ll_math_ldexp(double %x, INT %y) {
call fastcc void %__debug([12 x sbyte]* %__ll_math_ldexp) ; XXX: TODO: ll_math_ldexp
ret double 0.0
}
Modified: pypy/dist/pypy/translator/llvm2/module/ll_os.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_os.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_os.py Mon Aug 22 21:35:07 2005
@@ -1,17 +1,17 @@
extdeclarations = """
;ll_os.py
-declare ccc int %dup(int)
-declare ccc void %close(int)
-declare ccc int %open(sbyte*, int, int)
-declare ccc int %write(int, sbyte*, int)
-declare ccc int %read(int, sbyte*, int)
+declare ccc INT %dup(INT)
+declare ccc void %close(INT)
+declare ccc INT %open(sbyte*, INT, INT)
+declare ccc INT %write(INT, sbyte*, INT)
+declare ccc INT %read(INT, sbyte*, INT)
declare ccc sbyte* %strncpy(sbyte*, sbyte*, int)
-declare ccc int %isatty(int)
-declare ccc int %stat(sbyte*, [32 x int]*)
-declare ccc int %fstat(int, [32 x int]*)
-declare ccc int %lseek(int, int, int)
-declare ccc int %ftruncate(int, int)
-declare ccc sbyte* %getcwd(sbyte*, int)
+declare ccc INT %isatty(INT)
+declare ccc INT %stat(sbyte*, [32 x INT]*)
+declare ccc INT %fstat(INT, [32 x INT]*)
+declare ccc INT %lseek(INT, INT, INT)
+declare ccc INT %ftruncate(INT, INT)
+declare ccc sbyte* %getcwd(sbyte*, INT)
%errno = external global int
@@ -25,9 +25,9 @@
extfunctions = {}
extfunctions["%ll_os_dup"] = ((), """
-internal fastcc int %ll_os_dup(int %fd) {
- %ret = call ccc int %dup(int %fd)
- ret int %ret
+internal fastcc INT %ll_os_dup(INT %fd) {
+ %ret = call ccc INT %dup(INT %fd)
+ ret INT %ret
}
""")
@@ -37,8 +37,8 @@
call fastcc void %__debug([12 x sbyte]* %__ll_os_getcwd) ; XXX: Test: ll_os_getcwd
- %s = alloca sbyte, uint 1024
- %res = call ccc sbyte* %getcwd(sbyte* %s, int 1023)
+ %s = alloca sbyte, UINT 1024
+ %res = call ccc sbyte* %getcwd(sbyte* %s, INT 1023)
;if %res == null: raise...
%cwd = call fastcc %RPyString* %string_to_RPyString(sbyte* %s)
@@ -48,103 +48,103 @@
""")
extfunctions["%ll_os_close"] = ((), """
-internal fastcc void %ll_os_close(int %fd) {
- call ccc void %close(int %fd)
+internal fastcc void %ll_os_close(INT %fd) {
+ call ccc void %close(INT %fd)
ret void
}
""")
extfunctions["%ll_os_open"] = (("%cast",), """
-internal fastcc int %ll_os_open(%RPyString* %structstring, int %flag, int %mode) {
+internal fastcc INT %ll_os_open(%RPyString* %structstring, INT %flag, INT %mode) {
%dest = call fastcc sbyte* %cast(%RPyString* %structstring)
- %fd = call ccc int %open(sbyte* %dest, int %flag, int %mode)
- ret int %fd
+ %fd = call ccc INT %open(sbyte* %dest, INT %flag, INT %mode)
+ ret INT %fd
}
""")
extfunctions["%ll_os_write"] = (("%cast",), """
-internal fastcc int %ll_os_write(int %fd, %RPyString* %structstring) {
+internal fastcc INT %ll_os_write(INT %fd, %RPyString* %structstring) {
%reallengthptr = getelementptr %RPyString* %structstring, int 0, uint 1, uint 0
- %reallength = load int* %reallengthptr
+ %reallength = load INT* %reallengthptr
%dest = call fastcc sbyte* %cast(%RPyString* %structstring)
- %byteswritten = call ccc int %write(int %fd, sbyte* %dest, int %reallength)
- ret int %byteswritten
+ %byteswritten = call ccc INT %write(INT %fd, sbyte* %dest, INT %reallength)
+ ret INT %byteswritten
}
""")
extfunctions["%ll_read_into"] = ((), """
-internal fastcc int %ll_read_into(int %fd, %RPyString* %structstring) {
+internal fastcc INT %ll_read_into(INT %fd, %RPyString* %structstring) {
%reallengthptr = getelementptr %RPyString* %structstring, int 0, uint 1, uint 0
- %reallength = load int* %reallengthptr
+ %reallength = load INT* %reallengthptr
%destptr = getelementptr %RPyString* %structstring, int 0, uint 1, uint 1
%dest = cast [0 x sbyte]* %destptr to sbyte*
- %bytesread = call ccc int %read(int %fd, sbyte* %dest, int %reallength)
- ret int %bytesread
+ %bytesread = call ccc INT %read(INT %fd, sbyte* %dest, INT %reallength)
+ ret INT %bytesread
}
""")
extfunctions["%ll_os_isatty"] = ((), """
-internal fastcc bool %ll_os_isatty(int %fd) {
- %ret = call ccc int %isatty(int %fd)
- %ret.bool = cast int %ret to bool
+internal fastcc bool %ll_os_isatty(INT %fd) {
+ %ret = call ccc INT %isatty(INT %fd)
+ %ret.bool = cast INT %ret to bool
ret bool %ret.bool
}
""")
extfunctions["%ll_os_ftruncate"] = (("%__debug",), """
-internal fastcc void %ll_os_ftruncate(int %fd, int %length) {
+internal fastcc void %ll_os_ftruncate(INT %fd, INT %length) {
call fastcc void %__debug([12 x sbyte]* %__ll_os_ftruncate) ; XXX: Test: ll_os_ftruncate
- %res = call ccc int %ftruncate(int %fd, int %length)
+ %res = call ccc INT %ftruncate(INT %fd, INT %length)
;if res < 0 raise...
ret void
}
""")
extfunctions["%ll_os_lseek"] = (("%__debug",), """
-internal fastcc int %ll_os_lseek(int %fd, int %pos, int %how) {
+internal fastcc INT %ll_os_lseek(INT %fd, INT %pos, INT %how) {
call fastcc void %__debug([12 x sbyte]* %__ll_os_lseek) ; XXX: Test: ll_os_lseek
;TODO: determine correct %how
- %res = call ccc int %lseek(int %fd, int %pos, int %how)
+ %res = call ccc INT %lseek(INT %fd, INT %pos, INT %how)
;if res < 0 raise...
- ret int %res
+ ret INT %res
}
""")
extfunctions["%_stat_construct_result_helper"] = ((), """
-internal fastcc %RPySTAT_RESULT* %_stat_construct_result_helper([32 x int]* %src) {
+internal fastcc %RPySTAT_RESULT* %_stat_construct_result_helper([32 x INT]* %src) {
- %src0ptr = getelementptr [32 x int]* %src, int 0, uint 4 ;st_mode
- %src1ptr = getelementptr [32 x int]* %src, int 0, uint 3 ;st_ino
- %src2ptr = getelementptr [32 x int]* %src, int 0, uint 0 ;st_dev
- %src3ptr = getelementptr [32 x int]* %src, int 0, uint 5 ;st_nlink
- %src4ptr = getelementptr [32 x int]* %src, int 0, uint 6 ;st_uid
- %src5ptr = getelementptr [32 x int]* %src, int 0, uint 7 ;st_gid
- %src6ptr = getelementptr [32 x int]* %src, int 0, uint 11 ;st_size
- %src7ptr = getelementptr [32 x int]* %src, int 0, uint 14 ;st_atime
- %src8ptr = getelementptr [32 x int]* %src, int 0, uint 16 ;st_mtime
- %src9ptr = getelementptr [32 x int]* %src, int 0, uint 18 ;st_ctime
-
- %src0 = load int* %src0ptr
- %src1 = load int* %src1ptr
- %src2 = load int* %src2ptr
- %src3 = load int* %src3ptr
- %src4 = load int* %src4ptr
- %src5 = load int* %src5ptr
- %src6 = load int* %src6ptr
- %src7 = load int* %src7ptr
- %src8 = load int* %src8ptr
- %src9 = load int* %src9ptr
+ %src0ptr = getelementptr [32 x INT]* %src, int 0, uint 4 ;st_mode
+ %src1ptr = getelementptr [32 x INT]* %src, int 0, uint 3 ;st_ino
+ %src2ptr = getelementptr [32 x INT]* %src, int 0, uint 0 ;st_dev
+ %src3ptr = getelementptr [32 x INT]* %src, int 0, uint 5 ;st_nlink
+ %src4ptr = getelementptr [32 x INT]* %src, int 0, uint 6 ;st_uid
+ %src5ptr = getelementptr [32 x INT]* %src, int 0, uint 7 ;st_gid
+ %src6ptr = getelementptr [32 x INT]* %src, int 0, uint 11 ;st_size
+ %src7ptr = getelementptr [32 x INT]* %src, int 0, uint 14 ;st_atime
+ %src8ptr = getelementptr [32 x INT]* %src, int 0, uint 16 ;st_mtime
+ %src9ptr = getelementptr [32 x INT]* %src, int 0, uint 18 ;st_ctime
+
+ %src0 = load INT* %src0ptr
+ %src1 = load INT* %src1ptr
+ %src2 = load INT* %src2ptr
+ %src3 = load INT* %src3ptr
+ %src4 = load INT* %src4ptr
+ %src5 = load INT* %src5ptr
+ %src6 = load INT* %src6ptr
+ %src7 = load INT* %src7ptr
+ %src8 = load INT* %src8ptr
+ %src9 = load INT* %src9ptr
%malloc.Size = getelementptr %RPySTAT_RESULT* null, uint 1
- %malloc.SizeU = cast %RPySTAT_RESULT* %malloc.Size to uint
- %malloc.Ptr = call fastcc sbyte* %gc_malloc_atomic(uint %malloc.SizeU)
+ %malloc.SizeU = cast %RPySTAT_RESULT* %malloc.Size to UINT
+ %malloc.Ptr = call fastcc sbyte* %gc_malloc_atomic(UINT %malloc.SizeU)
%dest = cast sbyte* %malloc.Ptr to %RPySTAT_RESULT*
%dest0ptr = getelementptr %RPySTAT_RESULT* %dest, int 0, uint 0
@@ -158,16 +158,16 @@
%dest8ptr = getelementptr %RPySTAT_RESULT* %dest, int 0, uint 8
%dest9ptr = getelementptr %RPySTAT_RESULT* %dest, int 0, uint 9
- store int %src0, int* %dest0ptr
- store int %src1, int* %dest1ptr
- store int %src2, int* %dest2ptr
- store int %src3, int* %dest3ptr
- store int %src4, int* %dest4ptr
- store int %src5, int* %dest5ptr
- store int %src6, int* %dest6ptr
- store int %src7, int* %dest7ptr
- store int %src8, int* %dest8ptr
- store int %src9, int* %dest9ptr
+ store INT %src0, INT* %dest0ptr
+ store INT %src1, INT* %dest1ptr
+ store INT %src2, INT* %dest2ptr
+ store INT %src3, INT* %dest3ptr
+ store INT %src4, INT* %dest4ptr
+ store INT %src5, INT* %dest5ptr
+ store INT %src6, INT* %dest6ptr
+ store INT %src7, INT* %dest7ptr
+ store INT %src8, INT* %dest8ptr
+ store INT %src9, INT* %dest9ptr
ret %RPySTAT_RESULT* %dest
}
@@ -178,40 +178,40 @@
call fastcc void %__debug([12 x sbyte]* %__ll_os_stat) ; XXX: Test: ll_os_stat
- %st = alloca [32 x int]
+ %st = alloca [32 x INT]
%filename = call fastcc sbyte* %cast(%RPyString* %s)
- %error = call ccc int %stat(sbyte* %filename, [32 x int]* %st)
- %cond = seteq int %error, 0
+ %error = call ccc INT %stat(sbyte* %filename, [32 x INT]* %st)
+ %cond = seteq INT %error, 0
br bool %cond, label %cool, label %bwa
bwa:
- %errno_ = load int* %errno
- call fastcc void %ll_raise_OSError__Signed(int %errno_)
+ %errno_ = load INT* %errno
+ call fastcc void %ll_raise_OSError__Signed(INT %errno_)
ret %RPySTAT_RESULT* null
cool:
- %result = call fastcc %RPySTAT_RESULT* %_stat_construct_result_helper([32 x int]* %st)
+ %result = call fastcc %RPySTAT_RESULT* %_stat_construct_result_helper([32 x INT]* %st)
ret %RPySTAT_RESULT* %result
}
""")
extfunctions["%ll_os_fstat"] = (("%__debug", "%_stat_construct_result_helper"), """
-internal fastcc %RPySTAT_RESULT* %ll_os_fstat(int %fd) {
+internal fastcc %RPySTAT_RESULT* %ll_os_fstat(INT %fd) {
call fastcc void %__debug([12 x sbyte]* %__ll_os_fstat) ; XXX: Test: ll_os_fstat
- %st = alloca [32 x int]
- %error = call ccc int %fstat(int %fd, [32 x int]* %st)
- %cond = seteq int %error, 0
+ %st = alloca [32 x INT]
+ %error = call ccc INT %fstat(INT %fd, [32 x INT]* %st)
+ %cond = seteq INT %error, 0
br bool %cond, label %cool, label %bwa
bwa:
- %errno_ = load int* %errno
- call fastcc void %ll_raise_OSError__Signed(int %errno_)
+ %errno_ = load INT* %errno
+ call fastcc void %ll_raise_OSError__Signed(INT %errno_)
ret %RPySTAT_RESULT* null
cool:
- %result = call fastcc %RPySTAT_RESULT* %_stat_construct_result_helper([32 x int]* %st)
+ %result = call fastcc %RPySTAT_RESULT* %_stat_construct_result_helper([32 x INT]* %st)
ret %RPySTAT_RESULT* %result
}
Modified: pypy/dist/pypy/translator/llvm2/module/ll_time.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_time.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_time.py Mon Aug 22 21:35:07 2005
@@ -1,18 +1,18 @@
extdeclarations = '''
;ll_time.py
-%struct.timeval = type { int, int }
-%struct.timezone = type { int, int }
-%typedef.fd_set = type { [32 x int] }
+%struct.timeval = type { INT, INT }
+%struct.timezone = type { INT, INT }
+%typedef.fd_set = type { [32 x INT] }
%.str_1 = internal constant [16 x sbyte] c"select() failed\\00" ; <[16 x sbyte]*> [#uses=1]
declare ccc double %floor(double)
declare ccc double %fmod(double, double)
-declare ccc int %clock()
-declare ccc int %select(int, %typedef.fd_set*, %typedef.fd_set*, %typedef.fd_set*, %struct.timeval*)
-declare ccc int %gettimeofday(%struct.timeval*, %struct.timeval*)
-declare ccc int %time( int* )
+declare ccc INT %clock()
+declare ccc INT %select(INT, %typedef.fd_set*, %typedef.fd_set*, %typedef.fd_set*, %struct.timeval*)
+declare ccc INT %gettimeofday(%struct.timeval*, %struct.timeval*)
+declare ccc INT %time( INT* )
'''
extfunctions = {}
@@ -21,27 +21,27 @@
internal fastcc double %ll_time_time() {
%t = alloca %struct.timeval ; <%struct.timeval*> [#uses=3]
- %secs = alloca int ; <int*> [#uses=2]
- %tmp.0 = call int %gettimeofday( %struct.timeval* %t, %struct.timeval* null ) ; <int> [#uses=1]
- %tmp.1 = seteq int %tmp.0, 0 ; <bool> [#uses=2]
- %tmp.2 = cast bool %tmp.1 to int ; <int> [#uses=0]
+ %secs = alloca INT ; <int*> [#uses=2]
+ %tmp.0 = call INT %gettimeofday( %struct.timeval* %t, %struct.timeval* null ) ; <int> [#uses=1]
+ %tmp.1 = seteq INT %tmp.0, 0 ; <bool> [#uses=2]
+ %tmp.2 = cast bool %tmp.1 to INT ; <int> [#uses=0]
br bool %tmp.1, label %then, label %endif
then: ; preds = %entry
%tmp.3 = getelementptr %struct.timeval* %t, int 0, uint 0 ; <int*> [#uses=1]
- %tmp.4 = load int* %tmp.3 ; <int> [#uses=1]
- %tmp.5 = cast int %tmp.4 to double ; <double> [#uses=1]
+ %tmp.4 = load INT* %tmp.3 ; <int> [#uses=1]
+ %tmp.5 = cast INT %tmp.4 to double ; <double> [#uses=1]
%tmp.6 = getelementptr %struct.timeval* %t, int 0, uint 1 ; <int*> [#uses=1]
- %tmp.7 = load int* %tmp.6 ; <int> [#uses=1]
- %tmp.8 = cast int %tmp.7 to double ; <double> [#uses=1]
+ %tmp.7 = load INT* %tmp.6 ; <int> [#uses=1]
+ %tmp.8 = cast INT %tmp.7 to double ; <double> [#uses=1]
%tmp.9 = mul double %tmp.8, 1.000000e-06 ; <double> [#uses=1]
%tmp.10 = add double %tmp.5, %tmp.9 ; <double> [#uses=1]
ret double %tmp.10
endif: ; preds = %entry
- %tmp.11 = call int %time( int* %secs ) ; <int> [#uses=0]
- %tmp.12 = load int* %secs ; <int> [#uses=1]
- %tmp.13 = cast int %tmp.12 to double ; <double> [#uses=1]
+ %tmp.11 = call INT %time( INT* %secs ) ; <int> [#uses=0]
+ %tmp.12 = load INT* %secs ; <int> [#uses=1]
+ %tmp.13 = cast INT %tmp.12 to double ; <double> [#uses=1]
ret double %tmp.13
}
""")
@@ -49,8 +49,8 @@
extfunctions["%ll_time_clock"] = ((), """
internal fastcc double %ll_time_clock() {
entry:
- %tmp.0 = call int %clock( ) ; <int> [#uses=1]
- %tmp.1 = cast int %tmp.0 to double ; <double> [#uses=1]
+ %tmp.0 = call INT %clock( ) ; <int> [#uses=1]
+ %tmp.1 = cast INT %tmp.0 to double ; <double> [#uses=1]
%tmp.2 = div double %tmp.1, 1.000000e+06 ; <double> [#uses=1]
ret double %tmp.2
}
@@ -63,19 +63,19 @@
%tmp.0 = call double %fmod( double %secs, double 1.000000e+00 ) ; <double> [#uses=1]
%tmp.2 = call double %floor( double %secs ) ; <double> [#uses=1]
%tmp.4 = getelementptr %struct.timeval* %t, int 0, uint 0 ; <int*> [#uses=1]
- %tmp.6 = cast double %tmp.2 to int ; <int> [#uses=1]
- store int %tmp.6, int* %tmp.4
+ %tmp.6 = cast double %tmp.2 to INT ; <int> [#uses=1]
+ store INT %tmp.6, INT* %tmp.4
%tmp.7 = getelementptr %struct.timeval* %t, int 0, uint 1 ; <int*> [#uses=1]
%tmp.9 = mul double %tmp.0, 1.000000e+06 ; <double> [#uses=1]
- %tmp.10 = cast double %tmp.9 to int ; <int> [#uses=1]
- store int %tmp.10, int* %tmp.7
- %tmp.11 = call int %select( int 0, %typedef.fd_set* null, %typedef.fd_set* null, %typedef.fd_set* null, %struct.timeval* %t ) ; <int> [#uses=1]
- %tmp.12 = setne int %tmp.11, 0 ; <bool> [#uses=2]
- %tmp.13 = cast bool %tmp.12 to int ; <int> [#uses=0]
+ %tmp.10 = cast double %tmp.9 to INT ; <int> [#uses=1]
+ store INT %tmp.10, INT* %tmp.7
+ %tmp.11 = call INT %select( INT 0, %typedef.fd_set* null, %typedef.fd_set* null, %typedef.fd_set* null, %struct.timeval* %t ) ; <int> [#uses=1]
+ %tmp.12 = setne INT %tmp.11, 0 ; <bool> [#uses=2]
+ %tmp.13 = cast bool %tmp.12 to INT ; <int> [#uses=0]
br bool %tmp.12, label %then.1, label %return
then.1: ; preds = %entry
- ; XXX disabled for now: call void %RaiseSimpleException( int 1, sbyte* getelementptr ([16 x sbyte]* %.str_1, int 0, int 0) )
+ ; XXX disabled for now: call void %RaiseSimpleException( INT 1, sbyte* getelementptr ([16 x sbyte]* %.str_1, INT 0, INT 0) )
ret void
return: ; preds = %entry
Modified: pypy/dist/pypy/translator/llvm2/module/support.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/support.py (original)
+++ pypy/dist/pypy/translator/llvm2/module/support.py Mon Aug 22 21:35:07 2005
@@ -1,10 +1,10 @@
extdeclarations = """
declare ccc double %pow(double, double)
declare ccc double %fmod(double, double)
-declare ccc int %puts(sbyte*)
-declare ccc int %strlen(sbyte*)
-declare ccc int %strcmp(sbyte*, sbyte*)
-declare ccc sbyte* %memset(sbyte*, int, uint)
+declare ccc INT %puts(sbyte*)
+declare ccc INT %strlen(sbyte*)
+declare ccc INT %strcmp(sbyte*, sbyte*)
+declare ccc sbyte* %memset(sbyte*, INT, UINT)
%__print_debug_info = internal global bool false
%__print_debug_info_option = internal constant [19 x sbyte] c"--print-debug-info\\00"
@@ -40,12 +40,12 @@
extfunctions["%string_to_RPyString"] = ((), """
internal fastcc %RPyString* %string_to_RPyString(sbyte* %s) {
- %len = call ccc int %strlen(sbyte* %s)
+ %len = call ccc INT %strlen(sbyte* %s)
%rpy = call fastcc %RPyString* %RPyString_New__Signed(int %len)
%rpystrptr = getelementptr %RPyString* %rpy, int 0, uint 1, uint 1
%rpystr = cast [0 x sbyte]* %rpystrptr to sbyte*
- call ccc sbyte* %strncpy(sbyte* %rpystr, sbyte* %s, int %len)
+ call ccc sbyte* %strncpy(sbyte* %rpystr, sbyte* %s, INT %len)
ret %RPyString* %rpy
}
@@ -54,16 +54,16 @@
#abs functions
extfunctions["%int_abs"] = ((), """
-internal fastcc int %int_abs(int %x) {
+internal fastcc INT %int_abs(INT %x) {
block0:
- %cond1 = setge int %x, 0
+ %cond1 = setge INT %x, 0
br bool %cond1, label %return_block, label %block1
block1:
- %x2 = sub int 0, %x
+ %x2 = sub INT 0, %x
br label %return_block
return_block:
- %result = phi int [%x, %block0], [%x2, %block1]
- ret int %result
+ %result = phi INT [%x, %block0], [%x2, %block1]
+ ret INT %result
}
""")
@@ -117,7 +117,7 @@
#note: XXX this hardcoded int32 minint value is used because of a pre llvm1.6 bug!
int_ovf_test = """
- %cond2 = setne int %x, -2147483648
+ %cond2 = setne INT %x, -2147483648
br bool %cond2, label %return_block, label %ovf
ovf:
call fastcc void %__prepare_OverflowError()
@@ -129,10 +129,11 @@
for func_inst in "floordiv_zer:div mod_zer:rem".split():
func, inst = func_inst.split(':')
- for type_ in "int uint".split():
+ for prefix_type_ in "int:INT uint:UINT".split():
+ prefix, type_ = prefix_type_.split(':')
type_zer_test = zer_test % type_
- extfunctions["%%%(type_)s_%(func)s" % locals()] = (("%__prepare_ZeroDivisionError",), """
-internal fastcc %(type_)s %%%(type_)s_%(func)s(%(type_)s %%x, %(type_)s %%y) {
+ extfunctions["%%%(prefix)s_%(func)s" % locals()] = (("%__prepare_ZeroDivisionError",), """
+internal fastcc %(type_)s %%%(prefix)s_%(func)s(%(type_)s %%x, %(type_)s %%y) {
%(type_zer_test)s
%%z = %(inst)s %(type_)s %%x, %%y
ret %(type_)s %%z
@@ -144,26 +145,26 @@
#unary with OverflowError only
extfunctions["%int_neg_ovf"] = (("%__prepare_OverflowError",), """
-internal fastcc int %%int_neg_ovf(int %%x) {
+internal fastcc INT %%int_neg_ovf(INT %%x) {
block1:
- %%x2 = sub int 0, %%x
+ %%x2 = sub INT 0, %%x
%(int_ovf_test)s
return_block:
- ret int %%x2
+ ret INT %%x2
}
""" % locals())
extfunctions["%int_abs_ovf"] = (("%__prepare_OverflowError",), """
-internal fastcc int %%int_abs_ovf(int %%x) {
+internal fastcc INT %%int_abs_ovf(INT %%x) {
block0:
- %%cond1 = setge int %%x, 0
+ %%cond1 = setge INT %%x, 0
br bool %%cond1, label %%return_block, label %%block1
block1:
- %%x2 = sub int 0, %%x
+ %%x2 = sub INT 0, %%x
%(int_ovf_test)s
return_block:
- %%result = phi int [%%x, %%block0], [%%x2, %%block1]
- ret int %%result
+ %%result = phi INT [%%x, %%block0], [%%x2, %%block1]
+ ret INT %%result
}
""" % locals())
@@ -171,32 +172,32 @@
#binary with OverflowError only
extfunctions["%int_add_ovf"] = (("%__prepare_OverflowError",), """
-internal fastcc int %%int_add_ovf(int %%x, int %%y) {
- %%t = add int %%x, %%y
+internal fastcc INT %%int_add_ovf(INT %%x, INT %%y) {
+ %%t = add INT %%x, %%y
%(int_ovf_test)s
return_block:
; XXX: TEST int_add_ovf checking
- ret int %%t
+ ret INT %%t
}
""" % locals())
extfunctions["%int_sub_ovf"] = (("%__prepare_OverflowError",), """
-internal fastcc int %%int_sub_ovf(int %%x, int %%y) {
- %%t = sub int %%x, %%y
+internal fastcc INT %%int_sub_ovf(INT %%x, INT %%y) {
+ %%t = sub INT %%x, %%y
%(int_ovf_test)s
return_block:
; XXX: TEST int_sub_ovf checking
- ret int %%t
+ ret INT %%t
}
""" % locals())
extfunctions["%int_mul_ovf"] = (("%__prepare_OverflowError",), """
-internal fastcc int %%int_mul_ovf(int %%x, int %%y) {
- %%t = mul int %%x, %%y
+internal fastcc INT %%int_mul_ovf(INT %%x, INT %%y) {
+ %%t = mul INT %%x, %%y
%(int_ovf_test)s
return_block:
; XXX: TEST int_mul_ovf checking
- ret int %%t
+ ret INT %%t
}
""" % locals())
@@ -204,13 +205,13 @@
#binary with OverflowError and ValueError
extfunctions["%int_lshift_ovf_val"] = (("%__prepare_OverflowError","%__prepare_ValueError"), """
-internal fastcc int %%int_lshift_ovf_val(int %%x, int %%y) {
- %%yu = cast int %%y to ubyte
- %%t = shl int %%x, ubyte %%yu
+internal fastcc INT %%int_lshift_ovf_val(INT %%x, INT %%y) {
+ %%yu = cast INT %%y to ubyte
+ %%t = shl INT %%x, ubyte %%yu
%(int_ovf_test)s
return_block:
; XXX: TODO int_lshift_ovf_val checking VAL
- ret int %%t
+ ret INT %%t
}
""" % locals())
@@ -218,42 +219,42 @@
#binary with OverflowError and ZeroDivisionError
extfunctions["%int_floordiv_ovf_zer"] = (("%__prepare_OverflowError","%__prepare_ZeroDivisionError"), """
-internal fastcc int %%int_floordiv_ovf_zer(int %%x, int %%y) {
+internal fastcc INT %%int_floordiv_ovf_zer(INT %%x, INT %%y) {
%(int_zer_test)s
- %%t = div int %%x, %%y
+ %%t = div INT %%x, %%y
%(int_ovf_test)s
return_block:
; XXX: TEST int_floordiv_ovf_zer checking
- ret int %%t
+ ret INT %%t
}
""" % locals())
extfunctions["%int_mod_ovf_zer"] = (("%__prepare_OverflowError","%__prepare_ZeroDivisionError"), """
-internal fastcc int %%int_mod_ovf_zer(int %%x, int %%y) {
+internal fastcc INT %%int_mod_ovf_zer(INT %%x, INT %%y) {
%(int_zer_test)s
- %%t = rem int %%x, %%y
+ %%t = rem INT %%x, %%y
%(int_ovf_test)s
return_block:
; XXX: TEST int_mod_ovf_zer checking
- ret int %%t
+ ret INT %%t
}
""" % locals())
extfunctions["%main"] = (("%string_to_RPyString"), """
-int %main(int %argc, sbyte** %argv) {
+INT %main(INT %argc, sbyte** %argv) {
entry:
- %pypy_argv = call fastcc %RPyListOfString* %ll_newlist__listPtrConst_Signed.2(int 0)
+ %pypy_argv = call fastcc %RPyListOfString* %ll_newlist__listPtrConst_Signed.2(INT 0)
br label %no_exit
no_exit:
- %indvar = phi uint [ %indvar.next, %next_arg ], [ 0, %entry ]
- %i.0.0 = cast uint %indvar to int
- %tmp.8 = getelementptr sbyte** %argv, uint %indvar
+ %indvar = phi UINT [ %indvar.next, %next_arg ], [ 0, %entry ]
+ %i.0.0 = cast UINT %indvar to INT
+ %tmp.8 = getelementptr sbyte** %argv, UINT %indvar
%tmp.9 = load sbyte** %tmp.8
%t = getelementptr [19 x sbyte]* %__print_debug_info_option, int 0, int 0
- %res = call ccc int %strcmp(sbyte* %tmp.9, sbyte* %t)
- %cond = seteq int %res, 0
+ %res = call ccc INT %strcmp(sbyte* %tmp.9, sbyte* %t)
+ %cond = seteq INT %res, 0
br bool %cond, label %debugging, label %not_debugging
debugging:
@@ -266,14 +267,14 @@
br label %next_arg
next_arg:
- %inc = add int %i.0.0, 1
- %tmp.2 = setlt int %inc, %argc
- %indvar.next = add uint %indvar, 1
+ %inc = add INT %i.0.0, 1
+ %tmp.2 = setlt INT %inc, %argc
+ %indvar.next = add UINT %indvar, 1
br bool %tmp.2, label %no_exit, label %loopexit
loopexit:
- %ret = call fastcc int %entry_point(%structtype.list* %pypy_argv)
- ret int %ret
+ %ret = call fastcc INT %entry_point(%structtype.list* %pypy_argv)
+ ret INT %ret
}
""")
Modified: pypy/dist/pypy/translator/llvm2/opwriter.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/opwriter.py (original)
+++ pypy/dist/pypy/translator/llvm2/opwriter.py Mon Aug 22 21:35:07 2005
@@ -465,6 +465,8 @@
index = self._getindexhelper(op.args[1].value, op.args[0].concretetype.TO)
valuevar, valuetype = self.db.repr_argwithtype(op.args[2])
if valuetype != "void":
+ #Structure types require uint constants!
+ #see: http://llvm.cs.uiuc.edu/docs/LangRef.html#i_getelementptr
self.codewriter.getelementptr(tmpvar, structtype, struct,
("uint", index))
self.codewriter.store(valuetype, valuevar, tmpvar)
Modified: pypy/dist/pypy/translator/llvm2/structnode.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/structnode.py (original)
+++ pypy/dist/pypy/translator/llvm2/structnode.py Mon Aug 22 21:35:07 2005
@@ -73,7 +73,7 @@
current = self.struct
while isinstance(current, lltype.Struct):
last_pos = len(current._names_without_voids()) - 1
- indices_to_array.append(("uint", last_pos))
+ indices_to_array.append(("uint", last_pos)) #struct requires uint consts
name = current._names_without_voids()[-1]
current = current._flds[name]
assert isinstance(current, lltype.Array)
@@ -132,7 +132,8 @@
found = True
break
pos += 1
-
+ #Structure types require uint constants!
+ #see: http://llvm.cs.uiuc.edu/docs/LangRef.html#i_getelementptr
return "getelementptr(%s* %s, int 0, uint %s)" %(
self.get_typerepr(),
self.get_ref(),
Modified: pypy/dist/pypy/translator/llvm2/varsize.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/varsize.py (original)
+++ pypy/dist/pypy/translator/llvm2/varsize.py Mon Aug 22 21:35:07 2005
@@ -1,31 +1,16 @@
from pypy.rpython.rstr import STR
-# example for an array constructor in concrete llvm code:
-# (thanks to chris lattner)
-""" this function generates a LLVM function like the following:
-%array = type { int, [0 x double] }
-%array *%NewArray(int %len) {
- ;; Get the offset of the 'len' element of the array from the null
- ;; pointer.
- %size = getelementptr %array* null, int 0, uint 1, %int %len
- %usize = cast double* %size to uint
- %ptr = malloc sbyte, uint %usize
- %result = cast sbyte* %ptr to %array*
- %arraylength = getelementptr %array* %result, int 0, uint 0
- store int %len, int* %arraylength
- ret %array* %result
-}"""
-
def write_constructor(db, codewriter, ref, constructor_decl, ARRAY,
indices_to_array=(), atomicmalloc=False):
#varsized arrays and structs look like this:
- #Array: {int length , elemtype*}
+ #Array: {INT length , elemtype*}
#Struct: {...., Array}
# the following indices access the last element in the array
elemtype = db.repr_type(ARRAY.OF)
- lentype = db.get_machine_word()
+ word = lentype = db.get_machine_word()
+ uword = db.get_machine_uword()
codewriter.openfunc(constructor_decl)
@@ -37,12 +22,13 @@
elemindices = list(indices_to_array) + [("uint", 1), (lentype, "%actuallen")]
codewriter.getelementptr("%size", ref + "*", "null", *elemindices)
- codewriter.cast("%usize", elemtype + "*", "%size", "uint")
+ codewriter.cast("%usize", elemtype + "*", "%size", uword)
codewriter.malloc("%ptr", "sbyte", "%usize", atomic=atomicmalloc)
codewriter.cast("%result", "sbyte*", "%ptr", ref + "*")
if ARRAY is STR.chars:
- codewriter.call('%memset_result', 'sbyte*', '%memset', ['%ptr', '0', '%usize',], ['sbyte*', 'int', 'uint'], cconv='ccc')
+ #XXX instead of memset we could probably just zero the hash and string terminator
+ codewriter.call('%memset_result', 'sbyte*', '%memset', ['%ptr', '0', '%usize',], ['sbyte*', word, uword], cconv='ccc')
indices_to_arraylength = tuple(indices_to_array) + (("uint", 0),)
# the following accesses the length field of the array
@@ -50,16 +36,7 @@
"%result",
*indices_to_arraylength)
codewriter.store(lentype, "%len", "%arraylength")
-
- #if ARRAY is STR.chars: #(temp. disabled because we are moving memset from gc_malloc to here)
- # # NUL the last element
- # #lastelemindices = list(indices_to_array) + [("uint", 1), (lentype, "%len")]
- # #codewriter.getelementptr("%terminator",
- # # ref + "*",
- # # "%result",
- # # *lastelemindices)
- # #codewriter.store(elemtype, 0, "%terminator")
-
+
codewriter.ret(ref + "*", "%result")
codewriter.closefunc()
More information about the Pypy-commit
mailing list