summaryrefslogtreecommitdiffhomepage
path: root/Private/Frontend/Compiler/compiler_command.d
blob: ef8491919597a5a2b4c1e50a4725f8d0522b6a44 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 *	========================================================
 *
 *	MultiProcessor C Compiler
 * 	Copyright Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

module Frontend.Compiler.compiler_command;

///Authors: amlel
///Bugs: None
///Compiler Frontend

import std.stdio;
import Frontend.Compiler.compiler_macro_helpers;

public void mpcc_summon_executable(string path)
{
	import core.stdc.stdlib;
    import std.string;

	system(toStringz(path));
}

public class Platform
{
    public static string getIncludePath()
    {
        return "C:/SDK/Public/Kits/";
    }

    public static string getKernelPath()
    {
        return "C:/SDK/Private/Kits/";
    }
}

public class CompileCommandAMD64
{
    public void compile(string includePath, string[] files, bool is_lib, string output, bool compile_only)
    {
        import std.string;
        import std.algorithm;

        foreach (file; files)
        {
            if (file.length == 0)
                continue;

            import std.datetime;

            string input = "bpp";

            string[] arr_macros = CompilerMacroHelpers.getStandardMacros();

            foreach (string macro_name; arr_macros)
            {
                input ~= " -define ";
                input ~= macro_name;
                input ~= "1 ";
                input ~= " ";
            }

            input ~= "-define __FILE__ " ~ file;
            input ~= " ";
            input ~= "-define __DATE__ " ~ Clock.currTime(UTC()).toString();
            input ~= " ";
            input ~= "-working-dir ./ -include-dir " ~ includePath ~ " " ~ file;

            mpcc_summon_executable(input);

            string assembly_source;
            string ext;
            bool ext_now = false;

            foreach (ch; file)
            {
                if (ch == '.')
                {
                    ext_now = true;
                    break;
                }

                if (!ext_now)
                    assembly_source ~= ch;
                else
                    ext ~= ch;
            }

            mpcc_summon_executable("ccplus -fmax-exceptions 10 " ~
            file ~ ".pp");

            assembly_source ~= ".s";

            mpcc_summon_executable("i64asm " ~ assembly_source);
        }

        if (compile_only)
            return;

        string obj;

        foreach (file; files)
        {
            if (file.length == 0)
                    continue;

            string object_source;

            foreach (ch; file)
            {
                if (ch == '.')
                    break;

                object_source ~= ch;
            }

            object_source ~= ".obj";

            obj ~= object_source;
        }

        string shlib_enable = "";

        if (is_lib)
            shlib_enable = " -shared ";

        string output_object = shlib_enable;
        output_object ~= " -o ";
        output_object ~= output;

        mpcc_summon_executable("link -amd64 " ~ obj ~ output_object);
    }
}