summaryrefslogtreecommitdiffhomepage
path: root/CompilerFrontend
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2023-12-30 23:39:37 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2023-12-30 23:39:37 +0100
commit263915832993dd12beee10e204f9ebcc6c786ed2 (patch)
tree862e51208a99c35746e574a76564a4532b3a4a49 /CompilerFrontend
Meta: initial commit of WestCo optimized toolchain.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerFrontend')
-rw-r--r--CompilerFrontend/.gitkeep0
-rw-r--r--CompilerFrontend/cl/.gitignore14
-rw-r--r--CompilerFrontend/cl/.gitkeep0
-rw-r--r--CompilerFrontend/cl/bin/.gitkeep0
-rw-r--r--CompilerFrontend/cl/compiler.d129
-rw-r--r--CompilerFrontend/cl/main.d108
-rw-r--r--CompilerFrontend/cl/makefile12
-rw-r--r--CompilerFrontend/cl/man/mpcc.811
-rw-r--r--CompilerFrontend/cl/test/.gitkeep0
9 files changed, 274 insertions, 0 deletions
diff --git a/CompilerFrontend/.gitkeep b/CompilerFrontend/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/CompilerFrontend/.gitkeep
diff --git a/CompilerFrontend/cl/.gitignore b/CompilerFrontend/cl/.gitignore
new file mode 100644
index 0000000..8971316
--- /dev/null
+++ b/CompilerFrontend/cl/.gitignore
@@ -0,0 +1,14 @@
+bin/elf2pef
+bin/ld
+bin/cpp
+bin/cc
+bin/masm
+bin/mkcdfs
+bin/ccplus
+bin/cpp2
+
+*.c.pp
+*.cxx.pp
+test/*.c
+test/*.masm
+*.pp \ No newline at end of file
diff --git a/CompilerFrontend/cl/.gitkeep b/CompilerFrontend/cl/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/CompilerFrontend/cl/.gitkeep
diff --git a/CompilerFrontend/cl/bin/.gitkeep b/CompilerFrontend/cl/bin/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/CompilerFrontend/cl/bin/.gitkeep
diff --git a/CompilerFrontend/cl/compiler.d b/CompilerFrontend/cl/compiler.d
new file mode 100644
index 0000000..e510e1c
--- /dev/null
+++ b/CompilerFrontend/cl/compiler.d
@@ -0,0 +1,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 -marc " ~ 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 -marc " ~
+ obj ~ output_object);
+ }
+} \ No newline at end of file
diff --git a/CompilerFrontend/cl/main.d b/CompilerFrontend/cl/main.d
new file mode 100644
index 0000000..fcc4326
--- /dev/null
+++ b/CompilerFrontend/cl/main.d
@@ -0,0 +1,108 @@
+/*
+ * ========================================================
+ *
+ * MP-UX C Compiler
+ * Copyright WestCo, all rights reserved.
+ *
+ * ========================================================
+ */
+
+// @file main.d
+// @brief CLI of the X64000 C/C++ compiler
+
+module cl.main;
+
+import cl.compiler;
+import std.container.dlist;
+
+///Authors: Amlal EL Mahrouss
+///Examples: mcc_summon_manual("foo");
+void mcc_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.00, (c) WestCo all rights reserved.");
+
+ return;
+ }
+ else if (arg == "--help" ||
+ arg == "-h")
+ {
+ writeln("mpcc: summoning manual entry for mpcc...");
+ mcc_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/CompilerFrontend/cl/makefile b/CompilerFrontend/cl/makefile
new file mode 100644
index 0000000..14827ac
--- /dev/null
+++ b/CompilerFrontend/cl/makefile
@@ -0,0 +1,12 @@
+ #
+ # ========================================================
+ #
+ # C++Kit
+ # Copyright WestCo, all rights reserved.
+ #
+ # ========================================================
+ #
+
+.PHONY: mcc-build
+mcc-build:
+ dmd -I../ $(wildcard *.d) -ofmpcc \ No newline at end of file
diff --git a/CompilerFrontend/cl/man/mpcc.8 b/CompilerFrontend/cl/man/mpcc.8
new file mode 100644
index 0000000..363e378
--- /dev/null
+++ b/CompilerFrontend/cl/man/mpcc.8
@@ -0,0 +1,11 @@
+.Dd Dec 16, 2023
+.Dt mpcc 1.11
+.Os Mach4
+
+.Sh NAME
+.Nm mcc
+.Nd WestCo C/C++ Compiler
+
+.Sh DESCRIPTION
+
+This program compiles C/C++ sources into Mach4 Preferred Executable Format. \ No newline at end of file
diff --git a/CompilerFrontend/cl/test/.gitkeep b/CompilerFrontend/cl/test/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/CompilerFrontend/cl/test/.gitkeep