#include "llvm/Transforms/Utils/Linker.h"
#include "llvm/Module.h"
-#include "llvm/Function.h"
-#include "llvm/BasicBlock.h"
-#include "llvm/GlobalVariable.h"
#include "llvm/SymbolTable.h"
#include "llvm/DerivedTypes.h"
#include "llvm/iOther.h"
#include "llvm/Constants.h"
-#include "llvm/Argument.h"
-#include <iostream>
using std::cerr;
using std::string;
using std::map;
if (const ConstantArray *CPA = dyn_cast<ConstantArray>(CPV)) {
const std::vector<Use> &Ops = CPA->getValues();
std::vector<Constant*> Operands(Ops.size());
- for (unsigned i = 0; i < Ops.size(); ++i)
+ for (unsigned i = 0, e = Ops.size(); i != e; ++i)
Operands[i] =
cast<Constant>(RemapOperand(Ops[i], LocalMap, GlobalMap));
Result = ConstantArray::get(cast<ArrayType>(CPA->getType()), Operands);
Result = ConstantPointerRef::get(cast<GlobalValue>(V));
} else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CPV)) {
if (CE->getNumOperands() == 1) {
- // Cast instruction, unary operator
+ // Cast instruction
+ assert(CE->getOpcode() == Instruction::Cast);
Value *V = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap);
- Result = ConstantExpr::get(CE->getOpcode(), cast<Constant>(V),
- CE->getType());
+ Result = ConstantExpr::getCast(cast<Constant>(V), CE->getType());
} else if (CE->getNumOperands() == 2) {
// Binary operator...
Value *V1 = RemapOperand(CE->getOperand(0), LocalMap, GlobalMap);
Value *V2 = RemapOperand(CE->getOperand(1), LocalMap, GlobalMap);
Result = ConstantExpr::get(CE->getOpcode(), cast<Constant>(V1),
- cast<Constant>(V2), CE->getType());
+ cast<Constant>(V2));
} else {
// GetElementPtr Expression
assert(CE->getOpcode() == Instruction::GetElementPtr);
Indices.push_back(cast<Constant>(RemapOperand(CE->getOperand(i),
LocalMap, GlobalMap)));
- Result = ConstantExpr::get(CE->getOpcode(), cast<Constant>(Ptr),
- Indices, CE->getType());
+ Result = ConstantExpr::getGetElementPtr(cast<Constant>(Ptr), Indices);
}
} else {
}
// Cache the mapping in our local map structure...
- LocalMap.insert(std::make_pair(In, const_cast<Constant*>(CPV)));
+ LocalMap.insert(std::make_pair(In, Result));
return Result;
}
// the problem. Upon failure, the Dest module could be in a modified state, and
// shouldn't be relied on to be consistent.
//
-bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0) {
+bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg) {
// LinkTypes - Go through the symbol table of the Src module and see if any
// types are named in the src module that are not named in the Dst module.
//
map<const Value*, Value*> ValueMap;
- // FIXME:
- // FIXME: This should be a two step process:
- // FIXME: 1. LinkGlobals & LinkFunctionProtos
- // FIXME: 2. LinkGlobalContents
- // FIXME:
- // FIXME: Global variables and functions are the same!
- // FIXME:
-
-
// Insert all of the globals in src into the Dest module... without
// initializers
if (LinkGlobals(Dest, Src, ValueMap, ErrorMsg)) return true;