Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
OpenGEODE
Commits
216381cb
Commit
216381cb
authored
Aug 28, 2014
by
dbarbera
Browse files
Add optimization passes for generated LLVM IR
parent
82a0fc41
Changes
2
Hide whitespace changes
Inline
Side-by-side
LlvmGenerator.py
View file @
216381cb
...
...
@@ -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):
@
singledispatch
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
@
generate
.
register
(
ogAST
.
Process
)
def
_process
(
process
,
ctx
=
None
):
def
_process
(
process
,
ctx
=
None
,
options
=
None
):
''' Generate the IR for a process '''
process_name
=
str
(
process
.
processName
)
LOG
.
info
(
'Generating LLVM IR code for process '
+
process_name
)
...
...
@@ -463,6 +464,17 @@ def _process(process, ctx=None):
ctx
.
module
.
verify
()
if
options
and
options
.
optimization
:
LOG
.
info
(
'Optimizing generated LLVM IR code for process %s at level %d'
%
(
ctx
.
name
,
options
.
optimization
))
pm
=
passes
.
PassManager
.
new
()
pmb
=
passes
.
PassManagerBuilder
.
new
()
pmb
.
opt_level
=
options
.
optimization
pmb
.
populate
(
pm
)
pm
.
run
(
ctx
.
module
)
with
open
(
ctx
.
name
+
'.ll'
,
'w'
)
as
ll_file
:
ll_file
.
write
(
str
(
ctx
.
module
))
...
...
opengeode.py
View file @
216381cb
...
...
@@ -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
):
G_SYMBOLS
.
add
(
each
)
except
TypeError
as
err
:
except
TypeError
:
LOG
.
error
(
traceback
.
format_exc
())
# 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
:
LOG
.
info
(
'Generating LLVM code'
)
try
:
LlvmGenerator
.
generate
(
process
)
LlvmGenerator
.
generate
(
process
,
options
=
options
)
except
(
TypeError
,
ValueError
,
NameError
)
as
err
:
LOG
.
error
(
str
(
err
))
LOG
.
debug
(
str
(
traceback
.
format_exc
()))
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment