diff options
| author | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-09 21:47:33 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal.elmahrouss@icloud.com> | 2024-01-09 21:47:33 +0100 |
| commit | 9cef856478cebe4bfe00e1d39c9e2d49015dd0e4 (patch) | |
| tree | f04c6b6b1156057748c7044a766120485c45c885 /Frontend/Compiler/compiler.d | |
| parent | a8a55bc93e06cd8f75f7d397c013f7a312ea29a4 (diff) | |
MP-UX/hCore Assembler for 64x0, Release I.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Frontend/Compiler/compiler.d')
| -rw-r--r-- | Frontend/Compiler/compiler.d | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/Frontend/Compiler/compiler.d b/Frontend/Compiler/compiler.d new file mode 100644 index 0000000..e9d2cc8 --- /dev/null +++ b/Frontend/Compiler/compiler.d @@ -0,0 +1,137 @@ +/* + * ======================================================== + * + * MP-UX C Compiler + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +module mpcc.compiler; + +///Authors: amlel +///Bugs: None +///Compiler Frontend + +import std.stdio; + +public void mpcc_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; + + mpcc_summon_executable("/usr/local/bin/bin/cpp --define __64x0__ 1 --define __LP64__ 1 --define __64000__ 1 --define __BCCL__ 1 " ~ + "--define __FILE__ " ~ file ~ " --define __DATE__ " ~ Clock.currTime(UTC()).toString() + ~ " " ~ + " --working-dir ./ --include-dir " ~ includePath ~ " " ~ file); + + string changed; + string ext; + bool ext_now = false; + + foreach (ch; file) + { + if (ch == '.') + { + ext_now = true; + break; + } + + if (!ext_now) + changed ~= ch; + else + ext ~= ch; + } + + mpcc_summon_executable("/usr/local/bin/bin/bccl --asm=masm -fmax-exceptions 20 --compiler=dolvik " ~ + file ~ ".pp"); + + changed ~= ".64x"; + + mpcc_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; + + mpcc_summon_executable("/usr/local/bin/bin/ld -m64000 " ~ + obj ~ output_object); + } +}
\ No newline at end of file |
