Add support for alignment
authorChris Lattner <sabre@nondot.org>
Tue, 17 Aug 2004 19:14:29 +0000 (19:14 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 17 Aug 2004 19:14:29 +0000 (19:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@15888 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter.cpp

index b441ef540714ec61e15a8ef2db45b00522bd7b94..f21ed140b47fb0e72c2d9923284545ebc180effd 100644 (file)
@@ -47,7 +47,7 @@ namespace llvm {
 
     /// CommentChar - This indicates the comment character used by the
     /// assembler.
-    const char *CommentChar;
+    const char *CommentChar;     // Defaults to "#"
 
     /// GlobalPrefix - If this is set to a non-empty string, it is prepended
     /// onto all global symbols.  This is often used for "_" or ".".
@@ -71,6 +71,17 @@ namespace llvm {
     const char *Data32bitsDirective;  // Defaults to "\t.long\t"
     const char *Data64bitsDirective;  // Defaults to "\t.quad\t"
 
+    /// AlignDirective - The directive used to emit round up to an alignment
+    /// boundary.
+    ///
+    const char *AlignDirective;       // Defaults to "\t.align\t"
+
+    /// AlignmentIsInBytes - If this is true (the default) then the asmprinter
+    /// emits ".align N" directives, where N is the number of bytes to align to.
+    /// Otherwise, it emits ".align log2(N)", e.g. 3 to align to an 8 byte
+    /// boundary.
+    bool AlignmentIsInBytes;          // Defaults to true
+
     AsmPrinter(std::ostream &o, TargetMachine &tm)
       : O(o), TM(tm),
         CommentChar("#"),
@@ -80,7 +91,10 @@ namespace llvm {
         Data8bitsDirective("\t.byte\t"),
         Data16bitsDirective("\t.short\t"),
         Data32bitsDirective("\t.long\t"),
-        Data64bitsDirective("\t.quad\t") { }
+        Data64bitsDirective("\t.quad\t"),
+        AlignDirective("\t.align\t"),
+        AlignmentIsInBytes(true) {
+    }
 
     /// doInitialization - Set up the AsmPrinter when we are working on a new
     /// module.  If your pass overrides this, it must make sure to explicitly
@@ -95,6 +109,11 @@ namespace llvm {
     /// is being processed from runOnMachineFunction.
     void setupMachineFunction(MachineFunction &MF);
 
+    /// emitAlignment - Emit an alignment directive to the specified power of
+    /// two boundary.  For example, if you pass in 3 here, you will get an 8
+    /// byte alignment.
+    void emitAlignment(unsigned NumBits) const;
+
     /// emitConstantValueOnly - Print out the specified constant, without a
     /// storage class.  Only constants of first-class type are allowed here.
     void emitConstantValueOnly(const Constant *CV);
index 5fb356e58f0431efa3b1350b43f6985f72436655..35733c856466c6bf3a33117fae013ec8b37af23c 100644 (file)
@@ -33,6 +33,12 @@ void AsmPrinter::setupMachineFunction(MachineFunction &MF) {
   CurrentFnName = Mang->getValueName((Value*)MF.getFunction());
 }
 
+// emitAlignment - Emit an alignment directive to the specified power of two.
+void AsmPrinter::emitAlignment(unsigned NumBits) const {
+  if (AlignmentIsInBytes) NumBits = 1 << NumBits;
+  O << AlignDirective << NumBits << "\n";
+}
+
 // Print out the specified constant, without a storage class.  Only the
 // constants valid in constant expressions can occur here.
 void AsmPrinter::emitConstantValueOnly(const Constant *CV) {