Commit d3b47cde authored by Adam P. Goucher's avatar Adam P. Goucher

Major changes

parent 30ebf2b4
family = 4
bitplanes = 1
mantissa = {0, 1}
family = 0
bitplanes = 1
def mantissa(rulestring):
if 'b0' in rulestring:
return {0, 2, 4, 6, 8}
else:
return {0, 1, 2, 3, 4, 5, 6, 7, 8}
thing = 'test'
import os
import re
import sys
def get_script_path():
return os.path.dirname(os.path.realpath(sys.argv[0]))
def main():
os.chdir(get_script_path())
import genera
try:
os.makedirs('avxlife/lifelogic')
except OSError as e:
print(repr(e))
os.chdir('avxlife/lifelogic')
rules = list(sys.argv)[1:]
if (len(rules) == 0):
print("Usage:")
print("python rule2asm.py b3s23 b38s23 g4b2s345")
exit(1)
if (len(rules) > 8):
print("lifelib supports a maximum of 8 different rules")
exit(1)
# Determine rule families from genera:
families = [genera.rule_property(r, 'family') for r in rules]
# Obtain integers describing valid mantissae:
def mant2int(m):
if hasattr(m, '__iter__'):
m = sum([(1 << x) for x in xrange(9) if x in m])
return (m | 1)
mantissae = [mant2int(genera.rule_property(r, 'mantissa')) for r in rules]
# Write the main entry point:
with open('iterators_all.h', 'w') as f:
f.write('#pragma once\n')
f.write('#include <string>\n')
#include the generated code for each rule:
for rulestring in rules:
f.write('#include "iterators_%s.h"\n' % rulestring)
f.write('namespace apg {\n\n')
# Function to convert rulestring to rule integer:
f.write(' int rule2int(std::string rule) {\n')
for (i, r) in enumerate(rules):
f.write(' if (rule == "%s") { return %d; }\n' % (r, i))
f.write(' return -1;\n')
f.write(' }\n\n')
# Function to obtain family code from rule integer:
f.write(' int uli_get_family(int rule) {\n')
f.write(' switch (rule) {\n')
for x in enumerate(families):
f.write(' case %d : return %d;\n' % x)
f.write(' }\n')
f.write(' return 0;\n')
f.write(' }\n\n')
# Function to obtain mantissae from rule integer:
f.write(' uint64_t uli_valid_mantissa(int rule) {\n')
f.write(' switch (rule) {\n')
for x in enumerate(mantissae):
f.write(' case %d : return %d;\n' % x)
f.write(' }\n')
f.write(' return 3;\n')
f.write(' }\n\n')
'''
for hist in xrange(3):
write_all_iterators(f, hist, rules)
'''
f.write('}\n')
if __name__ == '__main__':
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment