//===-- Writer.cpp - Library for writing C files --------------------------===//
//
// This library implements the functionality defined in llvm/Assembly/CWriter.h
// and CLocalVars.h
//
// TODO : Recursive types.
//
//===-----------------------------------------------------------------------==//
#include "llvm/Assembly/CWriter.h"
#include "CLocalVars.h"
#include "llvm/SlotCalculator.h"
#include "llvm/Module.h"
#include "llvm/Argument.h"
#include "llvm/Function.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Constants.h"
#include "llvm/GlobalVariable.h"
#include "llvm/BasicBlock.h"
#include "llvm/iMemory.h"
#include "llvm/iTerminators.h"
#include "llvm/iPHINode.h"
#include "llvm/iOther.h"
#include "llvm/SymbolTable.h"
#include "llvm/Support/InstVisitor.h"
#include "Support/StringExtras.h"
#include "Support/STLExtras.h"
#include <algorithm>
#include <strstream>
using std::string;
using std::map;
using std::vector;
using std::ostream;
//===-----------------------------------------------------------------------==//
//
// Implementation of the CLocalVars methods
// Appends a variable to the LocalVars map if it does not already exist
// Also check that the type exists on the map.
void CLocalVars::addLocalVar(const Type *t, const string & var) {
if (!LocalVars.count(t) ||
find(LocalVars[t].begin(), LocalVars[t].end(), var)
== LocalVars[t].end()) {
LocalVars[t].push_back(var);
}
}
static string calcTypeNameVar(const Type *Ty,
map<const Type *, string> &TypeNames,
string VariableName, string NameSoFar);
static std::string getConstStrValue(const Constant* CPV);
//
//Getting opcodes in terms of the operator
//
static const char *getOpcodeOperName(const Instruction *I) {
switch (I->getOpcode()) {
// Standard binary operators...
case Instruction::Add: return "+";
case Instruction::Sub: return "-";
case Instruction::Mul: return "*";
case Instruction::Div: return "/";
case Instruction::Rem: return "%";
// Logical operators...
case Instruction::And: return "&";
case Instruction::Or: return "|";
case Instruction::Xor: return "^";
// SetCond operators...
case Instruction::SetEQ: return "==";
case Instruction::SetNE: return "!=";
case Instruction::SetLE: return "<=";
case Instruction::SetGE: return ">=";
case Instruction::SetLT: return "<";
case Instruction::SetGT: return ">";
//ShiftInstruction...
case Instruction::Shl : return "<<";
case Instruction::Shr : return ">>";
default:
cerr << "Invalid operator type!" << I->getOpcode()