How to make my target output XCOFF?

I am writing a backend for my own architecture. Its object file format is XCOFF.

Unlike ELF, XCOFF is only supported to a limited amount of targets in the current code base. I don’t know how to add my own target to the function XCOFFObjectFile::getFileFormatName(), and XCOFFObjectFile::getArch(). They only use the is64Bit() predicate to differentiate only two targets.

StringRef XCOFFObjectFile::getFileFormatName() const {
  return is64Bit() ? "aix5coff64-rs6000" : "aixcoff-rs6000";
}

Triple::ArchType XCOFFObjectFile::getArch() const {
  return is64Bit() ? Triple::ppc64 : Triple::ppc;
}

As for ELF, the getFileFormatName() and getArch() functions have switch-case statements to differentiate many target architectures.

Above is just an example, there are many other places where the XCOFF code looks “not that COMMONLY supported”, despite the word “common” in its full name.

Can anyone point me to the right direction? Any help is appreciated.

I went through COFFObjectFile.cpp and found out it used the Machine field in the coff_file_header to do all the switch-case work.

So it looks like I have to use getMagic() to do the switch-case. The official XCOFF document says the f_magic field has only 2 possible values for XCOFF32 and XCOFF64. I will have to hack it and make up my own magic number.