[pypy-svn] r16511 - in pypy/dist/pypy/translator/llvm2: . module
rxe at codespeak.net
rxe at codespeak.net
Thu Aug 25 17:54:12 CEST 2005
Author: rxe
Date: Thu Aug 25 17:54:10 2005
New Revision: 16511
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/support.py
Log:
Add ll_time_xxx functions ! (ericvrp/rxe)
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 17:54:10 2005
@@ -45,17 +45,18 @@
"%prepare_and_raise_ZeroDivisionError" : True,
"%prepare_and_raise_OverflowError" : True,
"%prepare_and_raise_ValueError" : True,
+ "%prepare_and_raise_IOError" : True,
}
for line in llcode.split('\n'):
comment = line.find(';')
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' % ("internal", DEFAULT_CCONV, line,)
+ #if line[-1:] == '{':
+ # returntype, s = line.split(' ', 1)
+ # funcname , s = s.split('(', 1)
+ # funcnames[funcname] = True
+ # line = '%s %s %s' % ("", DEFAULT_CCONV, line,)
ll_lines.append(line)
#patch calls to function that we just declared fastcc
@@ -181,6 +182,8 @@
math_fns = 'acos asin atan ceil cos cosh exp fabs floor log log10 atan2 fmod '
math_fns += 'sin sinh sqrt tan tanh frexp modf pow hypot ldexp is_error'
fns = [('ll_math_%s' % f) for f in math_fns.split()]
+ time_fns = "ll_time_time ll_time_clock ll_time_sleep ll_floattime"
+ fns += time_fns.split()
return get_ll(open(p).read(), extern_dir, fns)
def gen_llvm_source(self, func=None):
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 17:54:10 2005
@@ -38,9 +38,9 @@
extfunctions = {} #dependencies, llvm-code
-import support, ll_os, ll_os_path, ll_time, ll_math, ll_strtod
+import support, ll_os, ll_os_path, ll_math, ll_strtod
-for module in (support, ll_os, ll_os_path, ll_time, ll_math, ll_strtod):
+for module in (support, ll_os, ll_os_path, ll_math, ll_strtod):
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 17:54:10 2005
@@ -16,6 +16,7 @@
void prepare_and_raise_OverflowError(char *);
void prepare_and_raise_ValueError(char *);
+void prepare_and_raise_IOError(char *);
int ll_math_is_error(double x) {
@@ -224,3 +225,152 @@
LL_MATH_CHECK_ERROR(m, NULL);
return ll_frexp_result__Float_Signed(m, expo);
}
+
+/************************************************************/
+ /*** C header subsection: time module ***/
+
+#include <time.h>
+#ifndef MS_WINDOWS
+# include <sys/time.h>
+#endif
+
+
+/****** clock() ******/
+
+#if defined(MS_WINDOWS) && !defined(MS_WIN64) && !defined(__BORLANDC__)
+/* Win32 has better clock replacement
+ XXX Win64 does not yet, but might when the platform matures. */
+#include <windows.h>
+
+double ll_time_clock(void)
+{
+ static LARGE_INTEGER ctrStart;
+ static double divisor = 0.0;
+ LARGE_INTEGER now;
+ double diff;
+
+ if (divisor == 0.0) {
+ LARGE_INTEGER freq;
+ QueryPerformanceCounter(&ctrStart);
+ if (!QueryPerformanceFrequency(&freq) || freq.QuadPart == 0) {
+ /* Unlikely to happen - this works on all intel
+ machines at least! Revert to clock() */
+ return clock();
+ }
+ divisor = (double)freq.QuadPart;
+ }
+ QueryPerformanceCounter(&now);
+ diff = (double)(now.QuadPart - ctrStart.QuadPart);
+ return diff / divisor;
+}
+
+#else /* if !MS_WINDOWS */
+
+#ifndef CLOCKS_PER_SEC
+#ifdef CLK_TCK
+#define CLOCKS_PER_SEC CLK_TCK
+#else
+#define CLOCKS_PER_SEC 1000000
+#endif
+#endif
+
+double ll_time_clock(void)
+{
+ return ((double)clock()) / CLOCKS_PER_SEC;
+}
+#endif /* MS_WINDOWS */
+
+
+void ll_time_sleep(double secs)
+{
+#if defined(MS_WINDOWS)
+ double millisecs = secs * 1000.0;
+ unsigned long ul_millis;
+
+ if (millisecs > (double)ULONG_MAX) {
+ prepare_and_raise_OverflowError("sleep length is too large");
+ }
+ ul_millis = (unsigned long)millisecs;
+ /* XXX copy CPython to make this interruptible again */
+ /*if (ul_millis == 0)*/
+ Sleep(ul_millis);
+ /*else {
+ DWORD rc;
+ ResetEvent(hInterruptEvent);
+ rc = WaitForSingleObject(hInterruptEvent, ul_millis);
+ if (rc == WAIT_OBJECT_0) {
+ * Yield to make sure real Python signal
+ * handler called.
+ *
+ Sleep(1);
+ RPyRaiseSimpleException(PyExc_IOError, "interrupted");
+ return;
+ }
+ }*/
+#else
+ struct timeval t;
+ double frac;
+ frac = fmod(secs, 1.0);
+ secs = floor(secs);
+ t.tv_sec = (long)secs;
+ t.tv_usec = (long)(frac*1000000.0);
+ if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
+#ifdef EINTR
+ if (errno != EINTR) {
+#else
+ if (1) {
+#endif
+ prepare_and_raise_IOError("select() failed");
+ }
+ }
+#endif
+}
+
+
+#ifdef HAVE_FTIME
+#include <sys/timeb.h>
+#if !defined(MS_WINDOWS) && !defined(PYOS_OS2)
+extern int ftime(struct timeb *);
+#endif /* MS_WINDOWS */
+#endif /* HAVE_FTIME */
+
+static double
+ll_floattime(void)
+{
+ /* There are three ways to get the time:
+ (1) gettimeofday() -- resolution in microseconds
+ (2) ftime() -- resolution in milliseconds
+ (3) time() -- resolution in seconds
+ In all cases the return value is a float in seconds.
+ Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
+ fail, so we fall back on ftime() or time().
+ Note: clock resolution does not imply clock accuracy! */
+#ifdef HAVE_GETTIMEOFDAY
+ {
+ struct timeval t;
+#ifdef GETTIMEOFDAY_NO_TZ
+ if (gettimeofday(&t) == 0)
+ return (double)t.tv_sec + t.tv_usec*0.000001;
+#else /* !GETTIMEOFDAY_NO_TZ */
+ if (gettimeofday(&t, (struct timezone *)NULL) == 0)
+ return (double)t.tv_sec + t.tv_usec*0.000001;
+#endif /* !GETTIMEOFDAY_NO_TZ */
+ }
+#endif /* !HAVE_GETTIMEOFDAY */
+ {
+#if defined(HAVE_FTIME)
+ struct timeb t;
+ ftime(&t);
+ return (double)t.time + (double)t.millitm * (double)0.001;
+#else /* !HAVE_FTIME */
+ time_t secs;
+ time(&secs);
+ return (double)secs;
+#endif /* !HAVE_FTIME */
+ }
+}
+
+double ll_time_time(void) /* xxx had support for better resolutions */
+{
+ return ll_floattime();
+}
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 17:54:10 2005
@@ -99,7 +99,7 @@
""" % locals())
#prepare exceptions
-for exc in "ZeroDivisionError OverflowError ValueError".split(): #_ZER _OVF _VAL
+for exc in "IOError ZeroDivisionError OverflowError ValueError".split(): #_ZER _OVF _VAL
extfunctions["%%prepare_and_raise_%(exc)s" % locals()] = ((), """
internal fastcc void %%prepare_and_raise_%(exc)s(sbyte* %%msg) {
;XXX %%msg not used right now!
More information about the Pypy-commit
mailing list