Commit 597a09ae authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Add stg option in the command line

parent c879aa1e
......@@ -52,7 +52,7 @@ def generate(*args, **kwargs):
# Processing of the AST
@generate.register(ogAST.Process)
def _process(process, simu=False, **kwargs):
def _process(process, simu=False, stgfile='ada_source.st', **kwargs):
''' Generate the code for a complete process (AST Top level) '''
if not stg:
return
......@@ -60,7 +60,7 @@ def _process(process, simu=False, **kwargs):
# initialize string template
# will find the group in the file, and then retrieve the functions
# with group.getInstanceOf
group = stringtemplate3.StringTemplateGroup(file=open("ada_source.st"))
group = stringtemplate3.StringTemplateGroup(file=open(stgfile))
template = group.getInstanceOf("process")
template['name'] = process.processName
print str(template)
......
......@@ -1958,8 +1958,13 @@ def parse_args():
parser = argparse.ArgumentParser(version=__version__)
parser.add_argument('-g', '--debug', action='store_true', default=False,
help='Display debug information')
parser.add_argument('-l', '--shared', action='store_true', default=False,
help='Generate code to build a shared library (with callbacks)')
parser.add_argument('--shared', action='store_true', default=False,
help='Generate getters/setters to access internal state')
parser.add_argument('--dll', action='store_true', default=False,
help='Generate callback hooks when compiling as shared object')
parser.add_argument('--stg', type=str, default='ada_source.st',
metavar='file',
help='Generate code using a custom String Template file')
parser.add_argument('--check', action='store_true', dest='check',
help='Check a .pr file for syntax and semantics')
parser.add_argument('--toAda', dest='toAda', action='store_true',
......@@ -2044,11 +2049,10 @@ def parse(files):
def generate(process, options):
''' Generate code '''
if options.toAda or options.shared:
if options.toAda or options.shared or options.dll:
LOG.info('Generating Ada code')
try:
AdaGenerator.generate(process, simu=options.shared)
StgBackend.generate(process, simu=options.shared) # TEMP
AdaGenerator.generate(process, simu=options.dll)
except (TypeError, ValueError, NameError) as err:
LOG.error(str(err))
LOG.debug(str(traceback.format_exc()))
......@@ -2063,6 +2067,11 @@ def generate(process, options):
LOG.debug(str(traceback.format_exc()))
LOG.error('LLVM IR generation failed')
if options.stg:
LOG.info('Using backend file {}'.format(options.stg))
StgBackend.generate(process, simu=options.shared, stgfile=options.stg)
def export(ast, options):
''' Export process '''
......@@ -2130,7 +2139,8 @@ def cli(options):
if options.png or options.pdf or options.svg:
export(ast, options)
if options.toAda or options.llvm or options.shared:
if any((options.toAda, options.llvm, options.shared,
options.stg, options.dll)):
if not errors:
generate(ast.processes[0], options)
else:
......@@ -2196,7 +2206,8 @@ def opengeode():
LOG.debug('Starting OpenGEODE version ' + __version__)
if any((options.check, options.toAda, options.png, options.pdf,
options.svg, options.llvm, options.shared)):
options.svg, options.llvm, options.shared, options.stg,
options.dll)):
return cli(options)
else:
return gui(options)
......
Supports Markdown
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