clean up binary format code

Linux, FreeBSD, and QNX all use ELF, so no need to distinguish between
them when generating object files.  To avoid confusion, I've switch
from using operating system names to using binary format names where
applicable.
This commit is contained in:
Joel Dice
2012-08-02 12:15:15 -06:00
parent e641f23e6c
commit f03e5e8e55
11 changed files with 63 additions and 66 deletions

View File

@ -197,8 +197,8 @@ public:
const unsigned machine;
ElfPlatform(PlatformInfo::OperatingSystem os, PlatformInfo::Architecture arch):
Platform(PlatformInfo(os, arch)),
ElfPlatform(PlatformInfo::Architecture arch):
Platform(PlatformInfo(PlatformInfo::Elf, arch)),
machine(getElfPlatform(arch)) {}
class FileWriter {
@ -372,15 +372,9 @@ public:
}
};
ElfPlatform<uint32_t> elfLinuxX86Platform(PlatformInfo::Linux, PlatformInfo::x86);
ElfPlatform<uint32_t> elfLinuxArmPlatform(PlatformInfo::Linux, PlatformInfo::Arm);
ElfPlatform<uint32_t, false> elfLinuxPowerPCPlatform(PlatformInfo::Linux, PlatformInfo::PowerPC);
ElfPlatform<uint64_t> elfLinuxX86_64Platform(PlatformInfo::Linux, PlatformInfo::x86_64);
ElfPlatform<uint32_t> elfFreeBSDx86Platform(PlatformInfo::FreeBSD, PlatformInfo::x86);
ElfPlatform<uint32_t> elfFreeBSDArmPlatform(PlatformInfo::FreeBSD, PlatformInfo::Arm);
ElfPlatform<uint32_t, false> elfFreeBSDPowerPCPlatform(PlatformInfo::FreeBSD, PlatformInfo::PowerPC);
ElfPlatform<uint64_t> elfFreeBSDx86_64Platform(PlatformInfo::FreeBSD, PlatformInfo::x86_64);
ElfPlatform<uint32_t> elfX86Platform(PlatformInfo::x86);
ElfPlatform<uint32_t> elfArmPlatform(PlatformInfo::Arm);
ElfPlatform<uint32_t, false> elfPowerPCPlatform(PlatformInfo::PowerPC);
ElfPlatform<uint64_t> elfX86_64Platform(PlatformInfo::x86_64);
} // namespace

View File

@ -286,7 +286,7 @@ public:
}
MachOPlatform(PlatformInfo::Architecture arch):
Platform(PlatformInfo(PlatformInfo::Darwin, arch)) {}
Platform(PlatformInfo(PlatformInfo::MachO, arch)) {}
};

View File

@ -41,14 +41,14 @@ using namespace avian::tools;
bool
writeObject(uint8_t* data, size_t size, OutputStream* out, const char* startName,
const char* endName, const char* os,
const char* endName, const char* format,
const char* architecture, unsigned alignment, bool writable,
bool executable)
{
Platform* platform = Platform::getPlatform(PlatformInfo(PlatformInfo::osFromString(os), PlatformInfo::archFromString(architecture)));
Platform* platform = Platform::getPlatform(PlatformInfo(PlatformInfo::formatFromString(format), PlatformInfo::archFromString(architecture)));
if(!platform) {
fprintf(stderr, "unsupported platform: %s/%s\n", os, architecture);
fprintf(stderr, "unsupported platform: %s/%s\n", format, architecture);
return false;
}

View File

@ -269,7 +269,7 @@ public:
}
WindowsPlatform():
Platform(PlatformInfo(PlatformInfo::Windows, BytesPerWord == 4 ? PlatformInfo::x86 : PlatformInfo::x86_64)) {}
Platform(PlatformInfo(PlatformInfo::Pe, BytesPerWord == 4 ? PlatformInfo::x86 : PlatformInfo::x86_64)) {}
};
WindowsPlatform<4> windows32Platform;

View File

@ -85,17 +85,23 @@ void FileOutputStream::write(uint8_t byte) {
Platform* Platform::first = 0;
PlatformInfo::OperatingSystem PlatformInfo::osFromString(const char* os) {
if(strcmp(os, "linux") == 0) {
return Linux;
} else if(strcmp(os, "windows") == 0) {
return Windows;
} else if(strcmp(os, "darwin") == 0) {
return Darwin;
} else if(strcmp(os, "freebsd") == 0) {
return FreeBSD;
PlatformInfo::Format PlatformInfo::formatFromString(const char* format) {
if (strcmp(format, "elf") == 0
or strcmp(format, "linux") == 0
or strcmp(format, "freebsd") == 0
or strcmp(format, "qnx") == 0)
{
return Elf;
} else if (strcmp(format, "pe") == 0
or strcmp(format, "windows") == 0)
{
return Pe;
} else if (strcmp(format, "macho") == 0
or strcmp(format, "darwin") == 0)
{
return MachO;
} else {
return UnknownOS;
return UnknownFormat;
}
}

View File

@ -131,12 +131,11 @@ public:
class PlatformInfo {
public:
enum OperatingSystem {
Linux = AVIAN_PLATFORM_LINUX,
Windows = AVIAN_PLATFORM_WINDOWS,
Darwin = AVIAN_PLATFORM_DARWIN,
FreeBSD = AVIAN_PLATFORM_FREEBSD,
UnknownOS = AVIAN_PLATFORM_UNKNOWN
enum Format {
Elf = AVIAN_FORMAT_ELF,
Pe = AVIAN_FORMAT_PE,
MachO = AVIAN_FORMAT_MACHO,
UnknownFormat = AVIAN_FORMAT_UNKNOWN
};
enum Architecture {
@ -147,18 +146,18 @@ public:
UnknownArch = AVIAN_ARCH_UNKNOWN
};
const OperatingSystem os;
const Format format;
const Architecture arch;
static OperatingSystem osFromString(const char* os);
static Format formatFromString(const char* format);
static Architecture archFromString(const char* arch);
inline PlatformInfo(OperatingSystem os, Architecture arch):
os(os),
inline PlatformInfo(Format format, Architecture arch):
format(format),
arch(arch) {}
inline bool operator == (const PlatformInfo& other) {
return os == other.os && arch == other.arch;
return format == other.format && arch == other.arch;
}
inline bool isLittleEndian() {