aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2009-03-15 04:25:53 +0000
committerDavid Robillard <d@drobilla.net>2009-03-15 04:25:53 +0000
commitaeb026f51eea040f2b5df438d21150a89c0235c5 (patch)
treedfa7c715c0ae7c4e7f248eb6054864c21f7d1afe
parente4943a76e19b442e4cd7b1cf921127ff633d9c13 (diff)
downloadresp-aeb026f51eea040f2b5df438d21150a89c0235c5.tar.gz
resp-aeb026f51eea040f2b5df438d21150a89c0235c5.tar.bz2
resp-aeb026f51eea040f2b5df438d21150a89c0235c5.zip
Fix comparison operations with booleans.
git-svn-id: http://svn.drobilla.net/resp/tuplr@96 ad02d1e2-f140-0410-9f75-f8b11f17cedd
-rw-r--r--llvm.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/llvm.cpp b/llvm.cpp
index 5d929a2..7cfb3b0 100644
--- a/llvm.cpp
+++ b/llvm.cpp
@@ -431,10 +431,10 @@ AIf::compile(CEnv& cenv)
CValue
APrimitive::compile(CEnv& cenv)
{
- Value* a = LLVal(cenv.compile(at(1)));
- Value* b = LLVal(cenv.compile(at(2)));
- bool isInt = cenv.type(at(1))->str() == "Int";
- const string n = dynamic_cast<ASymbol*>(at(0))->str();
+ Value* a = LLVal(cenv.compile(at(1)));
+ Value* b = LLVal(cenv.compile(at(2)));
+ bool isFloat = cenv.type(at(1))->str() == "Float";
+ const string n = dynamic_cast<ASymbol*>(at(0))->str();
// Binary arithmetic operations
Instruction::BinaryOps op = (Instruction::BinaryOps)0;
@@ -444,8 +444,8 @@ APrimitive::compile(CEnv& cenv)
if (n == "and") op = Instruction::And;
if (n == "or") op = Instruction::Or;
if (n == "xor") op = Instruction::Xor;
- if (n == "/") op = isInt ? Instruction::SDiv : Instruction::FDiv;
- if (n == "%") op = isInt ? Instruction::SRem : Instruction::FRem;
+ if (n == "/") op = isFloat ? Instruction::FDiv : Instruction::SDiv;
+ if (n == "%") op = isFloat ? Instruction::FRem : Instruction::SRem;
if (op != 0) {
Value* val = llengine(cenv)->builder.CreateBinOp(op, a, b);
for (size_t i = 3; i < size(); ++i)
@@ -455,17 +455,17 @@ APrimitive::compile(CEnv& cenv)
// Comparison operations
CmpInst::Predicate pred = (CmpInst::Predicate)0;
- if (n == "=") pred = isInt ? CmpInst::ICMP_EQ : CmpInst::FCMP_OEQ;
- if (n == "!=") pred = isInt ? CmpInst::ICMP_NE : CmpInst::FCMP_ONE;
- if (n == ">") pred = isInt ? CmpInst::ICMP_SGT : CmpInst::FCMP_OGT;
- if (n == ">=") pred = isInt ? CmpInst::ICMP_SGE : CmpInst::FCMP_OGE;
- if (n == "<") pred = isInt ? CmpInst::ICMP_SLT : CmpInst::FCMP_OLT;
- if (n == "<=") pred = isInt ? CmpInst::ICMP_SLE : CmpInst::FCMP_OLE;
+ if (n == "=") pred = isFloat ? CmpInst::FCMP_OEQ : CmpInst::ICMP_EQ ;
+ if (n == "!=") pred = isFloat ? CmpInst::FCMP_ONE : CmpInst::ICMP_NE ;
+ if (n == ">") pred = isFloat ? CmpInst::FCMP_OGT : CmpInst::ICMP_SGT;
+ if (n == ">=") pred = isFloat ? CmpInst::FCMP_OGE : CmpInst::ICMP_SGE;
+ if (n == "<") pred = isFloat ? CmpInst::FCMP_OLT : CmpInst::ICMP_SLT;
+ if (n == "<=") pred = isFloat ? CmpInst::FCMP_OLE : CmpInst::ICMP_SLE;
if (pred != 0) {
- if (isInt)
- return llengine(cenv)->builder.CreateICmp(pred, a, b);
- else
+ if (isFloat)
return llengine(cenv)->builder.CreateFCmp(pred, a, b);
+ else
+ return llengine(cenv)->builder.CreateICmp(pred, a, b);
}
throw Error("unknown primitive", loc);