[pypy-svn] r16523 - in pypy/dist/pypy/translator/llvm2: . module

rxe at codespeak.net rxe at codespeak.net
Thu Aug 25 18:51:33 CEST 2005


Author: rxe
Date: Thu Aug 25 18:51:32 2005
New Revision: 16523

Removed:
   pypy/dist/pypy/translator/llvm2/module/ll_math.py
   pypy/dist/pypy/translator/llvm2/module/ll_strtod.py
   pypy/dist/pypy/translator/llvm2/module/ll_time.py
Modified:
   pypy/dist/pypy/translator/llvm2/genllvm.py
   pypy/dist/pypy/translator/llvm2/module/extfunction.py
   pypy/dist/pypy/translator/llvm2/module/genexterns.c
   pypy/dist/pypy/translator/llvm2/module/ll_os.py
   pypy/dist/pypy/translator/llvm2/module/support.py
Log:
Intermediate checkin after refactoring names to be similar to genc:
RPyString_FromString, RPyString_AsString and RPyString_Size.

Added LL_strtod_formatd() - not tested yet.

Tidied up and removed most of module/ll_xxx files.



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 18:51:32 2005
@@ -322,6 +322,8 @@
         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
+
         if self.debug:  print 'gen_llvm_source used_external_functions) ' + time.ctime()
         depdone = {}
         for funcname,value in extfuncnode.ExternalFuncNode.used_external_functions.iteritems():

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	Thu Aug 25 18:51:32 2005
@@ -38,9 +38,9 @@
 
 extfunctions = {}   #dependencies, llvm-code
 
-import support, ll_os, ll_os_path, ll_math, ll_strtod
+import support, ll_os
 
-for module in (support, ll_os, ll_os_path, ll_math, ll_strtod):
+for module in (support, ll_os):
     extdeclarations += module.extdeclarations
     extfunctions.update(module.extfunctions)
 extdeclarations += '\n;application function prototypes'

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 18:51:32 2005
@@ -1,4 +1,6 @@
 #include <errno.h>
+#include <locale.h>
+#include <ctype.h>
 #include <python2.3/Python.h>
 
 #define NULL (void *) 0
@@ -10,6 +12,7 @@
 
 struct RPyFREXP_RESULT;
 struct RPyMODF_RESULT;
+struct RPyString;
 
 struct RPyFREXP_RESULT *ll_frexp_result__Float_Signed(double, int);
 struct RPyMODF_RESULT *ll_modf_result__Float_Float(double, double);
@@ -18,7 +21,6 @@
 void prepare_and_raise_ValueError(char *);
 void prepare_and_raise_IOError(char *);
 
