Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Zwinkau
libfirm
Commits
a8479789
Commit
a8479789
authored
Jan 14, 2015
by
Matthias Braun
Browse files
gen_ir: delegate loading of filters/exports to specfile
This way we are independent of the type of specfile.
parent
ce4907ea
Changes
3
Hide whitespace changes
Inline
Side-by-side
scripts/gen_ir.py
View file @
a8479789
...
...
@@ -4,10 +4,9 @@
# Copyright (C) 2012 Karlsruhe Institute of Technology.
import
sys
import
argparse
from
jinja2
import
Environment
,
Template
from
irops
import
prepare_nodes
,
load_spec
from
jinja2
import
Environment
import
filters
import
i
rops
import
i
mp
import
jinjautil
def
main
(
argv
):
...
...
@@ -23,17 +22,14 @@ def main(argv):
help
=
'jinja2 template file'
)
config
=
parser
.
parse_args
()
spec
=
load_spec
(
config
.
specfile
)
(
nodes
,
abstract_nodes
)
=
prepare_nodes
(
spec
.
nodes
)
# Load
specfile
imp
.
load_source
(
'spec'
,
config
.
specfile
)
loader
=
jinjautil
.
SimpleLoader
()
env
=
Environment
(
loader
=
loader
,
keep_trailing_newline
=
True
)
env
.
globals
.
update
(
jinjautil
.
exports
)
env
.
filters
.
update
(
jinjautil
.
filters
)
env
.
globals
[
'nodes'
]
=
nodes
env
.
globals
[
'abstract_nodes'
]
=
abstract_nodes
env
.
globals
[
'spec'
]
=
spec
loader
.
includedirs
+=
config
.
includedirs
template
=
env
.
get_template
(
config
.
templatefile
)
result
=
template
.
render
()
...
...
scripts/ir_spec.py
View file @
a8479789
...
...
@@ -4,7 +4,8 @@
# Firm node specifications
# The comments are in (standard python) restructured text format and are used
# to generate documentation.
from
irops
import
abstract
,
op
,
Attribute
from
irops
import
abstract
,
op
,
Attribute
,
prepare_nodes
from
jinjautil
import
export
name
=
"ir"
...
...
@@ -860,3 +861,8 @@ class Unknown(object):
users of the original unknown node!"""
pinned
=
"yes"
flags
=
[
"start_block"
,
"constlike"
,
"dump_noblock"
]
(
nodes
,
abstract_nodes
)
=
prepare_nodes
(
globals
())
export
(
nodes
,
"nodes"
)
export
(
abstract_nodes
,
"abstract_nodes"
)
export
(
globals
(),
"spec"
)
scripts/irops.py
View file @
a8479789
...
...
@@ -433,7 +433,18 @@ def _preprocess_node(node):
node
.
arguments
=
arguments
node
.
initattrs
=
initattrs
def
prepare_nodes
(
nodes
):
def
prepare_nodes
(
namespace
):
nodes
=
[]
for
x
in
namespace
.
values
():
if
not
is_op
(
x
):
continue
setnodedefaults
(
x
)
verify_node
(
x
)
nodes
.
append
(
x
)
nodes
.
sort
(
key
=
lambda
x
:
x
.
name
)
if
len
(
nodes
)
==
0
:
print
(
"Warning: No nodes found in spec file '%s'"
%
filename
)
real_nodes
=
[]
abstract_nodes
=
[]
for
node
in
nodes
:
...
...
@@ -468,22 +479,5 @@ def verify_spec(spec):
if
not
hasattr
(
spec
,
"name"
):
sys
.
stderr
.
write
(
"Warning: No name specified in node spec
\n
"
)
def
load_spec
(
filename
):
module
=
imp
.
load_source
(
'spec'
,
filename
)
nodes
=
[]
for
x
in
module
.
__dict__
.
values
():
if
not
is_op
(
x
):
continue
setnodedefaults
(
x
)
verify_node
(
x
)
nodes
.
append
(
x
)
nodes
.
sort
(
key
=
lambda
x
:
x
.
name
)
module
.
nodes
=
nodes
if
len
(
nodes
)
==
0
:
print
(
"Warning: No nodes found in spec file '%s'"
%
filename
)
if
not
hasattr
(
module
,
"name"
):
print
(
"Warning: No name specified in file '%s'"
%
filename
)
return
module
export
(
is_dynamic_pinned
)
export
(
is_abstract
)
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