示例#1
0
文件: illink.cs 项目: lcc-816/lcc-816
    static int Main(string[] args)
    {
        string     aname = "a.exe", oname = String.Empty;
        int        i, nf = 0;
        bool       verbose = false;
        TextWriter outfile = Console.Out;
        ArrayList  thunks = new ArrayList(), unmanaged = new ArrayList(),
                   asmargs = new ArrayList(new string[] { "-nologo", "-quiet" });

        for (i = 0; i < args.Length; i++)
        {
            switch (args[i])
            {
            case "-help":
            case "-?":
                usage();
                continue;

            case "-log":                                // -log
                Log.New(Console.Error, argv);
                continue;

            case "-a":                                          // -a name
                if (++i >= args.Length)
                {
                    usage();
                }
                aname = args[i];
                continue;

            case "-debug":                              // -debug
                asmargs.Add(args[i]);
                continue;

            case "-o":                                          // -o file
                if (++i >= args.Length)
                {
                    usage();
                }
                oname = args[i];
                continue;

            case "-u":                                          // -u
                ListUndefined();
                continue;

            case "-v":                                          // -v
                verbose = true;
                continue;

            case "-l":                                          // -l file
                if (++i >= args.Length)
                {
                    usage();
                }
                Library.Search(args[i], verbose, Console.Out);
                continue;

            case "-":
                Pass1("-", Console.In, unmanaged);
                nf++;
                continue;
            }
            if (args[i].StartsWith("-log="))
            {
                Log.New(args[i].Substring(5), argv);
            }
            else if (!args[i].StartsWith("-"))
            {
                try {
                    StreamReader input = new StreamReader(args[i]);
                    Pass1(args[i], input, unmanaged);
                    input.Close();
                    asmargs.Add(args[i]);
                } catch {
                    Warning("can't read {0}", args[i]);
                }
                nf++;
            }
        }
        if (nf == 0)
        {
            Pass1("-", Console.In, unmanaged);
        }
        if (Symbols.refs.Count > 0)
        {
            Warning("undefined symbols:");
            ListUndefined();
        }
        if (oname == String.Empty)
        {
            oname = Path.GetTempFileName();
        }
        if (oname == "-")
        {
            Pass2(aname, unmanaged, Console.Out);
        }
        else
        {
            try {
                TextWriter output = new StreamWriter(oname);
                Pass2(aname, unmanaged, output);
                output.Close();
                asmargs.Add(oname);
            } catch {
                Warning("can't write {0}", oname);
            }
        }
        if (aname != String.Empty)
        {
            asmargs.Add("-out=" + aname);
        }
        ILasm.Run(asmargs, verbose, Console.Out);
        return(0);
    }