diff --git a/src/gen_headers/decaf.h.py b/src/gen_headers/decaf_h.py similarity index 99% rename from src/gen_headers/decaf.h.py rename to src/gen_headers/decaf_h.py index 159545c..702665f 100644 --- a/src/gen_headers/decaf.h.py +++ b/src/gen_headers/decaf_h.py @@ -1,7 +1,6 @@ -from curve_data import curve_data from gen_file import gen_file -gen_file( +decaf_h = gen_file( name = "decaf/%(c_ns)s.h", doc = """@brief A group of prime order p, based on %(iso_to)s.""", code = """ diff --git a/src/gen_headers/decaf.hxx.py b/src/gen_headers/decaf_hxx.py similarity index 99% rename from src/gen_headers/decaf.hxx.py rename to src/gen_headers/decaf_hxx.py index ab78ac5..795bef1 100644 --- a/src/gen_headers/decaf.hxx.py +++ b/src/gen_headers/decaf_hxx.py @@ -1,6 +1,6 @@ from gen_file import gen_file -gen_file( +decaf_hxx = gen_file( name = "decaf/%(c_ns)s.hxx", doc = """ @brief A group of prime order p, C++ wrapper. diff --git a/src/gen_headers/gen_file.py b/src/gen_headers/gen_file.py index 60e8367..61eb53c 100644 --- a/src/gen_headers/gen_file.py +++ b/src/gen_headers/gen_file.py @@ -25,25 +25,25 @@ gend_files = {} def gen_file(name,doc,code,author="Mike Hamburg"): 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 _,_,name_base = ns_name.rpartition("/") 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: - code = dedent("""\n + ns_code = dedent("""\n #ifndef %(header_guard)s #define %(header_guard)s 1 %(code)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 if ns_name == name: diff --git a/src/gen_headers/main.py b/src/gen_headers/main.py new file mode 100644 index 0000000..c96a164 --- /dev/null +++ b/src/gen_headers/main.py @@ -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") + + \ No newline at end of file