@@ -534,11 +534,19 @@ void CppWriter::printType(Type* Ty) {
534
534
case Type::StructTyID: {
535
535
StructType* ST = cast<StructType>(Ty);
536
536
if (!ST->isLiteral ()) {
537
- Out << " StructType *" << typeName << " = " ;
537
+ Out << " StructType *" << typeName << " = mod->getTypeByName(\" " ;
538
+ printEscapedString (ST->getName ());
539
+ Out << " \" );" ;
540
+ nl (Out);
541
+ Out << " if (!" << typeName << " ) {" ;
542
+ nl (Out);
543
+ Out << typeName << " = " ;
538
544
Out << " StructType::create(mod->getContext(), \" " ;
539
545
printEscapedString (ST->getName ());
540
546
Out << " \" );" ;
541
547
nl (Out);
548
+ Out << " }" ;
549
+ nl (Out);
542
550
// Indicate that this type is now defined.
543
551
DefinedTypes.insert (Ty);
544
552
}
@@ -560,12 +568,18 @@ void CppWriter::printType(Type* Ty) {
560
568
Out << " StructType *" << typeName << " = " ;
561
569
Out << " StructType::get(" << " mod->getContext(), " ;
562
570
} else {
571
+ Out << " if (" << typeName << " ->isOpaque()) {" ;
572
+ nl (Out);
563
573
Out << typeName << " ->setBody(" ;
564
574
}
565
575
566
576
Out << typeName << " _fields, /*isPacked=*/"
567
577
<< (ST->isPacked () ? " true" : " false" ) << " );" ;
568
578
nl (Out);
579
+ if (!ST->isLiteral ()) {
580
+ Out << " }" ;
581
+ nl (Out);
582
+ }
569
583
break ;
570
584
}
571
585
case Type::ArrayTyID: {
@@ -1538,13 +1552,12 @@ void CppWriter::printFunctionUses(const Function* F) {
1538
1552
1539
1553
void CppWriter::printFunctionHead (const Function* F) {
1540
1554
nl (Out) << " Function* " << getCppName (F);
1541
- if (is_inline) {
1542
- Out << " = mod->getFunction(\" " ;
1543
- printEscapedString (F->getName ());
1544
- Out << " \" , " << getCppName (F->getFunctionType ()) << " );" ;
1545
- nl (Out) << " if (!" << getCppName (F) << " ) {" ;
1546
- nl (Out) << getCppName (F);
1547
- }
1555
+ Out << " = mod->getFunction(\" " ;
1556
+ printEscapedString (F->getName ());
1557
+ Out << " \" );" ;
1558
+ nl (Out) << " if (!" << getCppName (F) << " ) {" ;
1559
+ nl (Out) << getCppName (F);
1560
+
1548
1561
Out<< " = Function::Create(" ;
1549
1562
nl (Out,1 ) << " /*Type=*/" << getCppName (F->getFunctionType ()) << " ," ;
1550
1563
nl (Out) << " /*Linkage=*/" ;
@@ -1581,10 +1594,8 @@ void CppWriter::printFunctionHead(const Function* F) {
1581
1594
Out << " ->setGC(\" " << F->getGC () << " \" );" ;
1582
1595
nl (Out);
1583
1596
}
1584
- if (is_inline) {
1585
- Out << " }" ;
1586
- nl (Out);
1587
- }
1597
+ Out << " }" ;
1598
+ nl (Out);
1588
1599
printAttributes (F->getAttributes (), getCppName (F));
1589
1600
printCppName (F);
1590
1601
Out << " ->setAttributes(" << getCppName (F) << " _PAL);" ;
0 commit comments