Пример #1
0
    private void gnuStdOutHandler(ref outputEntry[] errors, ref outputEntry[] warnings, string filename, string line)
    {
        //strip out the filename
        if (!line.StartsWith(filename))
        {
            return;
        }
        line = line.Replace(filename, "");

        //get the line number and column number
        string[] split  = line.Split(' ');
        string   header = split[0];

        string[] headerSplit = header.Split(':');
        int      lineNum     = 0;
        int      columnNum   = 0;

        int.TryParse(headerSplit[1], out lineNum);
        if (header.Length >= 3)
        {
            int.TryParse(headerSplit[2], out columnNum);
        }

        //get the type of message
        string messageType = split[1].Replace(":", "").ToLower();

        //read the message
        string message = "";

        for (int c = 2; c < split.Length; c++)
        {
            message += split[c] + (c == split.Length - 1 ? "" : " ");
        }

        //add the error/warning entry
        if (messageType == "error" || messageType == "warning" || messageType == "fatal")
        {
            outputEntry e = new outputEntry {
                line    = lineNum,
                column  = columnNum,
                message = message
            };

            if (messageType == "error" ||
                messageType == "fatal")
            {
                Helpers.AddObject(ref errors, e);
            }
            if (messageType == "warning")
            {
                Helpers.AddObject(ref warnings, e);
            }
        }
    }
Пример #2
0
    private void link(string[] files, string outputFile, StandardCompileOutput <Project> output, StandardOutputCallback stdOut)
    {
        //perform the link
        outputEntry[] errors   = new outputEntry[0];
        outputEntry[] warnings = new outputEntry[0];
        link(ref errors, ref warnings, files, outputFile, stdOut);

        //add the errors and warnings to the output object
        for (int c = 0; c < errors.Length; c++)
        {
            output.addError(null, 0, 0, errors[c].message);
        }
        for (int c = 0; c < warnings.Length; c++)
        {
            output.addWarning(null, 0, 0, warnings[c].message);
        }
    }
Пример #3
0
    private void compileAssembly(bool linkable, string outputFile, StandardCompileOutput <Project> output, fileObj[] files, StandardOutputCallback stdOut)
    {
        if (File.Exists(outputFile))
        {
            File.Delete(outputFile);
        }

        //collapse all the files into one file to compile
        string collapsed = collapseFiles(files, ".asm");

        //compile
        outputEntry[] errors   = new outputEntry[0];
        outputEntry[] warnings = new outputEntry[0];
        compileAssembly(linkable, ref errors, ref warnings, collapsed, outputFile, stdOut);
        processCompileResults(files, output, errors, warnings);

        //clean up
        File.Delete(collapsed);
    }
Пример #4
0
    private void resolveFile(outputEntry outputEntry, fileObj[] files, out ProjectFile file, out int line)
    {
        long lineTotal = 0;

        file = null;
        line = -1;
        for (int c = 0; c < files.Length; c++)
        {
            fileObj entry = files[c];

            int relativeLine = (int)(outputEntry.line - lineTotal);
            if (relativeLine <= entry.LineLength)
            {
                line = relativeLine;
                file = entry.ProjectFile;
                return;
            }
            lineTotal += entry.LineLength;
        }
    }
Пример #5
0
    private void compileC(string outputFile, StandardCompileOutput <Project> output, fileObj[] codeFiles, fileObj[] headerFiles, StandardOutputCallback stdOut)
    {
        if (File.Exists(outputFile))
        {
            File.Delete(outputFile);
        }

        //collapse the code files and header files into one array but add the header files first.
        fileObj[] files = new fileObj[0];
        Helpers.AddObject(ref files, headerFiles);
        Helpers.AddObject(ref files, codeFiles);

        //flatten the files down to a single file
        string collapsed = collapseFiles(files, ".c");

        //perform the compile
        outputEntry[] errors   = new outputEntry[0];
        outputEntry[] warnings = new outputEntry[0];
        compileC(ref errors, ref warnings, collapsed, outputFile, stdOut);
        processCompileResults(codeFiles, output, errors, warnings);

        //clean up
        File.Delete(collapsed);
    }
Пример #6
0
    private void resolveFile(outputEntry outputEntry, fileObj[] files, out ProjectFile file, out int line)
    {
        long lineTotal = 0;
        file = null;
        line = -1;
        for (int c = 0; c < files.Length; c++) {
            fileObj entry = files[c];

            int relativeLine = (int)(outputEntry.line - lineTotal);
            if (relativeLine <= entry.LineLength) {
                line = relativeLine;
                file = entry.ProjectFile;
                return;
            }
            lineTotal += entry.LineLength;
        }
    }
Пример #7
0
 private void processCompileResults(fileObj[] files, StandardCompileOutput<Project> output, outputEntry[] errors, outputEntry[] warnings)
 {
     for (int c = 0; c < errors.Length; c++) {
         ProjectFile file;
         int line;
         resolveFile(errors[c], files, out file, out line);
         output.addError(
             file,
             line,
             errors[c].column,
             errors[c].message);
     }
     for (int c = 0; c < warnings.Length; c++) {
         ProjectFile file;
         int line;
         resolveFile(warnings[c], files, out file, out line);
         output.addWarning(
             file,
             line,
             warnings[c].column,
             warnings[c].message);
     }
 }
