public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: tthomas@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Implement arithmetic and logical operations in ArithmeticUnit. Date: Fri, 09 Nov 2007 19:28:00 -0000 [thread overview] Message-ID: <20071109192817.15810.qmail@sourceware.org> (raw) The branch, master has been updated via 90461168c98edfed137f66e8633b66e04e15f499 (commit) from 0f6d423b274fdbde0e75003e468a041032284a8f (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit 90461168c98edfed137f66e8633b66e04e15f499 Author: Teresa Thomas <tthomas@redhat.com> Date: Fri Nov 9 14:22:27 2007 -0500 Implement arithmetic and logical operations in ArithmeticUnit. frysk-core/frysk/value/ChangeLog 2007-11-09 Teresa Thomas <tthomas@redhat.com> * FloatingPointUnit.java (lessThan): New. (greaterThan): New. (greaterThanOrEqualTo): New. (lessThanOrEqualTo): New. (equal): New. (notEqual): New. * IntegerUnit.java (shiftLeft): New. (lessThan): New. (greaterThan): New. (greaterThanOrEqualTo): New. (lessThanOrEqualTo): New. (equal): New. (notEqual): New. (bitWiseAnd): New. (bitWiseXor): New. (bitWiseOr): New. (bitWiseComplement): New. (logicalAnd): New. (logicalOr): New. (logicalNegation): New. (getLogicalValue): New. * Type.java (shiftLeft): Delete. (shiftRight): Delete. (lessThan): Delete. (greaterThan): Delete. (lessThanOrEqualTo): Delete. (greaterThanOrEqualTo): Delete. (equal): Delete. (notEqual): Delete. (bitWiseAnd): Delete. (bitWiseXor): Delete. (bitWiseOr): Delete. (bitWiseComplement): Delete. (logicalAnd): Delete. (logicalOr): Delete. (logicalNegation): Delete. (shiftLeftEqual): Delete. (shiftRightEqual): Delete. (bitWiseOrEqual): Delete. (bitWiseXorEqual): Delete. (bitWiseAndEqual): Delete. (getLogicalValue): Delete. * TypeDecorator.java: Delete above functions. * ArithmeticType.java: Ditto. (returnType): Delete function. * ArithmeticUnit.java: Add above functions. * TestValue.java: Updated. frysk-core/frysk/expr/ChangeLog 2007-11-09 Teresa Thomas <tthomas@redhat.com> * CExprEvaluator.g: Update evaluator to use Arithmetic Unit. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/expr/CExprEvaluator.g | 96 ++++++++---- frysk-core/frysk/expr/ChangeLog | 5 + frysk-core/frysk/value/ArithmeticType.java | 217 +------------------------ frysk-core/frysk/value/ArithmeticUnit.java | 105 +++++++++++-- frysk-core/frysk/value/ChangeLog | 50 ++++++ frysk-core/frysk/value/FloatingPointUnit.java | 51 ++++-- frysk-core/frysk/value/IntegerUnit.java | 89 +++++++++-- frysk-core/frysk/value/TestValue.java | 50 +++--- frysk-core/frysk/value/Type.java | 68 +-------- frysk-core/frysk/value/TypeDecorator.java | 72 +-------- 10 files changed, 359 insertions(+), 444 deletions(-) First 500 lines of diff: diff --git a/frysk-core/frysk/expr/CExprEvaluator.g b/frysk-core/frysk/expr/CExprEvaluator.g index 087ca64..411e134 100644 --- a/frysk-core/frysk/expr/CExprEvaluator.g +++ b/frysk-core/frysk/expr/CExprEvaluator.g @@ -193,58 +193,92 @@ expr returns [Value returnVar=null] .modEqual(v1, v2); } | #(MEMORY v1=expr ) { - returnVar = v1.getType().dereference(v1, exprSymTab.taskMemory()); + returnVar = v1.getType() + .dereference(v1, exprSymTab.taskMemory()); } | #(SHIFTLEFT v1=expr v2=expr) { - returnVar = v1.getType().shiftLeft(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .shiftLeft(v1, v2); } | #(SHIFTRIGHT v1=expr v2=expr) { - returnVar = v1.getType().shiftRight(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .shiftRight(v1, v2); } | #(LESSTHAN v1=expr v2=expr) { - returnVar = v1.getType().lessThan(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .lessThan(v1, v2); } | #(GREATERTHAN v1=expr v2=expr) { - returnVar = v1.getType().greaterThan(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .greaterThan(v1, v2); } | #(LESSTHANOREQUALTO v1=expr v2=expr) { - returnVar = v1.getType().lessThanOrEqualTo(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .lessThanOrEqualTo(v1, v2); } | #(GREATERTHANOREQUALTO v1=expr v2=expr) { - returnVar = v1.getType().greaterThanOrEqualTo(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .greaterThanOrEqualTo(v1, v2); } | #(NOTEQUAL v1=expr v2=expr) { - returnVar = v1.getType().notEqual(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .notEqual(v1, v2); } | #(EQUAL v1=expr v2=expr) { - returnVar = v1.getType().equal(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .equal(v1, v2); } | ( #(AMPERSAND expr expr) )=>#(AMPERSAND v1=expr v2=expr) { - returnVar = v1.getType().bitWiseAnd(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .bitWiseAnd(v1, v2); } | #(ADDRESS_OF v1=expr ) { - returnVar = v1.getType().addressOf(v1, exprSymTab.order(), exprSymTab.getWordSize()); + returnVar = v1.getType().addressOf(v1, + exprSymTab.order(), exprSymTab.getWordSize()); } | #(BITWISEXOR v1=expr v2=expr) { - returnVar = v1.getType().bitWiseXor(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .bitWiseXor(v1, v2); } | #(BITWISEOR v1=expr v2=expr) { - returnVar = v1.getType().bitWiseOr(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .bitWiseOr(v1, v2); } | #(AND v1=expr v2=expr) { - returnVar = v1.getType().logicalAnd(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .logicalAnd(v1, v2); } | #(OR v1=expr v2=expr) { - returnVar = v1.getType().logicalOr(v1, v2); + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .logicalOr(v1, v2); } | #(NOT v1=expr) { - returnVar = v1.getType().logicalNegation(v1); + returnVar = v1.getType().getALU(v1.getType(), + exprSymTab.getWordSize()) + .logicalNegation(v1); } | #(TILDE v1=expr) { - returnVar = v1.getType().bitWiseComplement(v1); + returnVar = v1.getType().getALU(v1.getType(), + exprSymTab.getWordSize()) + .bitWiseComplement(v1); } | #(COND_EXPR log_expr=expr v1=expr v2=expr) { - returnVar = ((log_expr.getType().getLogicalValue(log_expr)) ? v1 : v2); + returnVar = ((log_expr.getType().getALU(log_expr.getType(), + exprSymTab.getWordSize()) + .getLogicalValue(log_expr)) ? v1 : v2); } | o:OCTALINT { char c = o.getText().charAt(o.getText().length() - 1); @@ -291,24 +325,30 @@ expr returns [Value returnVar=null] returnVar = v1; } | #(SHIFTLEFTEQUAL v1=expr v2=expr) { - v1.getType().shiftLeftEqual(v1, v2); - returnVar = v1; + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .shiftLeftEqual(v1, v2); } | #(SHIFTRIGHTEQUAL v1=expr v2=expr) { - v1.getType().shiftRightEqual(v1, v2); - returnVar = v1; + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .shiftRightEqual(v1, v2); } | #(BITWISEANDEQUAL v1=expr v2=expr) { - v1.getType().bitWiseAndEqual(v1, v2); - returnVar = v1; + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .bitWiseAndEqual(v1, v2); + } | #(BITWISEXOREQUAL v1=expr v2=expr) { - v1.getType().bitWiseXorEqual(v1, v2); - returnVar = v1; + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .bitWiseXorEqual(v1, v2); } | #(BITWISEOREQUAL v1=expr v2=expr) { - v1.getType().bitWiseOrEqual(v1, v2); - returnVar = v1; + returnVar = v1.getType().getALU(v2.getType(), + exprSymTab.getWordSize()) + .bitWiseOrEqual(v1, v2); } | #(CAST pt:primitiveType v2=expr) { if(pt.getText().compareTo("long") == 0) { diff --git a/frysk-core/frysk/expr/ChangeLog b/frysk-core/frysk/expr/ChangeLog index 313f07b..24693ab 100644 --- a/frysk-core/frysk/expr/ChangeLog +++ b/frysk-core/frysk/expr/ChangeLog @@ -1,3 +1,8 @@ +2007-11-09 Teresa Thomas <tthomas@redhat.com> + + * CExprEvaluator.g: Update evaluator to + use Arithmetic Unit. + 2007-11-08 Teresa Thomas <tthomas@redhat.com> * ScratchSymTab.java (getWordSize): Return word size diff --git a/frysk-core/frysk/value/ArithmeticType.java b/frysk-core/frysk/value/ArithmeticType.java index 96f8a79..4134a05 100644 --- a/frysk-core/frysk/value/ArithmeticType.java +++ b/frysk-core/frysk/value/ArithmeticType.java @@ -65,226 +65,11 @@ public abstract class ArithmeticType public ByteOrder order() { return order; } - - /** - * Examine the underlying types to determine the result's Type; - * callers then use the result type to determine the type system - * to use, and conversion to perform, when applying the arithmetic - * operation. - * - * XXX: Is ther a better to handle this whole arithmetic thing; - * for instance Operator classes responsible for performing each - * operation? That would let us construct an expression tree and - * evaluate that using traversal. - */ - private ArithmeticType returnType(Value var1, Value var2) { - Type t1 = var1.getType().getUltimateType(); - Type t2 = var2.getType().getUltimateType(); - - // Floating point trumps everything else. - if (t1 instanceof FloatingPointType) { - if (t2 instanceof FloatingPointType) { - if (t1.getSize() > t2.getSize()) - return (ArithmeticType)t1; - else - return (ArithmeticType)t2; - } else if (t2 instanceof IntegerType) { - return (ArithmeticType)t1; - } else { - // Can't apply cast: (t1)t2 - throw new InvalidOperatorException(t2, - "(" + t1.toPrint() + ")"); - } - } else if (t1 instanceof IntegerType) { - if (t2 instanceof FloatingPointType) { - return (ArithmeticType)t2; - } else if (t2 instanceof IntegerType) { - if (t1.getSize() > t2.getSize()) - return (ArithmeticType)t1; - else - return (ArithmeticType)t2; - } else { - // Can't apply cast: (t1)t2 - throw new InvalidOperatorException(t2, - "(" + t1.toPrint() + ")"); - } - } else { - if (t2 instanceof ArithmeticType) { - // Can't apply cast: (t2)t1 - throw new InvalidOperatorException(t1, - "(" + t2.toPrint() + ")"); - } else { - throw new InvalidOperatorException(t1, "invalid type"); - } - } - } - - public Value shiftLeft(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue(var1.asLong() << var2.asLong()); - else - throw new InvalidOperatorException(type, "<<"); - } - - public Value shiftRight(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue(var1.asLong() >> var2.asLong()); - else - throw new InvalidOperatorException(type, ">>"); - } - - public Value lessThan(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() < var2.asLong()) ? 1 : 0); - else if (type instanceof FloatingPointType) - return type.createValue((var1.doubleValue() < var2.doubleValue()) ? 1 : 0); - else - throw new RuntimeException("type conversion botch"); - } - - public Value greaterThan(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() > var2.asLong()) ? 1 : 0); - else if (type instanceof FloatingPointType) - return type.createValue((var1.doubleValue() > var2.doubleValue()) ? 1 : 0); - else - throw new RuntimeException("type conversion botch"); - } - - public Value lessThanOrEqualTo(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() <= var2.asLong()) ? 1 : 0); - else if (type instanceof FloatingPointType) - return type.createValue((var1.doubleValue() <= var2.doubleValue()) ? 1 : 0); - else - throw new RuntimeException("type conversion botch"); - } - - public Value greaterThanOrEqualTo(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() >= var2.asLong()) ? 1 : 0); - else if (type instanceof FloatingPointType) - return type.createValue((var1.doubleValue() >= var2.doubleValue()) ? 1 : 0); - else - throw new RuntimeException("type conversion botch"); - } - - public Value equal(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() == var2.asLong()) ? 1 : 0); - else if (type instanceof FloatingPointType) - return type.createValue((var1.doubleValue() == var2.doubleValue()) ? 1 : 0); - else - throw new RuntimeException("type conversion botch"); - } - - public Value notEqual(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() != var2.asLong()) ? 1 : 0); - else if (type instanceof FloatingPointType) - return type.createValue((var1.doubleValue() != var2.doubleValue()) ? 1 : 0); - else - throw new RuntimeException("type conversion botch"); - } - - public Value bitWiseAnd(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue(var1.asLong() & var2.asLong()); - else - throw new InvalidOperatorException(type, "&"); - } - - public Value bitWiseOr(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() | var2.asLong())); - else - throw new InvalidOperatorException(type, "|"); - } - - public Value bitWiseXor(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() ^ var2.asLong())); - else - throw new InvalidOperatorException(type, "^"); - } - - public Value bitWiseComplement(Value var1) { - Type type = var1.getType().getUltimateType(); - if (type instanceof IntegerType) - return ((ArithmeticType)type).createValue((~var1.asLong())); - else - throw new InvalidOperatorException(type, "~"); - } - - public Value logicalAnd(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() == 0 ? false : true) - && (var2.asLong() == 0 ? false : true) ? 1 : 0); - else - throw new InvalidOperatorException(type, "&&"); - } - - public Value logicalOr(Value var1, Value var2) { - ArithmeticType type = returnType(var1, var2); - if (type instanceof IntegerType) - return type.createValue((var1.asLong() == 0 ? false : true) - || (var2.asLong() == 0 ? false : true) ? 1 : 0); - else - throw new InvalidOperatorException(var1.getType(), "||"); - } - - public Value logicalNegation(Value var1) { - Type type = var1.getType().getUltimateType(); - if (type instanceof IntegerType) - return ((ArithmeticType)type).createValue((var1.asLong() == 0 ? true : false) ? 1 : 0); - else - throw new InvalidOperatorException(var1.getType(), "||"); - } - + public Value assign(Value var1, Value var2) { return var1.assign(var2); } - public Value shiftLeftEqual(Value var1, Value var2) { - return var1.assign(shiftLeft(var1, var2)); - } - - public Value shiftRightEqual(Value var1, Value var2) { - return var1.assign(shiftRight(var1, var2)); - } - - public Value bitWiseOrEqual(Value var1, Value var2) { - return var1.assign(bitWiseOr(var1, var2)); - } - - public Value bitWiseXorEqual(Value var1, Value var2) { - return var1.assign(bitWiseXor(var1, var2)); - } - - public Value bitWiseAndEqual(Value var1, Value var2) { - return var1.assign(bitWiseAnd(var1, var2)); - } - - public boolean getLogicalValue (Value var1) { - Type type = var1.getType().getUltimateType(); - if (type instanceof IntegerType) - return ((var1.asLong() == 0) ? false : true); - else - throw new InvalidOperatorException(this, "(bool)"); - } - public void toPrint(PrintWriter writer) { writer.print(getName()); } diff --git a/frysk-core/frysk/value/ArithmeticUnit.java b/frysk-core/frysk/value/ArithmeticUnit.java index 736f89a..1daa863 100644 --- a/frysk-core/frysk/value/ArithmeticUnit.java +++ b/frysk-core/frysk/value/ArithmeticUnit.java @@ -47,48 +47,129 @@ public abstract class ArithmeticUnit { protected ArithmeticType retType; + // Multiplicative and Additive expressions public Value add(Value v1, Value v2) { throw new InvalidOperatorException (v1.getType(), v2.getType(), "+"); } - public Value subtract(Value v1, Value v2) { throw new InvalidOperatorException (v1.getType(), v2.getType(), "-"); } - public Value multiply (Value v1, Value v2) { throw new InvalidOperatorException (v1.getType(), v2.getType(), "*"); } - public Value divide(Value v1, Value v2) { throw new InvalidOperatorException (v1.getType(), v2.getType(), "/"); } - public Value mod(Value v1, Value v2) { throw new InvalidOperatorException (v1.getType(), v2.getType(), "%"); } - public Value plusEqual(Value v1, Value v2) { - return v1.assign(add(v1, v2)); + // Shift expressions + public Value shiftLeft (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), "<<"); + } + public Value shiftRight (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), ">>"); } - public Value minusEqual(Value v1, Value v2) { - return v1.assign(subtract(v1, v2)); + // Relational expressions + public Value lessThan (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), "<"); + } + public Value greaterThan (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), ">"); + } + public Value lessThanOrEqualTo (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), "<="); + } + public Value greaterThanOrEqualTo (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), ">="); + } + public Value equal (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), "=="); + } + public Value notEqual (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), "!="); } - public Value timesEqual(Value v1, Value v2) { - return v1.assign(multiply(v1, v2)); + // Bit wise expressions. + public Value bitWiseAnd (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), "&"); + } + public Value bitWiseXor (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), "^"); + } + public Value bitWiseOr (Value v1, Value v2) { + throw new InvalidOperatorException + (v1.getType(), v2.getType(), "|"); + } + public Value bitWiseComplement (Value v1) { + throw new InvalidOperatorException + (v1.getType(), "~"); } - public Value divideEqual (Value v1, Value v2) { - return v1.assign(divide(v1, v2)); + // Logical expressions - valid for scalar types. + public Value logicalAnd (Value v1, Value v2) { + throw new InvalidOperatorException hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2007-11-09 19:28 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20071109192817.15810.qmail@sourceware.org \ --to=tthomas@sourceware.org \ --cc=frysk-cvs@sourceware.org \ --cc=frysk@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).