diff options
Diffstat (limited to 'Frontend/Compiler')
| -rw-r--r-- | Frontend/Compiler/.gitignore | 17 | ||||
| -rw-r--r-- | Frontend/Compiler/.gitkeep | 0 | ||||
| -rw-r--r-- | Frontend/Compiler/bin/.gitkeep | 0 | ||||
| -rw-r--r-- | Frontend/Compiler/compiler.d | 137 | ||||
| -rw-r--r-- | Frontend/Compiler/main.d | 112 | ||||
| -rw-r--r-- | Frontend/Compiler/makefile | 13 | ||||
| -rw-r--r-- | Frontend/Compiler/man/mpcc.8 | 11 | ||||
| -rw-r--r-- | Frontend/Compiler/test/.gitkeep | 0 |
8 files changed, 290 insertions, 0 deletions
diff --git a/Frontend/Compiler/.gitignore b/Frontend/Compiler/.gitignore new file mode 100644 index 0000000..b8f5db3 --- /dev/null +++ b/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/Frontend/Compiler/.gitkeep b/Frontend/Compiler/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Frontend/Compiler/.gitkeep diff --git a/Frontend/Compiler/bin/.gitkeep b/Frontend/Compiler/bin/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Frontend/Compiler/bin/.gitkeep 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 diff --git a/Frontend/Compiler/main.d b/Frontend/Compiler/main.d new file mode 100644 index 0000000..aabc0ff --- /dev/null +++ b/Frontend/Compiler/main.d @@ -0,0 +1,112 @@ +/* + * ======================================================== + * + * MP-UX C Compiler + * Copyright Mahrouss Logic, all rights reserved. + * + * ======================================================== + */ + +// @file main.d +// @brief CLI of the X64000 C/C++ compiler + +module mpcc.main; + +import mpcc.compiler; +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/cc --asm=masm --compiler=dolvik --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/Frontend/Compiler/makefile b/Frontend/Compiler/makefile new file mode 100644 index 0000000..a2bc3d1 --- /dev/null +++ b/Frontend/Compiler/makefile @@ -0,0 +1,13 @@ + # + # ======================================================== + # + # MP-UX C Compiler + # Copyright Mahrouss Logic, all rights reserved. + # + # ======================================================== + # + +# build mpcc +.PHONY: mpcc-build +mpcc-build: + dmd -I../ $(wildcard *.d) -ofmpcc
\ No newline at end of file diff --git a/Frontend/Compiler/man/mpcc.8 b/Frontend/Compiler/man/mpcc.8 new file mode 100644 index 0000000..d362e5a --- /dev/null +++ b/Frontend/Compiler/man/mpcc.8 @@ -0,0 +1,11 @@ +.Dd Dec 16, 2023 +.Dt mpcc 1.11 +.Os MP-UX + +.Sh NAME +.Nm mcc +.Nd Mahrouss Logic BCCL/C++ Compiler + +.Sh DESCRIPTION + +This program compiles BCCL/C++ sources into MP-UX Preferred Executable Format.
\ No newline at end of file diff --git a/Frontend/Compiler/test/.gitkeep b/Frontend/Compiler/test/.gitkeep new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/Frontend/Compiler/test/.gitkeep |
