Commit 216381cb authored by dbarbera's avatar dbarbera
Browse files

Add optimization passes for generated LLVM IR

parent 82a0fc41
......@@ -23,6 +23,7 @@ from singledispatch import singledispatch
from llvm import core as lc
from llvm import ee as le
from llvm import passes
import ogAST
import Helper
......@@ -377,14 +378,14 @@ class CompileError(Exception):
def generate(ast, ctx=None):
def generate(ast, ctx=None, options=None):
''' Generate the IR for an AST node '''
raise CompileError('Unsupported AST construct "%s"' % ast.__class__.__name__)
# Processing of the AST
def _process(process, ctx=None):
def _process(process, ctx=None, options=None):
''' Generate the IR for a process '''
process_name = str(process.processName)'Generating LLVM IR code for process ' + process_name)
......@@ -463,6 +464,17 @@ def _process(process, ctx=None):
if options and options.optimization:'Optimizing generated LLVM IR code for process %s at level %d'
% (, options.optimization))
pm =
pmb =
pmb.opt_level = options.optimization
with open( + '.ll', 'w') as ll_file:
......@@ -24,7 +24,6 @@ import re
import code
import pprint
from functools import partial
from collections import deque
from itertools import chain
# Added to please py2exe - NOQA makes flake8 ignore the following lines:
......@@ -410,6 +409,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
def render_everything(self, ast):
''' Render a process and its children scenes, recursively '''
already_created = []
def recursive_render(content, dest_scene):
''' Process the rendering in scenes and nested scenes '''
if isinstance(content, ogAST.Process):
......@@ -420,7 +420,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
# Render top-level items and their children:
for each in Renderer.render(content, dest_scene):
except TypeError as err:
except TypeError:
# Render nested scenes, recursively:
......@@ -978,7 +978,6 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
pprint.pprint(selection.__dict__, None, 2, 1)
code.interact('type your command:', local=locals())
def create_subscene(self, context):
''' Create a new SDL scene, e.g. for nested symbols '''
subscene = SDL_Scene(context=context)
......@@ -986,7 +985,6 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
subscene.parent_scene = self
return subscene
def place_symbol(self, item_type, parent, pos=None):
''' Draw a symbol on the scene '''
item = item_type()
......@@ -1803,6 +1801,9 @@ def parse_args():
help='Generate Ada code for the .pr file')
parser.add_argument('--llvm', dest='llvm', action='store_true',
help='Generate LLVM IR code for the .pr file (experimental)')
parser.add_argument("-O", dest="optimization", metavar="LEVEL", type=int,
action="store", choices=[0, 1, 2, 3], default=0,
help="Optimize generated LLVM IR code")
parser.add_argument('--png', dest='png', action='store_true',
help='Generate a PNG file for the process')
parser.add_argument('--pdf', dest='pdf', action='store_true',
......@@ -1883,7 +1884,7 @@ def generate(process, options):
if options.llvm:'Generating LLVM code')
LlvmGenerator.generate(process, options=options)
except (TypeError, ValueError, NameError) as err:
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