aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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);