1 //===-- Writer.cpp - Library for converting LLVM code to C ----------------===//
3 // This library implements the functionality defined in llvm/Assembly/CWriter.h
5 // TODO : Recursive types.
7 //===-----------------------------------------------------------------------==//
9 #include "llvm/Assembly/CWriter.h"
10 #include "llvm/Constants.h"
11 #include "llvm/DerivedTypes.h"
12 #include "llvm/Module.h"
13 #include "llvm/GlobalVariable.h"
14 #include "llvm/Function.h"
15 #include "llvm/Argument.h"
16 #include "llvm/BasicBlock.h"
17 #include "llvm/iMemory.h"
18 #include "llvm/iTerminators.h"
19 #include "llvm/iPHINode.h"
20 #include "llvm/iOther.h"
21 #include "llvm/iOperators.h"
22 #include "llvm/SymbolTable.h"
23 #include "llvm/SlotCalculator.h"
24 #include "llvm/Support/InstVisitor.h"
25 #include "llvm/Support/InstIterator.h"
26 #include "Support/StringExtras.h"
27 #include "Support/STLExtras.h"
34 static std::string getConstStrValue(const Constant* CPV);
37 static std::string getConstArrayStrValue(const Constant* CPV) {
40 // As a special case, print the array as a string if it is an array of
41 // ubytes or an array of sbytes with positive values.
43 const Type *ETy = cast<ArrayType>(CPV->getType())->getElementType();
44 bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
46 // Make sure the last character is a null char, as automatically added by C
47 if (CPV->getNumOperands() == 0 ||
48 !cast<Constant>(*(CPV->op_end()-1))->isNullValue())
53 // Do not include the last character, which we know is null
54 for (unsigned i = 0, e = CPV->getNumOperands()-1; i != e; ++i) {
55 unsigned char C = (ETy == Type::SByteTy) ?
56 (unsigned char)cast<ConstantSInt>(CPV->getOperand(i))->getValue() :
57 (unsigned char)cast<ConstantUInt>(CPV->getOperand(i))->getValue();
63 case '\n': Result += "\\n"; break;
64 case '\t': Result += "\\t"; break;
65 case '\r': Result += "\\r"; break;
66 case '\v': Result += "\\v"; break;
67 case '\a': Result += "\\a"; break;
70 Result += ( C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A');
71 Result += ((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A');
79 if (CPV->getNumOperands()) {
80 Result += " " + getConstStrValue(cast<Constant>(CPV->getOperand(0)));
81 for (unsigned i = 1; i < CPV->getNumOperands(); i++)
82 Result += ", " + getConstStrValue(cast<Constant>(CPV->getOperand(i)));
90 static std::string getConstStrValue(const Constant* CPV) {
91 switch (CPV->getType()->getPrimitiveID()) {
92 case Type::BoolTyID: return CPV == ConstantBool::False ? "0" : "1";
95 case Type::IntTyID: return itostr(cast<ConstantSInt>(CPV)->getValue());
96 case Type::LongTyID: return itostr(cast<ConstantSInt>(CPV)->getValue())+"ll";
99 case Type::UShortTyID:return utostr(cast<ConstantUInt>(CPV)->getValue());
100 case Type::UIntTyID: return utostr(cast<ConstantUInt>(CPV)->getValue())+"u";
101 case Type::ULongTyID:return utostr(cast<ConstantUInt>(CPV)->getValue())+"ull";
103 case Type::FloatTyID:
104 case Type::DoubleTyID: return ftostr(cast<ConstantFP>(CPV)->getValue());
106 case Type::ArrayTyID: return getConstArrayStrValue(CPV);
108 case Type::StructTyID: {
109 std::string Result = "{";
110 if (CPV->getNumOperands()) {
111 Result += " " + getConstStrValue(cast<Constant>(CPV->getOperand(0)));
112 for (unsigned i = 1; i < CPV->getNumOperands(); i++)
113 Result += ", " + getConstStrValue(cast<Constant>(CPV->getOperand(i)));
115 return Result + " }";
119 cerr << "Unknown constant type: " << CPV << "\n";
124 // Pass the Type* variable and and the variable name and this prints out the
125 // variable declaration.
127 static string calcTypeNameVar(const Type *Ty,
128 map<const Type *, string> &TypeNames,
129 const string &NameSoFar, bool ignoreName = false){
130 if (Ty->isPrimitiveType())
131 switch (Ty->getPrimitiveID()) {
132 case Type::VoidTyID: return "void " + NameSoFar;
133 case Type::BoolTyID: return "bool " + NameSoFar;
134 case Type::UByteTyID: return "unsigned char " + NameSoFar;
135 case Type::SByteTyID: return "signed char " + NameSoFar;
136 case Type::UShortTyID: return "unsigned short " + NameSoFar;
137 case Type::ShortTyID: return "short " + NameSoFar;
138 case Type::UIntTyID: return "unsigned " + NameSoFar;
139 case Type::IntTyID: return "int " + NameSoFar;
140 case Type::ULongTyID: return "unsigned long long " + NameSoFar;
141 case Type::LongTyID: return "signed long long " + NameSoFar;
142 case Type::FloatTyID: return "float " + NameSoFar;
143 case Type::DoubleTyID: return "double " + NameSoFar;
145 cerr << "Unknown primitive type: " << Ty << "\n";
149 // Check to see if the type is named.
151 map<const Type *, string>::iterator I = TypeNames.find(Ty);
152 if (I != TypeNames.end())
153 return I->second + " " + NameSoFar;
157 switch (Ty->getPrimitiveID()) {
158 case Type::FunctionTyID: {
159 const FunctionType *MTy = cast<FunctionType>(Ty);
160 Result += calcTypeNameVar(MTy->getReturnType(), TypeNames, "");
161 Result += " " + NameSoFar + " (";
162 for (FunctionType::ParamTypes::const_iterator
163 I = MTy->getParamTypes().begin(),
164 E = MTy->getParamTypes().end(); I != E; ++I) {
165 if (I != MTy->getParamTypes().begin())
167 Result += calcTypeNameVar(*I, TypeNames, "");
169 if (MTy->isVarArg()) {
170 if (!MTy->getParamTypes().empty())
176 case Type::StructTyID: {
177 const StructType *STy = cast<const StructType>(Ty);
178 Result = NameSoFar + " {\n";
180 for (StructType::ElementTypes::const_iterator
181 I = STy->getElementTypes().begin(),
182 E = STy->getElementTypes().end(); I != E; ++I) {
183 Result += " " +calcTypeNameVar(*I, TypeNames, "field" + utostr(indx++));
189 case Type::PointerTyID:
190 return calcTypeNameVar(cast<const PointerType>(Ty)->getElementType(),
191 TypeNames, "*" + NameSoFar);
193 case Type::ArrayTyID: {
194 const ArrayType *ATy = cast<const ArrayType>(Ty);
195 int NumElements = ATy->getNumElements();
196 return calcTypeNameVar(ATy->getElementType(), TypeNames,
197 NameSoFar + "[" + itostr(NumElements) + "]");
200 assert(0 && "Unhandled case in getTypeProps!");
208 class CWriter : public InstVisitor<CWriter> {
210 SlotCalculator &Table;
211 const Module *TheModule;
212 map<const Type *, string> TypeNames;
213 std::set<const Value*> MangledGlobals;
215 inline CWriter(ostream &o, SlotCalculator &Tab, const Module *M)
216 : Out(o), Table(Tab), TheModule(M) {
219 inline void write(Module *M) { printModule(M); }
221 ostream& printType(const Type *Ty, const string &VariableName = "") {
222 return Out << calcTypeNameVar(Ty, TypeNames, VariableName);
225 void writeOperand(const Value *Operand);
226 void writeOperandInternal(const Value *Operand);
228 string getValueName(const Value *V);
231 void printModule(Module *M);
232 void printSymbolTable(const SymbolTable &ST);
233 void printGlobal(const GlobalVariable *GV);
234 void printFunctionSignature(const Function *F);
235 void printFunctionDecl(const Function *F); // Print just the forward decl
237 void printFunction(Function *);
239 // isInlinableInst - Attempt to inline instructions into their uses to build
240 // trees as much as possible. To do this, we have to consistently decide
241 // what is acceptable to inline, so that variable declarations don't get
242 // printed and an extra copy of the expr is not emitted.
244 static bool isInlinableInst(Instruction *I) {
245 // Must be an expression, must be used exactly once. If it is dead, we
246 // emit it inline where it would go.
247 if (I->getType() == Type::VoidTy || I->use_size() != 1 ||
248 isa<TerminatorInst>(I) || isa<CallInst>(I) || isa<PHINode>(I))
251 // Only inline instruction it it's use is in the same BB as the inst.
252 return I->getParent() == cast<Instruction>(I->use_back())->getParent();
255 // Instruction visitation functions
256 friend class InstVisitor<CWriter>;
258 void visitReturnInst(ReturnInst *I);
259 void visitBranchInst(BranchInst *I);
261 void visitPHINode(PHINode *I) {}
262 void visitNot(GenericUnaryInst *I);
263 void visitBinaryOperator(Instruction *I);
265 void visitCastInst(CastInst *I);
266 void visitCallInst(CallInst *I);
267 void visitShiftInst(ShiftInst *I) { visitBinaryOperator(I); }
269 void visitMallocInst(MallocInst *I);
270 void visitAllocaInst(AllocaInst *I);
271 void visitFreeInst(FreeInst *I);
272 void visitLoadInst(LoadInst *I);
273 void visitStoreInst(StoreInst *I);
274 void visitGetElementPtrInst(GetElementPtrInst *I);
276 void visitInstruction(Instruction *I) {
277 cerr << "C Writer does not know about " << I;
281 void outputLValue(Instruction *I) {
282 Out << " " << getValueName(I) << " = ";
284 void printBranchToBlock(BasicBlock *CurBlock, BasicBlock *SuccBlock,
286 void printIndexingExpr(MemAccessInst *MAI);
290 // We dont want identifier names with ., space, - in them.
291 // So we replace them with _
292 static string makeNameProper(string x) {
294 for (string::iterator sI = x.begin(), sEnd = x.end(); sI != sEnd; sI++)
296 case '.': tmp += "d_"; break;
297 case ' ': tmp += "s_"; break;
298 case '-': tmp += "D_"; break;
305 string CWriter::getValueName(const Value *V) {
306 if (V->hasName()) { // Print out the label if it exists...
307 if (isa<GlobalValue>(V) && // Do not mangle globals...
308 !MangledGlobals.count(V)) // Unless the name would collide unless we do.
309 return makeNameProper(V->getName());
311 return "l" + utostr(V->getType()->getUniqueID()) + "_" +
312 makeNameProper(V->getName());
315 int Slot = Table.getValSlot(V);
316 assert(Slot >= 0 && "Invalid value!");
317 return "ltmp_" + itostr(Slot) + "_" + utostr(V->getType()->getUniqueID());
320 void CWriter::writeOperandInternal(const Value *Operand) {
321 if (Operand->hasName()) {
322 Out << getValueName(Operand);
323 } else if (const Constant *CPV = dyn_cast<const Constant>(Operand)) {
324 if (isa<ConstantPointerNull>(CPV)) {
326 printType(CPV->getType(), "");
329 Out << getConstStrValue(CPV);
331 int Slot = Table.getValSlot(Operand);
332 assert(Slot >= 0 && "Malformed LLVM!");
333 Out << "ltmp_" << Slot << "_" << Operand->getType()->getUniqueID();
337 void CWriter::writeOperand(const Value *Operand) {
338 if (Instruction *I = dyn_cast<Instruction>(Operand))
339 if (isInlinableInst(I)) {
340 // Should we inline this instruction to build a tree?
347 if (isa<GlobalVariable>(Operand))
348 Out << "(&"; // Global variables are references as their addresses by llvm
350 writeOperandInternal(Operand);
352 if (isa<GlobalVariable>(Operand))
356 void CWriter::printModule(Module *M) {
357 // Calculate which global values have names that will collide when we throw
358 // away type information.
359 { // Scope to declare the FoundNames set when we are done with it...
360 std::set<string> FoundNames;
361 for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
362 if ((*I)->hasName()) // If the global has a name...
363 if (FoundNames.count((*I)->getName())) // And the name is already used
364 MangledGlobals.insert(*I); // Mangle the name
366 FoundNames.insert((*I)->getName()); // Otherwise, keep track of name
368 for (Module::giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
369 if ((*I)->hasName()) // If the global has a name...
370 if (FoundNames.count((*I)->getName())) // And the name is already used
371 MangledGlobals.insert(*I); // Mangle the name
373 FoundNames.insert((*I)->getName()); // Otherwise, keep track of name
377 // printing stdlib inclusion
378 // Out << "#include <stdlib.h>\n";
380 // get declaration for alloca
381 Out << "/* Provide Declarations */\n"
382 << "#include <alloca.h>\n\n"
384 // Provide a definition for null if one does not already exist.
385 << "#ifndef NULL\n#define NULL 0\n#endif\n\n"
386 << "typedef unsigned char bool;\n"
388 << "\n\n/* Global Symbols */\n";
390 // Loop over the symbol table, emitting all named constants...
391 if (M->hasSymbolTable())
392 printSymbolTable(*M->getSymbolTable());
394 Out << "\n\n/* Global Data */\n";
395 for (Module::const_giterator I = M->gbegin(), E = M->gend(); I != E; ++I) {
396 GlobalVariable *GV = *I;
397 if (GV->hasInternalLinkage()) Out << "static ";
398 printType(GV->getType()->getElementType(), getValueName(GV));
400 if (GV->hasInitializer()) {
402 writeOperand(GV->getInitializer());
407 // First output all the declarations of the functions as C requires Functions
408 // be declared before they are used.
410 Out << "\n\n/* Function Declarations */\n";
411 for_each(M->begin(), M->end(), bind_obj(this, &CWriter::printFunctionDecl));
413 // Output all of the functions...
414 Out << "\n\n/* Function Bodies */\n";
415 for_each(M->begin(), M->end(), bind_obj(this, &CWriter::printFunction));
419 // printSymbolTable - Run through symbol table looking for named constants
420 // if a named constant is found, emit it's declaration...
421 // Assuming that symbol table has only types and constants.
422 void CWriter::printSymbolTable(const SymbolTable &ST) {
423 for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) {
424 SymbolTable::type_const_iterator I = ST.type_begin(TI->first);
425 SymbolTable::type_const_iterator End = ST.type_end(TI->first);
427 for (; I != End; ++I)
428 if (const Type *Ty = dyn_cast<const StructType>(I->second)) {
429 string Name = "struct l_" + I->first;
430 Out << Name << ";\n";
432 TypeNames.insert(std::make_pair(Ty, Name));
438 for (SymbolTable::const_iterator TI = ST.begin(); TI != ST.end(); ++TI) {
439 SymbolTable::type_const_iterator I = ST.type_begin(TI->first);
440 SymbolTable::type_const_iterator End = ST.type_end(TI->first);
442 for (; I != End; ++I) {
443 const Value *V = I->second;
444 if (const Type *Ty = dyn_cast<const Type>(V)) {
445 string Name = "l_" + I->first;
446 if (isa<StructType>(Ty))
447 Name = "struct " + Name;
451 Out << calcTypeNameVar(Ty, TypeNames, Name, true) << ";\n";
458 // printFunctionDecl - Print function declaration
460 void CWriter::printFunctionDecl(const Function *F) {
461 printFunctionSignature(F);
465 void CWriter::printFunctionSignature(const Function *F) {
466 if (F->hasInternalLinkage()) Out << "static ";
468 // Loop over the arguments, printing them...
469 const FunctionType *FT = cast<FunctionType>(F->getFunctionType());
471 // Print out the return type and name...
472 printType(F->getReturnType());
473 Out << getValueName(F) << "(";
475 if (!F->isExternal()) {
476 if (!F->getArgumentList().empty()) {
477 printType(F->getArgumentList().front()->getType(),
478 getValueName(F->getArgumentList().front()));
480 for (Function::ArgumentListType::const_iterator
481 I = F->getArgumentList().begin()+1,
482 E = F->getArgumentList().end(); I != E; ++I) {
484 printType((*I)->getType(), getValueName(*I));
488 // Loop over the arguments, printing them...
489 for (FunctionType::ParamTypes::const_iterator I =
490 FT->getParamTypes().begin(),
491 E = FT->getParamTypes().end(); I != E; ++I) {
492 if (I != FT->getParamTypes().begin()) Out << ", ";
497 // Finish printing arguments...
498 if (FT->isVarArg()) {
499 if (FT->getParamTypes().size()) Out << ", ";
500 Out << "..."; // Output varargs portion of signature!
506 void CWriter::printFunction(Function *F) {
507 if (F->isExternal()) return;
509 Table.incorporateFunction(F);
511 printFunctionSignature(F);
514 // print local variable information for the function
515 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I)
516 if ((*I)->getType() != Type::VoidTy && !isInlinableInst(*I)) {
518 printType((*I)->getType(), getValueName(*I));
522 // print the basic blocks
523 for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
524 BasicBlock *BB = *I, *Prev = I != F->begin() ? *(I-1) : 0;
526 // Don't print the label for the basic block if there are no uses, or if the
527 // only terminator use is the precessor basic block's terminator. We have
528 // to scan the use list because PHI nodes use basic blocks too but do not
529 // require a label to be generated.
531 bool NeedsLabel = false;
532 for (Value::use_iterator UI = BB->use_begin(), UE = BB->use_end();
534 if (TerminatorInst *TI = dyn_cast<TerminatorInst>(*UI))
535 if (TI != Prev->getTerminator()) {
540 if (NeedsLabel) Out << getValueName(BB) << ":\n";
542 // Output all of the instructions in the basic block...
543 for (BasicBlock::iterator II = BB->begin(), E = BB->end()-1;
545 if (!isInlinableInst(*II) && !isa<PHINode>(*II)) {
546 Instruction *I = *II;
547 if (I->getType() != Type::VoidTy)
556 // Don't emit prefix or suffix for the terminator...
557 visit(BB->getTerminator());
561 Table.purgeFunction();
564 // Specific Instruction type classes... note that all of the casts are
565 // neccesary because we use the instruction classes as opaque types...
567 void CWriter::visitReturnInst(ReturnInst *I) {
568 // Don't output a void return if this is the last basic block in the function
569 if (I->getNumOperands() == 0 &&
570 *(I->getParent()->getParent()->end()-1) == I->getParent())
574 if (I->getNumOperands()) {
576 writeOperand(I->getOperand(0));
581 // Return true if BB1 immediately preceeds BB2.
582 static bool BBFollowsBB(BasicBlock *BB1, BasicBlock *BB2) {
583 Function *F = BB1->getParent();
584 Function::iterator I = find(F->begin(), F->end(), BB1);
585 assert(I != F->end() && "BB not in function!");
586 return *(I+1) == BB2;
589 static bool isGotoCodeNeccessary(BasicBlock *From, BasicBlock *To) {
590 // If PHI nodes need copies, we need the copy code...
591 if (isa<PHINode>(To->front()) ||
592 !BBFollowsBB(From, To)) // Not directly successor, need goto
595 // Otherwise we don't need the code.
599 void CWriter::printBranchToBlock(BasicBlock *CurBB, BasicBlock *Succ,
601 for (BasicBlock::iterator I = Succ->begin();
602 PHINode *PN = dyn_cast<PHINode>(*I); ++I) {
603 // now we have to do the printing
604 Out << string(Indent, ' ');
606 writeOperand(PN->getIncomingValue(PN->getBasicBlockIndex(CurBB)));
607 Out << "; /* for PHI node */\n";
610 if (!BBFollowsBB(CurBB, Succ)) {
611 Out << string(Indent, ' ') << " goto ";
617 // Brach instruction printing - Avoid printing out a brach to a basic block that
618 // immediately succeeds the current one.
620 void CWriter::visitBranchInst(BranchInst *I) {
621 if (I->isConditional()) {
622 if (isGotoCodeNeccessary(I->getParent(), I->getSuccessor(0))) {
624 writeOperand(I->getCondition());
627 printBranchToBlock(I->getParent(), I->getSuccessor(0), 2);
629 if (isGotoCodeNeccessary(I->getParent(), I->getSuccessor(1))) {
630 Out << " } else {\n";
631 printBranchToBlock(I->getParent(), I->getSuccessor(1), 2);
634 // First goto not neccesary, assume second one is...
636 writeOperand(I->getCondition());
639 printBranchToBlock(I->getParent(), I->getSuccessor(1), 2);
644 printBranchToBlock(I->getParent(), I->getSuccessor(0), 0);
650 void CWriter::visitNot(GenericUnaryInst *I) {
652 writeOperand(I->getOperand(0));
655 void CWriter::visitBinaryOperator(Instruction *I) {
656 // binary instructions, shift instructions, setCond instructions.
657 if (isa<PointerType>(I->getType())) {
659 printType(I->getType());
663 if (isa<PointerType>(I->getType())) Out << "(long long)";
664 writeOperand(I->getOperand(0));
666 switch (I->getOpcode()) {
667 case Instruction::Add: Out << " + "; break;
668 case Instruction::Sub: Out << " - "; break;
669 case Instruction::Mul: Out << "*"; break;
670 case Instruction::Div: Out << "/"; break;
671 case Instruction::Rem: Out << "%"; break;
672 case Instruction::And: Out << " & "; break;
673 case Instruction::Or: Out << " | "; break;
674 case Instruction::Xor: Out << " ^ "; break;
675 case Instruction::SetEQ: Out << " == "; break;
676 case Instruction::SetNE: Out << " != "; break;
677 case Instruction::SetLE: Out << " <= "; break;
678 case Instruction::SetGE: Out << " >= "; break;
679 case Instruction::SetLT: Out << " < "; break;
680 case Instruction::SetGT: Out << " > "; break;
681 case Instruction::Shl : Out << " << "; break;
682 case Instruction::Shr : Out << " >> "; break;
683 default: cerr << "Invalid operator type!" << I; abort();
686 if (isa<PointerType>(I->getType())) Out << "(long long)";
687 writeOperand(I->getOperand(1));
690 void CWriter::visitCastInst(CastInst *I) {
692 printType(I->getType());
694 writeOperand(I->getOperand(0));
697 void CWriter::visitCallInst(CallInst *I) {
698 const PointerType *PTy = cast<PointerType>(I->getCalledValue()->getType());
699 const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
700 const Type *RetTy = FTy->getReturnType();
702 Out << getValueName(I->getOperand(0)) << "(";
704 if (I->getNumOperands() > 1) {
705 writeOperand(I->getOperand(1));
707 for (unsigned op = 2, Eop = I->getNumOperands(); op != Eop; ++op) {
709 writeOperand(I->getOperand(op));
715 void CWriter::visitMallocInst(MallocInst *I) {
717 printType(I->getType());
718 Out << ")malloc(sizeof(";
719 printType(I->getType()->getElementType());
722 if (I->isArrayAllocation()) {
724 writeOperand(I->getOperand(0));
729 void CWriter::visitAllocaInst(AllocaInst *I) {
731 printType(I->getType());
732 Out << ") alloca(sizeof(";
733 printType(I->getType()->getElementType());
735 if (I->isArrayAllocation()) {
737 writeOperand(I->getOperand(0));
742 void CWriter::visitFreeInst(FreeInst *I) {
744 writeOperand(I->getOperand(0));
748 void CWriter::printIndexingExpr(MemAccessInst *MAI) {
749 MemAccessInst::op_iterator I = MAI->idx_begin(), E = MAI->idx_end();
751 // If accessing a global value with no indexing, avoid *(&GV) syndrome
752 if (GlobalValue *V = dyn_cast<GlobalValue>(MAI->getPointerOperand())) {
753 writeOperandInternal(V);
757 Out << "*"; // Implicit zero first argument: '*x' is equivalent to 'x[0]'
760 writeOperand(MAI->getPointerOperand());
764 // Print out the -> operator if possible...
765 Constant *CI = dyn_cast<Constant>(*I);
766 if (CI && CI->isNullValue() && I+1 != E &&
767 (*(I+1))->getType() == Type::UByteTy) {
768 Out << "->field" << cast<ConstantUInt>(*(I+1))->getValue();
773 if ((*I)->getType() == Type::UIntTy) {
778 Out << ".field" << cast<ConstantUInt>(*I)->getValue();
782 void CWriter::visitLoadInst(LoadInst *I) {
783 printIndexingExpr(I);
786 void CWriter::visitStoreInst(StoreInst *I) {
787 printIndexingExpr(I);
789 writeOperand(I->getOperand(0));
792 void CWriter::visitGetElementPtrInst(GetElementPtrInst *I) {
794 printIndexingExpr(I);
797 //===----------------------------------------------------------------------===//
798 // External Interface declaration
799 //===----------------------------------------------------------------------===//
801 void WriteToC(const Module *M, ostream &Out) {
802 assert(M && "You can't write a null module!!");
803 SlotCalculator SlotTable(M, false);
804 CWriter W(Out, SlotTable, M);