Ejemplo n.º 1
0
def prepare_nodes(nodes):
	real_nodes = []
	for node in nodes:
		if isAbstract(node):
			continue
		real_nodes.append(node)

	return real_nodes
Ejemplo n.º 2
0
def main(argv):
	if len(argv) < 3:
		print "usage: %s specname(ignored) destdirectory" % argv[0]
		sys.exit(1)

	specfile     = argv[1]
	templatefile = argv[2]

	spec  = load_spec(specfile)
	nodes = spec.nodes
	real_nodes = []
	for node in nodes:
		if isAbstract(node):
			continue
		preprocess_node(node)
		real_nodes.append(node)

	env.globals['nodes']   = real_nodes
	env.globals['spec']    = spec
	env.globals['warning'] = "/* Warning: automatically generated file */"
	env.globals['hasattr'] = hasattr

	template = env.get_template(templatefile)
	sys.stdout.write(template.render().encode("utf-8"))
Ejemplo n.º 3
0
def format_ifabstract(string, node):
	if isAbstract(node):
		return string
	return ""
Ejemplo n.º 4
0
def preprocess_node(node):
	if not isAbstract(node):
		setdefault(node, "java_add", "")
		setldefault(node, "parent", node.__base__)
		verify_node(node)
	else:
		setldefault(node, "parent", ir_spec.Op)
		ir_spec.Op.classname = "Node"
	setldefault(node, "attrs", [])
	setldefault(node, "constructor_args", [])
	node.classname = format_camel_case_big(node.name)

	# dynamic pin node?
	if is_dynamic_pinned(node) and not hasattr(node, "pinned_init"):
		node.constructor_args.append(dict(
			name = "pin_state",
			type = "op_pin_state"
		))

	# transform outs into name, comment tuples if not in this format already
	if hasattr(node, "outs"):
		for i in range(0,len(node.outs)):
			out = node.outs[i]
			if not isinstance(out, tuple):
				out = (out, "")
			node.outs[i] = out

	# construct node arguments
	if not isAbstract(node):
		arguments = [ ]
		for input in node.ins:
			arguments.append(dict(
				name = input,
				type = "Node"
			))
		if node.arity == "variable" or node.arity == "dynamic":
			arguments.append(dict(
				name = "ins",
				type = "Node[]"
			))
		if not hasattr(node, "mode"):
			arguments.append(dict(
				name = "mode",
				type = "firm.Mode"
			))
		for attr in node.attrs:
			prepare_attr(attr)
			if "init" in attr:
				continue
			
			arguments.append(dict(
				name = attr["java_name"],
				type = attr["java_type"],
				to_wrapper = attr["to_wrapper"]
			))
		for arg in node.constructor_args:
			old_type = arg["type"]
			(java_type,wrap_type,to_wrapper,from_wrapper) = get_java_type(old_type)

			arguments.append(dict(
				name = arg["name"],
				type = java_type,
				to_wrapper = to_wrapper
			))

		for arg in arguments:
			arg['name'] = format_filter_keywords(arg['name'])
			
		node.arguments = arguments
Ejemplo n.º 5
0
def preprocess_node(node):
    if not isAbstract(node):
        setdefault(node, "java_add", "")
        if hasattr(node, "__base__"):
            setldefault(node, "parent", node.__base__)
        else:
            setldefault(node, "parent", Node)
        verify_node(node)
    else:
        setldefault(node, "parent", Node)
    setdefault(node, "attrs", [])
    setldefault(node, "constructor_args", [])
    node.classname = format_camel_case_big(node.name)

    # dynamic pin node?
    if is_dynamic_pinned(node) and not hasattr(node, "pinned_init"):
        node.constructor_args.append(
            Attribute("pin_state", type="op_pin_state"))

    # transform ins into name, comment tuples if not in this format already
    if hasattr(node, "ins"):
        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

    # transform outs into name, comment tuples if not in this format already
    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

    # construct node arguments
    if not isAbstract(node):
        arguments = []
        for input in node.ins:
            arguments.append(
                Attribute(name=input.name, type="Node", comment=input.comment))
        if node.arity == "variable" or node.arity == "dynamic":
            arguments.append(Attribute("ins", type="Node[]"))
        if not hasattr(node, "mode"):
            arguments.append(Attribute("mode", type="firm.Mode"))
        for attr in node.attrs:
            prepare_attr(attr)
            if attr.init is not None:
                continue

            arguments.append(
                JavaArgument(name=attr.java_name,
                             type=attr.java_type,
                             to_wrapper=attr.to_wrapper,
                             comment=attr.comment))
        for arg in node.constructor_args:
            old_type = arg.type
            (java_type, wrap_type, to_wrapper,
             from_wrapper) = get_java_type(old_type)

            arguments.append(
                JavaArgument(name=arg.name,
                             type=java_type,
                             to_wrapper=to_wrapper,
                             comment=arg.comment))

        for arg in arguments:
            arg.name = format_filter_keywords(arg.name)

        node.arguments = arguments