[SCM] master: Slice operation for pointers. Format - ptr[i:j]

tthomas@sourceware.org tthomas@sourceware.org
Mon Nov 26 21:20:00 GMT 2007


The branch, master has been updated
       via  192fa4ac83d415465dbe2e4477f123fc82d122e5 (commit)
      from  de0b15f0884e98811140b942d64325e8225d15ac (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 192fa4ac83d415465dbe2e4477f123fc82d122e5
Author: Teresa Thomas <tthomas@redhat.com>
Date:   Mon Nov 26 15:56:27 2007 -0500

    Slice operation for pointers. Format - ptr[i:j]
    
    frysk-core/frysk/value/ChangeLog
    2007-11-26  Teresa Thomas  <tthomas@redhat.com>
    
    	* PointerType.java (slice): New.
    	* TestPointer.java (testCharPointerSlice): New test.
    
    frysk-core/frysk/pkglibdir/ChangeLog
    2007-11-26 Teresa Thomas <tthomas@redhat.com>
    
    	* funit-addresses.c (ptrStrings): New.

-----------------------------------------------------------------------

Summary of changes:
 frysk-core/frysk/pkglibdir/ChangeLog         |    4 ++
 frysk-core/frysk/pkglibdir/funit-addresses.c |    1 +
 frysk-core/frysk/value/ChangeLog             |    5 +++
 frysk-core/frysk/value/PointerType.java      |   43 ++++++++++++++++++++++++-
 frysk-core/frysk/value/TestPointer.java      |   22 ++++++++++++-
 5 files changed, 72 insertions(+), 3 deletions(-)

First 500 lines of diff:
diff --git a/frysk-core/frysk/pkglibdir/ChangeLog b/frysk-core/frysk/pkglibdir/ChangeLog
index 47a460b..67dfeab 100644
--- a/frysk-core/frysk/pkglibdir/ChangeLog
+++ b/frysk-core/frysk/pkglibdir/ChangeLog
@@ -1,3 +1,7 @@
+2007-11-26 Teresa Thomas <tthomas@redhat.com>
+
+	* funit-addresses.c (ptrStrings): New.
+	
 2007-11-26  Stan Cox  <scox@redhat.com>
 
 	* gen-type-funit-tests.py: Cleanup imports.
diff --git a/frysk-core/frysk/pkglibdir/funit-addresses.c b/frysk-core/frysk/pkglibdir/funit-addresses.c
index e35142d..ba02f13 100644
--- a/frysk-core/frysk/pkglibdir/funit-addresses.c
+++ b/frysk-core/frysk/pkglibdir/funit-addresses.c
@@ -64,6 +64,7 @@ int twoD[2][3] = { {99, 88, 77},
 int oneD[] = { 4, 3, 2, 1};                
 char* string = "hello world";
 int* ptr = NULL;
+char* ptrStrings[] = {"zero", "one", "two", "three"};
 
 int main(int argc, char* argv[])
 {
diff --git a/frysk-core/frysk/value/ChangeLog b/frysk-core/frysk/value/ChangeLog
index ce55ce4..46a2743 100644
--- a/frysk-core/frysk/value/ChangeLog
+++ b/frysk-core/frysk/value/ChangeLog
@@ -1,3 +1,8 @@
+2007-11-26  Teresa Thomas  <tthomas@redhat.com>
+
+	* PointerType.java (slice): New.
+	* TestPointer.java (testCharPointerSlice): New test.
+	
 2007-11-22  Sami Wagiaalla  <swagiaal@redhat.com>
 
 	* CompositeType.java (addStaticMember): New overloaded functions.
diff --git a/frysk-core/frysk/value/PointerType.java b/frysk-core/frysk/value/PointerType.java
index 0e6cad1..6766a1e 100644
--- a/frysk-core/frysk/value/PointerType.java
+++ b/frysk-core/frysk/value/PointerType.java
@@ -44,6 +44,7 @@ import inua.eio.ByteBuffer;
 import inua.eio.ByteOrder;
 import java.io.PrintWriter;
 import java.math.BigInteger;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -124,13 +125,51 @@ public class PointerType
     }
 
     /**
-     * Index Operation for pointers to strings.
+     * Index Operation for pointers.
      */
     public Value index (Value v, Value idx, ByteBuffer taskMem)
     {    
-	Value offset = createValue (v.asLong() + idx.asLong()*type.getSize());
+	Value offset = createValue (v.asLong() + idx.asLong()*type.getSize());	
 	return dereference (offset, taskMem) ;      
     }    
+    
+    /**
+     * Slice operation for pointers. 
+     * 
+     * Supports upto 2-dimensional results.
+     */
+    public Value slice (Value v, Value i, Value j, ByteBuffer taskMem)
+    {
+	// Evaluate length and offset of slice.
+	long offset = v.asLong() + i.asLong()*type.getSize();	
+	int len = (int)(j.asLong() - i.asLong() + 1)*type.getSize();	
+	// Create a simple memory location with it.
+	Location loc = PieceLocation.createSimpleLoc
+	               (offset, len, taskMem);
+	
+	/* Determine return type.
+	 * Note: Slicing can give one D or multi-D results 
+	 * depending on the type of value being pointed to.
+         */
+	
+	ArrayList dims = new ArrayList();
+	// Set default return type as type of value being
+	// pointed to.
+	Type resultType = type;
+	
+	// When length of slice calculated is greater than type's 
+	// size, result will be an array.
+	if (len > type.getSize())
+	{
+	    dims.add(new Integer(len/type.getSize()-1));
+	    // Create 2-d arrays in case of ptrs to ptrs or arrays.
+	    if (type instanceof PointerType || type instanceof ArrayType)
+		dims.add(new Integer(len-1));
+	    resultType =  new ArrayType(type, len, dims);
+	}	
+	
+	return new Value (resultType, loc);
+    }
 
     /* getALUs are double dispatch functions to determine 
      * the ArithmeticUnit for an operation between two types.
diff --git a/frysk-core/frysk/value/TestPointer.java b/frysk-core/frysk/value/TestPointer.java
index 7ff487e..5e266a5 100644
--- a/frysk-core/frysk/value/TestPointer.java
+++ b/frysk-core/frysk/value/TestPointer.java
@@ -66,7 +66,7 @@ public class TestPointer
 	// Construct a buffer with a string in it.
 	ArrayByteBuffer memory
 	    = new ArrayByteBuffer("0123Hello World\0>>>".getBytes());
-	Type t = new PointerType("xxx", ByteOrder.BIG_ENDIAN, 1,
+	Type t = new PointerType("Char ptr", ByteOrder.BIG_ENDIAN, 1,
 				 new CharType("char", ByteOrder.BIG_ENDIAN,
 					      1, true));
 	// Construct the pointer to it..
@@ -78,4 +78,24 @@ public class TestPointer
 	Value idx = new Value(t_idx, l_idx);
 	assertEquals("toPrint", "\'W\'", t.index(string, idx, memory).toPrint());
     }
+    
+    public void testCharPointerSlice() {
+	// Construct a buffer with a string in it.
+	ArrayByteBuffer memory
+	    = new ArrayByteBuffer("0123Hello World\0>>>".getBytes());
+	Type t = new PointerType("Char ptr", ByteOrder.BIG_ENDIAN, 1,
+				 new CharType("char", ByteOrder.BIG_ENDIAN,
+					      1, true));
+	// Construct the pointer to it..
+	Location l = new ScratchLocation(new byte[] { 4 });
+	Value string = new Value (t, l);
+	// Create indices
+	Location l_idx = new ScratchLocation(new byte[] { 6 });
+	IntegerType t_idx = new UnsignedType("type", ByteOrder.BIG_ENDIAN, 1);
+	Location l_idx2 = new ScratchLocation(new byte[] { 8 });
+	IntegerType t_idx2 = new UnsignedType("type", ByteOrder.BIG_ENDIAN, 1);	
+	Value idx = new Value(t_idx, l_idx);
+	Value idx2 = new Value(t_idx2, l_idx2);	
+	assertEquals("toPrint", "\"Wor\"", t.slice(string, idx, idx2, memory).toPrint());
+    }    
 }


hooks/post-receive
--
frysk system monitor/debugger



More information about the Frysk-cvs mailing list