summaryrefslogtreecommitdiffhomepage
path: root/Private/Frontend/Compiler
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-27 09:12:14 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-27 09:12:14 +0100
commit59a2e775507d01f3ebc8435bf749ab6d3d5b3eeb (patch)
tree2061a6494b2cd14b1109030ba9540685cf60a551 /Private/Frontend/Compiler
parentf1746ae6c3e305f1be21c68a79e01f57d6ec911a (diff)
Breaking changes: Reworked structure of project.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'Private/Frontend/Compiler')
-rw-r--r--Private/Frontend/Compiler/.gitignore17
-rw-r--r--Private/Frontend/Compiler/.gitkeep0
-rw-r--r--Private/Frontend/Compiler/bin/.gitkeep0
-rw-r--r--Private/Frontend/Compiler/compiler_command.d152
-rw-r--r--Private/Frontend/Compiler/compiler_macro_helpers.d10
-rw-r--r--Private/Frontend/Compiler/compiler_start.d112
-rw-r--r--Private/Frontend/Compiler/makefile13
-rw-r--r--Private/Frontend/Compiler/man/mpcc.811
-rw-r--r--Private/Frontend/Compiler/test/.gitkeep0
9 files changed, 315 insertions, 0 deletions
diff --git a/Private/Frontend/Compiler/.gitignore b/Private/Frontend/Compiler/.gitignore
new file mode 100644
index 0000000..b8f5db3
--- /dev/null
+++ b/Private/Frontend/Compiler/.gitignore
@@ -0,0 +1,17 @@
+bin/elf2pef
+bin/ld
+bin/cpp
+bin/cc
+bin/masm
+bin/mkcdfs
+bin/ccplus
+bin/cppfront
+bin/bccl
+bin/bpp
+test/*.cc
+test/*.64x
+*.c.pp
+*.cxx.pp
+test/*.c
+test/*.masm
+*.pp \ No newline at end of file
diff --git a/Private/Frontend/Compiler/.gitkeep b/Private/Frontend/Compiler/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Private/Frontend/Compiler/.gitkeep
diff --git a/Private/Frontend/Compiler/bin/.gitkeep b/Private/Frontend/Compiler/bin/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Private/Frontend/Compiler/bin/.gitkeep
diff --git a/Private/Frontend/Compiler/compiler_command.d b/Private/Frontend/Compiler/compiler_command.d
new file mode 100644
index 0000000..80d8673
--- /dev/null
+++ b/Private/Frontend/Compiler/compiler_command.d
@@ -0,0 +1,152 @@
+/*
+ * ========================================================
+ *
+ * MP-UX C Compiler
+ * Copyright 2024, 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()
+ {
+ 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;
+
+ string input = "/usr/local/bin/bin/cpp";
+
+ 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("/usr/local/bin/bin/ccplus --asm=masm -fmax-exceptions 10 --compiler=vanhalen " ~
+ file ~ ".pp");
+
+ assembly_source ~= ".64x";
+
+ mpcc_summon_executable("/usr/local/bin/bin/64asm " ~ 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 ~= ".o";
+
+ 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("/usr/local/bin/bin/ld " ~ obj ~ output_object);
+ }
+} \ No newline at end of file
diff --git a/Private/Frontend/Compiler/compiler_macro_helpers.d b/Private/Frontend/Compiler/compiler_macro_helpers.d
new file mode 100644
index 0000000..4dfe65e
--- /dev/null
+++ b/Private/Frontend/Compiler/compiler_macro_helpers.d
@@ -0,0 +1,10 @@
+module Frontend.Compiler.compiler_macro_helpers;
+
+class CompilerMacroHelpers
+{
+ static public string[] getStandardMacros()
+ {
+ string[] macros = [ "__64x0__", "__mpux__" ];
+ return macros;
+ }
+} \ No newline at end of file
diff --git a/Private/Frontend/Compiler/compiler_start.d b/Private/Frontend/Compiler/compiler_start.d
new file mode 100644
index 0000000..44e17da
--- /dev/null
+++ b/Private/Frontend/Compiler/compiler_start.d
@@ -0,0 +1,112 @@
+/*
+ * ========================================================
+ *
+ * MP-UX C Compiler
+ * Copyright 2024, Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+// @file main.d
+// @brief CLI of the X64000 C/C++ compiler
+
+module Frontend.Compiler.compiler_start;
+
+import Frontend.Compiler.compiler_command;
+import std.container.dlist;
+
+///Authors: Amlal EL Mahrouss
+///Examples: mpcc_summon_manual("foo");
+void mpcc_summon_manual(string path)
+{
+ import core.stdc.stdlib;
+ import std.string;
+ import std.file;
+
+ string base = "man ";
+ base ~= "/usr/local/bin/man/";
+
+ string extension = ".8";
+
+ core.stdc.stdlib.system(toStringz(base ~ path ~ extension));
+}
+
+void main(string[] args)
+{
+ import std.range, std.stdio;
+
+ bool shared_library = false;
+ bool compile_only = false;
+ bool kernel_driver = false;
+ string output_file = "a.out";
+ size_t index = 0UL;
+
+ string[255] args_list;
+
+ foreach (arg ; args)
+ {
+ if (arg[0] == '-')
+ {
+ if (arg == "-version" ||
+ arg == "-v")
+ {
+ writeln("mpcc: version 1.01, (c) Mahrouss Logic all rights reserved.");
+ return;
+ }
+ else if (arg == "-dialect")
+ {
+ mpcc_summon_executable("/usr/local/bin/bin/ccplus --asm=masm --compiler=vanhalen --dialect");
+ return;
+ }
+ else if (arg == "--help" ||
+ arg == "-h")
+ {
+ writeln("mpcc: summoning manual entry for mpcc...");
+ mpcc_summon_manual("mpcc");
+
+ return;
+ }
+ else if (arg == "-c")
+ {
+ compile_only = true;
+ continue;
+ }
+ else if (arg == "-kernel")
+ {
+ kernel_driver = true;
+ continue;
+ }
+ else if (arg == "-shared")
+ {
+ output_file = "a.lib";
+ shared_library = true;
+ continue;
+ }
+
+ writeln("mpcc: unknown argument " ~ arg);
+ return;
+ }
+
+ if (index == 0)
+ {
+ ++index;
+ continue;
+ }
+
+ args_list[index] = arg;
+ ++index;
+ }
+
+ if (args_list[1] == null)
+ {
+ writeln("mpcc: no input files.");
+ return;
+ }
+
+ auto compiler = new CompileCommand();
+
+ if (kernel_driver)
+ compiler.compile(Platform.getKernelPath(), args_list, shared_library, output_file, compile_only);
+ else
+ compiler.compile(Platform.getIncludePath(), args_list, shared_library, output_file, compile_only);
+} \ No newline at end of file
diff --git a/Private/Frontend/Compiler/makefile b/Private/Frontend/Compiler/makefile
new file mode 100644
index 0000000..96902a0
--- /dev/null
+++ b/Private/Frontend/Compiler/makefile
@@ -0,0 +1,13 @@
+ #
+ # ========================================================
+ #
+ # MP-UX C Compiler
+ # Copyright 2024, Mahrouss Logic, all rights reserved.
+ #
+ # ========================================================
+ #
+
+# build mpcc
+.PHONY: mpcc-build
+mpcc-build:
+ ldc2 -I../ $(wildcard *.d) -ofmpcc \ No newline at end of file
diff --git a/Private/Frontend/Compiler/man/mpcc.8 b/Private/Frontend/Compiler/man/mpcc.8
new file mode 100644
index 0000000..afbeac4
--- /dev/null
+++ b/Private/Frontend/Compiler/man/mpcc.8
@@ -0,0 +1,11 @@
+.Dd Jan 21, 2024
+.Dt mpcc 1.11
+.Os MP-UX
+
+.Sh NAME
+.Nm mpcc
+.Nd Mahrouss Logic BCCL/C++ Compiler
+
+.Sh DESCRIPTION
+
+This program compiles BCCL/C++ sources into the Preferred Executable Format. \ No newline at end of file
diff --git a/Private/Frontend/Compiler/test/.gitkeep b/Private/Frontend/Compiler/test/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Private/Frontend/Compiler/test/.gitkeep