Fix bug when tracefile is not aligned. Now supports exotic architectures.
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Thu, 19 Apr 2012 22:17:45 +0000 (18:17 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 1 May 2012 13:47:44 +0000 (09:47 -0400)
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
22 files changed:
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/event/CTFEventFieldTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/headless/ReadTrace.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/ArrayDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDeclarationTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/EnumDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDeclarationTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/IntegerDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDeclarationTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/SequenceDefinitionTest.java
org.eclipse.linuxtools.ctf.core.tests/src/org/eclipse/linuxtools/ctf/core/tests/types/VariantDefinitionTest.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/ArrayDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/EnumDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/FloatDefinition.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/SequenceDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StringDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/StructDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/VariantDeclaration.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/StreamInputPacketReader.java
org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/internal/ctf/core/event/metadata/IOStructGen.java

index 7b5e2da1c13c58bbb4db6bae90b380c5a56c965c..b90a512a1f189cf8e53db94bd2704f1528e5ceca 100644 (file)
@@ -65,13 +65,13 @@ public class CTFEventFieldTest {
 
     /**
      * Run the CTFEventField parseField(Definition,String) method test.
-     * @throws CTFReaderException 
+     * @throws CTFReaderException
      */
     @Test
     public void testParseField_complex() throws CTFReaderException {
         int len = 32;
         IntegerDeclaration id = new IntegerDeclaration(len, false, len,
-                ByteOrder.LITTLE_ENDIAN, Encoding.ASCII, null);
+                ByteOrder.LITTLE_ENDIAN, Encoding.ASCII, null, 32);
         String lengthName = "LengthName"; //$NON-NLS-1$
         StructDeclaration structDec = new StructDeclaration(0);
         structDec.addField(lengthName, id);
@@ -93,7 +93,7 @@ public class CTFEventFieldTest {
 
     /**
      * Run the CTFEventField parseField(Definition,String) method test.
-     * @throws CTFReaderException 
+     * @throws CTFReaderException
      */
     @Test
     public void testParseField_simple() throws CTFReaderException {
@@ -110,7 +110,7 @@ public class CTFEventFieldTest {
     public void testParseField_simple2() {
         IntegerDefinition fieldDef = new IntegerDefinition(
                 new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
-                        Encoding.ASCII, null), null, fieldName);
+                        Encoding.ASCII, null, 8), null, fieldName);
         fieldDef.setValue(1L);
 
         assertNotNull(fieldDef);
@@ -136,7 +136,7 @@ public class CTFEventFieldTest {
     @Test
     public void testParseField_manual() {
         Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(20,
-                new IntegerDeclaration(8, false, 8, null, Encoding.UTF8, null)),
+                new IntegerDeclaration(8, false, 8, null, Encoding.UTF8, null, 8)),
                 null, fieldName);
         ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H');
         ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e');
@@ -160,7 +160,7 @@ public class CTFEventFieldTest {
     @Test
     public void testParseField_manual2() {
         Definition fieldDef = new ArrayDefinition(new ArrayDeclaration(12,
-                new IntegerDeclaration(32, false, 32, null, null, null)), null,
+                new IntegerDeclaration(32, false, 32, null, null, null, 8)), null,
                 fieldName);
         ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[0]).setValue('H');
         ((IntegerDefinition) ((ArrayDefinition) fieldDef).getDefinitions()[1]).setValue('e');
index 6f078863f866e26149345a60113680f5859eefa8..9f09b810fbe79f6bf7d50beae826877d9b842f18 100644 (file)
@@ -29,10 +29,10 @@ public class ReadTrace {
      */
     @SuppressWarnings("nls")
     public static void main(String[] args) {
-        final String TRACE_PATH = "Tests/traces/trace20m1";
+        final String TRACE_PATH = "/home/ematkho/lttng-traces/lt-hello-4175-20120405-092230";
 
         // Change this to enable text output
-        final boolean USE_TEXT = false;
+        final boolean USE_TEXT = true;
 
         final int LOOP_COUNT = 1;
 
@@ -70,7 +70,7 @@ public class ReadTrace {
                                 + trace.getOffset());
                         System.out.println(traceReader.getIndex() + ", "
                                 + output + ", " + ed.getDeclaration().getName()
-                                + ", " + ed.getCPU());
+                                + ", " + ed.getCPU() + ed.getFields().toString()) ;
                     }
 
                     traceReader.advance();
index b2bb8017018553c8a3a3ca56301c5ca4981ba7b8..906f1b571fefefd3382ee368b8573c4e0b4aa7a3 100644 (file)
@@ -67,14 +67,14 @@ public class ArrayDefinitionTest {
     }
 
     private ArrayDefinition createLongArray() {
-        IntegerDeclaration decl = new IntegerDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none"); //$NON-NLS-1$
+        IntegerDeclaration decl = new IntegerDeclaration(32, false, 10, ByteOrder.BIG_ENDIAN, Encoding.NONE, "none",8); //$NON-NLS-1$
         IntegerDefinition[] defs = createIntDefs(10, 32);
         ArrayDefinition temp = setUpDeclaration(decl, defs);
         return temp;
     }
 
     private ArrayDefinition createCharArray() {
-        IntegerDeclaration decl = new IntegerDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none"); //$NON-NLS-1$
+        IntegerDeclaration decl = new IntegerDeclaration(8, false, 10, ByteOrder.BIG_ENDIAN, Encoding.UTF8, "none",8); //$NON-NLS-1$
         IntegerDefinition[] defs = createIntDefs(4,8);
         ArrayDefinition temp = setUpDeclaration(decl, defs);
         return temp;
@@ -113,7 +113,7 @@ public class ArrayDefinitionTest {
 
             String content = "test" + i; //$NON-NLS-1$
             defs[i] = new IntegerDefinition(new IntegerDeclaration(bits, false,
-                    16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content), null, content);
+                    16, ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, content, 24), null, content);
             defs[i].setValue(i);
         }
         return defs;
@@ -226,7 +226,7 @@ public class ArrayDefinitionTest {
     @Test
     public void testIsString_complex() {
         final IntegerDeclaration id = new IntegerDeclaration(8, false, 16,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
         ArrayDeclaration ad = new ArrayDeclaration(0, id);
         ArrayDefinition ownFixture = new ArrayDefinition(ad, this.trace,
                 "Testx"); //$NON-NLS-1$
index e89c39b11406e775cc44bfab5c8f29d90639dc24..89ab4edf6f68bdc13f915d11ceb9826822cfa9fb 100644 (file)
@@ -43,7 +43,7 @@ public class EnumDeclarationTest {
     @Before
     public void setUp() {
         fixture = new EnumDeclaration(new IntegerDeclaration(1, true, 1,
-                ByteOrder.BIG_ENDIAN, Encoding.ASCII, null));
+                ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8));
     }
 
     /**
@@ -60,7 +60,7 @@ public class EnumDeclarationTest {
     @Test
     public void testEnumDeclaration() {
         IntegerDeclaration containerType = new IntegerDeclaration(1, true, 1,
-                ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
+                ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
 
         EnumDeclaration result = new EnumDeclaration(containerType);
 
index 15c827c1dbb29f3b7fe1218a14e307aeaa4538c2..a7d76d0fdcd8b25b95f08540fc7a5150ac58cb36 100644 (file)
@@ -44,7 +44,7 @@ public class EnumDefinitionTest {
     public void setUp() {
         EnumDeclaration declaration = new EnumDeclaration(
                 new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
-                        Encoding.ASCII, null));
+                        Encoding.ASCII, null, 8));
         String fieldName = ""; //$NON-NLS-1$
 
         fixture = new EnumDefinition(declaration, null, fieldName);
index b75873ffa625e7abb98553399b3022590d9433ea..c700365bbe4fdc0392ab79bd00d4f9e483968f5a 100644 (file)
@@ -38,7 +38,7 @@ public class IntegerDeclarationTest {
     @Before
     public void setUp() {
         fixture = new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
-                Encoding.ASCII, null);
+                Encoding.ASCII, null, 32);
     }
 
     /**
@@ -62,7 +62,7 @@ public class IntegerDeclarationTest {
         Encoding encoding = Encoding.ASCII;
 
         IntegerDeclaration result = new IntegerDeclaration(len, signed, base,
-                byteOrder, encoding, null);
+                byteOrder, encoding, null, 16);
 
         assertNotNull(result);
         assertEquals(1, result.getBase());
@@ -129,7 +129,7 @@ public class IntegerDeclarationTest {
     @Test
     public void testIsCharacter_8bytes() {
         IntegerDeclaration fixture8 = new IntegerDeclaration(8, true, 1,
-                ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
+                ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
 
         boolean result = fixture8.isCharacter();
         assertEquals(true, result);
@@ -150,56 +150,12 @@ public class IntegerDeclarationTest {
     @Test
     public void testIsSigned_unsigned() {
         IntegerDeclaration fixture_unsigned = new IntegerDeclaration(1, false,
-                1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
+                1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
 
         boolean result = fixture_unsigned.isSigned();
         assertEquals(false, result);
     }
 
-    /**
-     * Run the void setBase(int) method test.
-     */
-    @Test
-    public void testSetBase() {
-        int base = 1;
-        fixture.setBase(base);
-    }
-
-    /**
-     * Run the void setByteOrder(ByteOrder) method test.
-     */
-    @Test
-    public void testSetByteOrder() {
-        ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
-        fixture.setByteOrder(byteOrder);
-    }
-
-    /**
-     * Run the void setEncoding(Encoding) method test.
-     */
-    @Test
-    public void testSetEncoding() {
-        Encoding encoding = Encoding.ASCII;
-        fixture.setEncoding(encoding);
-    }
-
-    /**
-     * Run the void setLength(int) method test.
-     */
-    @Test
-    public void testSetLength() {
-        int length = 1;
-        fixture.setLength(length);
-    }
-
-    /**
-     * Run the void setSigned(boolean) method test.
-     */
-    @Test
-    public void testSetSigned() {
-        boolean signed = true;
-        fixture.setSigned(signed);
-    }
 
     /**
      * Run the String toString() method test.
index 1d6a8eb83f292ea104b16f8be3085d6f67d7bce0..2915e2755e18f319d1936f4269094bb39e432d85 100644 (file)
@@ -45,8 +45,8 @@ public class IntegerDefinitionTest {
     /**
      * Perform pre-test initialization. We know the structDef won't be null (or
      * else the tests will fail), so we can safely suppress the warning.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Before
     public void setUp() throws CTFReaderException {
@@ -88,7 +88,7 @@ public class IntegerDefinitionTest {
     @Test
     public void testIntegerDefinition() {
         IntegerDeclaration declaration = new IntegerDeclaration(1, true, 1,
-                ByteOrder.BIG_ENDIAN, Encoding.ASCII, null);
+                ByteOrder.BIG_ENDIAN, Encoding.ASCII, null, 8);
         IDefinitionScope definitionScope = null;
         String fieldName = ""; //$NON-NLS-1$
 
index 56c17d53fdbf3f04e317c5a044708e8167ad4977..f6cb96ffa3bfe440af9f5b02ad557822ee2f49b4 100644 (file)
@@ -71,7 +71,7 @@ public class SequenceDeclarationTest {
     @Test
     public void testCreateDefinition() {
         IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 32);
 
         StructDeclaration structDec = new StructDeclaration(0);
         structDec.addField(fieldName, id);
index 11745a81f1ec0403824928fe0bd7852b05c18ec4..5cf9b92887da3c149cae9f226345df628c342a67 100644 (file)
@@ -43,7 +43,7 @@ public class SequenceDefinitionTest {
 
     /**
      * Perform pre-test initialization.
-     * @throws CTFReaderException 
+     * @throws CTFReaderException
      */
     @Before
     public void setUp() throws CTFReaderException {
@@ -51,7 +51,7 @@ public class SequenceDefinitionTest {
         StructDefinition structDef;
 
         IntegerDeclaration id = new IntegerDeclaration(8, false, 8,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null, 8);
         String lengthName = "LengthName"; //$NON-NLS-1$
         structDec = new StructDeclaration(0);
         structDec.addField(lengthName, id);
@@ -83,7 +83,7 @@ public class SequenceDefinitionTest {
 
         int len = 32;
         IntegerDeclaration id = new IntegerDeclaration(len, false, len,
-                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null);
+                ByteOrder.LITTLE_ENDIAN, Encoding.UTF8, null,8);
         String lengthName = "LengthName"; //$NON-NLS-1$
         structDec = new StructDeclaration(0);
         structDec.addField(lengthName, id);
index e670f24c9648a8b455ceab004453874e48d1dbc9..cf2eb5d9c613d95a19de9fc199894efe409857c5 100644 (file)
@@ -51,8 +51,8 @@ public class VariantDefinitionTest {
      * Perform pre-test initialization.
      *
      * Not sure it needs to be that complicated, oh well...
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Before
     public void setUp() throws CTFReaderException {
@@ -76,7 +76,7 @@ public class VariantDefinitionTest {
         sDef2 = new StructDefinition(new StructDeclaration(1L), vDef2, fName);
 
         eDef = new EnumDefinition(new EnumDeclaration(new IntegerDeclaration(1,
-                true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, fName)), sDef2, fName);
+                true, 1, ByteOrder.BIG_ENDIAN, Encoding.ASCII, fName, 8)), sDef2, fName);
 
         fixture = new VariantDefinition(vDecl1, sDef1, fName);
         fixture.setTagDefinition(eDef);
@@ -93,8 +93,8 @@ public class VariantDefinitionTest {
 
     /**
      * Run the VariantDefinition(VariantDeclaration,DefinitionScope,String)
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Test
     public void testVariantDefinition() throws CTFReaderException {
@@ -276,8 +276,8 @@ public class VariantDefinitionTest {
 
     /**
      * Run the void setTagDefinition(EnumDefinition) method test.
-     * 
-     * @throws CTFReaderException 
+     *
+     * @throws CTFReaderException
      */
     @Test
     public void testSetTagDefinition() throws CTFReaderException {
@@ -293,7 +293,7 @@ public class VariantDefinitionTest {
         structDef = new StructDefinition(new StructDeclaration(1L), vDef, fName);
         tagDefinition = new EnumDefinition(new EnumDeclaration(
                 new IntegerDeclaration(1, true, 1, ByteOrder.BIG_ENDIAN,
-                        Encoding.ASCII, fName)), structDef, fName);
+                        Encoding.ASCII, fName, 8)), structDef, fName);
 
         fixture.setTagDefinition(tagDefinition);
     }
index 30730c7607c81dfd9b15db8bec5e74bab723cd20..84c5f599eccec24f7e223fa0fb205ec1683fe696 100644 (file)
@@ -45,6 +45,11 @@ public class ArrayDeclaration implements IDeclaration {
         return length;
     }
 
+    @Override
+    public long getAlignment() {
+        long retVal = this.getElementType().getAlignment();
+        return retVal;
+    }
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
index 2ae8b29d05230af7a3b3c55e3109d985736318fb..f1fa82cb44acd7960acbff8a90d63871db1efcc8 100644 (file)
@@ -43,6 +43,10 @@ public class EnumDeclaration implements IDeclaration {
         return containerType;
     }
 
+    @Override
+    public long getAlignment() {
+        return this.getContainerType().getAlignment();
+    }
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -137,4 +141,5 @@ public class EnumDeclaration implements IDeclaration {
         return "[declaration] enum[" + Integer.toHexString(hashCode()) + ']'; //$NON-NLS-1$
     }
 
+
 }
index da99c811beedf182b2f65da47ace43cfc135b7eb..89ef7e523b78968c9131f593bb939fbae64b0425 100644 (file)
@@ -8,6 +8,7 @@
  *
  * Contributors: Matthew Khouzam - Initial API and implementation
  *******************************************************************************/
+
 package org.eclipse.linuxtools.ctf.core.event.types;
 
 import java.nio.ByteOrder;
@@ -23,17 +24,19 @@ public class FloatDeclaration implements IDeclaration {
     private final int exp;
     private final ByteOrder byteOrder;
     private final Encoding encoding;
+    private final long alignment;
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
     public FloatDeclaration(int exponent, int mantissa, ByteOrder byteOrder,
-            Encoding encoding) {
+            Encoding encoding, long alignment) {
         mant = mantissa;
         exp = exponent;
         this.byteOrder = byteOrder;
         this.encoding = encoding;
+        this.alignment = alignment;
 
     }
 
@@ -41,8 +44,6 @@ public class FloatDeclaration implements IDeclaration {
     // Gettters/Setters/Predicates
     // ------------------------------------------------------------------------
 
-
-
     /**
      * @return the mant
      */
@@ -71,6 +72,10 @@ public class FloatDeclaration implements IDeclaration {
         return encoding;
     }
 
+    public long getAlignment() {
+        return alignment;
+    }
+
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
index cdb0a52797069e914a9200fbb870554a83ed71d9..dfc55087c5e22fdf616da0ec152991e1de7d57ef 100644 (file)
@@ -57,11 +57,11 @@ public class FloatDefinition extends Definition {
         int exp = declaration.getExponent();
         int mant = declaration.getMantissa();
         if( (exp + mant) == 32 ){
-            readRawFloat32(input, mant , exp);
+            value = readRawFloat32(input, mant , exp);
         }
         else if((exp + mant) == 64)
         {
-            readRawFloat64(input, mant,exp);
+            value = readRawFloat64(input, mant,exp);
         }
         else
         {
@@ -71,15 +71,13 @@ public class FloatDefinition extends Definition {
 
 
 
-    private void readRawFloat64(BitBuffer input, final int manBits, final int expBits) {
+    private static double readRawFloat64(BitBuffer input, final int manBits, final int expBits) {
        long low = input.getInt(32, false);
        low = low & 0x00000000FFFFFFFFL;
        long high = input.getInt(32, false);
        high = high & 0x00000000FFFFFFFFL;
        long temp = (high << 32) | low;
-
-
-       value = createFloat(temp, manBits, expBits);
+       return createFloat(temp, manBits-1, expBits);
     }
 
     /**
@@ -88,25 +86,24 @@ public class FloatDefinition extends Definition {
      * @param expBits
      */
     private static double createFloat(long rawValue, final int manBits, final int expBits) {
-        long manShift = 1L << manBits;
-           long manMask = manShift -1;
-           long expMask = (1L << expBits) -1;
-
-           int exp =(int)( rawValue >> manBits);
-           long man  = (rawValue & manMask);
-           double expPow = Math.pow(2.0, exp-(1 << (expBits-1)));
-           double ret = man * 1.0f;
-           ret /= manShift;
-           ret += 1.0;
-           ret *= expPow;
-           return ret;
+        long manShift = 1L << (manBits);
+        long manMask = manShift - 1;
+        long expMask = (1L << expBits) - 1;
+
+        int exp = (int) ((rawValue >> (manBits))&expMask)+1;
+        long man = (rawValue & manMask);
+        double expPow = Math.pow(2.0, exp - (1 << (expBits - 1)));
+        double ret = man * 1.0f;
+        ret /= manShift;
+        ret += 1.0;
+        ret *= expPow;
+        return ret;
     }
 
-    private void readRawFloat32(BitBuffer input, final int manBits,
+    private static double readRawFloat32(BitBuffer input, final int manBits,
     final int expBits) {
         long temp = input.getInt(32, false);
-
-        value = createFloat(temp, manBits, expBits);
+        return createFloat(temp, manBits-1, expBits);
     }
 
     @Override
index 87f86f2c4796112ff9ee06adb9a599d3510fc20f..171bad33ef6796ee01623562d6a2be6cae730928 100644 (file)
@@ -19,4 +19,6 @@ public interface IDeclaration {
 
     public Definition createDefinition(IDefinitionScope definitionScope,
             String fieldName);
+
+    public long getAlignment();
 }
index c8b7fbbf7017f9379ae725ccd92f2a97da16f6b0..32729d86b1ee97170121a11b902ba37057728f9d 100644 (file)
@@ -23,26 +23,27 @@ public class IntegerDeclaration implements IDeclaration {
     // Attributes
     // ------------------------------------------------------------------------
 
-    private int length;
-    private boolean signed;
-    private int base;
-    private ByteOrder byteOrder;
-    private Encoding encoding;
-    @SuppressWarnings("unused")
-    private final String clock;
+    final private int length;
+    final private boolean signed;
+    final private int base;
+    final private ByteOrder byteOrder;
+    final private Encoding encoding;
+    final private long alignment;
+    final private String clock;
 
     // ------------------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------------------
 
     public IntegerDeclaration(int len, boolean signed, int base,
-            ByteOrder byteOrder, Encoding encoding, String clock) {
+            ByteOrder byteOrder, Encoding encoding, String clock, long alignment) {
         this.length = len;
         this.signed = signed;
         this.base = base;
         this.byteOrder = byteOrder;
         this.encoding = encoding;
         this.clock = clock;
+        this.alignment = alignment;
     }
 
     // ------------------------------------------------------------------------
@@ -53,39 +54,19 @@ public class IntegerDeclaration implements IDeclaration {
         return signed;
     }
 
-    public void setSigned(boolean signed) {
-        this.signed = signed;
-    }
-
     public int getBase() {
         return base;
     }
 
-    public void setBase(int base) {
-        this.base = base;
-    }
-
     public ByteOrder getByteOrder() {
         return byteOrder;
     }
 
-    public void setByteOrder(ByteOrder byteOrder) {
-        this.byteOrder = byteOrder;
-    }
-
     public Encoding getEncoding() {
         return encoding;
     }
 
-    public void setEncoding(Encoding encoding) {
-        this.encoding = encoding;
-    }
-
-    public void setLength(int length) {
-        this.length = length;
-    }
-
-    public boolean isCharacter() {
+   public boolean isCharacter() {
         return (length == 8) && (encoding != Encoding.NONE);
     }
 
@@ -93,6 +74,13 @@ public class IntegerDeclaration implements IDeclaration {
         return length;
     }
 
+    public long getAlignment(){
+        return alignment;
+    }
+
+    public String getClock(){
+        return clock;
+    }
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
index 8532e6e67d9e7516f9d9a9d673ad2a0f968af2de..2ea5081bcb05604e89098d9deebd6669cd7395e1 100644 (file)
@@ -47,6 +47,10 @@ public class SequenceDeclaration implements IDeclaration {
         return lengthName;
     }
 
+    @Override
+    public long getAlignment() {
+        return getElementType().getAlignment();
+    }
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
index 5fc519d9b265a6627d2cfbdc2e52b7a0ca64a4e1..0f62d91732433e022e00d7866fa071e2dffa2e66 100644 (file)
@@ -50,6 +50,10 @@ public class StringDeclaration implements IDeclaration {
         this.encoding = encoding;
     }
 
+    @Override
+    public long getAlignment() {
+        return 8; //FIXME: should be the elementtype.
+    }
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
index 1e43be6b24e41aa7e98bb8c411810e853c70f328..2f0ef53b1df62bb2b18706fbcecc6f5f1104459e 100644 (file)
@@ -61,6 +61,10 @@ public class StructDeclaration implements IDeclaration {
         return this.fieldsList;
     }
 
+    @Override
+    public long getAlignment() {
+        return getMinAlign();
+    }
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
index bad6ba49a1a12448b1bd9a00acbd6b9af8cf34bc..c0338cf35a0f44e768f73f47621e20243a14f838 100644 (file)
@@ -24,6 +24,7 @@ public class VariantDeclaration implements IDeclaration {
     // ------------------------------------------------------------------------
 
     private String tag = null;
+    private long alignment;
     private final HashMap<String, IDeclaration> fields = new HashMap<String, IDeclaration>();
 
     // ------------------------------------------------------------------------
@@ -57,6 +58,10 @@ public class VariantDeclaration implements IDeclaration {
         return this.fields;
     }
 
+    @Override
+    public long getAlignment() {
+        return alignment;
+    }
     // ------------------------------------------------------------------------
     // Operations
     // ------------------------------------------------------------------------
@@ -69,6 +74,7 @@ public class VariantDeclaration implements IDeclaration {
 
     public void addField(String fieldTag, IDeclaration declaration) {
         fields.put(fieldTag, declaration);
+        alignment = Math.max(alignment, declaration.getAlignment());
     }
 
     @Override
index 53e410605edd4612557065f833b907a5e417904d..9b4b2cbbf67bab71b36fb9a801a2b01742d48c43 100644 (file)
@@ -294,7 +294,7 @@ class StreamInputPacketReader implements IDefinitionScope {
         long timestamp = 0;
 
         /*
-         * Read thestream event header.
+         * Read the stream event header.
          */
         if (getStreamEventHeaderDef() != null) {
             getStreamEventHeaderDef().read(getBitBuffer());
@@ -367,6 +367,11 @@ class StreamInputPacketReader implements IDefinitionScope {
          * Read the event fields.
          */
         if (eventDef.fields != null) {
+            int pos = getBitBuffer().position();
+            int minAlign = (int) eventDef.fields.getDeclaration().getMinAlign();
+            int offset = pos % minAlign;
+            pos += (minAlign - offset)%minAlign;
+            getBitBuffer().position(pos);
             eventDef.fields.read(getBitBuffer());
         }
 
index 45707a7df9af074f335f481a35a7bde4e2e6e666..7e3071960d424357027bff3dbc61bb1fbe9dfdeb 100644 (file)
@@ -1256,7 +1256,7 @@ public class IOStructGen {
             }
         }
 
-        floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, encoding);
+        floatDeclaration = new FloatDeclaration(exponent, mantissa, byteOrder, encoding, alignment);
 
         assert (floatDeclaration != null);
         return floatDeclaration;
@@ -1387,7 +1387,7 @@ public class IOStructGen {
         }
 
         integerDeclaration = new IntegerDeclaration((int) size, signed, base,
-                byteOrder, encoding, clock);
+                byteOrder, encoding, clock, alignment);
 
         assert (integerDeclaration != null);
         return integerDeclaration;
@@ -1551,6 +1551,12 @@ public class IOStructGen {
 
             /* Parse the body */
             parseStructBody(structBody, structDeclaration);
+            long maxFieldAlign = -1;
+            for( IDeclaration field : structDeclaration.getFields().values())
+            {
+                maxFieldAlign = Math.max(maxFieldAlign, field.getAlignment());
+            }
+            structDeclaration.setMinAlign(maxFieldAlign);
 
             /* If struct has name, add it to the current scope. */
             if (hasName) {
This page took 0.042897 seconds and 5 git commands to generate.