summaryrefslogtreecommitdiffhomepage
path: root/CompilerFrontend/cl/compiler.d
blob: b2cb8f5575f00cb42a3c9a3473c344e452b11619 (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
/*
 *	========================================================
 *
 *	MP-UX C Compiler
 * 	Copyright WestCo, all rights reserved.
 *
 * 	========================================================
 */

module cl.compiler;

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

import std.stdio;

public void mcc_summon_executable(string path) 
{
	import core.stdc.stdlib;
    import std.string;
    
	system(toStringz(path));
}

public class Platform
{
    public static string getIncludePath()
    {
	    import core.stdc.stdlib;
        import std.string;
        import std.conv;
        import std.path;
        
        string pathHome = expandTilde("~");
        pathHome ~= "/mp-ux/libc/";

        return pathHome;
    }

    public static string getKernelPath()
    {
	    import core.stdc.stdlib;
        import std.string;
        import std.conv;
        import std.path;
        
        string pathHome = expandTilde("~");
        pathHome ~= "/mp-ux/mp-ux/";

        return pathHome;
    }
}

public class CompileCommand
{
    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;

            mcc_summon_executable("/usr/local/bin/bin/cpp --define __LP64__ 1 --define __NC64K__ 1 --define __NEWCPU__ 1 --define __STDC__ 1 --define __HISYS__ 1 " ~
                                 "--define __FILE__ " ~ file ~ " --define __DATE__ " ~ Clock.currTime(UTC()).toString() 
                                 ~ " " ~
                                " --working-dir ./ --include-dir " ~ includePath ~ " " ~ file);

            mcc_summon_executable("/usr/local/bin/bin/cc --asm=masm -fmax-exceptions 20 --compiler=dolvik " ~
                                    file ~ ".pp");

            string changed;

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

                changed ~= ch;
            }

            changed ~= ".masm";

            mcc_summon_executable("/usr/local/bin/bin/masm -m64000 " ~ changed);
        }

        if (compile_only)
            return;

        string obj;

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

            string changed;

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

                changed ~= ch;
            }

            changed ~= ".o ";

            obj ~= changed;
        }

        string shlib_enable = "";

        if (is_lib)
            shlib_enable = " -shared ";

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

        mcc_summon_executable("/usr/local/bin/bin/ld -m64000 " ~
        obj ~ output_object);
    }
}