@@ -1,7 +1,6 @@ | |||||
from curve_data import curve_data | |||||
from gen_file import gen_file | from gen_file import gen_file | ||||
gen_file( | |||||
decaf_h = gen_file( | |||||
name = "decaf/%(c_ns)s.h", | name = "decaf/%(c_ns)s.h", | ||||
doc = """@brief A group of prime order p, based on %(iso_to)s.""", | doc = """@brief A group of prime order p, based on %(iso_to)s.""", | ||||
code = """ | code = """ |
@@ -1,6 +1,6 @@ | |||||
from gen_file import gen_file | from gen_file import gen_file | ||||
gen_file( | |||||
decaf_hxx = gen_file( | |||||
name = "decaf/%(c_ns)s.hxx", | name = "decaf/%(c_ns)s.hxx", | ||||
doc = """ | doc = """ | ||||
@brief A group of prime order p, C++ wrapper. | @brief A group of prime order p, C++ wrapper. |
@@ -25,25 +25,25 @@ gend_files = {} | |||||
def gen_file(name,doc,code,author="Mike Hamburg"): | def gen_file(name,doc,code,author="Mike Hamburg"): | ||||
is_header = name.endswith(".h") or name.endswith(".hxx") or name.endswith(".h++") | is_header = name.endswith(".h") or name.endswith(".hxx") or name.endswith(".h++") | ||||
for curve,data in [("Ed448",curve_data["Ed448"])]: #curve_data.iteritems(): | |||||
for curve,data in curve_data.iteritems(): | |||||
ns_name = name % data | ns_name = name % data | ||||
_,_,name_base = ns_name.rpartition("/") | _,_,name_base = ns_name.rpartition("/") | ||||
header_guard = "__" + name_base.replace(".","_").upper() + "__" | header_guard = "__" + name_base.replace(".","_").upper() + "__" | ||||
doc = dedent(doc).strip().rstrip() | |||||
doc = redoc(ns_name, doc % data, author) | |||||
code = code % data | |||||
ret = doc + "\n" | |||||
ns_doc = dedent(doc).strip().rstrip() | |||||
ns_doc = redoc(ns_name, ns_doc % data, author) | |||||
ns_code = code % data | |||||
ret = ns_doc + "\n" | |||||
if is_header: | if is_header: | ||||
code = dedent("""\n | |||||
ns_code = dedent("""\n | |||||
#ifndef %(header_guard)s | #ifndef %(header_guard)s | ||||
#define %(header_guard)s 1 | #define %(header_guard)s 1 | ||||
%(code)s | %(code)s | ||||
#endif /* %(header_guard)s */ | #endif /* %(header_guard)s */ | ||||
""") % { "header_guard" : header_guard, "code": code } | |||||
ret += code[1:-1] | |||||
""") % { "header_guard" : header_guard, "code": ns_code } | |||||
ret += ns_code[1:-1] | |||||
gend_files[ns_name] = ret | gend_files[ns_name] = ret | ||||
if ns_name == name: | if ns_name == name: | ||||
@@ -0,0 +1,24 @@ | |||||
from gen_file import gend_files | |||||
import os | |||||
import argparse | |||||
parser = argparse.ArgumentParser(description='Generate Decaf headers and other such files.') | |||||
parser.add_argument('--hpre', required = True, help = "Where to put the header files") | |||||
parser.add_argument('--cpre', required = True, help = "Where to put the C/C++ implementation files") | |||||
args = parser.parse_args() | |||||
prefixes = { "h" : args.hpre, "hxx" : args.hpre, "c" : args.cpre } | |||||
from decaf_hxx import decaf_hxx | |||||
from decaf_h import decaf_h | |||||
for name,code in gend_files.iteritems(): | |||||
_,_,name_suffix = name.partition(".") | |||||
prefix = prefixes[name_suffix] | |||||
if not os.path.exists(os.path.dirname(prefix + "/" + name)): | |||||
os.makedirs(os.path.dirname(prefix + "/" + name)) | |||||
with open(prefix + "/" + name,"w") as f: | |||||
f.write(code + "\n") | |||||