Skip to content

Commit

Permalink
tools/golang: Initial commit of generated code
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Rosbrook <rosbrookn@ainfosec.com>
  • Loading branch information
Nick Rosbrook committed Sep 23, 2019
1 parent 9985dde commit aa3e517
Show file tree
Hide file tree
Showing 3 changed files with 4,614 additions and 4 deletions.
21 changes: 17 additions & 4 deletions tools/golang/gengotypes.py
Expand Up @@ -35,7 +35,7 @@
# after a helper func definition.
helper_extras = []

def xenlight_golang_generate_types(path = None, types = None):
def xenlight_golang_generate_types(path = None, types = None, comment = None):
"""
Generate a .go file (xenlight_types.go by default)
that contains a Go type for each type in types.
Expand All @@ -44,6 +44,8 @@ def xenlight_golang_generate_types(path = None, types = None):
path = 'xenlight_types.go'

with open(path, 'w') as f:
if comment is not None:
f.write(comment)
f.write('package xenlight\n')

for ty in types:
Expand Down Expand Up @@ -217,7 +219,7 @@ def go_fmt(path):
""" Call go fmt on the given path. """
os.system('go fmt {}'.format(path))

def xenlight_golang_generate_helpers(path = None, types = None):
def xenlight_golang_generate_helpers(path = None, types = None, comment = None):
"""
Generate a .go file (xenlight_helpers.go by default)
that contains helper functions for marshaling between
Expand All @@ -227,6 +229,8 @@ def xenlight_golang_generate_helpers(path = None, types = None):
path = 'xenlight_helpers.go'

with open(path, 'w') as f:
if comment is not None:
f.write(comment)
f.write('package xenlight\n')
f.write('import (\n"unsafe"\n"errors"\n"fmt"\n)\n')

Expand Down Expand Up @@ -686,7 +690,16 @@ def xenlight_golang_array_to_C(ty = None, dispose_fn = ''):
name = b.typename
builtin_type_names[name] = xenlight_golang_fmt_name(name)

header_comment="""// DO NOT EDIT.
//
// This file is generated by:
// {}
//
""".format(' '.join(sys.argv))

xenlight_golang_generate_types(types=types,
path='xenlight/xenlight_types.go')
path='xenlight/xenlight_types.go',
comment=header_comment)
xenlight_golang_generate_helpers(types=types,
path='xenlight/xenlight_helpers.go')
path='xenlight/xenlight_helpers.go',
comment=header_comment)

0 comments on commit aa3e517

Please sign in to comment.