diff --git a/codegenerator.cpp b/codegenerator.cpp index 5de8ed584..881ccc926 100644 --- a/codegenerator.cpp +++ b/codegenerator.cpp @@ -89,7 +89,23 @@ CodeGenerator::CodeGenerator(std::string Input, // We only support ELF for now auto *TheBinary = cast(BinaryHandle.getBinary()); - SourceArchitecture = Architecture(1, + unsigned InstructionAlignment = 0; + switch (TheBinary->getArch()) { + case Triple::x86_64: + InstructionAlignment = 1; + break; + case Triple::arm: + InstructionAlignment = 4; + break; + case Triple::mips: + InstructionAlignment = 4; + break; + default: + assert(false); + } + + SourceArchitecture = Architecture(InstructionAlignment, + 1, TheBinary->isLittleEndian(), TheBinary->getBytesInAddress() * 8); diff --git a/revamb.h b/revamb.h index 422ab13dd..392916870 100644 --- a/revamb.h +++ b/revamb.h @@ -41,30 +41,37 @@ public: public: Architecture() : + InstructionAlignment(1), DefaultAlignment(1), Endianess(LittleEndian), PointerSize(64) { } - Architecture(unsigned DefaultAlignment, + Architecture(unsigned InstructionAlignment, + unsigned DefaultAlignment, EndianessType Endianess, unsigned PointerSize) : + InstructionAlignment(InstructionAlignment), DefaultAlignment(DefaultAlignment), Endianess(Endianess), PointerSize(PointerSize) { } - Architecture(unsigned DefaultAlignment, + Architecture(unsigned InstructionAlignment, + unsigned DefaultAlignment, bool IsLittleEndian, unsigned PointerSize) : + InstructionAlignment(InstructionAlignment), DefaultAlignment(DefaultAlignment), Endianess(IsLittleEndian ? LittleEndian : BigEndian), PointerSize(PointerSize) { } + unsigned instructionAlignment() { return InstructionAlignment; } unsigned defaultAlignment() { return DefaultAlignment; } EndianessType endianess() { return Endianess; } unsigned pointerSize() { return PointerSize; } bool isLittleEndian() { return Endianess == LittleEndian; } private: + unsigned InstructionAlignment; unsigned DefaultAlignment; EndianessType Endianess; unsigned PointerSize;