aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Target
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2002-05-09 03:12:34 +0000
committerChris Lattner <sabre@nondot.org>2002-05-09 03:12:34 +0000
commitf34ee81c5ef50c10679873bcd491fa1f6796c638 (patch)
tree932bd81eea65fe1b840bed0cce4160a0a7dd3ebe /lib/Target
parentb5af06a0ec7e646b9b405ef7f1e3e23b19cf415d (diff)
downloadexternal_llvm-f34ee81c5ef50c10679873bcd491fa1f6796c638.zip
external_llvm-f34ee81c5ef50c10679873bcd491fa1f6796c638.tar.gz
external_llvm-f34ee81c5ef50c10679873bcd491fa1f6796c638.tar.bz2
Incorporate and purge function before and after printing them so unnamed values
have some hope of working right. Function calls do not try to emit an lvalue if they return void. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2569 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Target')
-rw-r--r--lib/Target/CBackend/CBackend.cpp27
-rw-r--r--lib/Target/CBackend/Writer.cpp27
2 files changed, 32 insertions, 22 deletions
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 68e0da8..031a26e 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -650,7 +650,10 @@ void CInstPrintVisitor::visitCastInst(CastInst *I) {
}
void CInstPrintVisitor::visitCallInst(CallInst *I) {
- outputLValue(I);
+
+ if (I->getType() != Type::VoidTy)
+ outputLValue(I);
+
Operand = I->getNumOperands() ? I->getOperand(0) : 0;
const PointerType *PTy = dyn_cast<PointerType>(Operand->getType());
const FunctionType *MTy = PTy
@@ -737,11 +740,11 @@ void CInstPrintVisitor::visitBranchInst(BranchInst *I) {
}
void CInstPrintVisitor::visitSwitchInst(SwitchInst *I) {
- Out << "\n";
+ assert(0 && "Switch not implemented!");
}
void CInstPrintVisitor::visitInvokeInst(InvokeInst *I) {
- Out << "\n";
+ assert(0 && "Invoke not implemented!");
}
void CInstPrintVisitor::visitMallocInst(MallocInst *I) {
@@ -749,9 +752,9 @@ void CInstPrintVisitor::visitMallocInst(MallocInst *I) {
Operand = I->getNumOperands() ? I->getOperand(0) : 0;
string tempstr = "";
Out << "(";
- CW.printType(cast<const PointerType>(I->getType())->getElementType(), Out);
+ CW.printType(cast<PointerType>(I->getType())->getElementType(), Out);
Out << "*) malloc(sizeof(";
- CW.printTypeVar(cast<const PointerType>(I->getType())->getElementType(),
+ CW.printTypeVar(cast<PointerType>(I->getType())->getElementType(),
tempstr);
Out << ")";
if (I->getNumOperands()) {
@@ -1110,6 +1113,8 @@ void CWriter::printFunctionArgument(const Argument *Arg) {
void CWriter::printFunction(const Function *F) {
if (F->isExternal()) return;
+ Table.incorporateFunction(F);
+
// Process each of the basic blocks, gather information and call the
// output methods on the CLocalVars and Function* objects.
@@ -1143,6 +1148,7 @@ void CWriter::printFunction(const Function *F) {
for_each(F->begin(), F->end(), bind_obj(this, &CWriter::outputBasicBlock));
Out << "}\n";
+ Table.purgeFunction();
}
void CWriter::outputBasicBlock(const BasicBlock* BB) {
@@ -1189,11 +1195,10 @@ void CWriter::writeOperand(const Value *Operand,
// External Interface declaration
//===----------------------------------------------------------------------===//
-void WriteToC(const Module *C, ostream &Out) {
- assert(C && "You can't write a null module!!");
- SlotCalculator SlotTable(C, true);
- CWriter W(Out, SlotTable, C);
- W.write(C);
+void WriteToC(const Module *M, ostream &Out) {
+ assert(M && "You can't write a null module!!");
+ SlotCalculator SlotTable(M, false);
+ CWriter W(Out, SlotTable, M);
+ W.write(M);
Out.flush();
}
-
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index 68e0da8..031a26e 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -650,7 +650,10 @@ void CInstPrintVisitor::visitCastInst(CastInst *I) {
}
void CInstPrintVisitor::visitCallInst(CallInst *I) {
- outputLValue(I);
+
+ if (I->getType() != Type::VoidTy)
+ outputLValue(I);
+
Operand = I->getNumOperands() ? I->getOperand(0) : 0;
const PointerType *PTy = dyn_cast<PointerType>(Operand->getType());
const FunctionType *MTy = PTy
@@ -737,11 +740,11 @@ void CInstPrintVisitor::visitBranchInst(BranchInst *I) {
}
void CInstPrintVisitor::visitSwitchInst(SwitchInst *I) {
- Out << "\n";
+ assert(0 && "Switch not implemented!");
}
void CInstPrintVisitor::visitInvokeInst(InvokeInst *I) {
- Out << "\n";
+ assert(0 && "Invoke not implemented!");
}
void CInstPrintVisitor::visitMallocInst(MallocInst *I) {
@@ -749,9 +752,9 @@ void CInstPrintVisitor::visitMallocInst(MallocInst *I) {
Operand = I->getNumOperands() ? I->getOperand(0) : 0;
string tempstr = "";
Out << "(";
- CW.printType(cast<const PointerType>(I->getType())->getElementType(), Out);
+ CW.printType(cast<PointerType>(I->getType())->getElementType(), Out);
Out << "*) malloc(sizeof(";
- CW.printTypeVar(cast<const PointerType>(I->getType())->getElementType(),
+ CW.printTypeVar(cast<PointerType>(I->getType())->getElementType(),
tempstr);
Out << ")";
if (I->getNumOperands()) {
@@ -1110,6 +1113,8 @@ void CWriter::printFunctionArgument(const Argument *Arg) {
void CWriter::printFunction(const Function *F) {
if (F->isExternal()) return;
+ Table.incorporateFunction(F);
+
// Process each of the basic blocks, gather information and call the
// output methods on the CLocalVars and Function* objects.
@@ -1143,6 +1148,7 @@ void CWriter::printFunction(const Function *F) {
for_each(F->begin(), F->end(), bind_obj(this, &CWriter::outputBasicBlock));
Out << "}\n";
+ Table.purgeFunction();
}
void CWriter::outputBasicBlock(const BasicBlock* BB) {
@@ -1189,11 +1195,10 @@ void CWriter::writeOperand(const Value *Operand,
// External Interface declaration
//===----------------------------------------------------------------------===//
-void WriteToC(const Module *C, ostream &Out) {
- assert(C && "You can't write a null module!!");
- SlotCalculator SlotTable(C, true);
- CWriter W(Out, SlotTable, C);
- W.write(C);
+void WriteToC(const Module *M, ostream &Out) {
+ assert(M && "You can't write a null module!!");
+ SlotCalculator SlotTable(M, false);
+ CWriter W(Out, SlotTable, M);
+ W.write(M);
Out.flush();
}
-