Add support for 'weak' linkage.
authorChris Lattner <sabre@nondot.org>
Thu, 16 Oct 2003 18:28:50 +0000 (18:28 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 16 Oct 2003 18:28:50 +0000 (18:28 +0000)
For now, we translate linkonce into weak linkage in the bytecode format because
we don't have enough bits to represent it.  We will rev the bytecode version
soon anyways, so this will be fixed in the near future.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@9170 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bytecode/Reader/Reader.cpp
lib/Bytecode/Writer/Writer.cpp

index e8e1afd52e803ed759937dd81edb6870b5df3742..29d0a71b58921aa47ba2f699b0715b299a686eb8 100644 (file)
@@ -318,7 +318,12 @@ void BytecodeParser::materializeFunction(Function* F) {
       throw std::string("ParseFunction: Error reading from buffer.");
     if (LinkageType & ~0x3) 
       throw std::string("Invalid linkage type for Function.");
-    Linkage = (GlobalValue::LinkageTypes)LinkageType;
+    switch (LinkageType) {
+    case 0: Linkage = GlobalValue::ExternalLinkage; break;
+    case 1: Linkage = GlobalValue::WeakLinkage; break;
+    case 2: Linkage = GlobalValue::AppendingLinkage; break;
+    case 3: Linkage = GlobalValue::InternalLinkage; break;
+    }
   } else {
     // We used to only support two linkage models: internal and external
     unsigned isInternal;
@@ -436,7 +441,12 @@ void BytecodeParser::ParseModuleGlobalInfo(const unsigned char *&Buf,
       // VarType Fields: bit0 = isConstant, bit1 = hasInitializer,
       // bit2,3 = Linkage, bit4+ = slot#
       SlotNo = VarType >> 4;
-      Linkage = (GlobalValue::LinkageTypes)((VarType >> 2) & 3);
+      switch ((VarType >> 2) & 3) {
+      case 0: Linkage = GlobalValue::ExternalLinkage;  break;
+      case 1: Linkage = GlobalValue::WeakLinkage;      break;
+      case 2: Linkage = GlobalValue::AppendingLinkage; break;
+      case 3: Linkage = GlobalValue::InternalLinkage;  break;
+      }
     } else {
       // VarType Fields: bit0 = isConstant, bit1 = hasInitializer,
       // bit2 = isInternal, bit3+ = slot#
index 413fd293dbd7eb46d0c6168b84a23f9885655697..1e6d63a0f1e56acb4b88a05f48b79e811a41ef8d 100644 (file)
@@ -158,6 +158,17 @@ void BytecodeWriter::outputConstants(bool isFunction) {
     }
 }
 
+static unsigned getEncodedLinkage(const GlobalValue *GV) {
+  switch (GV->getLinkage()) {
+  default: assert(0 && "Invalid linkage!");
+  case GlobalValue::ExternalLinkage:  return 0;
+  case GlobalValue::LinkOnceLinkage:  return 1;
+  case GlobalValue::WeakLinkage:      return 1;
+  case GlobalValue::AppendingLinkage: return 2;
+  case GlobalValue::InternalLinkage:  return 3;
+  }
+}
+
 void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
   BytecodeBlock ModuleInfoBlock(BytecodeFormat::ModuleGlobalInfo, Out);
   
@@ -168,7 +179,7 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
 
     // Fields: bit0 = isConstant, bit1 = hasInitializer, bit2,3=Linkage,
     // bit4+ = Slot # for type
-    unsigned oSlot = ((unsigned)Slot << 4) | ((unsigned)I->getLinkage() << 2) |
+    unsigned oSlot = ((unsigned)Slot << 4) | (getEncodedLinkage(I) << 2) |
                      (I->hasInitializer() << 1) | I->isConstant();
     output_vbr(oSlot, Out);
 
@@ -195,7 +206,7 @@ void BytecodeWriter::outputModuleInfoBlock(const Module *M) {
 
 void BytecodeWriter::outputFunction(const Function *F) {
   BytecodeBlock FunctionBlock(BytecodeFormat::Function, Out);
-  output_vbr((unsigned)F->getLinkage(), Out);
+  output_vbr(getEncodedLinkage(F), Out);
   // Only output the constant pool and other goodies if needed...
   if (!F->isExternal()) {