< prev index next >

test/jdk/java/nicl/types/StructTest.java

Print this page




  28 
  29 import java.nicl.*;
  30 import java.nicl.metadata.*;
  31 import java.nicl.metadata.Array;
  32 import java.nicl.types.*;
  33 
  34 public class StructTest {
  35     public static final boolean DEBUG = Boolean.getBoolean("StructTest.DEBUG");
  36 
  37     public static final long TOTAL_SIZE = 16;
  38     public static final long A_OFFSET  = 0;
  39     public static final long A_LENGTH  = 4;
  40     public static final long M_OFFSET  = 256;
  41     public static final long MA_OFFSET = 512;
  42     public static final int MA_LENGTH = 2;
  43 
  44     public static long alignUp(long n, long alignment) {
  45         return (n + alignment - 1) & ~(alignment - 1);
  46     }
  47 
  48     @C(file="dummy", line=47, column=11, USR="c:@S@MyStruct")
  49     @NativeType(layout="[4i]", ctype="struct MyStruct", size=16l, isRecordType=true)

  50     static interface MyStruct extends Struct<MyStruct> {
  51         @C(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@field1")
  52         @NativeType(layout="4i", ctype="off_t", size=4l)
  53         @Array(elementType="int", elementSize=4l, length=4l)
  54         @Offset(offset=0l)
  55         int[] a$get();
  56         void a$set(int[] a);
  57     }
  58 
  59     public int buildInt(long baseValue) {
  60         int tmp = 0;
  61 
  62         for (int i = 0; i < 4; i++) {
  63             tmp |= baseValue++ << (i * 8);
  64         }
  65 
  66         return tmp;
  67     }
  68 
  69 
  70     public long buildLong(long baseValue) {
  71         long tmp = 0;
  72 




  28 
  29 import java.nicl.*;
  30 import java.nicl.metadata.*;
  31 import java.nicl.metadata.Array;
  32 import java.nicl.types.*;
  33 
  34 public class StructTest {
  35     public static final boolean DEBUG = Boolean.getBoolean("StructTest.DEBUG");
  36 
  37     public static final long TOTAL_SIZE = 16;
  38     public static final long A_OFFSET  = 0;
  39     public static final long A_LENGTH  = 4;
  40     public static final long M_OFFSET  = 256;
  41     public static final long MA_OFFSET = 512;
  42     public static final int MA_LENGTH = 2;
  43 
  44     public static long alignUp(long n, long alignment) {
  45         return (n + alignment - 1) & ~(alignment - 1);
  46     }
  47 
  48     @NativeLocation(file="dummy", line=47, column=11, USR="c:@S@MyStruct")
  49     @NativeStruct("[4i]")
  50     @NativeType(ctype="struct MyStruct")
  51     static interface MyStruct extends Struct<MyStruct> {
  52         @NativeLocation(file="dummy", line=47, column=11, USR="c:@SA@MyStruct@field1")
  53         @NativeType(layout="4i", ctype="off_t")
  54         @Array(elementType="int", elementSize=4l, length=4l)
  55         @Offset(offset=0l)
  56         int[] a$get();
  57         void a$set(int[] a);
  58     }
  59 
  60     public int buildInt(long baseValue) {
  61         int tmp = 0;
  62 
  63         for (int i = 0; i < 4; i++) {
  64             tmp |= baseValue++ << (i * 8);
  65         }
  66 
  67         return tmp;
  68     }
  69 
  70 
  71     public long buildLong(long baseValue) {
  72         long tmp = 0;
  73 


< prev index next >