07319d595a1f2d7280121fb4283515b489d4ff66
[oota-llvm.git] / lib / CodeGen / AsmPrinter.cpp
1 //===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the AsmPrinter class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/AsmPrinter.h"
15 #include "llvm/Assembly/Writer.h"
16 #include "llvm/DerivedTypes.h"
17 #include "llvm/Constants.h"
18 #include "llvm/Module.h"
19 #include "llvm/CodeGen/MachineConstantPool.h"
20 #include "llvm/CodeGen/MachineJumpTableInfo.h"
21 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/Mangler.h"
23 #include "llvm/Support/MathExtras.h"
24 #include "llvm/Support/Streams.h"
25 #include "llvm/Target/TargetAsmInfo.h"
26 #include "llvm/Target/TargetData.h"
27 #include "llvm/Target/TargetLowering.h"
28 #include "llvm/Target/TargetMachine.h"
29 #include <cerrno>
30 using namespace llvm;
31
32 static cl::opt<bool>
33 AsmVerbose("asm-verbose", cl::Hidden, cl::desc("Add comments to directives."));
34
35 char AsmPrinter::ID = 0;
36 AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm,
37                        const TargetAsmInfo *T)
38   : MachineFunctionPass((intptr_t)&ID), FunctionNumber(0), O(o), TM(tm), TAI(T)
39 {}
40
41 std::string AsmPrinter::getSectionForFunction(const Function &F) const {
42   return TAI->getTextSection();
43 }
44
45
46 /// SwitchToTextSection - Switch to the specified text section of the executable
47 /// if we are not already in it!
48 ///
49 void AsmPrinter::SwitchToTextSection(const char *NewSection,
50                                      const GlobalValue *GV) {
51   std::string NS;
52   if (GV && GV->hasSection())
53     NS = TAI->getSwitchToSectionDirective() + GV->getSection();
54   else
55     NS = NewSection;
56   
57   // If we're already in this section, we're done.
58   if (CurrentSection == NS) return;
59
60   // Close the current section, if applicable.
61   if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
62     O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
63
64   CurrentSection = NS;
65
66   if (!CurrentSection.empty())
67     O << CurrentSection << TAI->getTextSectionStartSuffix() << '\n';
68 }
69
70 /// SwitchToDataSection - Switch to the specified data section of the executable
71 /// if we are not already in it!
72 ///
73 void AsmPrinter::SwitchToDataSection(const char *NewSection,
74                                      const GlobalValue *GV) {
75   std::string NS;
76   if (GV && GV->hasSection())
77     NS = TAI->getSwitchToSectionDirective() + GV->getSection();
78   else
79     NS = NewSection;
80   
81   // If we're already in this section, we're done.
82   if (CurrentSection == NS) return;
83
84   // Close the current section, if applicable.
85   if (TAI->getSectionEndDirectiveSuffix() && !CurrentSection.empty())
86     O << CurrentSection << TAI->getSectionEndDirectiveSuffix() << "\n";
87
88   CurrentSection = NS;
89   
90   if (!CurrentSection.empty())
91     O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
92 }
93
94
95 bool AsmPrinter::doInitialization(Module &M) {
96   Mang = new Mangler(M, TAI->getGlobalPrefix());
97   
98   if (!M.getModuleInlineAsm().empty())
99     O << TAI->getCommentString() << " Start of file scope inline assembly\n"
100       << M.getModuleInlineAsm()
101       << "\n" << TAI->getCommentString()
102       << " End of file scope inline assembly\n";
103
104   SwitchToDataSection("");   // Reset back to no section.
105   
106   if (MachineModuleInfo *MMI = getAnalysisToUpdate<MachineModuleInfo>()) {
107     MMI->AnalyzeModule(M);
108   }
109   
110   return false;
111 }
112
113 bool AsmPrinter::doFinalization(Module &M) {
114   if (TAI->getWeakRefDirective()) {
115     if (!ExtWeakSymbols.empty())
116       SwitchToDataSection("");
117
118     for (std::set<const GlobalValue*>::iterator i = ExtWeakSymbols.begin(),
119          e = ExtWeakSymbols.end(); i != e; ++i) {
120       const GlobalValue *GV = *i;
121       std::string Name = Mang->getValueName(GV);
122       O << TAI->getWeakRefDirective() << Name << "\n";
123     }
124   }
125
126   if (TAI->getSetDirective()) {
127     if (!M.alias_empty())
128       SwitchToTextSection(TAI->getTextSection());
129
130     O << "\n";
131     for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
132          I!=E; ++I) {
133       std::string Name = Mang->getValueName(I);
134       std::string Target;
135       
136       if (const GlobalValue *GV = I->getAliasedGlobal())
137         Target = Mang->getValueName(GV);
138       else
139         assert(0 && "Unsupported aliasee");
140       
141       if (I->hasExternalLinkage())
142         O << "\t.globl\t" << Name << "\n";
143       else if (I->hasWeakLinkage())
144         O << TAI->getWeakRefDirective() << Name << "\n";
145       else if (!I->hasInternalLinkage())
146         assert(0 && "Invalid alias linkage");
147       
148       O << TAI->getSetDirective() << Name << ", " << Target << "\n";
149     }
150   }
151
152   delete Mang; Mang = 0;
153   return false;
154 }
155
156 void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
157   // What's my mangled name?
158   CurrentFnName = Mang->getValueName(MF.getFunction());
159   IncrementFunctionNumber();
160 }
161
162 /// EmitConstantPool - Print to the current output stream assembly
163 /// representations of the constants in the constant pool MCP. This is
164 /// used to print out constants which have been "spilled to memory" by
165 /// the code generator.
166 ///
167 void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
168   const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
169   if (CP.empty()) return;
170
171   // Some targets require 4-, 8-, and 16- byte constant literals to be placed
172   // in special sections.
173   std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
174   std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
175   std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
176   std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
177   std::vector<std::pair<MachineConstantPoolEntry,unsigned> > TargetCPs;
178   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
179     MachineConstantPoolEntry CPE = CP[i];
180     const Type *Ty = CPE.getType();
181     if (TAI->getFourByteConstantSection() &&
182         TM.getTargetData()->getTypeSize(Ty) == 4)
183       FourByteCPs.push_back(std::make_pair(CPE, i));
184     else if (TAI->getEightByteConstantSection() &&
185              TM.getTargetData()->getTypeSize(Ty) == 8)
186       EightByteCPs.push_back(std::make_pair(CPE, i));
187     else if (TAI->getSixteenByteConstantSection() &&
188              TM.getTargetData()->getTypeSize(Ty) == 16)
189       SixteenByteCPs.push_back(std::make_pair(CPE, i));
190     else
191       OtherCPs.push_back(std::make_pair(CPE, i));
192   }
193
194   unsigned Alignment = MCP->getConstantPoolAlignment();
195   EmitConstantPool(Alignment, TAI->getFourByteConstantSection(), FourByteCPs);
196   EmitConstantPool(Alignment, TAI->getEightByteConstantSection(), EightByteCPs);
197   EmitConstantPool(Alignment, TAI->getSixteenByteConstantSection(),
198                    SixteenByteCPs);
199   EmitConstantPool(Alignment, TAI->getConstantPoolSection(), OtherCPs);
200 }
201
202 void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
203                std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
204   if (CP.empty()) return;
205
206   SwitchToDataSection(Section);
207   EmitAlignment(Alignment);
208   for (unsigned i = 0, e = CP.size(); i != e; ++i) {
209     O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << '_'
210       << CP[i].second << ":\t\t\t\t\t" << TAI->getCommentString() << " ";
211     WriteTypeSymbolic(O, CP[i].first.getType(), 0) << '\n';
212     if (CP[i].first.isMachineConstantPoolEntry())
213       EmitMachineConstantPoolValue(CP[i].first.Val.MachineCPVal);
214      else
215       EmitGlobalConstant(CP[i].first.Val.ConstVal);
216     if (i != e-1) {
217       const Type *Ty = CP[i].first.getType();
218       unsigned EntSize =
219         TM.getTargetData()->getTypeSize(Ty);
220       unsigned ValEnd = CP[i].first.getOffset() + EntSize;
221       // Emit inter-object padding for alignment.
222       EmitZeros(CP[i+1].first.getOffset()-ValEnd);
223     }
224   }
225 }
226
227 /// EmitJumpTableInfo - Print assembly representations of the jump tables used
228 /// by the current function to the current output stream.  
229 ///
230 void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
231                                    MachineFunction &MF) {
232   const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
233   if (JT.empty()) return;
234   bool IsPic = TM.getRelocationModel() == Reloc::PIC_;
235   
236   // Use JumpTableDirective otherwise honor the entry size from the jump table
237   // info.
238   const char *JTEntryDirective = TAI->getJumpTableDirective();
239   bool HadJTEntryDirective = JTEntryDirective != NULL;
240   if (!HadJTEntryDirective) {
241     JTEntryDirective = MJTI->getEntrySize() == 4 ?
242       TAI->getData32bitsDirective() : TAI->getData64bitsDirective();
243   }
244   
245   // Pick the directive to use to print the jump table entries, and switch to 
246   // the appropriate section.
247   TargetLowering *LoweringInfo = TM.getTargetLowering();
248
249   const char* JumpTableDataSection = TAI->getJumpTableDataSection();  
250   if ((IsPic && !(LoweringInfo && LoweringInfo->usesGlobalOffsetTable())) ||
251      !JumpTableDataSection) {
252     // In PIC mode, we need to emit the jump table to the same section as the
253     // function body itself, otherwise the label differences won't make sense.
254     // We should also do if the section name is NULL.
255     const Function *F = MF.getFunction();
256     SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
257   } else {
258     SwitchToDataSection(JumpTableDataSection);
259   }
260   
261   EmitAlignment(Log2_32(MJTI->getAlignment()));
262   
263   for (unsigned i = 0, e = JT.size(); i != e; ++i) {
264     const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
265     
266     // If this jump table was deleted, ignore it. 
267     if (JTBBs.empty()) continue;
268
269     // For PIC codegen, if possible we want to use the SetDirective to reduce
270     // the number of relocations the assembler will generate for the jump table.
271     // Set directives are all printed before the jump table itself.
272     std::set<MachineBasicBlock*> EmittedSets;
273     if (TAI->getSetDirective() && IsPic)
274       for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii)
275         if (EmittedSets.insert(JTBBs[ii]).second)
276           printSetLabel(i, JTBBs[ii]);
277     
278     // On some targets (e.g. darwin) we want to emit two consequtive labels
279     // before each jump table.  The first label is never referenced, but tells
280     // the assembler and linker the extents of the jump table object.  The
281     // second label is actually referenced by the code.
282     if (const char *JTLabelPrefix = TAI->getJumpTableSpecialLabelPrefix())
283       O << JTLabelPrefix << "JTI" << getFunctionNumber() << '_' << i << ":\n";
284     
285     O << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
286       << '_' << i << ":\n";
287     
288     for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
289       O << JTEntryDirective << ' ';
290       // If we have emitted set directives for the jump table entries, print 
291       // them rather than the entries themselves.  If we're emitting PIC, then
292       // emit the table entries as differences between two text section labels.
293       // If we're emitting non-PIC code, then emit the entries as direct
294       // references to the target basic blocks.
295       if (!EmittedSets.empty()) {
296         O << TAI->getPrivateGlobalPrefix() << getFunctionNumber()
297           << '_' << i << "_set_" << JTBBs[ii]->getNumber();
298       } else if (IsPic) {
299         printBasicBlockLabel(JTBBs[ii], false, false);
300         // If the arch uses custom Jump Table directives, don't calc relative to
301         // JT
302         if (!HadJTEntryDirective) 
303           O << '-' << TAI->getPrivateGlobalPrefix() << "JTI"
304             << getFunctionNumber() << '_' << i;
305       } else {
306         printBasicBlockLabel(JTBBs[ii], false, false);
307       }
308       O << '\n';
309     }
310   }
311 }
312
313 /// EmitSpecialLLVMGlobal - Check to see if the specified global is a
314 /// special global used by LLVM.  If so, emit it and return true, otherwise
315 /// do nothing and return false.
316 bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
317   // Ignore debug and non-emitted data.
318   if (GV->getSection() == "llvm.metadata") return true;
319   
320   if (!GV->hasAppendingLinkage()) return false;
321
322   assert(GV->hasInitializer() && "Not a special LLVM global!");
323   
324   if (GV->getName() == "llvm.used") {
325     if (TAI->getUsedDirective() != 0)    // No need to emit this at all.
326       EmitLLVMUsedList(GV->getInitializer());
327     return true;
328   }
329
330   if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
331     SwitchToDataSection(TAI->getStaticCtorsSection());
332     EmitAlignment(2, 0);
333     EmitXXStructorList(GV->getInitializer());
334     return true;
335   } 
336   
337   if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
338     SwitchToDataSection(TAI->getStaticDtorsSection());
339     EmitAlignment(2, 0);
340     EmitXXStructorList(GV->getInitializer());
341     return true;
342   }
343   
344   return false;
345 }
346
347 /// EmitLLVMUsedList - For targets that define a TAI::UsedDirective, mark each
348 /// global in the specified llvm.used list as being used with this directive.
349 void AsmPrinter::EmitLLVMUsedList(Constant *List) {
350   const char *Directive = TAI->getUsedDirective();
351
352   // Should be an array of 'sbyte*'.
353   ConstantArray *InitList = dyn_cast<ConstantArray>(List);
354   if (InitList == 0) return;
355   
356   for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i) {
357     O << Directive;
358     EmitConstantValueOnly(InitList->getOperand(i));
359     O << "\n";
360   }
361 }
362
363 /// EmitXXStructorList - Emit the ctor or dtor list.  This just prints out the 
364 /// function pointers, ignoring the init priority.
365 void AsmPrinter::EmitXXStructorList(Constant *List) {
366   // Should be an array of '{ int, void ()* }' structs.  The first value is the
367   // init priority, which we ignore.
368   if (!isa<ConstantArray>(List)) return;
369   ConstantArray *InitList = cast<ConstantArray>(List);
370   for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
371     if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
372       if (CS->getNumOperands() != 2) return;  // Not array of 2-element structs.
373
374       if (CS->getOperand(1)->isNullValue())
375         return;  // Found a null terminator, exit printing.
376       // Emit the function pointer.
377       EmitGlobalConstant(CS->getOperand(1));
378     }
379 }
380
381 /// getGlobalLinkName - Returns the asm/link name of of the specified
382 /// global variable.  Should be overridden by each target asm printer to
383 /// generate the appropriate value.
384 const std::string AsmPrinter::getGlobalLinkName(const GlobalVariable *GV) const{
385   std::string LinkName;
386   
387   if (isa<Function>(GV)) {
388     LinkName += TAI->getFunctionAddrPrefix();
389     LinkName += Mang->getValueName(GV);
390     LinkName += TAI->getFunctionAddrSuffix();
391   } else {
392     LinkName += TAI->getGlobalVarAddrPrefix();
393     LinkName += Mang->getValueName(GV);
394     LinkName += TAI->getGlobalVarAddrSuffix();
395   }  
396   
397   return LinkName;
398 }
399
400 /// EmitExternalGlobal - Emit the external reference to a global variable.
401 /// Should be overridden if an indirect reference should be used.
402 void AsmPrinter::EmitExternalGlobal(const GlobalVariable *GV) {
403   O << getGlobalLinkName(GV);
404 }
405
406
407
408 //===----------------------------------------------------------------------===//
409 /// LEB 128 number encoding.
410
411 /// PrintULEB128 - Print a series of hexidecimal values (separated by commas)
412 /// representing an unsigned leb128 value.
413 void AsmPrinter::PrintULEB128(unsigned Value) const {
414   do {
415     unsigned Byte = Value & 0x7f;
416     Value >>= 7;
417     if (Value) Byte |= 0x80;
418     O << "0x" << std::hex << Byte << std::dec;
419     if (Value) O << ", ";
420   } while (Value);
421 }
422
423 /// SizeULEB128 - Compute the number of bytes required for an unsigned leb128
424 /// value.
425 unsigned AsmPrinter::SizeULEB128(unsigned Value) {
426   unsigned Size = 0;
427   do {
428     Value >>= 7;
429     Size += sizeof(int8_t);
430   } while (Value);
431   return Size;
432 }
433
434 /// PrintSLEB128 - Print a series of hexidecimal values (separated by commas)
435 /// representing a signed leb128 value.
436 void AsmPrinter::PrintSLEB128(int Value) const {
437   int Sign = Value >> (8 * sizeof(Value) - 1);
438   bool IsMore;
439   
440   do {
441     unsigned Byte = Value & 0x7f;
442     Value >>= 7;
443     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
444     if (IsMore) Byte |= 0x80;
445     O << "0x" << std::hex << Byte << std::dec;
446     if (IsMore) O << ", ";
447   } while (IsMore);
448 }
449
450 /// SizeSLEB128 - Compute the number of bytes required for a signed leb128
451 /// value.
452 unsigned AsmPrinter::SizeSLEB128(int Value) {
453   unsigned Size = 0;
454   int Sign = Value >> (8 * sizeof(Value) - 1);
455   bool IsMore;
456   
457   do {
458     unsigned Byte = Value & 0x7f;
459     Value >>= 7;
460     IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
461     Size += sizeof(int8_t);
462   } while (IsMore);
463   return Size;
464 }
465
466 //===--------------------------------------------------------------------===//
467 // Emission and print routines
468 //
469
470 /// PrintHex - Print a value as a hexidecimal value.
471 ///
472 void AsmPrinter::PrintHex(int Value) const { 
473   O << "0x" << std::hex << Value << std::dec;
474 }
475
476 /// EOL - Print a newline character to asm stream.  If a comment is present
477 /// then it will be printed first.  Comments should not contain '\n'.
478 void AsmPrinter::EOL() const {
479   O << "\n";
480 }
481 void AsmPrinter::EOL(const std::string &Comment) const {
482   if (AsmVerbose && !Comment.empty()) {
483     O << "\t"
484       << TAI->getCommentString()
485       << " "
486       << Comment;
487   }
488   O << "\n";
489 }
490
491 /// EmitULEB128Bytes - Emit an assembler byte data directive to compose an
492 /// unsigned leb128 value.
493 void AsmPrinter::EmitULEB128Bytes(unsigned Value) const {
494   if (TAI->hasLEB128()) {
495     O << "\t.uleb128\t"
496       << Value;
497   } else {
498     O << TAI->getData8bitsDirective();
499     PrintULEB128(Value);
500   }
501 }
502
503 /// EmitSLEB128Bytes - print an assembler byte data directive to compose a
504 /// signed leb128 value.
505 void AsmPrinter::EmitSLEB128Bytes(int Value) const {
506   if (TAI->hasLEB128()) {
507     O << "\t.sleb128\t"
508       << Value;
509   } else {
510     O << TAI->getData8bitsDirective();
511     PrintSLEB128(Value);
512   }
513 }
514
515 /// EmitInt8 - Emit a byte directive and value.
516 ///
517 void AsmPrinter::EmitInt8(int Value) const {
518   O << TAI->getData8bitsDirective();
519   PrintHex(Value & 0xFF);
520 }
521
522 /// EmitInt16 - Emit a short directive and value.
523 ///
524 void AsmPrinter::EmitInt16(int Value) const {
525   O << TAI->getData16bitsDirective();
526   PrintHex(Value & 0xFFFF);
527 }
528
529 /// EmitInt32 - Emit a long directive and value.
530 ///
531 void AsmPrinter::EmitInt32(int Value) const {
532   O << TAI->getData32bitsDirective();
533   PrintHex(Value);
534 }
535
536 /// EmitInt64 - Emit a long long directive and value.
537 ///
538 void AsmPrinter::EmitInt64(uint64_t Value) const {
539   if (TAI->getData64bitsDirective()) {
540     O << TAI->getData64bitsDirective();
541     PrintHex(Value);
542   } else {
543     if (TM.getTargetData()->isBigEndian()) {
544       EmitInt32(unsigned(Value >> 32)); O << "\n";
545       EmitInt32(unsigned(Value));
546     } else {
547       EmitInt32(unsigned(Value)); O << "\n";
548       EmitInt32(unsigned(Value >> 32));
549     }
550   }
551 }
552
553 /// toOctal - Convert the low order bits of X into an octal digit.
554 ///
555 static inline char toOctal(int X) {
556   return (X&7)+'0';
557 }
558
559 /// printStringChar - Print a char, escaped if necessary.
560 ///
561 static void printStringChar(std::ostream &O, unsigned char C) {
562   if (C == '"') {
563     O << "\\\"";
564   } else if (C == '\\') {
565     O << "\\\\";
566   } else if (isprint(C)) {
567     O << C;
568   } else {
569     switch(C) {
570     case '\b': O << "\\b"; break;
571     case '\f': O << "\\f"; break;
572     case '\n': O << "\\n"; break;
573     case '\r': O << "\\r"; break;
574     case '\t': O << "\\t"; break;
575     default:
576       O << '\\';
577       O << toOctal(C >> 6);
578       O << toOctal(C >> 3);
579       O << toOctal(C >> 0);
580       break;
581     }
582   }
583 }
584
585 /// EmitString - Emit a string with quotes and a null terminator.
586 /// Special characters are emitted properly.
587 /// \literal (Eg. '\t') \endliteral
588 void AsmPrinter::EmitString(const std::string &String) const {
589   const char* AscizDirective = TAI->getAscizDirective();
590   if (AscizDirective)
591     O << AscizDirective;
592   else
593     O << TAI->getAsciiDirective();
594   O << "\"";
595   for (unsigned i = 0, N = String.size(); i < N; ++i) {
596     unsigned char C = String[i];
597     printStringChar(O, C);
598   }
599   if (AscizDirective)
600     O << "\"";
601   else
602     O << "\\0\"";
603 }
604
605
606 //===----------------------------------------------------------------------===//
607
608 // EmitAlignment - Emit an alignment directive to the specified power of
609 // two boundary.  For example, if you pass in 3 here, you will get an 8
610 // byte alignment.  If a global value is specified, and if that global has
611 // an explicit alignment requested, it will unconditionally override the
612 // alignment request.  However, if ForcedAlignBits is specified, this value
613 // has final say: the ultimate alignment will be the max of ForcedAlignBits
614 // and the alignment computed with NumBits and the global.
615 //
616 // The algorithm is:
617 //     Align = NumBits;
618 //     if (GV && GV->hasalignment) Align = GV->getalignment();
619 //     Align = std::max(Align, ForcedAlignBits);
620 //
621 void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV,
622                                unsigned ForcedAlignBits) const {
623   if (GV && GV->getAlignment())
624     NumBits = Log2_32(GV->getAlignment());
625   NumBits = std::max(NumBits, ForcedAlignBits);
626   
627   if (NumBits == 0) return;   // No need to emit alignment.
628   if (TAI->getAlignmentIsInBytes()) NumBits = 1 << NumBits;
629   O << TAI->getAlignDirective() << NumBits << "\n";
630 }
631
632     
633 /// EmitZeros - Emit a block of zeros.
634 ///
635 void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
636   if (NumZeros) {
637     if (TAI->getZeroDirective()) {
638       O << TAI->getZeroDirective() << NumZeros;
639       if (TAI->getZeroDirectiveSuffix())
640         O << TAI->getZeroDirectiveSuffix();
641       O << "\n";
642     } else {
643       for (; NumZeros; --NumZeros)
644         O << TAI->getData8bitsDirective() << "0\n";
645     }
646   }
647 }
648
649 // Print out the specified constant, without a storage class.  Only the
650 // constants valid in constant expressions can occur here.
651 void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
652   if (CV->isNullValue() || isa<UndefValue>(CV))
653     O << "0";
654   else if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
655     O << CI->getZExtValue();
656   } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
657     // This is a constant address for a global variable or function. Use the
658     // name of the variable or function as the address value, possibly
659     // decorating it with GlobalVarAddrPrefix/Suffix or
660     // FunctionAddrPrefix/Suffix (these all default to "" )
661     if (isa<Function>(GV)) {
662       O << TAI->getFunctionAddrPrefix()
663         << Mang->getValueName(GV)
664         << TAI->getFunctionAddrSuffix();
665     } else {
666       O << TAI->getGlobalVarAddrPrefix()
667         << Mang->getValueName(GV)
668         << TAI->getGlobalVarAddrSuffix();
669     }
670   } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
671     const TargetData *TD = TM.getTargetData();
672     unsigned Opcode = CE->getOpcode();    
673     switch (Opcode) {
674     case Instruction::GetElementPtr: {
675       // generate a symbolic expression for the byte address
676       const Constant *ptrVal = CE->getOperand(0);
677       SmallVector<Value*, 8> idxVec(CE->op_begin()+1, CE->op_end());
678       if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), &idxVec[0],
679                                                 idxVec.size())) {
680         if (Offset)
681           O << "(";
682         EmitConstantValueOnly(ptrVal);
683         if (Offset > 0)
684           O << ") + " << Offset;
685         else if (Offset < 0)
686           O << ") - " << -Offset;
687       } else {
688         EmitConstantValueOnly(ptrVal);
689       }
690       break;
691     }
692     case Instruction::Trunc:
693     case Instruction::ZExt:
694     case Instruction::SExt:
695     case Instruction::FPTrunc:
696     case Instruction::FPExt:
697     case Instruction::UIToFP:
698     case Instruction::SIToFP:
699     case Instruction::FPToUI:
700     case Instruction::FPToSI:
701       assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
702       break;
703     case Instruction::BitCast:
704       return EmitConstantValueOnly(CE->getOperand(0));
705
706     case Instruction::IntToPtr: {
707       // Handle casts to pointers by changing them into casts to the appropriate
708       // integer type.  This promotes constant folding and simplifies this code.
709       Constant *Op = CE->getOperand(0);
710       Op = ConstantExpr::getIntegerCast(Op, TD->getIntPtrType(), false/*ZExt*/);
711       return EmitConstantValueOnly(Op);
712     }
713       
714       
715     case Instruction::PtrToInt: {
716       // Support only foldable casts to/from pointers that can be eliminated by
717       // changing the pointer to the appropriately sized integer type.
718       Constant *Op = CE->getOperand(0);
719       const Type *Ty = CE->getType();
720
721       // We can emit the pointer value into this slot if the slot is an
722       // integer slot greater or equal to the size of the pointer.
723       if (Ty->isInteger() &&
724           TD->getTypeSize(Ty) >= TD->getTypeSize(Op->getType()))
725         return EmitConstantValueOnly(Op);
726       
727       assert(0 && "FIXME: Don't yet support this kind of constant cast expr");
728       EmitConstantValueOnly(Op);
729       break;
730     }
731     case Instruction::Add:
732     case Instruction::Sub:
733       O << "(";
734       EmitConstantValueOnly(CE->getOperand(0));
735       O << (Opcode==Instruction::Add ? ") + (" : ") - (");
736       EmitConstantValueOnly(CE->getOperand(1));
737       O << ")";
738       break;
739     default:
740       assert(0 && "Unsupported operator!");
741     }
742   } else {
743     assert(0 && "Unknown constant value!");
744   }
745 }
746
747 /// printAsCString - Print the specified array as a C compatible string, only if
748 /// the predicate isString is true.
749 ///
750 static void printAsCString(std::ostream &O, const ConstantArray *CVA,
751                            unsigned LastElt) {
752   assert(CVA->isString() && "Array is not string compatible!");
753
754   O << "\"";
755   for (unsigned i = 0; i != LastElt; ++i) {
756     unsigned char C =
757         (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getZExtValue();
758     printStringChar(O, C);
759   }
760   O << "\"";
761 }
762
763 /// EmitString - Emit a zero-byte-terminated string constant.
764 ///
765 void AsmPrinter::EmitString(const ConstantArray *CVA) const {
766   unsigned NumElts = CVA->getNumOperands();
767   if (TAI->getAscizDirective() && NumElts && 
768       cast<ConstantInt>(CVA->getOperand(NumElts-1))->getZExtValue() == 0) {
769     O << TAI->getAscizDirective();
770     printAsCString(O, CVA, NumElts-1);
771   } else {
772     O << TAI->getAsciiDirective();
773     printAsCString(O, CVA, NumElts);
774   }
775   O << "\n";
776 }
777
778 /// EmitGlobalConstant - Print a general LLVM constant to the .s file.
779 ///
780 void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
781   const TargetData *TD = TM.getTargetData();
782
783   if (CV->isNullValue() || isa<UndefValue>(CV)) {
784     EmitZeros(TD->getTypeSize(CV->getType()));
785     return;
786   } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
787     if (CVA->isString()) {
788       EmitString(CVA);
789     } else { // Not a string.  Print the values in successive locations
790       for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
791         EmitGlobalConstant(CVA->getOperand(i));
792     }
793     return;
794   } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
795     // Print the fields in successive locations. Pad to align if needed!
796     const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
797     uint64_t sizeSoFar = 0;
798     for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
799       const Constant* field = CVS->getOperand(i);
800
801       // Check if padding is needed and insert one or more 0s.
802       uint64_t fieldSize = TD->getTypeSize(field->getType());
803       uint64_t padSize = ((i == e-1? cvsLayout->getSizeInBytes()
804                            : cvsLayout->getElementOffset(i+1))
805                           - cvsLayout->getElementOffset(i)) - fieldSize;
806       sizeSoFar += fieldSize + padSize;
807
808       // Now print the actual field value
809       EmitGlobalConstant(field);
810
811       // Insert the field padding unless it's zero bytes...
812       EmitZeros(padSize);
813     }
814     assert(sizeSoFar == cvsLayout->getSizeInBytes() &&
815            "Layout of constant struct may be incorrect!");
816     return;
817   } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
818     // FP Constants are printed as integer constants to avoid losing
819     // precision...
820     double Val = CFP->getValue();
821     if (CFP->getType() == Type::DoubleTy) {
822       if (TAI->getData64bitsDirective())
823         O << TAI->getData64bitsDirective() << DoubleToBits(Val) << "\t"
824           << TAI->getCommentString() << " double value: " << Val << "\n";
825       else if (TD->isBigEndian()) {
826         O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
827           << "\t" << TAI->getCommentString()
828           << " double most significant word " << Val << "\n";
829         O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
830           << "\t" << TAI->getCommentString()
831           << " double least significant word " << Val << "\n";
832       } else {
833         O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val))
834           << "\t" << TAI->getCommentString()
835           << " double least significant word " << Val << "\n";
836         O << TAI->getData32bitsDirective() << unsigned(DoubleToBits(Val) >> 32)
837           << "\t" << TAI->getCommentString()
838           << " double most significant word " << Val << "\n";
839       }
840       return;
841     } else {
842       O << TAI->getData32bitsDirective() << FloatToBits(Val)
843         << "\t" << TAI->getCommentString() << " float " << Val << "\n";
844       return;
845     }
846   } else if (CV->getType() == Type::Int64Ty) {
847     if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
848       uint64_t Val = CI->getZExtValue();
849
850       if (TAI->getData64bitsDirective())
851         O << TAI->getData64bitsDirective() << Val << "\n";
852       else if (TD->isBigEndian()) {
853         O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
854           << "\t" << TAI->getCommentString()
855           << " Double-word most significant word " << Val << "\n";
856         O << TAI->getData32bitsDirective() << unsigned(Val)
857           << "\t" << TAI->getCommentString()
858           << " Double-word least significant word " << Val << "\n";
859       } else {
860         O << TAI->getData32bitsDirective() << unsigned(Val)
861           << "\t" << TAI->getCommentString()
862           << " Double-word least significant word " << Val << "\n";
863         O << TAI->getData32bitsDirective() << unsigned(Val >> 32)
864           << "\t" << TAI->getCommentString()
865           << " Double-word most significant word " << Val << "\n";
866       }
867       return;
868     }
869   } else if (const ConstantVector *CP = dyn_cast<ConstantVector>(CV)) {
870     const VectorType *PTy = CP->getType();
871     
872     for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
873       EmitGlobalConstant(CP->getOperand(I));
874     
875     return;
876   }
877
878   const Type *type = CV->getType();
879   printDataDirective(type);
880   EmitConstantValueOnly(CV);
881   O << "\n";
882 }
883
884 void
885 AsmPrinter::EmitMachineConstantPoolValue(MachineConstantPoolValue *MCPV) {
886   // Target doesn't support this yet!
887   abort();
888 }
889
890 /// PrintSpecial - Print information related to the specified machine instr
891 /// that is independent of the operand, and may be independent of the instr
892 /// itself.  This can be useful for portably encoding the comment character
893 /// or other bits of target-specific knowledge into the asmstrings.  The
894 /// syntax used is ${:comment}.  Targets can override this to add support
895 /// for their own strange codes.
896 void AsmPrinter::PrintSpecial(const MachineInstr *MI, const char *Code) {
897   if (!strcmp(Code, "private")) {
898     O << TAI->getPrivateGlobalPrefix();
899   } else if (!strcmp(Code, "comment")) {
900     O << TAI->getCommentString();
901   } else if (!strcmp(Code, "uid")) {
902     // Assign a unique ID to this machine instruction.
903     static const MachineInstr *LastMI = 0;
904     static const Function *F = 0;
905     static unsigned Counter = 0U-1;
906
907     // Comparing the address of MI isn't sufficient, because machineinstrs may
908     // be allocated to the same address across functions.
909     const Function *ThisF = MI->getParent()->getParent()->getFunction();
910     
911     // If this is a new machine instruction, bump the counter.
912     if (LastMI != MI || F != ThisF) {
913       ++Counter;
914       LastMI = MI;
915       F = ThisF;
916     }
917     O << Counter;
918   } else {
919     cerr << "Unknown special formatter '" << Code
920          << "' for machine instr: " << *MI;
921     exit(1);
922   }    
923 }
924
925
926 /// printInlineAsm - This method formats and prints the specified machine
927 /// instruction that is an inline asm.
928 void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
929   unsigned NumOperands = MI->getNumOperands();
930   
931   // Count the number of register definitions.
932   unsigned NumDefs = 0;
933   for (; MI->getOperand(NumDefs).isReg() && MI->getOperand(NumDefs).isDef();
934        ++NumDefs)
935     assert(NumDefs != NumOperands-1 && "No asm string?");
936   
937   assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?");
938
939   // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
940   const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
941
942   // If this asmstr is empty, don't bother printing the #APP/#NOAPP markers.
943   if (AsmStr[0] == 0) {
944     O << "\n";  // Tab already printed, avoid double indenting next instr.
945     return;
946   }
947   
948   O << TAI->getInlineAsmStart() << "\n\t";
949
950   // The variant of the current asmprinter.
951   int AsmPrinterVariant = TAI->getAssemblerDialect();
952
953   int CurVariant = -1;            // The number of the {.|.|.} region we are in.
954   const char *LastEmitted = AsmStr; // One past the last character emitted.
955   
956   while (*LastEmitted) {
957     switch (*LastEmitted) {
958     default: {
959       // Not a special case, emit the string section literally.
960       const char *LiteralEnd = LastEmitted+1;
961       while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
962              *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
963         ++LiteralEnd;
964       if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
965         O.write(LastEmitted, LiteralEnd-LastEmitted);
966       LastEmitted = LiteralEnd;
967       break;
968     }
969     case '\n':
970       ++LastEmitted;   // Consume newline character.
971       O << "\n";       // Indent code with newline.
972       break;
973     case '$': {
974       ++LastEmitted;   // Consume '$' character.
975       bool Done = true;
976
977       // Handle escapes.
978       switch (*LastEmitted) {
979       default: Done = false; break;
980       case '$':     // $$ -> $
981         if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
982           O << '$';
983         ++LastEmitted;  // Consume second '$' character.
984         break;
985       case '(':             // $( -> same as GCC's { character.
986         ++LastEmitted;      // Consume '(' character.
987         if (CurVariant != -1) {
988           cerr << "Nested variants found in inline asm string: '"
989                << AsmStr << "'\n";
990           exit(1);
991         }
992         CurVariant = 0;     // We're in the first variant now.
993         break;
994       case '|':
995         ++LastEmitted;  // consume '|' character.
996         if (CurVariant == -1) {
997           cerr << "Found '|' character outside of variant in inline asm "
998                << "string: '" << AsmStr << "'\n";
999           exit(1);
1000         }
1001         ++CurVariant;   // We're in the next variant.
1002         break;
1003       case ')':         // $) -> same as GCC's } char.
1004         ++LastEmitted;  // consume ')' character.
1005         if (CurVariant == -1) {
1006           cerr << "Found '}' character outside of variant in inline asm "
1007                << "string: '" << AsmStr << "'\n";
1008           exit(1);
1009         }
1010         CurVariant = -1;
1011         break;
1012       }
1013       if (Done) break;
1014       
1015       bool HasCurlyBraces = false;
1016       if (*LastEmitted == '{') {     // ${variable}
1017         ++LastEmitted;               // Consume '{' character.
1018         HasCurlyBraces = true;
1019       }
1020       
1021       const char *IDStart = LastEmitted;
1022       char *IDEnd;
1023       errno = 0;
1024       long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
1025       if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
1026         cerr << "Bad $ operand number in inline asm string: '" 
1027              << AsmStr << "'\n";
1028         exit(1);
1029       }
1030       LastEmitted = IDEnd;
1031       
1032       char Modifier[2] = { 0, 0 };
1033       
1034       if (HasCurlyBraces) {
1035         // If we have curly braces, check for a modifier character.  This
1036         // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
1037         if (*LastEmitted == ':') {
1038           ++LastEmitted;    // Consume ':' character.
1039           if (*LastEmitted == 0) {
1040             cerr << "Bad ${:} expression in inline asm string: '" 
1041                  << AsmStr << "'\n";
1042             exit(1);
1043           }
1044           
1045           Modifier[0] = *LastEmitted;
1046           ++LastEmitted;    // Consume modifier character.
1047         }
1048         
1049         if (*LastEmitted != '}') {
1050           cerr << "Bad ${} expression in inline asm string: '" 
1051                << AsmStr << "'\n";
1052           exit(1);
1053         }
1054         ++LastEmitted;    // Consume '}' character.
1055       }
1056       
1057       if ((unsigned)Val >= NumOperands-1) {
1058         cerr << "Invalid $ operand number in inline asm string: '" 
1059              << AsmStr << "'\n";
1060         exit(1);
1061       }
1062       
1063       // Okay, we finally have a value number.  Ask the target to print this
1064       // operand!
1065       if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
1066         unsigned OpNo = 1;
1067
1068         bool Error = false;
1069
1070         // Scan to find the machine operand number for the operand.
1071         for (; Val; --Val) {
1072           if (OpNo >= MI->getNumOperands()) break;
1073           unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
1074           OpNo += (OpFlags >> 3) + 1;
1075         }
1076
1077         if (OpNo >= MI->getNumOperands()) {
1078           Error = true;
1079         } else {
1080           unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
1081           ++OpNo;  // Skip over the ID number.
1082
1083           AsmPrinter *AP = const_cast<AsmPrinter*>(this);
1084           if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
1085             Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
1086                                               Modifier[0] ? Modifier : 0);
1087           } else {
1088             Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
1089                                         Modifier[0] ? Modifier : 0);
1090           }
1091         }
1092         if (Error) {
1093           cerr << "Invalid operand found in inline asm: '"
1094                << AsmStr << "'\n";
1095           MI->dump();
1096           exit(1);
1097         }
1098       }
1099       break;
1100     }
1101     }
1102   }
1103   O << "\n\t" << TAI->getInlineAsmEnd() << "\n";
1104 }
1105
1106 /// printLabel - This method prints a local label used by debug and
1107 /// exception handling tables.
1108 void AsmPrinter::printLabel(const MachineInstr *MI) const {
1109   O << "\n"
1110     << TAI->getPrivateGlobalPrefix()
1111     << "label"
1112     << MI->getOperand(0).getImmedValue()
1113     << ":\n";
1114 }
1115
1116 /// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
1117 /// instruction, using the specified assembler variant.  Targets should
1118 /// overried this to format as appropriate.
1119 bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
1120                                  unsigned AsmVariant, const char *ExtraCode) {
1121   // Target doesn't support this yet!
1122   return true;
1123 }
1124
1125 bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
1126                                        unsigned AsmVariant,
1127                                        const char *ExtraCode) {
1128   // Target doesn't support this yet!
1129   return true;
1130 }
1131
1132 /// printBasicBlockLabel - This method prints the label for the specified
1133 /// MachineBasicBlock
1134 void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
1135                                       bool printColon,
1136                                       bool printComment) const {
1137   O << TAI->getPrivateGlobalPrefix() << "BB" << FunctionNumber << "_"
1138     << MBB->getNumber();
1139   if (printColon)
1140     O << ':';
1141   if (printComment && MBB->getBasicBlock())
1142     O << '\t' << TAI->getCommentString() << MBB->getBasicBlock()->getName();
1143 }
1144
1145 /// printSetLabel - This method prints a set label for the specified
1146 /// MachineBasicBlock
1147 void AsmPrinter::printSetLabel(unsigned uid, 
1148                                const MachineBasicBlock *MBB) const {
1149   if (!TAI->getSetDirective())
1150     return;
1151   
1152   O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1153     << getFunctionNumber() << '_' << uid << "_set_" << MBB->getNumber() << ',';
1154   printBasicBlockLabel(MBB, false, false);
1155   O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
1156     << '_' << uid << '\n';
1157 }
1158
1159 void AsmPrinter::printSetLabel(unsigned uid, unsigned uid2,
1160                                const MachineBasicBlock *MBB) const {
1161   if (!TAI->getSetDirective())
1162     return;
1163   
1164   O << TAI->getSetDirective() << ' ' << TAI->getPrivateGlobalPrefix()
1165     << getFunctionNumber() << '_' << uid << '_' << uid2
1166     << "_set_" << MBB->getNumber() << ',';
1167   printBasicBlockLabel(MBB, false, false);
1168   O << '-' << TAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber() 
1169     << '_' << uid << '_' << uid2 << '\n';
1170 }
1171
1172 /// printDataDirective - This method prints the asm directive for the
1173 /// specified type.
1174 void AsmPrinter::printDataDirective(const Type *type) {
1175   const TargetData *TD = TM.getTargetData();
1176   switch (type->getTypeID()) {
1177   case Type::IntegerTyID: {
1178     unsigned BitWidth = cast<IntegerType>(type)->getBitWidth();
1179     if (BitWidth <= 8)
1180       O << TAI->getData8bitsDirective();
1181     else if (BitWidth <= 16)
1182       O << TAI->getData16bitsDirective();
1183     else if (BitWidth <= 32)
1184       O << TAI->getData32bitsDirective();
1185     else if (BitWidth <= 64) {
1186       assert(TAI->getData64bitsDirective() &&
1187              "Target cannot handle 64-bit constant exprs!");
1188       O << TAI->getData64bitsDirective();
1189     }
1190     break;
1191   }
1192   case Type::PointerTyID:
1193     if (TD->getPointerSize() == 8) {
1194       assert(TAI->getData64bitsDirective() &&
1195              "Target cannot handle 64-bit pointer exprs!");
1196       O << TAI->getData64bitsDirective();
1197     } else {
1198       O << TAI->getData32bitsDirective();
1199     }
1200     break;
1201   case Type::FloatTyID: case Type::DoubleTyID:
1202     assert (0 && "Should have already output floating point constant.");
1203   default:
1204     assert (0 && "Can't handle printing this type of thing");
1205     break;
1206   }
1207 }
1208