From 9cef856478cebe4bfe00e1d39c9e2d49015dd0e4 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Tue, 9 Jan 2024 21:47:33 +0100 Subject: MP-UX/hCore Assembler for 64x0, Release I. Signed-off-by: Amlal El Mahrouss --- Frontend/Compiler/compiler.d | 137 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 Frontend/Compiler/compiler.d (limited to 'Frontend/Compiler/compiler.d') 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 -- cgit v1.2.3