From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26435 invoked by alias); 21 Nov 2007 20:13:56 -0000 Received: (qmail 26385 invoked by uid 9708); 21 Nov 2007 20:13:56 -0000 Date: Wed, 21 Nov 2007 20:13:00 -0000 Message-ID: <20071121201356.26370.qmail@sourceware.org> From: tthomas@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Slice operation for array types. X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 87b91e7ae7c2e392a0ce9fb24626e202835e4d99 X-Git-Newrev: b1e11394a6989b141abfb1c708d3c0566bfb5847 Mailing-List: contact frysk-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: frysk-cvs-owner@sourceware.org Reply-To: frysk@sourceware.org X-SW-Source: 2007-q4/txt/msg00417.txt.bz2 The branch, master has been updated via b1e11394a6989b141abfb1c708d3c0566bfb5847 (commit) via 525ef64021a632e20ccd48f6e3c18d1b97b5a1ce (commit) from 87b91e7ae7c2e392a0ce9fb24626e202835e4d99 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit b1e11394a6989b141abfb1c708d3c0566bfb5847 Author: Teresa Thomas Date: Wed Nov 21 15:13:09 2007 -0500 Slice operation for array types. frysk-core/frysk/value/ChangeLog 2007-11-21 Teresa Thomas * ArrayType.java (slice): New. * Type.java (slice): New. * TypeDecorator.java (slice): New. * TestArray.java (testSlice): New test. frysk-core/frysk/expr/ChangeLog 2007-11-21 Teresa Thomas * CExprEvaluator.g (SLICE): New. * CExpr.g: Add grammar for slice operation. commit 525ef64021a632e20ccd48f6e3c18d1b97b5a1ce Author: Teresa Thomas Date: Wed Nov 21 11:27:52 2007 -0500 Commenting and reindentation. frysk-core/frysk/value/ChangeLog 2007-11-21 Teresa Thomas * Type.java: Comments added. * TypeDecorator.java: Re-indent. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/expr/CExpr.g | 10 ++- frysk-core/frysk/expr/CExprEvaluator.g | 7 ++- frysk-core/frysk/expr/ChangeLog | 5 ++ frysk-core/frysk/value/ArrayType.java | 39 ++++++++++++ frysk-core/frysk/value/ChangeLog | 11 ++++ frysk-core/frysk/value/TestArray.java | 16 +++++ frysk-core/frysk/value/Type.java | 22 +++++++- frysk-core/frysk/value/TypeDecorator.java | 93 +++++++++++++++-------------- 8 files changed, 152 insertions(+), 51 deletions(-) First 500 lines of diff: diff --git a/frysk-core/frysk/expr/CExpr.g b/frysk-core/frysk/expr/CExpr.g index 3ed9860..037ba18 100644 --- a/frysk-core/frysk/expr/CExpr.g +++ b/frysk-core/frysk/expr/CExpr.g @@ -115,6 +115,7 @@ imaginaryTokenDefinitions MEMBER SIZEOF INDEX + SLICE ; /** @@ -321,9 +322,12 @@ postfix_expression! astPostExpr = #(#[MEMBER, "Member"], #astPostExpr, #id_expr2); } ) - | LSQUARE arrExpr1:expressionList RSQUARE - { astPostExpr = #(#[INDEX, "Index"], #astPostExpr, #arrExpr1); - } + | LSQUARE arrExpr1:expressionList + ( RSQUARE { astPostExpr = #(#[INDEX, "Index"], + #astPostExpr, #arrExpr1); } + | COLON arrExpr2:expressionList RSQUARE { astPostExpr = #(#[SLICE, "Slice"], + #astPostExpr, #arrExpr1, #arrExpr2); } + ) | LPAREN! expressionList RPAREN! | PLUSPLUS { astPostExpr = #(PLUSPLUS, #astPostExpr); diff --git a/frysk-core/frysk/expr/CExprEvaluator.g b/frysk-core/frysk/expr/CExprEvaluator.g index 1cb0c25..d751de3 100644 --- a/frysk-core/frysk/expr/CExprEvaluator.g +++ b/frysk-core/frysk/expr/CExprEvaluator.g @@ -132,7 +132,7 @@ identifier returns [String idSpelling=null] : ident:IDENT {idSpelling=ident.getText();} ; expr returns [Value returnVar=null] -{ Value v1, v2, log_expr; String s1; } +{ Value v1, v2, v3, log_expr; String s1; } : #(PLUS v1=expr v2=expr) { returnVar = v1.getType().getALU(v2.getType(), exprSymTab.getWordSize()) @@ -382,7 +382,10 @@ expr returns [Value returnVar=null] } | #(INDEX v1=expr v2=expr) { returnVar = v1.getType().index(v1, v2, exprSymTab.taskMemory()); - } + } + | #(SLICE v1=expr v2=expr v3=expr) { + returnVar = v1.getType().slice(v1, v2, v3, exprSymTab.taskMemory()); + } | ident:IDENT { returnVar = ((Value)exprSymTab.getValue(ident.getText())); } diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog index 655400e..5fea450 100644 --- a/frysk-core/frysk/expr/ChangeLog +++ b/frysk-core/frysk/expr/ChangeLog @@ -1,3 +1,8 @@ +2007-11-21 Teresa Thomas + + * CExprEvaluator.g (SLICE): New. + * CExpr.g: Add grammar for slice operation. + 2007-11-20 Stan Cox * CExprEvaluator.g: Remove lib.dwfl.BaseTypes; diff --git a/frysk-core/frysk/value/ArrayType.java b/frysk-core/frysk/value/ArrayType.java index c5e7b06..0011ead 100644 --- a/frysk-core/frysk/value/ArrayType.java +++ b/frysk-core/frysk/value/ArrayType.java @@ -160,6 +160,45 @@ public class ArrayType } /** + * Slice returns a slice of an array. For example: + * SLICE[1:2] on {9, 8, 7, 6} returns {8, 7} + * SLICE[1:2] on { {11, 11}, {0, 0}, {9, 9} } returns { {0, 0}, {9, 9} } + * + * Note: j should be greater than i. + */ + public Value slice (Value v, Value i, Value j, ByteBuffer taskMem) + { + int len = (int)(j.asLong() - i.asLong() + 1); + + // FIXME: Allow this case instead of throwing error? + if (len < 0) { + throw new RuntimeException("Error: Index 1 should be less than Index 2"); + } + + // Create a new dimensions list + ArrayList dims = new ArrayList(); + // Length of elements at 0th dimension changes. + // Rest remain same. + dims.add(new Integer(len-1)); + for (int k=1; k + + * ArrayType.java (slice): New. + * Type.java (slice): New. + * TypeDecorator.java (slice): New. + * TestArray.java (testSlice): New test. + + * Type.java: Comments added. + * TypeDecorator.java: Re-indent. + (slice): New. + 2007-11-20 Sami Wagiaalla * Variable.java (toPrint): No longer prints variable values; diff --git a/frysk-core/frysk/value/TestArray.java b/frysk-core/frysk/value/TestArray.java index 25015c6..1147d10 100644 --- a/frysk-core/frysk/value/TestArray.java +++ b/frysk-core/frysk/value/TestArray.java @@ -100,6 +100,22 @@ public class TestArray extends TestCase { } /** + * Test slice operation for 1-d array. + */ + public void testSlice() { + ArrayList dims = new ArrayList(); + dims.add(new Integer(4 - 1)); + ArrayType arrayType = new ArrayType(int4_t, buf.length , dims); + Value arr = new Value(arrayType, new ScratchLocation(buf)); + Location l1 = new ScratchLocation(new byte[] { 1 }); + Location l2 = new ScratchLocation(new byte[] { 3 }); + IntegerType t = new UnsignedType("type", ByteOrder.BIG_ENDIAN, 1); + Value idx1 = new Value(t, l1); + Value idx2 = new Value(t, l2); + assertEquals("Array[idx1:idx2]", "{84281096,151653132,219025168}", arrayType.slice(arr, idx1, idx2, null).toPrint()); + } + + /** * Test add operation for 1-d array. */ public void testAdd() { diff --git a/frysk-core/frysk/value/Type.java b/frysk-core/frysk/value/Type.java index f9c16e7..e2e4018 100644 --- a/frysk-core/frysk/value/Type.java +++ b/frysk-core/frysk/value/Type.java @@ -146,17 +146,29 @@ public abstract class Type { public ArithmeticUnit getALU(int wordSize) { throw new RuntimeException("Invalid Arithmetic Unit"); } - + + /** + * Evaluates the address of a variable. + */ public Value addressOf(Value var1, ByteOrder order, int wordSize) { PointerType pType = new PointerType("AddressPtr", order, wordSize, this); return pType.createValue(var1.getLocation().getAddress()); } + /** + * Implements dereference operation for a pointer type. + */ public Value dereference(Value var1, ByteBuffer taskMem) { throw new InvalidOperatorException(this, "*"); } + /** + * Implements dot operation on a composite type. + */ public Value member(Value var1, String member) { throw new InvalidOperatorException(this, "."); } + /** + * Implements subscript operation for a pointer or array type. + */ public Value index(Value var1, Value var2, ByteBuffer taskMem) { // In C, var1[var2] = var2[var1] if (var2.getType() instanceof ArrayType || @@ -165,6 +177,14 @@ public abstract class Type { throw new InvalidOperatorException(this, "[]"); } + /** + * Implements slice operation for a pointer or array type - slice + * the array from index I to index J. + */ + public Value slice(Value var, Value i, Value j, ByteBuffer taskMem) { + throw new InvalidOperatorException(this, "slice"); + } + /** * Assign VALUE to LOCATION; possibly performing type-conversion. */ diff --git a/frysk-core/frysk/value/TypeDecorator.java b/frysk-core/frysk/value/TypeDecorator.java index a597ccc..307ad4d 100644 --- a/frysk-core/frysk/value/TypeDecorator.java +++ b/frysk-core/frysk/value/TypeDecorator.java @@ -49,56 +49,59 @@ import inua.eio.ByteBuffer; */ abstract class TypeDecorator extends Type { - private Type decorated; - TypeDecorator(String name, Type decorated) { - super(name, decorated.getSize()); - this.decorated = decorated; - } + private Type decorated; + TypeDecorator(String name, Type decorated) { + super(name, decorated.getSize()); + this.decorated = decorated; + } - public String toString() { - return ("{" - + super.toString() - + ",decorated=" + decorated.toString() - + "}"); - } + public String toString() { + return ("{" + + super.toString() + + ",decorated=" + decorated.toString() + + "}"); + } - public Type getUltimateType() { - return decorated.getUltimateType(); - } + public Type getUltimateType() { + return decorated.getUltimateType(); + } - public int getSize() { - return decorated.getSize(); - } + public int getSize() { + return decorated.getSize(); + } - void toPrint(PrintWriter writer, Location location, - ByteBuffer memory, Format format, int indent) { - decorated.toPrint(writer, location, memory, format, 0); + void toPrint(PrintWriter writer, Location location, + ByteBuffer memory, Format format, int indent) { + decorated.toPrint(writer, location, memory, format, 0); + } + /** + * A guess; sub classes should override. + */ + public void toPrint(PrintWriter writer, int indent) { + if (getUltimateType() instanceof PointerType) { + decorated.toPrint(writer, 0); + writer.print(" " + getName()); } - /** - * A guess; sub classes should override. - */ - public void toPrint(PrintWriter writer, int indent) { - if (getUltimateType() instanceof PointerType) { - decorated.toPrint(writer, 0); - writer.print(" " + getName()); - } - else { - writer.print(getName()); - writer.print(" "); - decorated.toPrint(writer, 0); - } + else { + writer.print(getName()); + writer.print(" "); + decorated.toPrint(writer, 0); } + } - void assign(Location location, Value value) { - decorated.assign(location, value); - } - public Type pack(int bitSize, int bitOffset) { - return decorated.pack(bitSize, bitOffset); - } - public Value member(Value var1, String member) { - return decorated.member(var1, member); - } - public Value index(Value var1, Value var2, ByteBuffer taskMem) { - return decorated.index(var1, var2, taskMem); - } + void assign(Location location, Value value) { + decorated.assign(location, value); + } + public Type pack(int bitSize, int bitOffset) { + return decorated.pack(bitSize, bitOffset); + } + public Value member(Value var1, String member) { + return decorated.member(var1, member); + } + public Value index(Value var1, Value var2, ByteBuffer taskMem) { + return decorated.index(var1, var2, taskMem); + } + public Value slice(Value var1, Value var2, Value var3, ByteBuffer taskMem) { + return decorated.slice(var1, var2, var3, taskMem); + } } hooks/post-receive -- frysk system monitor/debugger