llvm.org GIT mirror llvm / 7509ccd
When emitting a single function with cppgen=function, you don't want to emit initializers of global variables used in the function. Also make sure to emit the operands of a constant. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@120253 91177308-0d34-0410-b5e6-96231b3b80d8 Nicolas Geoffray 10 years ago
1 changed file(s) with 26 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
15631563 // If the operand references a GVal or Constant, make a note of it
15641564 if (GlobalValue* GV = dyn_cast(operand)) {
15651565 gvs.insert(GV);
1566 if (GlobalVariable *GVar = dyn_cast(GV))
1567 if (GVar->hasInitializer())
1568 consts.insert(GVar->getInitializer());
1569 } else if (Constant* C = dyn_cast(operand))
1566 if (GenerationType != GenFunction)
1567 if (GlobalVariable *GVar = dyn_cast(GV))
1568 if (GVar->hasInitializer())
1569 consts.insert(GVar->getInitializer());
1570 } else if (Constant* C = dyn_cast(operand)) {
15701571 consts.insert(C);
1572 for (unsigned j = 0; j < C->getNumOperands(); ++j) {
1573 // If the operand references a GVal or Constant, make a note of it
1574 Value* operand = C->getOperand(j);
1575 printType(operand->getType());
1576 if (GlobalValue* GV = dyn_cast(operand)) {
1577 gvs.insert(GV);
1578 if (GenerationType != GenFunction)
1579 if (GlobalVariable *GVar = dyn_cast(GV))
1580 if (GVar->hasInitializer())
1581 consts.insert(GVar->getInitializer());
1582 }
1583 }
1584 }
15711585 }
15721586 }
15731587 }
15901604 printVariableHead(F);
15911605 }
15921606
1593 // Print the constants found
1607 // Print the constants found
15941608 nl(Out) << "// Constant Definitions"; nl(Out);
15951609 for (SmallPtrSet::iterator I = consts.begin(),
15961610 E = consts.end(); I != E; ++I) {
16001614 // Process the global variables definitions now that all the constants have
16011615 // been emitted. These definitions just couple the gvars with their constant
16021616 // initializers.
1603 nl(Out) << "// Global Variable Definitions"; nl(Out);
1604 for (SmallPtrSet::iterator I = gvs.begin(), E = gvs.end();
1605 I != E; ++I) {
1606 if (GlobalVariable* GV = dyn_cast(*I))
1607 printVariableBody(GV);
1617 if (GenerationType != GenFunction) {
1618 nl(Out) << "// Global Variable Definitions"; nl(Out);
1619 for (SmallPtrSet::iterator I = gvs.begin(), E = gvs.end();
1620 I != E; ++I) {
1621 if (GlobalVariable* GV = dyn_cast(*I))
1622 printVariableBody(GV);
1623 }
16081624 }
16091625 }
16101626