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
459c0c85
Commit
459c0c85
authored
Nov 14, 2014
by
Matthias Braun
Browse files
gen_ir: Rework Input/Output specification
parent
ed9f2032
Changes
7
Hide whitespace changes
Inline
Side-by-side
scripts/gen_ir.py
View file @
459c0c85
...
...
@@ -83,7 +83,7 @@ def format_insdecl(node):
res
+=
"
\n\t
ir_node **r_in= ALLOCAN(ir_node*, r_arity);"
i
=
0
for
input
in
node
.
ins
:
res
+=
"
\n\t
r_in["
+
repr
(
i
)
+
"] = irn_"
+
input
[
0
]
+
";"
res
+=
"
\n\t
r_in["
+
repr
(
i
)
+
"] = irn_"
+
input
.
name
+
";"
i
+=
1
res
+=
"
\n\t
memcpy(&r_in["
+
repr
(
insarity
)
+
"], in, sizeof(ir_node *) * arity);
\n\t
"
elif
arity
==
0
:
...
...
@@ -92,7 +92,7 @@ def format_insdecl(node):
res
=
"ir_node *in["
+
repr
(
arity
)
+
"];"
i
=
0
for
input
in
node
.
ins
:
res
+=
"
\n\t
in["
+
repr
(
i
)
+
"] = irn_"
+
input
[
0
]
+
";"
res
+=
"
\n\t
in["
+
repr
(
i
)
+
"] = irn_"
+
input
.
name
+
";"
i
+=
1
return
res
...
...
@@ -230,8 +230,8 @@ def preprocess_node(node):
initattrs
=
[
]
for
input
in
node
.
ins
:
arguments
.
append
(
Attribute
(
"irn_"
+
input
[
0
]
,
type
=
"ir_node *"
,
comment
=
input
[
1
]
))
Attribute
(
"irn_"
+
input
.
name
,
type
=
"ir_node *"
,
comment
=
input
.
name
))
if
node
.
arity
==
"variable"
or
node
.
arity
==
"dynamic"
:
arguments
.
append
(
...
...
scripts/spec_util.py
View file @
459c0c85
...
...
@@ -36,7 +36,7 @@ def is_fragile(node):
def
inout_contains
(
l
,
name
):
for
entry
in
l
:
if
entry
[
0
]
==
name
:
if
entry
.
name
==
name
:
return
True
return
False
...
...
@@ -81,6 +81,21 @@ def setdefault(node, attr, val):
if
not
hasattr
(
node
,
attr
):
setattr
(
node
,
attr
,
val
)
class
Operand
(
object
):
pass
def
Input
(
name
,
comment
=
None
):
op
=
Operand
()
op
.
name
=
name
op
.
comment
=
comment
return
op
def
Output
(
name
,
comment
=
None
):
op
=
Operand
()
op
.
name
=
name
op
.
comment
=
comment
return
op
def
setnodedefaults
(
node
):
setldefault
(
node
,
"name"
,
node
.
__name__
)
if
isAbstract
(
node
):
...
...
@@ -102,6 +117,40 @@ def setnodedefaults(node):
node
.
block
=
"get_irg_start_block(irg)"
setdefault
(
node
,
"usesGraph"
,
node
.
block
!=
None
)
# As a shortcut you can specify inputs either as a list of strings or
# as a list of (name, comment) tuples. Normalize it to Input objects
new_ins
=
[]
for
i
in
node
.
ins
:
if
isinstance
(
i
,
basestring
):
i
=
Input
(
i
)
elif
isinstance
(
i
,
tuple
):
i
=
Input
(
name
=
i
[
0
],
comment
=
i
[
1
])
new_ins
.
append
(
i
)
node
.
ins
=
new_ins
if
hasattr
(
node
,
"outs"
):
new_outs
=
[]
for
o
in
node
.
outs
:
if
isinstance
(
o
,
basestring
):
o
=
Output
(
o
)
elif
isinstance
(
o
,
tuple
):
o
=
Output
(
name
=
o
[
0
],
comment
=
o
[
1
])
new_outs
.
append
(
o
)
node
.
outs
=
new_outs
def
collect_ops
(
moduledict
):
return
[
node
for
node
in
moduledict
.
values
()
if
isOp
(
node
)
]
def
setdefaults
(
nodes
):
for
node
in
nodes
:
setnodedefaults
(
node
)
return
nodes
def
verify_spec
(
spec
):
if
len
(
spec
.
nodes
)
==
0
:
sys
.
stderr
.
write
(
"Warning: No nodes found in spec
\n
"
)
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
=
[]
...
...
scripts/templates/gen_irdump.c.inl
View file @
459c0c85
...
...
@@ -3,7 +3,7 @@
{%- if node.outs %}
static const pns_lookup_t {{node.name}}_lut[] = {
{%- for out in node.outs %}
{ pn_{{node.name}}_{{out
[0]
}}, "{{out
[0]
}}" },
{ pn_{{node.name}}_{{out
.name
}}, "{{out
.name
}}" },
{%- endfor %}
};
{% endif -%}
...
...
scripts/templates/gen_irio.c.inl
View file @
459c0c85
...
...
@@ -6,7 +6,7 @@ static ir_node *read_{{node.name}}(read_env_t *env)
ir_node *block = read_node_ref(env);
{%- endif %}
{%- for input in node.ins %}
ir_node *irn_{{input
[0]
}} = read_node_ref(env);
ir_node *irn_{{input
.name
}} = read_node_ref(env);
{%- endfor %}
{%- if not hasattr(node, "mode") %}
ir_mode *mode = read_mode_ref(env);
...
...
@@ -72,7 +72,7 @@ static void write_{{node.name}}(write_env_t *env, const ir_node *node)
write_node_ref(env, get_nodes_block(node));
{%- endif %}
{%- for input in node.ins %}
write_node_ref(env, get_{{node.name}}_{{input
[0]
}}(node));
write_node_ref(env, get_{{node.name}}_{{input
.name
}}(node));
{%- endfor %}
{%- if not hasattr(node, "mode") %}
write_mode_ref(env, get_irn_mode(node));
...
...
scripts/templates/gen_irnode.c
View file @
459c0c85
...
...
@@ -132,14 +132,14 @@ ir_node *new_{{node.name}}(
{
%
endif
%
}
{
%-
for
input
in
node
.
ins
%
}
ir_node
*
(
get_
{{
node
.
name
}}
_
{{
input
[
0
]
}})(
const
ir_node
*
node
)
ir_node
*
(
get_
{{
node
.
name
}}
_
{{
input
.
name
}})(
const
ir_node
*
node
)
{
return
get_
{{
node
.
name
}}
_
{{
input
[
0
]
}}(
node
);
return
get_
{{
node
.
name
}}
_
{{
input
.
name
}}(
node
);
}
void
(
set_
{{
node
.
name
}}
_
{{
input
[
0
]
}})(
ir_node
*
node
,
ir_node
*
{{
input
[
0
]
|
escape_keywords
}})
void
(
set_
{{
node
.
name
}}
_
{{
input
.
name
}})(
ir_node
*
node
,
ir_node
*
{{
input
.
name
|
escape_keywords
}})
{
set_
{{
node
.
name
}}
_
{{
input
[
0
]
}}
_
(
node
,
{{
input
[
0
]
|
escape_keywords
}});
set_
{{
node
.
name
}}
_
{{
input
.
name
}}
_
(
node
,
{{
input
.
name
|
escape_keywords
}});
}
{
%
endfor
%
}
...
...
scripts/templates/gen_irnode.h
View file @
459c0c85
...
...
@@ -17,8 +17,8 @@
#define set_{{node.name}}_{{attr.name}}(node, {{attr.name}}) set_{{node.name}}_{{attr.name}}_(node, {{attr.name}})
{
%-
endfor
-%
}
{
%-
for
input
in
node
.
ins
%
}
#define get_{{node.name}}_{{input
[0]
}}(node) get_{{node.name}}_{{input
[0]
}}_(node)
#define set_{{node.name}}_{{input
[0]
}}(node, {{input
[0]
|escape_keywords}}) set_{{node.name}}_{{input
[0]
}}_(node, {{input
[0]
|escape_keywords}})
#define get_{{node.name}}_{{input
.name
}}(node) get_{{node.name}}_{{input
.name
}}_(node)
#define set_{{node.name}}_{{input
.name
}}(node, {{input
.name
|escape_keywords}}) set_{{node.name}}_{{input
.name
}}_(node, {{input
.name
|escape_keywords}})
{
%-
endfor
-%
}
{
%-
if
node
.
input_name
%
}
#define get_{{node.name}}_n_{{node.input_name}}s(node) get_{{node.name}}_n_{{node.input_name}}s_(node)
...
...
@@ -42,16 +42,16 @@ static inline int is_{{node.name}}_(const ir_node *node)
}
{
%-
for
input
in
node
.
ins
%
}
static
inline
ir_node
*
get_
{{
node
.
name
}}
_
{{
input
[
0
]
}}
_
(
const
ir_node
*
node
)
static
inline
ir_node
*
get_
{{
node
.
name
}}
_
{{
input
.
name
}}
_
(
const
ir_node
*
node
)
{
assert
(
is_
{{
node
.
name
}}(
node
));
return
get_irn_n
(
node
,
n_
{{
node
.
name
}}
_
{{
input
[
0
]
}});
return
get_irn_n
(
node
,
n_
{{
node
.
name
}}
_
{{
input
.
name
}});
}
static
inline
void
set_
{{
node
.
name
}}
_
{{
input
[
0
]
}}
_
(
ir_node
*
node
,
ir_node
*
{{
input
[
0
]
|
escape_keywords
}})
static
inline
void
set_
{{
node
.
name
}}
_
{{
input
.
name
}}
_
(
ir_node
*
node
,
ir_node
*
{{
input
.
name
|
escape_keywords
}})
{
assert
(
is_
{{
node
.
name
}}(
node
));
set_irn_n
(
node
,
n_
{{
node
.
name
}}
_
{{
input
[
0
]
}},
{{
input
[
0
]
|
escape_keywords
}});
set_irn_n
(
node
,
n_
{{
node
.
name
}}
_
{{
input
.
name
}},
{{
input
.
name
|
escape_keywords
}});
}
{
%
endfor
%
}
...
...
scripts/templates/nodes.h
View file @
459c0c85
...
...
@@ -44,9 +44,9 @@ int is_{{spec.name}}_node(const ir_node *node);
*/
typedef
enum
{
{
%-
for
input
in
node
.
ins
%
}
n_
{{
node
.
name
}}
_
{{
input
[
0
]}},
n_
{{
node
.
name
}}
_
{{
input
.
name
}},
/**< {{input.comment}} */
{
%-
endfor
%
}
n_
{{
node
.
name
}}
_max
=
n_
{{
node
.
name
}}
_
{{
node
.
ins
[
-
1
]
[
0
]
}}
n_
{{
node
.
name
}}
_max
=
n_
{{
node
.
name
}}
_
{{
node
.
ins
[
-
1
]
.
name
}}
}
n_
{{
node
.
name
}};
{
%
endif
-%
}
{
%
if
node
.
outs
%
}
...
...
@@ -55,9 +55,9 @@ typedef enum {
*/
typedef
enum
{
{
%
for
out
in
node
.
outs
-%
}
pn_
{{
node
.
name
}}
_
{{
out
[
0
]
}},
/**< {{out
[1]
}} */
pn_
{{
node
.
name
}}
_
{{
out
.
name
}},
/**< {{out
.comment
}} */
{
%
endfor
-%
}
pn_
{{
node
.
name
}}
_max
=
pn_
{{
node
.
name
}}
_
{{
node
.
outs
[
-
1
]
[
0
]
}}
pn_
{{
node
.
name
}}
_max
=
pn_
{{
node
.
name
}}
_
{{
node
.
outs
[
-
1
]
.
name
}}
}
pn_
{{
node
.
name
}};
{
%
endif
%
}
{
%-
if
not
node
.
noconstructor
%
}
...
...
@@ -117,10 +117,10 @@ typedef enum {
{{
FIRM_API
}}
int
is_
{{
node
.
name
}}(
const
ir_node
*
node
);
{
%
for
input
in
node
.
ins
-%
}
/** Returns {{input
[0]
}} input of {{node.name|a_an}} node. */
{{
FIRM_API
}}
ir_node
*
get_
{{
node
.
name
}}
_
{{
input
[
0
]
}}(
const
ir_node
*
node
);
/** Sets {{input
[0]
}} input of {{node.name|a_an}} node. */
{{
FIRM_API
}}
void
set_
{{
node
.
name
}}
_
{{
input
[
0
]
}}(
ir_node
*
node
,
ir_node
*
{{
input
[
0
]
|
escape_keywords
}});
/** Returns {{input
.name
}} input of {{node.name|a_an}} node. */
{{
FIRM_API
}}
ir_node
*
get_
{{
node
.
name
}}
_
{{
input
.
name
}}(
const
ir_node
*
node
);
/** Sets {{input
.name
}} input of {{node.name|a_an}} node. */
{{
FIRM_API
}}
void
set_
{{
node
.
name
}}
_
{{
input
.
name
}}(
ir_node
*
node
,
ir_node
*
{{
input
.
name
|
escape_keywords
}});
{
%
endfor
-%
}
{
%-
if
node
.
input_name
-%
}
/** Get the number of {{node.name}} {{node.input_name}}s. */
...
...
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