[pypy-svn] r16554 - in pypy/dist/pypy/translator/llvm2: . module test
rxe at codespeak.net
rxe at codespeak.net
Thu Aug 25 21:44:04 CEST 2005
Author: rxe
Date: Thu Aug 25 21:44:03 2005
New Revision: 16554
Modified:
pypy/dist/pypy/translator/llvm2/build_llvm_module.py
pypy/dist/pypy/translator/llvm2/genllvm.py
pypy/dist/pypy/translator/llvm2/module/genexterns.c
pypy/dist/pypy/translator/llvm2/module/support.py
pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
Log:
Checking in temp - see next msg for useful info.
Modified: pypy/dist/pypy/translator/llvm2/build_llvm_module.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/build_llvm_module.py (original)
+++ pypy/dist/pypy/translator/llvm2/build_llvm_module.py Thu Aug 25 21:44:03 2005
@@ -74,12 +74,15 @@
else:
optimization_switches = SIMPLE_OPTIMIZATION_SWITCHES
- cmds = ["llvm-as %s.ll" % b]
+ #XXX outcommented for testing merging extern.ll in main .ll file
+ #cmds = ["llvm-as %s.ll" % b]
+ #
+ #bcfile = dirpath.join("externs", "externs_linked.bc")
+ #cmds.append("llvm-link %s.bc %s -o %s_all.bc" % (b, str(bcfile), b))
+ #ball = str(dirpath.join('%s_all.bc' % b))
+ #cmds.append("opt %s %s -f -o %s.bc" % (OPTIMIZATION_SWITCHES, ball, b))
- bcfile = dirpath.join("externs", "externs_linked.bc")
- cmds.append("llvm-link %s.bc %s -o %s_all.bc" % (b, str(bcfile), b))
- ball = str(dirpath.join('%s_all.bc' % b))
- cmds.append("opt %s %s -f -o %s.bc" % (OPTIMIZATION_SWITCHES, ball, b))
+ cmds = ["llvm-as < %s.ll | opt %s -f -o %s.bc" % (b, OPTIMIZATION_SWITCHES, b)]
if False and sys.maxint == 2147483647: #32 bit platform
cmds.append("llc %s %s.bc -f -o %s.s" % (EXCEPTIONS_SWITCHES, b, b))
@@ -91,8 +94,8 @@
#this special case for x86-64 (called ia64 in llvm) can go as soon as llc supports ia64 assembly output!
cmds.append("llc %s %s.bc -march=c -f -o %s.c" % (EXCEPTIONS_SWITCHES, b, b))
if exe_name:
- cmds.append("gcc %s.c -c -O2 -fomit-frame-pointer" % (b,))
- cmds.append("gcc %s.o -static %s -lm -o %s" % (b, gc_libs, exe_name))
+ cmds.append("gcc -g %s.c -c -O2 -fomit-frame-pointer" % (b,))
+ cmds.append("gcc -g %s.o -static %s -lm -o %s" % (b, gc_libs, exe_name))
source_files.append("%s.c" % b)
try:
Modified: pypy/dist/pypy/translator/llvm2/genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/genllvm.py (original)
+++ pypy/dist/pypy/translator/llvm2/genllvm.py Thu Aug 25 21:44:03 2005
@@ -55,11 +55,12 @@
if comment >= 0:
line = line[:comment]
line = line.rstrip()
- #if line[-1:] == '{':
- # returntype, s = line.split(' ', 1)
- # funcname , s = s.split('(', 1)
- # funcnames[funcname] = True
- # line = '%s %s %s' % ("", DEFAULT_CCONV, line,)
+ if line[-1:] == '{':
+ returntype, s = line.split(' ', 1)
+ funcname , s = s.split('(', 1)
+ funcnames[funcname] = True
+ assert line.find("internal") == -1
+ line = '%s %s %s' % ("", DEFAULT_CCONV, line,)
ll_lines.append(line)
#patch calls to function that we just declared fastcc
@@ -83,28 +84,31 @@
ll_lines2.append(line)
llcode = '\n'.join(ll_lines2)
+ return llcode.split('implementation') #XXX testing
- # create file
- llfilename = extern_dir.join("externs").new(ext='.ll')
- f = open(str(llfilename), 'w')
- f.write(llcode)
- f.close()
-
+ #XXX temp disabled
+ #
+ ## create file
+ #llfilename = extern_dir.join("externs").new(ext='.ll')
+ #f = open(str(llfilename), 'w')
+ #f.write(llcode)
+ #f.close()
+ #
# create bytecode
- os.chdir(str(extern_dir))
- cmdexec('llvm-as externs.ll')
- bcfilename = extern_dir.join("externs").new(ext='.bc')
- if functions:
- for func in functions:
- # extract
- cmdexec('llvm-extract -func %s -o %s.bc externs.bc' % (func, func))
-
- # link all the ll files
- functions_bcs = ' '.join(['%s.bc' % func for func in functions])
- cmdexec('llvm-link -o externs_linked.bc ' + functions_bcs)
- bcfilename = extern_dir.join("externs_linked").new(ext='.bc')
-
- return bcfilename
+ #os.chdir(str(extern_dir))
+ #cmdexec('llvm-as externs.ll')
+ #bcfilename = extern_dir.join("externs").new(ext='.bc')
+ #if functions:
+ # for func in functions:
+ # # extract
+ # cmdexec('llvm-extract -func %s -o %s.bc externs.bc' % (func, func))
+ #
+ # # link all the ll files
+ # functions_bcs = ' '.join(['%s.bc' % func for func in functions])
+ # cmdexec('llvm-link -o externs_linked.bc ' + functions_bcs)
+ # bcfilename = extern_dir.join("externs_linked").new(ext='.bc')
+ #
+ #return bcfilename
class GenLLVM(object):
@@ -214,7 +218,7 @@
self.translator.rtyper.specialize_more_blocks()
self.db.setup_all()
- self.generate_llfile(extern_decls)
+ lldeclarations, llimplementation = self.generate_llfile(extern_decls)
#if self.debug: print 'gen_llvm_source typ_decl.writedatatypedecl) ' + time.ctime()
#if self.debug: print 'gen_llvm_source n_nodes) %d' % len(self.db.getnodes())
@@ -235,6 +239,10 @@
comment = codewriter.comment
nl = codewriter.newline
+ nl(); comment("EXTERNAL FUNCTION DECLARATIONS") ; nl()
+ for s in lldeclarations.split('\n'):
+ codewriter.append(s)
+
nl(); comment("Type Declarations"); nl()
for c_name, obj in extern_decls:
@@ -327,7 +335,10 @@
if entryfunc_name != 'main' and entryfunc_name == 'entry_point': #XXX just to get on with translate_pypy
extfuncnode.ExternalFuncNode.used_external_functions['%main'] = True
- extfuncnode.ExternalFuncNode.used_external_functions['%RPyString_FromString'] = True
+ for f in "prepare_and_raise_OverflowError prepare_and_raise_ValueError "\
+ "prepare_and_raise_ZeroDivisionError prepare_and_raise_IOError "\
+ "RPyString_FromString RPyString_AsString RPyString_Size".split():
+ extfuncnode.ExternalFuncNode.used_external_functions["%" + f] = True
if self.debug: print 'gen_llvm_source used_external_functions) ' + time.ctime()
depdone = {}
@@ -347,6 +358,10 @@
codewriter.append(extfunc)
depdone[dep] = True
+ nl(); comment("EXTERNAL FUNCTION IMPLEMENTATION") ; nl()
+ for s in llimplementation.split('\n'):
+ codewriter.append(s)
+
comment("End of file") ; nl()
if self.debug: print 'gen_llvm_source return) ' + time.ctime()
return filename
@@ -355,7 +370,7 @@
filename,
really_compile=True,
standalone=False,
- optimize=False,
+ optimize=True,
exe_name=None):
if not llvm_is_on_path():
Modified: pypy/dist/pypy/translator/llvm2/module/genexterns.c
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/genexterns.c (original)
+++ pypy/dist/pypy/translator/llvm2/module/genexterns.c Thu Aug 25 21:44:03 2005
@@ -18,7 +18,7 @@
struct RPyMODF_RESULT *ll_modf_result__Float_Float(double, double);
char *RPyString_AsString(struct RPyString*);
-int RPyString_Size(struct RPyString_Size*);
+int RPyString_Size(struct RPyString*);
struct RPyString *RPyString_FromString(char *);
void prepare_and_raise_OverflowError(char *);
@@ -340,8 +340,7 @@
#endif /* MS_WINDOWS */
#endif /* HAVE_FTIME */
-static double
-ll_floattime(void)
+double ll_floattime(void)
{
/* There are three ways to get the time:
(1) gettimeofday() -- resolution in microseconds
@@ -381,6 +380,7 @@
return ll_floattime();
}
+
double ll_strtod_parts_to_float(struct RPyString *sign,
struct RPyString *beforept,
struct RPyString *afterpt,
@@ -392,18 +392,25 @@
int decimal_point_len;
double x;
char *last;
- char *expo = RPyString_AsString(exponent);
int buf_size;
char *s;
+ char *expo = NULL;
+
+ fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX1111111111XXXXXX hello\n");
+
+ expo = RPyString_AsString(exponent);
+ fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXX222222222XXXXXXXXXXXXXXXXXX hello\n");
if (*expo == '\0') {
expo = "0";
}
+ fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX33333XXXXXXXXXXXXX hello\n");
locale_data = localeconv();
decimal_point = locale_data->decimal_point;
decimal_point_len = strlen(decimal_point);
+ fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX44444XXXXXXXX hello\n");
buf_size = RPyString_Size(sign) +
RPyString_Size(beforept) +
decimal_point_len +
@@ -412,6 +419,7 @@
strlen(expo) +
1 /* asciiz */ ;
+ fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5555XXXX hello\n");
s = malloc(buf_size);
strcpy(s, RPyString_AsString(sign));
@@ -421,20 +429,26 @@
strcat(s, "e");
strcat(s, expo);
+ fprintf(stderr, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX6666 hello\n");
last = s + (buf_size-1);
x = strtod(s, &fail_pos);
errno = 0;
- free(s);
+ fprintf(stderr, "XXXXXXXXX77777777777777777777799999999999999999999999hello\n");
if (fail_pos > last)
fail_pos = last;
+ fprintf(stderr, "XXXXX888888888888888888888888999999999999999999999999hello\n");
if (fail_pos == s || *fail_pos != '\0' || fail_pos != last) {
+ free(s);
prepare_and_raise_ValueError("invalid float literal");
return -1.0;
}
+ fprintf(stderr, "XXXXXXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa9999999999999hello\n");
if (x == 0.0) { /* maybe a denormal value, ask for atof behavior */
x = strtod(s, NULL);
errno = 0;
}
+ fprintf(stderr, "XXXXXXXXXXXX99999999999999999999999999999999999999999hello\n");
+ free(s);
return x;
}
@@ -443,6 +457,7 @@
char buffer[120]; /* this should be enough, from PyString_Format code */
int buflen = 120;
int res;
+
res = snprintf(buffer, buflen, RPyString_AsString(fmt), x);
if (res <= 0 || res >= buflen) {
strcpy(buffer, "??.?"); /* should not occur */
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 Thu Aug 25 21:44:03 2005
@@ -3,7 +3,7 @@
declare ccc double %pow(double, double)
declare ccc double %fmod(double, double)
declare ccc int %puts(sbyte*)
-declare ccc int %strlen(sbyte*)
+declare ccc uint %strlen(sbyte*)
declare ccc int %strcmp(sbyte*, sbyte*)
declare ccc sbyte* %memset(sbyte*, int, uint)
@@ -43,7 +43,7 @@
internal fastcc int %RPyString_Size(%RPyString* %structstring) {
%sizeptr = getelementptr %RPyString* %structstring, int 0, uint 1, uint 0
%size = load int* %sizeptr
- return %size
+ ret int %size
}
@@ -51,7 +51,8 @@
extfunctions["%RPyString_FromString"] = ((), """
internal fastcc %RPyString* %RPyString_FromString(sbyte* %s) {
- %len = call ccc int %strlen(sbyte* %s)
+ %lenu = call ccc uint %strlen(sbyte* %s)
+ %len = cast uint %lenu to int
%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*
Modified: pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_extfunc.py (original)
+++ pypy/dist/pypy/translator/llvm2/test/test_extfunc.py Thu Aug 25 21:44:03 2005
@@ -247,15 +247,11 @@
def test_rarith_formatd():
from pypy.rpython.rarithmetic import formatd
as_float = [ 0.0 , 1.5 , 2.0 ]
- as_string = ["0.00", "1.50", "2.01"]
+ as_string = ["0.00", "1.50", "2.00"]
def fn(i):
- if formatd("%.2f", as_float[i]) == as_string[i]:
- return 1
- else:
- return 0
+ return formatd("%.2f", as_float[i]) == as_string[i]
f = compile_function(fn, [int])
for i, s in enumerate(as_string):
- res = f(i)
- assert res == 1
+ assert f(i)
# end of tests taken from c backend
More information about the Pypy-commit
mailing list