-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecutableCreator.cs
More file actions
52 lines (47 loc) · 1.22 KB
/
ExecutableCreator.cs
File metadata and controls
52 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
namespace Compiler
{
class ExecutableCreator
{
private string _outputPath;
// Constructor
// outputFile: resulting executable
public ExecutableCreator(string outputPath)
{
_outputPath = outputPath;
}
// Methods compile assembly code to executable file
// input: assembly file path or assembly code string
// output: none
public void FromString(string assembly)
{
File.WriteAllText("temp.asm", assembly);
FromFile("temp.asm");
}
public void FromFile(string filePath)
{
Process nasm = Process.Start("nasm", "-fwin32 -o temp.obj " + filePath);
nasm.WaitForExit();
if (nasm.ExitCode != 0)
throw new ImplementationError("Error in assembly!");
Process gcc = Process.Start("gcc", "temp.obj -o " + _outputPath);
gcc.WaitForExit();
if (gcc.ExitCode != 0)
throw new ImplementationError("Error in linker!");
}
// Method runs resulting executable
// input: none
// return: none
public void Run()
{
Process program = Process.Start(_outputPath);
program.WaitForExit();
if (program.ExitCode != 0)
throw new ImplementationError("Error in executable!");
}
}
}