Commit 39c1e1ea authored by Matthias Braun's avatar Matthias Braun
Browse files

generate is_XXX and getters/setters for abstract node bases

= is_entconst(), is_typeconst, get_entconst_entity() and
get_typeconst_type()
parent 5ea4510c
......@@ -351,10 +351,6 @@ FIRM_API ir_entity *get_Call_callee(const ir_node *call);
/** Returns a human readable string for the ir_builtin_kind. */
FIRM_API const char *get_builtin_kind_name(ir_builtin_kind kind);
/** Tests whether node is a binary operation (opcode arity is #oparity_binary)
* @returns 1 if @p node is an binary operation, 0 otherwise
*/
FIRM_API int is_binop(const ir_node *node);
/** Returns left operand of binary operation @p node. */
FIRM_API ir_node *get_binop_left(const ir_node *node);
/** Sets left operand of binary operation @p node. */
......
......@@ -696,32 +696,27 @@ ir_entity *get_Call_callee(const ir_node *node)
return entity;
}
int (is_binop)(const ir_node *node)
{
return is_binop_(node);
}
ir_node *get_binop_left(const ir_node *node)
{
assert(node->op->opar == oparity_binary);
assert(is_binop(node));
return get_irn_n(node, node->op->op_index);
}
void set_binop_left(ir_node *node, ir_node *left)
{
assert(node->op->opar == oparity_binary);
assert(is_binop(node));
set_irn_n(node, node->op->op_index, left);
}
ir_node *get_binop_right(const ir_node *node)
{
assert(node->op->opar == oparity_binary);
assert(is_binop(node));
return get_irn_n(node, node->op->op_index + 1);
}
void set_binop_right(ir_node *node, ir_node *right)
{
assert(node->op->opar == oparity_binary);
assert(is_binop(node));
set_irn_n(node, node->op->op_index + 1, right);
}
......
......@@ -2,15 +2,19 @@
# Copyright (C) 2012 Karlsruhe Institute of Technology.
import re
def format_arguments(string, voidwhenempty = False):
def format_filtjoin(string, joinstring):
args = re.split('\s*\n\s*', string)
if args[0] == '':
args = args[1:]
if len(args) > 0 and args[-1] == '':
args = args[:-1]
if len(args) == 0 and voidwhenempty:
return joinstring.join(args)
def format_arguments(string, voidwhenempty = False):
joined = format_filtjoin(string, ", ")
if joined == "" and voidwhenempty:
return "void"
return ", ".join(args)
return joined
def filter_hasnot(list, flag):
return filter(lambda x: not hasattr(x, flag) or not getattr(x, flag), list)
......
......@@ -5,7 +5,7 @@
import sys
from jinja2 import Environment, Template, FileSystemLoader
from spec_util import is_dynamic_pinned, isAbstract, setdefault, load_spec, Attribute
from filters import format_arguments, filter_has, filter_hasnot
from filters import format_arguments, format_filtjoin, filter_has, filter_hasnot
def format_parameterlist(parameterlist):
return "\n".join(parameterlist)
......@@ -190,6 +190,7 @@ env.filters['blockparameterhelp'] = format_blockparameterhelp
env.filters['curblock'] = format_curblock
env.filters['escape_keywords'] = format_escape_keywords
env.filters['flags'] = format_flags
env.filters['filtjoin'] = format_filtjoin
env.filters['has'] = filter_has
env.filters['hasnot'] = filter_hasnot
env.filters['insdecl'] = format_insdecl
......@@ -260,29 +261,31 @@ def preprocess_node(node):
def prepare_nodes(nodes):
real_nodes = []
abstract_nodes = []
for node in nodes:
if isAbstract(node):
continue
real_nodes.append(node)
abstract_nodes.append(node)
else:
real_nodes.append(node)
for node in real_nodes:
preprocess_node(node)
return real_nodes
return (real_nodes, abstract_nodes)
def main(argv):
if len(argv) < 3:
print("usage: %s specfile templatefile" % argv[0])
sys.exit(1)
specfile = argv[1]
spec = load_spec(specfile)
nodes = spec.nodes
real_nodes = prepare_nodes(nodes)
specfile = argv[1]
spec = load_spec(specfile)
(nodes, abstract_nodes) = prepare_nodes(spec.nodes)
templatefile = argv[2]
env.globals['nodes'] = real_nodes
env.globals['nodes'] = nodes
env.globals['abstract_nodes'] = abstract_nodes
env.globals['spec'] = spec
env.globals['len'] = len
env.globals['hasattr'] = hasattr
......
......@@ -38,7 +38,7 @@ class EntConst(object):
@abstract
@op
class TypeConst:
class TypeConst(object):
"""A symbolic constant that represents an aspect of a type"""
name = "typeconst"
flags = [ "constlike", "start_block" ]
......
......@@ -135,21 +135,6 @@ ir_node *new_{{node.name}}(
}
{% endif %}
int (is_{{node.name}})(const ir_node *node)
{
return is_{{node.name}}_(node);
}
{% for attr in node.attrs|hasnot("noprop") %}
{{attr.type}} (get_{{node.name}}_{{attr.name}})(const ir_node *node)
{
return get_{{node.name}}_{{attr.name}}_(node);
}
void (set_{{node.name}}_{{attr.name}})(ir_node *node, {{attr.type}} {{attr.name}})
{
set_{{node.name}}_{{attr.name}}_(node, {{attr.name}});
}
{% endfor -%}
{%- for input in node.ins %}
ir_node *(get_{{node.name}}_{{input[0]}})(const ir_node *node)
{
......@@ -191,6 +176,26 @@ ir_op *get_op_{{node.name}}(void)
}
{% endfor %}
{%- for node in nodes+abstract_nodes %}
int (is_{{node.name}})(const ir_node *node)
{
return is_{{node.name}}_(node);
}
{%- for attr in node.attrs|hasnot("noprop") %}
{{attr.type}} (get_{{node.name}}_{{attr.name}})(const ir_node *node)
{
return get_{{node.name}}_{{attr.name}}_(node);
}
void (set_{{node.name}}_{{attr.name}})(ir_node *node, {{attr.type}} {{attr.name}})
{
set_{{node.name}}_{{attr.name}}_(node, {{attr.name}});
}
{%- endfor -%}
{% endfor %}
void {{spec.name}}_init_opcodes(void)
{
{%- if spec.external %}
......
......@@ -27,35 +27,19 @@
#define get_{{node.name}}_{{node.input_name}}_arr(node) get_{{node.name}}_{{node.input_name}}_arr_(node)
{%- endif %}
{% endfor %}
{% for node in abstract_nodes %}
{%- for attr in node.attrs|hasnot("noprop") %}
#define is_{{node.name}}(node) is_{{node.name}}_(node)
#define get_{{node.name}}_{{attr.name}}(node) get_{{node.name}}_{{attr.name}}_(node)
#define set_{{node.name}}_{{attr.name}}(node, {{attr.name}}) set_{{node.name}}_{{attr.name}}_(node, {{attr.name}})
{%- endfor -%}
{% endfor %}
{%- for node in nodes %}
static inline int is_{{node.name}}_(const ir_node *node)
{
return get_irn_op(node) == op_{{node.name}};
}
{% for attr in node.attrs|hasnot("noprop") %}
static inline {{attr.type}} get_{{node.name}}_{{attr.name}}_(const ir_node *node)
{
assert(is_{{node.name}}(node));
{% if spec.external -%}
{{node.attr_struct}} const *const attr = ({{node.attr_struct}} const*)get_irn_generic_attr_const(node);
return attr->{{attr.name}};
{%- else -%}
return node->attr.{{node.attrs_name}}.{{attr.name}};
{%- endif %}
}
static inline void set_{{node.name}}_{{attr.name}}_(ir_node *node, {{attr.type}} {{attr.name}})
{
assert(is_{{node.name}}(node));
{% if spec.external -%}
{{node.attr_struct}} *attr = ({{node.attr_struct}}*)get_irn_generic_attr(node);
attr->{{attr.name}} = {{attr.name}};
{%- else -%}
node->attr.{{node.attrs_name}}.{{attr.name}} = {{attr.name}};
{% endif %}
}
{% endfor -%}
{%- for input in node.ins %}
static inline ir_node *get_{{node.name}}_{{input[0]}}_(const ir_node *node)
......@@ -98,6 +82,48 @@ static inline ir_node **get_{{node.name}}_{{node.input_name}}_arr_(ir_node *node
{% endif -%}
{% endfor -%}
{%- for node in abstract_nodes %}
{%- if node.name != "binop" %}
static inline int is_{{node.name}}_(const ir_node *node)
{
return {% filter filtjoin(' || ') -%}
{% for subc in node.__subclasses__() %}
is_{{subc.name}}(node)
{% endfor %}
{%- endfilter %};
}
{% endif -%}
{% endfor -%}
{% for node in nodes+abstract_nodes %}
{%- for attr in node.attrs|hasnot("noprop") %}
static inline {{attr.type}} get_{{node.name}}_{{attr.name}}_(const ir_node *node)
{
assert(is_{{node.name}}(node));
{% if spec.external -%}
{{node.attr_struct}} const *const attr = ({{node.attr_struct}} const*)get_irn_generic_attr_const(node);
return attr->{{attr.name}};
{%- else -%}
return node->attr.{{node.attrs_name}}.{{attr.name}};
{%- endif %}
}
static inline void set_{{node.name}}_{{attr.name}}_(ir_node *node, {{attr.type}} {{attr.name}})
{
assert(is_{{node.name}}(node));
{% if spec.external -%}
{{node.attr_struct}} *attr = ({{node.attr_struct}}*)get_irn_generic_attr(node);
attr->{{attr.name}} = {{attr.name}};
{%- else -%}
node->attr.{{node.attrs_name}}.{{attr.name}} = {{attr.name}};
{%- endif %}
}
{% endfor -%}
{% endfor -%}
void {{spec.name}}_init_opcodes(void);
void {{spec.name}}_finish_opcodes(void);
......
......@@ -150,6 +150,22 @@ ir_node **get_{{node.name}}_{{node.input_name}}_arr(ir_node *node);
{% endfor -%}
{% for node in abstract_nodes -%}
/**
* Test if node is a {{node.name}}
* @returns 1 if the node is a {{node.name}} node, 0 otherwise
*/
{{FIRM_API}} int is_{{node.name}}(const ir_node *node);
{%- for attr in node.attrs|hasnot("noprop") %}
/** Returns {{attr.name}} attribute of {{node.name|a_an}} node. */
{{FIRM_API}} {{attr.type}} get_{{node.name}}_{{attr.name}}(const ir_node *node);
/** Sets {{attr.name}} attribute of {{node.name|a_an}} node. */
{{FIRM_API}} void set_{{node.name}}_{{attr.name}}(ir_node *node, {{attr.type}} {{attr.name}});
{% endfor -%}
{% endfor %}
/** @} */
#endif
Markdown is supported
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