Browse Source

generator is almost ready to drop in

master
Michael Hamburg 9 years ago
parent
commit
47d4b080e9
4 changed files with 34 additions and 11 deletions
  1. +1
    -2
      src/gen_headers/decaf_h.py
  2. +1
    -1
      src/gen_headers/decaf_hxx.py
  3. +8
    -8
      src/gen_headers/gen_file.py
  4. +24
    -0
      src/gen_headers/main.py

src/gen_headers/decaf.h.py → src/gen_headers/decaf_h.py View File

@@ -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 = """

src/gen_headers/decaf.hxx.py → src/gen_headers/decaf_hxx.py View File

@@ -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.

+ 8
- 8
src/gen_headers/gen_file.py View File

@@ -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:


+ 24
- 0
src/gen_headers/main.py View File

@@ -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")

Loading…
Cancel
Save