summaryrefslogtreecommitdiffstats
path: root/clang/CodeGen
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-13 05:18:11 +0000
committerChris Lattner <sabre@nondot.org>2007-07-13 05:18:11 +0000
commit6e9d9b350e7573b4baceeafe92ea99f11d215d8f (patch)
tree48041bd11417f992034794eaced8738aa6162f0c /clang/CodeGen
parentd14bfa94a6cbe5301edbb2b722336c5fa68a5b8e (diff)
downloadbcm5719-llvm-6e9d9b350e7573b4baceeafe92ea99f11d215d8f.tar.gz
bcm5719-llvm-6e9d9b350e7573b4baceeafe92ea99f11d215d8f.zip
"Codegen for Character Literals and Conditional Operator
Both in one patch, and the test case that Chris didn't commit last time is in there too... I'll split the patch up if somebody wants it split." Patch by Keith Bauer. llvm-svn: 39796
Diffstat (limited to 'clang/CodeGen')
-rw-r--r--clang/CodeGen/CGExpr.cpp48
-rw-r--r--clang/CodeGen/CodeGenFunction.h8
2 files changed, 54 insertions, 2 deletions
diff --git a/clang/CodeGen/CGExpr.cpp b/clang/CodeGen/CGExpr.cpp
index ff55e960869..fc59ec076b0 100644
--- a/clang/CodeGen/CGExpr.cpp
+++ b/clang/CodeGen/CGExpr.cpp
@@ -464,6 +464,8 @@ RValue CodeGenFunction::EmitExpr(const Expr *E) {
return EmitIntegerLiteral(cast<IntegerLiteral>(E));
case Expr::FloatingLiteralClass:
return EmitFloatingLiteral(cast<FloatingLiteral>(E));
+ case Expr::CharacterLiteralClass:
+ return EmitCharacterLiteral(cast<CharacterLiteral>(E));
// Operators.
case Expr::ParenExprClass:
@@ -476,6 +478,9 @@ RValue CodeGenFunction::EmitExpr(const Expr *E) {
return EmitCallExpr(cast<CallExpr>(E));
case Expr::BinaryOperatorClass:
return EmitBinaryOperator(cast<BinaryOperator>(E));
+
+ case Expr::ConditionalOperatorClass:
+ return EmitConditionalOperator(cast<ConditionalOperator>(E));
}
}
@@ -487,7 +492,10 @@ RValue CodeGenFunction::EmitFloatingLiteral(const FloatingLiteral *E) {
return RValue::get(llvm::ConstantFP::get(ConvertType(E->getType()),
E->getValue()));
}
-
+RValue CodeGenFunction::EmitCharacterLiteral(const CharacterLiteral *E) {
+ return RValue::get(llvm::ConstantInt::get(ConvertType(E->getType()),
+ E->getValue()));
+}
RValue CodeGenFunction::EmitArraySubscriptExprRV(const ArraySubscriptExpr *E) {
// Emit subscript expressions in rvalue context's. For most cases, this just
@@ -1322,3 +1330,41 @@ RValue CodeGenFunction::EmitBinaryComma(const BinaryOperator *E) {
EmitExpr(E->getLHS());
return EmitExpr(E->getRHS());
}
+
+RValue CodeGenFunction::EmitConditionalOperator(const ConditionalOperator *E) {
+ llvm::BasicBlock *LHSBlock = new llvm::BasicBlock("cond.?");
+ llvm::BasicBlock *RHSBlock = new llvm::BasicBlock("cond.:");
+ llvm::BasicBlock *ContBlock = new llvm::BasicBlock("cond.cont");
+
+ llvm::Value *Cond = EvaluateExprAsBool(E->getCond());
+ Builder.CreateCondBr(Cond, LHSBlock, RHSBlock);
+
+ // FIXME: LHS & RHS need the "usual arithmetic conversions" but
+ // that's not possible with the current design.
+
+ EmitBlock(LHSBlock);
+ QualType LHSTy;
+ llvm::Value *LHSValue = E->getLHS() ? // GNU extension
+ EmitExprWithUsualUnaryConversions(E->getLHS(), LHSTy).getVal() :
+ Cond;
+ Builder.CreateBr(ContBlock);
+ LHSBlock = Builder.GetInsertBlock();
+
+ EmitBlock(RHSBlock);
+ QualType RHSTy;
+ llvm::Value *RHSValue =
+ EmitExprWithUsualUnaryConversions(E->getRHS(), RHSTy).getVal();
+ Builder.CreateBr(ContBlock);
+ RHSBlock = Builder.GetInsertBlock();
+
+ const llvm::Type *LHSType = LHSValue->getType();
+ assert(LHSType == RHSValue->getType() && "?: LHS & RHS must have same type");
+
+ EmitBlock(ContBlock);
+ llvm::PHINode *PN = Builder.CreatePHI(LHSType, "cond");
+ PN->reserveOperandSpace(2);
+ PN->addIncoming(LHSValue, LHSBlock);
+ PN->addIncoming(RHSValue, RHSBlock);
+
+ return RValue::get(PN);
+}
diff --git a/clang/CodeGen/CodeGenFunction.h b/clang/CodeGen/CodeGenFunction.h
index 268a70276a7..7a07f252bb0 100644
--- a/clang/CodeGen/CodeGenFunction.h
+++ b/clang/CodeGen/CodeGenFunction.h
@@ -46,12 +46,14 @@ namespace clang {
class StringLiteral;
class IntegerLiteral;
class FloatingLiteral;
+ class CharacterLiteral;
class CastExpr;
class CallExpr;
class UnaryOperator;
class BinaryOperator;
class CompoundAssignOperator;
class ArraySubscriptExpr;
+ class ConditionalOperator;
class BlockVarDecl;
class EnumConstantDecl;
@@ -309,7 +311,8 @@ public:
RValue EmitExpr(const Expr *E);
RValue EmitIntegerLiteral(const IntegerLiteral *E);
RValue EmitFloatingLiteral(const FloatingLiteral *E);
-
+ RValue EmitCharacterLiteral(const CharacterLiteral *E);
+
RValue EmitCastExpr(const CastExpr *E);
RValue EmitCallExpr(const CallExpr *E);
RValue EmitArraySubscriptExprRV(const ArraySubscriptExpr *E);
@@ -351,6 +354,9 @@ public:
RValue EmitBinaryAssign(const BinaryOperator *E);
RValue EmitBinaryComma(const BinaryOperator *E);
+
+ // Conditional Operator.
+ RValue EmitConditionalOperator(const ConditionalOperator *E);
};
} // end namespace CodeGen
} // end namespace clang
OpenPOWER on IntegriCloud