Пример #8
0
    private void link(ref outputEntry[] errors, ref outputEntry[] warnings, string[] files, string outputFile, StandardOutputCallback stdOut)
    {
        //define the filename for the linker
        string linker = new FileInfo("compilers/linker/ld.exe").FullName;
        //linker = "C:\\cygwin\\bin\\ld.exe";

        //define the arguments to pass to the linker
        string args = "-m elf_i386 -o \"" + outputFile + "\" "; //-m elf_i386
        for (int c = 0; c < files.Length; c++) {
            args += "\"" + files[c] + "\" ";
        }

        //invoke the linker
        outputEntry[] e = errors;
        outputEntry[] w = warnings;
        Helpers.SpawnProcess(
            linker,
            null,
            args,
            true,
            delegate(string line) {
                stdOut(line);
                gnuStdOutHandler(ref e, ref w, "/linker/ld", line);
            });

        //clean up
        errors = e;
        warnings = w;
    }
Пример #9
0
    private void link(string[] files, string outputFile, StandardCompileOutput<Project> output, StandardOutputCallback stdOut)
    {
        //perform the link
        outputEntry[] errors = new outputEntry[0];
        outputEntry[] warnings = new outputEntry[0];
        link(ref errors, ref warnings, files, outputFile, stdOut);

        //add the errors and warnings to the output object
        for (int c = 0; c < errors.Length; c++) {
            output.addError(null, 0, 0, errors[c].message);
        }
        for (int c = 0; c < warnings.Length; c++) {
            output.addWarning(null, 0, 0, warnings[c].message);
        }
    }
Пример #10
0
    private void gnuStdOutHandler(ref outputEntry[] errors, ref outputEntry[] warnings, string filename, string line)
    {
        //strip out the filename
        if (!line.StartsWith(filename)) { return; }
        line = line.Replace(filename, "");

        //get the line number and column number
        string[] split = line.Split(' ');
        string header = split[0];
        string[] headerSplit = header.Split(':');
        int lineNum = 0;
        int columnNum = 0;
        int.TryParse(headerSplit[1], out lineNum);
        if (header.Length >= 3) { int.TryParse(headerSplit[2], out columnNum); }

        //get the type of message
        string messageType = split[1].Replace(":", "").ToLower();

        //read the message
        string message = "";
        for (int c = 2; c < split.Length; c++) {
            message += split[c] + (c == split.Length - 1 ? "" : " ");
        }

        //add the error/warning entry
        if (messageType == "error" || messageType == "warning" || messageType == "fatal") {
            outputEntry e = new outputEntry {
                line = lineNum,
                column = columnNum,
                message = message
            };

            if (messageType == "error" ||
                messageType == "fatal") {
                Helpers.AddObject(ref errors, e);
            }
            if (messageType == "warning") {
                Helpers.AddObject(ref warnings, e);
            }
        }
    }
Пример #11
0
    private void compileC(ref outputEntry[] errors, ref outputEntry[] warnings, string filename, string outputFile, StandardOutputCallback stdOut)
    {
        //get the filename for the GCC compiler
        string gcc = new FileInfo("compilers/gcc/bin/gcc.exe").FullName;

        //invoke the GCC compiler
        outputEntry[] e = errors;
        outputEntry[] w = warnings;
        Helpers.SpawnProcess(
            gcc,
            null,
            "-c \"" + filename + "\" -o \"" + outputFile + "\" " +
            "-Wall -Wextra -nostdlib -nostartfiles -nodefaultlibs -m32",
            true,
            delegate(string line) {
                stdOut(line);
                gnuStdOutHandler(ref e, ref w, filename, line);
            });

        //clean up
        errors = e;
        warnings = w;
    }
Пример #12
0
    private void compileC(string outputFile, StandardCompileOutput<Project> output, fileObj[] codeFiles, fileObj[] headerFiles, StandardOutputCallback stdOut)
    {
        if (File.Exists(outputFile)) { File.Delete(outputFile); }

        //collapse the code files and header files into one array but add the header files first.
        fileObj[] files = new fileObj[0];
        Helpers.AddObject(ref files, headerFiles);
        Helpers.AddObject(ref files, codeFiles);

        //flatten the files down to a single file
        string collapsed = collapseFiles(files, ".c");

        //perform the compile
        outputEntry[] errors = new outputEntry[0];
        outputEntry[] warnings = new outputEntry[0];
        compileC(ref errors, ref warnings, collapsed, outputFile, stdOut);
        processCompileResults(codeFiles, output, errors, warnings);

        //clean up
        File.Delete(collapsed);
    }
Пример #13
0
    private void compileAssembly(bool linkable, ref outputEntry[] errors, ref outputEntry[] warnings, string filename, string outputFile, StandardOutputCallback stdOut)
    {
        //define the filename for the NASM compiler
        string nasmCompiler = new FileInfo("compilers/nasm/nasm.exe").FullName;

        //call nasm to compile the ASM code.
        outputEntry[] e = errors;
        outputEntry[] w = warnings;
        Helpers.SpawnProcess(
            nasmCompiler,
            new FileInfo(filename).Directory.FullName,
            (linkable ? "-f elf32 " : "") +
            "\"" + filename + "\" " +
            "-o \"" + outputFile + "\"",
            true,
            delegate(string line) {
                stdOut(line);
                gnuStdOutHandler(
                    ref e,
                    ref w,
                    filename,
                    line);
            });

        //clean up
        errors = e;
        warnings = w;
    }
Пример #14
0
    private void compileAssembly(bool linkable, string outputFile, StandardCompileOutput<Project> output, fileObj[] files, StandardOutputCallback stdOut)
    {
        if (File.Exists(outputFile)) { File.Delete(outputFile); }

        //collapse all the files into one file to compile
        string collapsed = collapseFiles(files, ".asm");

        //compile
        outputEntry[] errors = new outputEntry[0];
        outputEntry[] warnings = new outputEntry[0];
        compileAssembly(linkable, ref errors, ref warnings, collapsed, outputFile, stdOut);
        processCompileResults(files, output, errors, warnings);

        //clean up
        File.Delete(collapsed);
    }