[llvm-commits] CVS: llvm/lib/Bytecode/Writer/Writer.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Oct 16 13:29:03 PDT 2003


Changes in directory llvm/lib/Bytecode/Writer:

Writer.cpp updated: 1.39 -> 1.40

---
Log message:

Add support for 'weak' linkage.

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.


---
Diffs of the changes:  (+13 -2)

Index: llvm/lib/Bytecode/Writer/Writer.cpp
diff -u llvm/lib/Bytecode/Writer/Writer.cpp:1.39 llvm/lib/Bytecode/Writer/Writer.cpp:1.40
--- llvm/lib/Bytecode/Writer/Writer.cpp:1.39	Sun Oct 12 22:32:07 2003
+++ llvm/lib/Bytecode/Writer/Writer.cpp	Thu Oct 16 13:28:50 2003
@@ -158,6 +158,17 @@
     }
 }
 
+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 @@
 
     // 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::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()) {
 





More information about the llvm-commits mailing list