Пример #1
0
def run_all(infile, outfile):
	"Transforms the source infile to a binary outfile."
	Err.count = 0
	z = Ophis.Frontend.parse(infile)
	env = Ophis.Environment.Environment()

	
	m = Ophis.Passes.ExpandMacros()
	i = Ophis.Passes.InitLabels()
	l_basic = Ophis.Passes.UpdateLabels()
	l = Ophis.Passes.FixPoint("label update", [l_basic], lambda: l_basic.changed == 0)
	c = Ophis.Passes.Collapse()
	a = Ophis.Passes.Assembler()

	passes = []
	passes.append(Ophis.Passes.DefineMacros())
	passes.append(Ophis.Passes.FixPoint("macro expansion", [m], lambda: m.changed == 0))
	passes.append(Ophis.Passes.FixPoint("label initialization", [i], lambda: i.changed == 0))
	passes.extend([Ophis.Passes.CircularityCheck(), Ophis.Passes.CheckExprs(), Ophis.Passes.EasyModes()])
	passes.append(Ophis.Passes.FixPoint("instruction selection", [l, c], lambda: c.collapsed == 0))
	passes.extend([Ophis.Passes.NormalizeModes(), Ophis.Passes.UpdateLabels(), a])

	for p in passes: p.go(z, env)

	if Err.count == 0:
		try:
			output = file(outfile, 'wb')
			output.write("".join(map(chr, a.output)))
		except IOError:
			print "Could not write to "+outfile
	else:
		Err.report()
Пример #2
0
def run_all(infile, outfile):
	"Transforms the source infile to a binary outfile."
	Err.count = 0
	z = Ophis.Frontend.parse(infile)
	env = Ophis.Environment.Environment()

	m = Ophis.Passes.ExpandMacros()
	i = Ophis.Passes.InitLabels()
	l_basic = Ophis.Passes.UpdateLabels()
	l = Ophis.Passes.FixPoint("label update", [l_basic], lambda: l_basic.changed == 0)
	c = Ophis.Passes.Collapse()
	a = Ophis.Passes.Assembler()

	passes = []
	passes.append(Ophis.Passes.DefineMacros())
	passes.append(Ophis.Passes.FixPoint("macro expansion", [m], lambda: m.changed == 0))
	passes.append(Ophis.Passes.FixPoint("label initialization", [i], lambda: i.changed == 0))
	passes.extend([Ophis.Passes.CircularityCheck(), Ophis.Passes.CheckExprs(), Ophis.Passes.EasyModes()])
	passes.append(Ophis.Passes.FixPoint("instruction selection", [l, c], lambda: c.collapsed == 0))
	passes.extend([Ophis.Passes.NormalizeModes(), Ophis.Passes.UpdateLabels(), a])

	for p in passes: p.go(z, env)

	if Err.count == 0:
		try:
			output = file(outfile, 'wb')
			output.write("".join(map(chr, a.output)))
		except IOError:
			print "Could not write to "+outfile
	else:
		Err.report()
