summaryrefslogtreecommitdiff
path: root/src/mem/slicc/ast
diff options
context:
space:
mode:
authorDavid Hashe <david.hashe@amd.com>2015-07-20 09:15:18 -0500
committerDavid Hashe <david.hashe@amd.com>2015-07-20 09:15:18 -0500
commit93fff6f636b94524fd8c4d1f9d0e01cfcd695c50 (patch)
treec8530fd4ac981398024aecc1d0cdf132d987dac2 /src/mem/slicc/ast
parentee0d414fa8dac2371b439778374ec585b358e549 (diff)
downloadgem5-93fff6f636b94524fd8c4d1f9d0e01cfcd695c50.tar.xz
slicc: improve support for prefix operations
This patch fixes the type handling when prefix operations are used. Previously prefix operators would assume a void return type, which made it impossible to combine prefix operations with other expressions. This patch allows SLICC programmers to use prefix operations more naturally.
Diffstat (limited to 'src/mem/slicc/ast')
-rw-r--r--src/mem/slicc/ast/OperatorExprAST.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/mem/slicc/ast/OperatorExprAST.py b/src/mem/slicc/ast/OperatorExprAST.py
index f449a358a..b1614b6a0 100644
--- a/src/mem/slicc/ast/OperatorExprAST.py
+++ b/src/mem/slicc/ast/OperatorExprAST.py
@@ -107,8 +107,22 @@ class PrefixOperatorExprAST(ExprAST):
opcode = self.slicc.codeFormatter()
optype = self.operand.generate(opcode)
+ # Figure out what the input and output types should be
+ opmap = {"!": "bool", "-": "int", "++": "Scalar"}
+ if self.op in opmap:
+ output = opmap[self.op]
+ type_in_symtab = self.symtab.find(opmap[self.op], Type)
+ if (optype != type_in_symtab):
+ self.error("Type mismatch: right operand of " +
+ "unary operator '%s' must be of type '%s'. ",
+ self.op, type_in_symtab)
+ else:
+ self.error("Invalid prefix operator '%s'",
+ self.op)
+
+ # All is well
fix = code.nofix()
code("(${{self.op}} $opcode)")
code.fix(fix)
- return self.symtab.find("void", Type)
+ return self.symtab.find(output, Type)