summaryrefslogtreecommitdiff
path: root/Orchestrator/Program.cs
blob: c5d7538f177fee87ee20a2d25e98c781ad26fa2b (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
namespace Orchestrator;

using CommandLine;
using Q1.Assembler;
using Q1.Compiler;
using Q1.Emulator;

class Program
{
    static void Main(string[] args)
    {
        Parser p = new(with =>
        {
            with.CaseInsensitiveEnumValues = true;
        });

        p.ParseArguments<Options>(args).WithParsed(Main);
    }

    private static void Main(Options options)
    {
        string compiledFile = Path.ChangeExtension(options.InputFile, "asm");
        string assembledFile = Path.ChangeExtension(options.InputFile, "q1");

        if (!options.NoCompile)
            Q1.Compiler.Program.Main(
                new CompilerOptions
                {
                    CommentCompilationMode = options.CommentCompilationMode,
                    InputFile = options.InputFile,
                    OutputFile = compiledFile,
                    Verbose = options.Verbose
                });

        if (!options.NoAssemble)
            Q1.Assembler.Program.Main(
                new AssemblerOptions
                {
                    InputFile = compiledFile,
                    OutputFile = assembledFile
                });

        if (!options.NoEmulate)
            Q1.Emulator.Program.Main(
                new EmulatorOptions
                {
                    InputFile = assembledFile,
                });
    }
}

class Options
{
    [Option('i', "input", Required = true, HelpText = "Input file to process.")]
    public string InputFile { get; set; }

    [Option(
        'c', "comment-compilation", Required = false,
        HelpText = "Comments to preserve in the compiled result")]
    public CommentCompilationMode CommentCompilationMode { get; set; } =
        CommentCompilationMode.UserDefined;

    [Option("no-compile", HelpText = "Skip compilation")]
    public bool NoCompile { get; set; } = false;

    [Option("no-assemble", HelpText = "Skip assembling")]
    public bool NoAssemble { get; set; } = false;

    [Option("no-emulate", HelpText = "Skip emulation")]
    public bool NoEmulate { get; set; } = false;
    
    [Option('v', "verbose", HelpText = "Enable verbose output")]
    public bool Verbose { get; set; } = false;
}