Пример #3
0
def run_all():
    """Transforms the source infiles to a binary outfile.

    Returns a shell-style exit code: 1 if there were errors, 0 if there
    were no errors.

    """
    Err.count = 0
    z = Ophis.Frontend.parse(Ophis.CmdLine.infiles)
    env = Ophis.Environment.Environment()

    m = Ophis.Passes.ExpandMacros()
    i = Ophis.Passes.InitLabels()
    l_basic = Ophis.Passes.UpdateLabels()
    l = Ophis.Passes.FixPoint("label update", [l_basic],
                              lambda: not l_basic.changed)

    # The instruction selector is a bunch of fixpoints, and which
    # passes run depends on the command line options a bit.
    c_basic = Ophis.Passes.Collapse()
    c = Ophis.Passes.FixPoint("instruction selection 1", [l, c_basic],
                              lambda: not c_basic.changed)

    if Ophis.CmdLine.enable_branch_extend:
        b = Ophis.Passes.ExtendBranches()
        instruction_select = Ophis.Passes.FixPoint("instruction selection 2",
                                                   [c, b],
                                                   lambda: not b.changed)
    else:
        instruction_select = c
    a = Ophis.Passes.Assembler()

    passes = []
    passes.append(Ophis.Passes.DefineMacros())
    passes.append(Ophis.Passes.FixPoint("macro expansion", [m],
                                        lambda: not m.changed))
    passes.append(Ophis.Passes.FixPoint("label initialization", [i],
                                        lambda: not i.changed))
    passes.extend([Ophis.Passes.CircularityCheck(),
                   Ophis.Passes.CheckExprs(),
                   Ophis.Passes.EasyModes()])
    passes.append(instruction_select)
    passes.extend([Ophis.Passes.NormalizeModes(),
                   Ophis.Passes.UpdateLabels(),
                   a])

    for p in passes:
        p.go(z, env)

    if Err.count == 0:
        try:
            outfile = Ophis.CmdLine.outfile
            if outfile == '-':
                output = sys.stdout
                if sys.platform == "win32":
                    # We can't dump our binary in text mode; that would be
                    # disastrous. So, we'll do some platform-specific
                    # things here to force our stdout to binary mode.
                    import msvcrt
                    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
            elif outfile is None:
                output = file('ophis.bin', 'wb')
            else:
                output = file(outfile, 'wb')
            output.write("".join(map(chr, a.output)))
            output.flush()
            if outfile != '-':
                output.close()
            return 0
        except IOError:
            print>>sys.stderr, "Could not write to " + outfile
            return 1
    else:
        Err.report()
        return 1
Пример #4
0
def run_all():
    """Transforms the source infiles to a binary outfile.

    Returns a shell-style exit code: 1 if there were errors, 0 if there
    were no errors.

    """
    Err.count = 0
    z = Ophis.Frontend.parse(Ophis.CmdLine.infiles)
    env = Ophis.Environment.Environment()

    m = Ophis.Passes.ExpandMacros()
    i = Ophis.Passes.InitLabels()
    l_basic = Ophis.Passes.UpdateLabels()
    l = Ophis.Passes.FixPoint("label update", [l_basic],
                              lambda: not l_basic.changed)

    # The instruction selector is a bunch of fixpoints, and which
    # passes run depends on the command line options a bit.
    c_basic = Ophis.Passes.Collapse()
    c = Ophis.Passes.FixPoint("instruction selection 1", [l, c_basic],
                              lambda: not c_basic.changed)

    if Ophis.CmdLine.enable_branch_extend:
        b = Ophis.Passes.ExtendBranches()
        instruction_select = Ophis.Passes.FixPoint("instruction selection 2",
                                                   [c, b],
                                                   lambda: not b.changed)
    else:
        instruction_select = c
    a = Ophis.Passes.Assembler()

    passes = []
    passes.append(Ophis.Passes.DefineMacros())
    passes.append(
        Ophis.Passes.FixPoint("macro expansion", [m], lambda: not m.changed))
    passes.append(
        Ophis.Passes.FixPoint("label initialization", [i],
                              lambda: not i.changed))
    passes.extend([
        Ophis.Passes.CircularityCheck(),
        Ophis.Passes.CheckExprs(),
        Ophis.Passes.EasyModes()
    ])
    passes.append(instruction_select)
    passes.extend(
        [Ophis.Passes.NormalizeModes(),
         Ophis.Passes.UpdateLabels(), a])

    for p in passes:
        p.go(z, env)

    if Err.count == 0:
        try:
            outfile = Ophis.CmdLine.outfile
            if outfile == '-':
                output = sys.stdout
                if sys.platform == "win32":
                    # We can't dump our binary in text mode; that would be
                    # disastrous. So, we'll do some platform-specific
                    # things here to force our stdout to binary mode.
                    import msvcrt
                    msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
            elif outfile is None:
                output = file('ophis.bin', 'wb')
            else:
                output = file(outfile, 'wb')
            output.write("".join(map(chr, a.output)))
            output.flush()
            if outfile != '-':
                output.close()
            return 0
        except IOError:
            print >> sys.stderr, "Could not write to " + outfile
            return 1
    else:
        Err.report()
        return 1