-
 int ll_math_is_error(double x) {
 	if (errno == ERANGE) {
 		if (!x) 
@@ -374,3 +376,109 @@
 {
 	return ll_floattime();
 }
+
+double ll_strtod_parts_to_float(struct RPyString *sign, 
+				struct RPyString *beforept, 
+				struct RPyString *afterpt, 
+				struct RPyString *exponent)
+{
+	char *fail_pos;
+	struct lconv *locale_data;
+	const char *decimal_point;
+	int decimal_point_len;
+	double x;
+	char *last;
+	char *expo = RPyString_AsString(exponent);
+	int buf_size;
+	char *s;
+
+	if (*expo == '\0') {
+		expo = "0";
+	}
+
+	locale_data = localeconv();
+	decimal_point = locale_data->decimal_point;
+	decimal_point_len = strlen(decimal_point);
+
+	buf_size = RPyString_Size(sign) + 
+	  RPyString_Size(beforept) +
+	  decimal_point_len +
+	  RPyString_Size(afterpt) +
+	  1 /* e */ +
+	  strlen(expo) + 
+	  1 /*  asciiz  */ ;
+
+        s = malloc(buf_size);
+
+	strcpy(s, RPyString_AsString(sign));
+	strcat(s, RPyString_AsString(beforept));
+	strcat(s, decimal_point);
+	strcat(s, RPyString_AsString(afterpt));
+	strcat(s, "e");
+	strcat(s, expo);
+
+	last = s + (buf_size-1);
+	x = strtod(s, &fail_pos);
+	errno = 0;
+	free(s);
+	if (fail_pos > last)
+		fail_pos = last;
+	if (fail_pos == s || *fail_pos != '\0' || fail_pos != last) {
+		RPyRaiseSimpleException(PyExc_ValueError, "invalid float literal");
+		return -1.0;
+	}
+	if (x == 0.0) { /* maybe a denormal value, ask for atof behavior */
+		x = strtod(s, NULL);
+		errno = 0;
+	}
+	return x;
+}
+
+
+struct RPyString *LL_strtod_formatd(struct RPyString *fmt, double x) {
+	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 */
+	} else {
+		struct lconv *locale_data;
+		const char *decimal_point;
+		int decimal_point_len;
+		char *p;
+
+		locale_data = localeconv();
+		decimal_point = locale_data->decimal_point;
+		decimal_point_len = strlen(decimal_point);
+
+		if (decimal_point[0] != '.' || 
+		    decimal_point[1] != 0)
+		{
+			p = buffer;
+
+			if (*p == '+' || *p == '-')
+				p++;
+
+			while (isdigit((unsigned char)*p))
+				p++;
+
+			if (strncmp(p, decimal_point, decimal_point_len) == 0)
+			{
+				*p = '.';
+				p++;
+				if (decimal_point_len > 1) {
+					int rest_len;
+					rest_len = strlen(p + (decimal_point_len - 1));
+					memmove(p, p + (decimal_point_len - 1), 
+						rest_len);
+					p[rest_len] = 0;
+				}
+			}
+		}
+		
+	}
+
+	return RPyString_FromString(buffer);
+}
+

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	Thu Aug 25 18:51:32 2005
@@ -32,7 +32,7 @@
 
 """)
 
-extfunctions["%ll_os_getcwd"] = (("%string_to_RPyString", "%__debug"), """
+extfunctions["%ll_os_getcwd"] = (("%RPyString_FromString", "%__debug"), """
 internal fastcc %RPyString* %ll_os_getcwd() {
 
     call fastcc void %__debug([12 x sbyte]* %__ll_os_getcwd) ; XXX: Test: ll_os_getcwd
@@ -41,7 +41,7 @@
     %res = call ccc sbyte* %getcwd(sbyte* %s, int 1023)
     ;if %res == null: raise...
 
-    %cwd = call fastcc %RPyString* %string_to_RPyString(sbyte* %s)
+    %cwd = call fastcc %RPyString* %RPyString_FromString(sbyte* %s)
     ret %RPyString* %cwd
 }
 
@@ -55,20 +55,20 @@
 
 """)
 
-extfunctions["%ll_os_open"] = (("%cast",), """
+extfunctions["%ll_os_open"] = (("%RPyString_AsString",), """
 internal fastcc int %ll_os_open(%RPyString* %structstring, int %flag, int %mode) {
-    %dest  = call fastcc sbyte* %cast(%RPyString* %structstring)
+    %dest  = call fastcc sbyte* %RPyString_AsString(%RPyString* %structstring)
     %fd    = call ccc    int    %open(sbyte* %dest, int %flag, int %mode)
     ret int %fd 
 }
 
 """)
 
-extfunctions["%ll_os_write"] = (("%cast",), """
+extfunctions["%ll_os_write"] = (("%RPyString_AsString",), """
 internal fastcc int %ll_os_write(int %fd, %RPyString* %structstring) {
     %reallengthptr = getelementptr %RPyString* %structstring, int 0, uint 1, uint 0
     %reallength    = load int* %reallengthptr 
-    %dest          = call fastcc sbyte* %cast(%RPyString* %structstring)
+    %dest          = call fastcc sbyte* %RPyString_AsString(%RPyString* %structstring)
     %byteswritten  = call ccc    int    %write(int %fd, sbyte* %dest, int %reallength)
     ret int %byteswritten
 }
@@ -173,13 +173,13 @@
 }
 """)
 
-extfunctions["%ll_os_stat"] = (("%cast", "%__debug", "%_stat_construct_result_helper"), """
+extfunctions["%ll_os_stat"] = (("%RPyString_AsString", "%__debug", "%_stat_construct_result_helper"), """
 internal fastcc %RPySTAT_RESULT* %ll_os_stat(%RPyString* %s) {
 
     call fastcc void %__debug([12 x sbyte]* %__ll_os_stat) ; XXX: Test: ll_os_stat
 
     %st       = alloca [32 x int]
-    %filename = call fastcc sbyte* %cast(%RPyString* %s)
+    %filename = call fastcc sbyte* %RPyString_AsString(%RPyString* %s)
     %error    = call ccc int %stat(sbyte* %filename, [32 x int]* %st)
     %cond     = seteq int %error, 0
     br bool %cond, label %cool, label %bwa

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 18:51:32 2005
@@ -1,3 +1,4 @@
+
 extdeclarations = """
 declare ccc double %pow(double, double)
 declare ccc double %fmod(double, double)
@@ -29,8 +30,8 @@
 
 """)
 
-extfunctions["%cast"] = (("%string_to_RPyString",), """
-internal fastcc sbyte* %cast(%RPyString* %structstring) {
+extfunctions["%RPyString_AsString"] = (("%RPyString_FromString",), """
+internal fastcc sbyte* %RPyString_AsString(%RPyString* %structstring) {
     %source1ptr = getelementptr %RPyString* %structstring, int 0, uint 1, uint 1
     %source1 = cast [0 x sbyte]* %source1ptr to sbyte*
     ret sbyte* %source1
@@ -38,8 +39,19 @@
 
 """)
 
-extfunctions["%string_to_RPyString"] = ((), """
-internal fastcc %RPyString* %string_to_RPyString(sbyte* %s) {
+extfunctions["%RPyString_Size"] = ((), """
+internal fastcc int %RPyString_Size(%RPyString* %structstring) {
+    %sizeptr = getelementptr %RPyString* %structstring, int 0, uint 0
+    %size = load int* %sizeptr
+    return %size
+
+}
+
+""")
+
+
+extfunctions["%RPyString_FromString"] = ((), """
+internal fastcc %RPyString* %RPyString_FromString(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
@@ -255,7 +267,7 @@
 }
 """ % locals())
 
-extfunctions["%main"] = (("%string_to_RPyString"), """
+extfunctions["%main"] = ((), """
 int %main(int %argc, sbyte** %argv) {
 entry:
     %pypy_argv = call fastcc %RPyListOfString* %ll_newlist__listPtrConst_Signed.2(int 0)
@@ -277,7 +289,7 @@
     br label %next_arg
 
 not_debugging:
-    %rpy = call fastcc %RPyString* %string_to_RPyString(sbyte* %tmp.9)
+    %rpy = call fastcc %RPyString* %RPyString_FromString(sbyte* %tmp.9)
     call fastcc void %ll_append__listPtr_rpy_stringPtr(%RPyListOfString* %pypy_argv, %RPyString* %rpy)
     br label %next_arg
 



More information about the Pypy-commit mailing list