Skip to content

Commit

Permalink
Remove parts of py2llvm that are implemented in the new compiler.
Browse files Browse the repository at this point in the history
whitequark committed Aug 10, 2015
1 parent 62e6f8a commit 200330a
Showing 23 changed files with 169 additions and 2,746 deletions.
6 changes: 0 additions & 6 deletions artiq/py2llvm_old/__init__.py

This file was deleted.

539 changes: 0 additions & 539 deletions artiq/py2llvm_old/ast_body.py

This file was deleted.

321 changes: 0 additions & 321 deletions artiq/py2llvm_old/base_types.py

This file was deleted.

75 changes: 0 additions & 75 deletions artiq/py2llvm_old/infer_types.py

This file was deleted.

51 changes: 0 additions & 51 deletions artiq/py2llvm_old/iterators.py

This file was deleted.

72 changes: 0 additions & 72 deletions artiq/py2llvm_old/lists.py

This file was deleted.

62 changes: 0 additions & 62 deletions artiq/py2llvm_old/module.py

This file was deleted.

169 changes: 169 additions & 0 deletions artiq/py2llvm_old/test/py2llvm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import unittest
from pythonparser import parse, ast
import inspect
from fractions import Fraction
from ctypes import CFUNCTYPE, c_int, c_int32, c_int64, c_double
import struct

import llvmlite_or1k.binding as llvm

from artiq.language.core import int64
from artiq.py2llvm.infer_types import infer_function_types
from artiq.py2llvm import base_types, lists
from artiq.py2llvm.module import Module

def simplify_encode(a, b):
f = Fraction(a, b)
return f.numerator*1000 + f.denominator


def frac_arith_encode(op, a, b, c, d):
if op == 0:
f = Fraction(a, b) - Fraction(c, d)
elif op == 1:
f = Fraction(a, b) + Fraction(c, d)
elif op == 2:
f = Fraction(a, b) * Fraction(c, d)
else:
f = Fraction(a, b) / Fraction(c, d)
return f.numerator*1000 + f.denominator


def frac_arith_encode_int(op, a, b, x):
if op == 0:
f = Fraction(a, b) - x
elif op == 1:
f = Fraction(a, b) + x
elif op == 2:
f = Fraction(a, b) * x
else:
f = Fraction(a, b) / x
return f.numerator*1000 + f.denominator


def frac_arith_encode_int_rev(op, a, b, x):
if op == 0:
f = x - Fraction(a, b)
elif op == 1:
f = x + Fraction(a, b)
elif op == 2:
f = x * Fraction(a, b)
else:
f = x / Fraction(a, b)
return f.numerator*1000 + f.denominator


def frac_arith_float(op, a, b, x):
if op == 0:
return Fraction(a, b) - x
elif op == 1:
return Fraction(a, b) + x
elif op == 2:
return Fraction(a, b) * x
else:
return Fraction(a, b) / x


def frac_arith_float_rev(op, a, b, x):
if op == 0:
return x - Fraction(a, b)
elif op == 1:
return x + Fraction(a, b)
elif op == 2:
return x * Fraction(a, b)
else:
return x / Fraction(a, b)


class CodeGenCase(unittest.TestCase):
def test_frac_simplify(self):
simplify_encode_c = CompiledFunction(
simplify_encode, {"a": base_types.VInt(), "b": base_types.VInt()})
for a in _test_range():
for b in _test_range():
self.assertEqual(
simplify_encode_c(a, b), simplify_encode(a, b))

def _test_frac_arith(self, op):
frac_arith_encode_c = CompiledFunction(
frac_arith_encode, {
"op": base_types.VInt(),
"a": base_types.VInt(), "b": base_types.VInt(),
"c": base_types.VInt(), "d": base_types.VInt()})
for a in _test_range():
for b in _test_range():
for c in _test_range():
for d in _test_range():
self.assertEqual(
frac_arith_encode_c(op, a, b, c, d),
frac_arith_encode(op, a, b, c, d))

def test_frac_add(self):
self._test_frac_arith(0)

def test_frac_sub(self):
self._test_frac_arith(1)

def test_frac_mul(self):
self._test_frac_arith(2)

def test_frac_div(self):
self._test_frac_arith(3)

def _test_frac_arith_int(self, op, rev):
f = frac_arith_encode_int_rev if rev else frac_arith_encode_int
f_c = CompiledFunction(f, {
"op": base_types.VInt(),
"a": base_types.VInt(), "b": base_types.VInt(),
"x": base_types.VInt()})
for a in _test_range():
for b in _test_range():
for x in _test_range():
self.assertEqual(
f_c(op, a, b, x),
f(op, a, b, x))

def test_frac_add_int(self):
self._test_frac_arith_int(0, False)
self._test_frac_arith_int(0, True)

def test_frac_sub_int(self):
self._test_frac_arith_int(1, False)
self._test_frac_arith_int(1, True)

def test_frac_mul_int(self):
self._test_frac_arith_int(2, False)
self._test_frac_arith_int(2, True)

def test_frac_div_int(self):
self._test_frac_arith_int(3, False)
self._test_frac_arith_int(3, True)

def _test_frac_arith_float(self, op, rev):
f = frac_arith_float_rev if rev else frac_arith_float
f_c = CompiledFunction(f, {
"op": base_types.VInt(),
"a": base_types.VInt(), "b": base_types.VInt(),
"x": base_types.VFloat()})
for a in _test_range():
for b in _test_range():
for x in _test_range():
self.assertAlmostEqual(
f_c(op, a, b, x/2),
f(op, a, b, x/2))

def test_frac_add_float(self):
self._test_frac_arith_float(0, False)
self._test_frac_arith_float(0, True)

def test_frac_sub_float(self):
self._test_frac_arith_float(1, False)
self._test_frac_arith_float(1, True)

def test_frac_mul_float(self):
self._test_frac_arith_float(2, False)
self._test_frac_arith_float(2, True)

def test_frac_div_float(self):
self._test_frac_arith_float(3, False)
self._test_frac_arith_float(3, True)
5 changes: 0 additions & 5 deletions artiq/py2llvm_old/tools.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
94 changes: 0 additions & 94 deletions artiq/py2llvm_old/values.py

This file was deleted.

372 changes: 0 additions & 372 deletions artiq/test/py2llvm.py

This file was deleted.

44 changes: 0 additions & 44 deletions artiq/test/transforms.py

This file was deleted.

Empty file removed artiq/transforms/__init__.py
Empty file.
156 changes: 0 additions & 156 deletions artiq/transforms/fold_constants.py

This file was deleted.

59 changes: 0 additions & 59 deletions artiq/transforms/remove_dead_code.py

This file was deleted.

149 changes: 0 additions & 149 deletions artiq/transforms/remove_inter_assigns.py

This file was deleted.

141 changes: 0 additions & 141 deletions artiq/transforms/tools.py

This file was deleted.

600 changes: 0 additions & 600 deletions artiq/transforms/unparse.py

This file was deleted.

0 comments on commit 200330a

Please sign in to comment.