summaryrefslogtreecommitdiffhomepage
path: root/CompilerDriver
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-03 23:40:16 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-03 23:40:16 +0100
commitb03f3d83efcbc012c4153da14eaf158bb50031d2 (patch)
treedc004f8d0ef866c77fff7aa4ec271363b5417f9d /CompilerDriver
parent05c51485d56b14f7cd3c05afebd920157d7a0b8b (diff)
tools: incremental changes, support for a C compiler will soon be here.
alongside the 32x0. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerDriver')
-rw-r--r--CompilerDriver/.gitignore1
-rw-r--r--CompilerDriver/cc.cc (renamed from CompilerDriver/cc.cxx)5
-rw-r--r--CompilerDriver/ccplus.cc (renamed from CompilerDriver/ccplus.cxx)6
-rw-r--r--CompilerDriver/cpp.cc (renamed from CompilerDriver/cpp.cxx)0
-rw-r--r--CompilerDriver/ld.cc (renamed from CompilerDriver/ld.cxx)41
-rw-r--r--CompilerDriver/makefile16
-rw-r--r--CompilerDriver/masm.cc (renamed from CompilerDriver/masm.cxx)17
7 files changed, 52 insertions, 34 deletions
diff --git a/CompilerDriver/.gitignore b/CompilerDriver/.gitignore
index ce5ef93..23a095f 100644
--- a/CompilerDriver/.gitignore
+++ b/CompilerDriver/.gitignore
@@ -1,4 +1,5 @@
bin/ld
+bin/mld
bin/cpp
bin/cc
bin/masm
diff --git a/CompilerDriver/cc.cxx b/CompilerDriver/cc.cc
index 0a8647d..899734b 100644
--- a/CompilerDriver/cc.cxx
+++ b/CompilerDriver/cc.cc
@@ -1755,12 +1755,13 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////
#define kPrintF printf
-#define kSplashCxx() kPrintF(kWhite "%s\n", "cc, v1.13, (c) Western Company")
+#define kSplashCxx() kPrintF(kWhite "%s\n", "cc, v1.14, (c) Western Company")
static void cc_print_help()
{
kSplashCxx();
- kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile to a specific assembler syntax. (masm)");
+
+ kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile with a specific syntax. (64x0, 32x0)");
kPrintF(kWhite "--compiler={COMPILER}: %s\n", "Select compiler engine (builtin -> dolvik).");
}
diff --git a/CompilerDriver/ccplus.cxx b/CompilerDriver/ccplus.cc
index d9ef3fe..f9f94e4 100644
--- a/CompilerDriver/ccplus.cxx
+++ b/CompilerDriver/ccplus.cc
@@ -464,18 +464,18 @@ public:
/////////////////////////////////////////////////////////////////////////////////////////
#define kPrintF printf
-#define kSplashCxx() kPrintF(kWhite "%s\n", "ccplus, v1.13, (c) Western Company.")
+#define kSplashCxx() kPrintF(kWhite "%s\n", "ccplus, v1.14, (c) Western Company.")
static void cxx_print_help()
{
kSplashCxx();
- kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile to a specific assembler syntax. (masm)");
+ kPrintF(kWhite "--asm={MACHINE}: %s\n", "Compile with a specific syntax. (64x0, 32x0)");
kPrintF(kWhite "--compiler={COMPILER}: %s\n", "Select compiler engine (builtin -> vanhalen++).");
}
/////////////////////////////////////////////////////////////////////////////////////////
-#define kExt ".c"
+#define kExt ".cc"
int main(int argc, char** argv)
{
diff --git a/CompilerDriver/cpp.cxx b/CompilerDriver/cpp.cc
index 6986e27..6986e27 100644
--- a/CompilerDriver/cpp.cxx
+++ b/CompilerDriver/cpp.cc
diff --git a/CompilerDriver/ld.cxx b/CompilerDriver/ld.cc
index d316fe3..d9e1ffe 100644
--- a/CompilerDriver/ld.cxx
+++ b/CompilerDriver/ld.cc
@@ -28,9 +28,9 @@
#include <C++Kit/StdKit/AE.hpp>
//! @brief standard PEF entry.
-#define kPefStart "__start"
+#define kPefStart "__start"
-#define kToolVersion "ld v1.15, (c) Western Company"
+#define kToolVersion "ld v1.17, (c) Western Company"
#define StringCompare(dst, src) strcmp(dst, src)
@@ -59,7 +59,6 @@ std::ofstream& operator<<(std::ofstream& fp, CxxKit::PEFCommandHeader& container
}
static std::string kOutput = "a.out";
-
static Int32 kAbi = kAbiMpUx;
static Int32 kSubArch = kPefNoSubCpu;
static Int32 kArch = kPefNoCpu;
@@ -88,7 +87,7 @@ int main(int argc, char** argv)
kStdOut << "-v: Print program version.\n";
kStdOut << "-verbose: Print program backtrace (verbose mode).\n";
kStdOut << "-shared: Output as a shared library.\n";
- kStdOut << "-m64000: Link for the X64000.\n";
+ kStdOut << "-m64000: Link for the 64x0.\n";
kStdOut << "-fatbin: Output as FAT PEF.\n";
kStdOut << "-o: Select output filename.\n";
@@ -165,12 +164,15 @@ int main(int argc, char** argv)
{
if (!std::filesystem::exists(obj))
{
+ // if filesystem doesn't find file
+ // -> throw error.
kStdOut << "ld: no such file: " << obj << std::endl;
return CXXKIT_EXEC_ERROR;
}
}
}
+ // PEF expects a valid architecture when outputing a binary.
if (kArch == 0)
{
kStdOut << "ld: no target architecture set, can't continue." << std::endl;
@@ -179,10 +181,11 @@ int main(int argc, char** argv)
CxxKit::PEFContainer pef_container{};
+ int32_t archs = kArch;
+
pef_container.Count = 0UL;
pef_container.Kind = CxxKit::kPefKindExec;
pef_container.SubCpu = kSubArch;
- pef_container.Cpu = kArch;
pef_container.Linker = kPefLinkerNumId; // Western Company Linker
pef_container.Abi = kAbi; // Multi-Processor UX ABI
pef_container.Magic[0] = kPefMagic[kFatBinaryEnable ? 2 : 0];
@@ -190,7 +193,7 @@ int main(int argc, char** argv)
pef_container.Magic[2] = kPefMagic[kFatBinaryEnable ? 0 : 2];
pef_container.Version = kPefVersion;
- // specify the start address.
+ // specify the start address, can be 0x10000
pef_container.Start = kPefDeaultOrg;
pef_container.HdrSz = sizeof(CxxKit::PEFContainer);
@@ -206,13 +209,6 @@ int main(int argc, char** argv)
return -CXXKIT_FILE_NOT_FOUND;
}
- output_fc << pef_container;
-
- if (kVerbose)
- {
- kStdOut << "ld: PEF: wrote container header.\n";
- }
-
//! Read AE to convert as PEF.
std::vector<CxxKit::PEFCommandHeader> pef_command_hdrs;
@@ -233,12 +229,12 @@ int main(int argc, char** argv)
if (ae_header.fArch != kArch)
{
if (kVerbose)
- kStdOut << "ld: PEF: is a fat binary? : ";
+ kStdOut << "ld: pef: is a fat binary? : ";
if (!kFatBinaryEnable)
{
if (kVerbose)
- kStdOut << "NO\n";
+ kStdOut << "no.\n";
kStdOut << "ld: error: object " << i << " is a different kind of architecture and output isn't treated as FAT binary." << std::endl;
@@ -249,7 +245,7 @@ int main(int argc, char** argv)
{
if (kVerbose)
{
- kStdOut << "YES\n";
+ kStdOut << "yes.\n";
}
}
}
@@ -258,6 +254,8 @@ int main(int argc, char** argv)
ae_header.fMagic[1] == kAEMag1 &&
ae_header.fSize == sizeof(CxxKit::AEHeader))
{
+ // append arch type to archs varaible.
+ archs |= ae_header.fArch;
std::size_t cnt = ae_header.fCount;
if (kVerbose)
@@ -331,13 +329,22 @@ ld_mark_header:
continue;
}
- kStdOut << "ld: not an object " << i << std::endl;
+ kStdOut << "ld: not an object: " << i << std::endl;
std::remove(kOutput.c_str());
// don't continue, it is a fatal error.
return -CXXKIT_EXEC_ERROR;
}
+ pef_container.Cpu = archs;
+
+ output_fc << pef_container;
+
+ if (kVerbose)
+ {
+ kStdOut << "ld: pef: wrote container header.\n";
+ }
+
output_fc.seekp(std::streamsize(pef_container.HdrSz));
std::vector<std::string> not_found;
diff --git a/CompilerDriver/makefile b/CompilerDriver/makefile
index f22ded6..e1060d5 100644
--- a/CompilerDriver/makefile
+++ b/CompilerDriver/makefile
@@ -9,30 +9,31 @@
LINK_CC=g++ -std=c++20
LINK_INC=-I../ -I../C++Kit
-LINK_SRC=ld.cxx
+LINK_SRC=ld.cc
LINK_OUTPUT=bin/ld
+LINK_ALT_OUTPUT=bin/mld
-PP_SRC=cpp.cxx
+PP_SRC=cpp.cc
PP_OUTPUT=bin/cpp
CC2_OUTPUT=bin/cppfront
CC2_SRC=cc2/source/cppfront.cpp
-CC_SRC=ccplus.cxx ../C++Kit/StdKit/*.cpp ../C++Kit/AsmKit/*.cpp
+CC_SRC=ccplus.cc ../C++Kit/StdKit/*.cc ../C++Kit/AsmKit/*.cc
CC_OUTPUT=bin/ccplus
-CC_SRC=cc.cxx ../C++Kit/StdKit/*.cpp ../C++Kit/AsmKit/*.cpp
+CC_SRC=cc.cc ../C++Kit/StdKit/*.cc ../C++Kit/AsmKit/*.cc
CC_OUTPUT=bin/cc
-CXX_SRC=ccplus.cxx ../C++Kit/StdKit/*.cpp ../C++Kit/AsmKit/*.cpp
+CXX_SRC=ccplus.cc ../C++Kit/StdKit/*.cc ../C++Kit/AsmKit/*.cc
CXX_OUTPUT=bin/ccplus
-MASM_SRC=masm.cxx ../C++Kit/StdKit/*.cpp ../C++Kit/AsmKit/*.cpp
+MASM_SRC=masm.cc ../C++Kit/StdKit/*.cc ../C++Kit/AsmKit/*.cc
MASM_OUTPUT=bin/masm
.PHONY: all
all: cxx
- @echo "[make] done build"
+ @echo "[make] done build."
.PHONY: cxx
cxx: ld
@@ -45,6 +46,7 @@ cxx: ld
.PHONY: ld
ld:
$(LINK_CC) $(LINK_INC) $(LINK_SRC) -o $(LINK_OUTPUT)
+ cp $(LINK_OUTPUT) $(LINK_ALT_OUTPUT)
.PHONY: help
help:
diff --git a/CompilerDriver/masm.cxx b/CompilerDriver/masm.cc
index e3be378..849e141 100644
--- a/CompilerDriver/masm.cxx
+++ b/CompilerDriver/masm.cc
@@ -36,7 +36,7 @@
#define kWhite "\e[0;97m"
#define kYellow "\e[0;33m"
-#define kStdOut (std::cout << kWhite)
+#define kStdOut (std::cout << kWhite)
static char kOutputArch = CxxKit::kPefArch64000;
@@ -122,7 +122,7 @@ int main(int argc, char** argv)
{
if (strcmp(argv[i], "-v") == 0)
{
- kStdOut << "masm: The MP-UX Assembler.\nmasm: Copyright (c) 2023 Western Company.\n";
+ kStdOut << "masm: The MP-UX Assembler.\nmasm: v1.10\nmasm: Copyright (c) 2023 Western Company.\n";
return 0;
}
@@ -135,9 +135,16 @@ int main(int argc, char** argv)
return 0;
}
- else if (strcmp(argv[i], "-m64000") == 0)
+ else if (strcmp(argv[i], "-m64000") == 0 ||
+ strcmp(argv[i], "-m64x0") == 0)
{
kOutputArch = CxxKit::kPefArch64000;
+
+ if (kVerbose)
+ {
+ kStdOut << "masm: Select 64x0 as object output.\n";
+ }
+
continue;
}
else if (strcmp(argv[i], "-verbose") == 0)
@@ -555,7 +562,7 @@ static std::string masm_check_line(std::string& line, const std::string& file)
std::vector<std::string> opcodes_list = { "jb", "psh", "stw", "ldw", "lda", "sta" };
- for (auto& opcodes : kOpcodesStd)
+ for (auto& opcodes : kOpcodes64x0)
{
if (line.find(opcodes.fName) != std::string::npos)
{
@@ -739,7 +746,7 @@ static bool masm_write_number(std::size_t pos, std::string& jump_label)
static void masm_read_instruction(std::string& line, const std::string& file)
{
- for (auto& opcodes : kOpcodesStd)
+ for (auto& opcodes : kOpcodes64x0)
{
if (ParserKit::find_word(line, opcodes.fName))
{