| 1 |
import py |
| 2 |
import sys |
| 3 |
from rpython.tool.version import rpythonroot |
| 4 |
from rpython.rtyper.lltypesystem import lltype, rffi |
| 5 |
from rpython.translator.tool.cbuild import ExternalCompilationInfo |
| 6 |
from rpython.rtyper.tool import rffi_platform as platform |
| 7 |
from rpython.translator.platform import platform as trans_plaform |
| 8 |
|
| 9 |
ROOT = py.path.local(rpythonroot).join('rpython', 'rlib', 'rutf8') |
| 10 |
SRC = ROOT.join('src') |
| 11 |
|
| 12 |
if sys.platform.startswith('linux'): |
| 13 |
_libs = ['dl'] |
| 14 |
else: |
| 15 |
_libs = [] |
| 16 |
|
| 17 |
|
| 18 |
IDXTAB = lltype.ForwardReference() |
| 19 |
IDXTAB.become(rffi.CStruct("fu8_idxtab", |
| 20 |
('character_step', rffi.INT), |
| 21 |
('byte_positions', rffi.SIZE_TP), |
| 22 |
('bytepos_table_length', rffi.SIZE_T))) |
| 23 |
IDXTABP = lltype.Ptr(IDXTAB) |
| 24 |
|
| 25 |
def setup(): |
| 26 |
compile_extra = ['-DRPYTHON_LL2CTYPES', '-DALLOW_SURROGATES=0', '-fPIC'] |
| 27 |
eci_kwds = dict( |
| 28 |
include_dirs = [SRC], |
| 29 |
includes = ['utf8.h'], |
| 30 |
libraries = _libs, |
| 31 |
compile_extra = compile_extra) |
| 32 |
|
| 33 |
compile_extra.append('-msse4.1') |
| 34 |
ofile_eci = ExternalCompilationInfo(**eci_kwds) |
| 35 |
sse4_o, = trans_plaform._compile_o_files([SRC.join('utf8-sse4.c')], ofile_eci) |
| 36 |
compile_extra.pop() |
| 37 |
compile_extra.append('-mavx2') |
| 38 |
ofile_eci = ExternalCompilationInfo(**eci_kwds) |
| 39 |
avx_o, = trans_plaform._compile_o_files([SRC.join('utf8-avx.c')], ofile_eci) |
| 40 |
del ofile_eci |
| 41 |
|
| 42 |
eci_kwds['separate_module_files'] = [SRC.join('utf8.c')] |
| 43 |
eci_kwds['link_files'] = [sse4_o.strpath, avx_o.strpath] |
| 44 |
eci = ExternalCompilationInfo(**eci_kwds) |
| 45 |
platform.verify_eci(eci) |
| 46 |
count_utf8_codepoints = rffi.llexternal("fu8_count_utf8_codepoints", |
| 47 |
[rffi.CCHARP, rffi.SSIZE_T], |
| 48 |
rffi.SSIZE_T, compilation_info=eci, |
| 49 |
_nowrapper=True) |
| 50 |
index2byteposition = rffi.llexternal("fu8_idx2bytepos", |
| 51 |
[rffi.SIZE_T, rffi.CCHARP, rffi.SIZE_T, IDXTABP], |
| 52 |
rffi.SSIZE_T, compilation_info=eci, |
| 53 |
_nowrapper=True) |
| 54 |
|
| 55 |
return CInterface(locals()) |
| 56 |
|
| 57 |
|
| 58 |
class CInterface(object): |
| 59 |
def __init__(self, namespace): |
| 60 |
for k, v in namespace.iteritems(): |
| 61 |
setattr(self, k, v) |
| 62 |
|
| 63 |
def _freeze_(self): |
| 64 |
return True |
| 65 |
|
| 66 |
|