diff options
Diffstat (limited to 'src/msil/ch/epfl')
-rw-r--r-- | src/msil/ch/epfl/lamp/compiler/msil/Assembly.java | 6 | ||||
-rw-r--r-- | src/msil/ch/epfl/lamp/compiler/msil/PEFile.java | 23 | ||||
-rw-r--r-- | src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala | 14 |
3 files changed, 19 insertions, 24 deletions
diff --git a/src/msil/ch/epfl/lamp/compiler/msil/Assembly.java b/src/msil/ch/epfl/lamp/compiler/msil/Assembly.java index d2adf3750a..59bbeee3a4 100644 --- a/src/msil/ch/epfl/lamp/compiler/msil/Assembly.java +++ b/src/msil/ch/epfl/lamp/compiler/msil/Assembly.java @@ -45,13 +45,11 @@ public abstract class Assembly extends CustomAttributeProvider { // dir = dir.getCanonicalFile(); // } catch (java.io.IOException e) {} - if (name.endsWith(".exe") || name.endsWith(".EXE") || - name.endsWith(".dll") || name.endsWith(".DLL")) - { + if (name.toUpperCase().endsWith(".EXE") || name.toUpperCase().endsWith(".DLL")) { file = new File(dir, name); pefile = getPEFile(file); name = name.substring(0, name.length() - 4); - } + } File adir = pefile == null ? new File(dir, name) : null; diff --git a/src/msil/ch/epfl/lamp/compiler/msil/PEFile.java b/src/msil/ch/epfl/lamp/compiler/msil/PEFile.java index 481d5f2116..3eb22b9985 100644 --- a/src/msil/ch/epfl/lamp/compiler/msil/PEFile.java +++ b/src/msil/ch/epfl/lamp/compiler/msil/PEFile.java @@ -95,7 +95,7 @@ public class PEFile { /** Ecma 335, 25.2.1 MS-DOS header: * * "The PE format starts with an MS-DOS stub of exactly the following 128 bytes to - * be placed at the front of the module." + * be placed at the front of the module." * * We are only checking for MZ (Mark Zbikowski) */ @@ -107,13 +107,13 @@ public class PEFile { /** Ecma 335, 25.2.1 MS-DOS header: * * "At offset 0x3c in the DOS header is a 4-byte unsigned integer offset, lfanew, - * to the PE signature (shall be "PE\0\0"), immediately followed by the PE file header. + * to the PE signature (shall be "PE\0\0"), immediately followed by the PE file header." */ seek(0x3c); PE_SIGNATURE_OFFSET = readInt(); seek(PE_SIGNATURE_OFFSET); - + // start of PE signature (a signature that is just 4 bytes long) fileFormatCheck(readByte() != 0x50, "Invalid PE file format: " + filename); // 'P' fileFormatCheck(readByte() != 0x45, "Invalid PE file format: " + filename); // 'E' fileFormatCheck(readByte() != 0x00, "Invalid PE file format: " + filename); // 0 @@ -125,26 +125,19 @@ public class PEFile { PE_HEADER_OFFSET = COFF_HEADER_OFFSET + 20; seek(COFF_HEADER_OFFSET); - skip(2); - /** Ecma 335, 25.2.2: "Number of sections; indicates size of the Section Table" */ - numOfSections = readShort(); - //trace("Number of sections = " + numOfSections); - /** Ecma 335, 25.2.2: "Time and date the file was created in seconds since - * January 1st 1970 00:00:00 or 0." - */ + /* start of PE file header, Sec. 25.2.2 in Partition II */ + skip(2); // Machine (always 0x14c) + numOfSections = readShort(); // Number of sections; indicates size of the Section Table Date timeStamp = new Date(readInt() * 1000L); - //trace("Time stamp = " + timeStamp); - - skip(2 * INT_SIZE); + skip(2 * INT_SIZE); // skip Pointer to Symbol Table (always 0) and Number of Symbols (always 0) optHeaderSize = readShort(); int characteristics = readShort(); isDLL = (characteristics & 0x2000) != 0; - //trace("Characteristics = " + Integer.toHexString(characteristics)); seek(PE_HEADER_OFFSET + 208); // p.157, Partition II - CLI_RVA = readInt(); + CLI_RVA = readInt(); // called "Data Directory Table" in Ch. 4 of Expert IL book CLI_Length = readInt(); //trace("CLI_RVA = 0x" + Table.int2hex(CLI_RVA)); //trace("CLI_Length = 0x" + Table.int2hex(CLI_Length)); diff --git a/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala b/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala index c7899c7f54..2223a6db0f 100644 --- a/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala +++ b/src/msil/ch/epfl/lamp/compiler/msil/emit/ILGenerator.scala @@ -402,16 +402,20 @@ import ILGenerator._ * sets the line of the source file corresponding to the next instruction */ def setPosition(line: Int) { - if (line != 0) - lineNums.put(lastLabel, Integer.toString(line)) + if (line != 0) lineNums.put(lastLabel, Integer.toString(line)) } def setPosition(line: Int, filename: String) { - if (line != 0) - lineNums.put(lastLabel, line + " '" + filename + "'") + if (line != 0) lineNums.put(lastLabel, line + " '" + filename + "'") } - def getLocals(): Array[LocalBuilder] = localList.toArray + def setPosition(startLine: Int, endLine: Int, startCol: Int, endCol: Int, filename: String) { + val lineRange = startLine + "," + endLine + val colRange = startCol + "," + endCol + lineNums.put(lastLabel, lineRange + ":" + colRange + " '" + filename + "'") + } + + def getLocals(): Array[LocalBuilder] = localList.toArray def getLabelIterator() = labelList.iterator |