示例#1
0
文件: generator.py 项目: qznc/jFirm
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
示例#2
0
文件: gen_ir.py 项目: qznc/libfirm
def preprocess_node(node):
	setdefault(node, "attrs_name", node.name.lower())
	setdefault(node, "block", "block")

	# construct node arguments
	arguments = [ ]
	initattrs = [ ]
	for input in node.ins:
		arguments.append(dict(
				type    = "ir_node *",
				name    = "irn_" + input[0],
				comment = input[1]))

	if node.arity == "variable" or node.arity == "dynamic":
		arguments.append(dict(
				type    = "int",
				name    = "arity",
				comment = "size of additional inputs array"))
		arguments.append(dict(
				type    = "ir_node *const *",
				name    = "in",
				comment = "additional inputs"))

	if not hasattr(node, "mode"):
		arguments.append(dict(
				type    = "ir_mode *",
				name    = "mode",
				comment = "mode of the operations result"))
		node.mode = "mode"

	for attr in node.attrs:
		attr["fqname"] = attr["name"]
		if "init" in attr:
			continue
		arguments.append(attr)

	# dynamic pin state means more constructor arguments
	if is_dynamic_pinned(node):
		if hasattr(node, "pinned_init"):
			initattrs.append(dict(
				fqname = "exc.pin_state",
				init   = node.pinned_init
			))
		else:
			node.constructor_args.append(
				dict(
					name    = "pin_state",
					type    = "op_pin_state",
					comment = "pinned state",
				)
			)
			initattrs.append(dict(
				fqname = "exc.pin_state",
				init   = "pin_state"
			))
	if hasattr(node, "throws_init"):
		initattrs.append(dict(
			fqname = "exc.throws_exception",
			init   = node.throws_init
		))

	for arg in node.constructor_args:
		arguments.append(prepare_attr(arg))

	node.arguments = arguments
	node.initattrs = initattrs
示例#3
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