11#include " IR.h"
22#include " ../Utils.h"
33
4- IR::IR (std::string libName) : libName(std::move(libName)) {
5- if (this ->libName == " native" ) {
6- /* there are at most 3 objects in the file.
7- * All of them will have distinct names. */
8- libObjectName = " nativeLib" ;
9- } else {
10- libObjectName = this ->libName ;
11- }
12- }
4+ IR::IR (std::string libName, std::string linkName, std::string objectName,
5+ std::string packageName)
6+ : libName(std::move(libName)), linkName(std::move(linkName)),
7+ objectName(std::move(objectName)), packageName(packageName) {}
138
149void IR::addFunction (std::string name, std::vector<Parameter> parameters,
1510 std::string retType, bool isVariadic) {
@@ -54,12 +49,15 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) {
5449 << " import scala.scalanative.native._\n\n " ;
5550 }
5651
57- std::string libObjName = handleReservedWords (ir.libObjectName );
52+ std::string objectName = handleReservedWords (ir.objectName );
5853
5954 if (!ir.libObjEmpty ()) {
60- s << " @native.link(\" " << ir.libName << " \" )\n "
61- << " @native.extern\n "
62- << " object " << libObjName << " {\n " ;
55+ if (!ir.linkName .empty ()) {
56+ s << " @native.link(\" " << ir.linkName << " \" )\n " ;
57+ }
58+
59+ s << " @native.extern\n "
60+ << " object " << objectName << " {\n " ;
6361
6462 for (const auto &typeDef : ir.typeDefs ) {
6563 s << typeDef;
@@ -73,7 +71,7 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &s, const IR &ir) {
7371 }
7472
7573 if (!ir.enums .empty () || ir.hasHelperMethods ()) {
76- s << " import " << libObjName << " ._\n\n " ;
74+ s << " import " << objectName << " ._\n\n " ;
7775 }
7876
7977 if (!ir.enums .empty ()) {
@@ -207,10 +205,6 @@ bool IR::typeIsUsedOnlyInTypeDefs(std::string type) {
207205 isTypeUsed (unions, type));
208206}
209207
210- void IR::setPackageName (std::string packageName) {
211- this ->packageName = std::move (packageName);
212- }
213-
214208void IR::setScalaNames () {
215209 /* Renaming according to Scala naming conventions
216210 * should happen here */
0 commit comments