[LLVMbugs] [Bug 16701] New: [PowerPC] PPCAsmParser request: support darwin asm syntax in PPCAsmParser

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Jul 24 16:43:30 PDT 2013


            Bug ID: 16701
           Summary: [PowerPC] PPCAsmParser request: support darwin asm
                    syntax in PPCAsmParser
           Product: libraries
           Version: trunk
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: PowerPC
          Assignee: unassignedbugs at nondot.org
          Reporter: fang at csl.cornell.edu
                CC: hfinkel at anl.gov, llvmbugs at cs.uiuc.edu,
                    ulrich.weigand at de.ibm.com
    Classification: Unclassified

This is a feature request for supporting darwin asm syntax for PPC assembly.  
The most noticeable difference is in the naming of register operands.

% cat hello-puts.c
extern int puts(const char*);
main(int argc, char* argv[]) {
        puts("Hello, world!\n");
        return 0;

% make hello-puts.s
~/local/src/LLVM-svn/gcc40-cmake-build/bin/clang -v -fno-common -DPIC
-femit-all-decls -c hello-puts.c -S -o hello-puts.s
clang version 3.4 
Target: powerpc-apple-darwin8.11.0
Thread model: posix
 "/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/clang-3.4" -cc1 -triple
powerpc-apple-macosx10.4.0 -S -disable-free -main-file-name hello-puts.c
-mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -v
-coverage-file /Users/fang/temp/clang/hello-puts.s -resource-dir
/Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/../lib/clang/3.4 -D PIC
-fdebug-compilation-dir /Users/fang/temp/clang -ferror-limit 19
-fmessage-length 80 -femit-all-decls -mstackrealign -fblocks
-fblocks-runtime-optional -fobjc-runtime=macosx-10.4.0
-fobjc-default-synthesize-properties -fencode-extended-block-signature
-fno-common -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -o
hello-puts.s -x c hello-puts.c
clang -cc1 version 3.4 based upon LLVM 3.4git-969f343 default target
ignoring nonexistent directory "/usr/local/include"
#include "..." search starts here:
#include <...> search starts here:
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.

% cat hello-puts.s
        .machine ppc7400
        .section        __TEXT,__textcoal_nt,coalesced,pure_instructions
        .section        __TEXT,__text,regular,pure_instructions
        .globl  _main
        .align  4
_main:                                  ; @main
; BB#0:                                 ; %entry
        mflr r0
        stw r31, -4(r1)
        stw r0, 8(r1)
        stwu r1, -96(r1)
        mr r31, r1
        bl L0$pb
        mflr r2
        li r5, 0
        stw r5, 88(r31)
        stw r3, 84(r31)
        addis r2, r2, ha16(L_.str-L0$pb)
        stw r4, 80(r31)
        la r2, lo16(L_.str-L0$pb)(r2)
        stw r3, 76(r31)                 ; 4-byte Folded Spill
        mr r3, r2
        stw r4, 72(r31)                 ; 4-byte Folded Spill
        stw r5, 68(r31)                 ; 4-byte Folded Spill
        bl L_puts$stub
        lwz r2, 72(r31)                 ; 4-byte Folded Reload
        lwz r4, 76(r31)                 ; 4-byte Folded Reload
        lwz r5, 68(r31)                 ; 4-byte Folded Reload
        stw r3, 64(r31)                 ; 4-byte Folded Spill
        mr r3, r5
        stw r2, 60(r31)                 ; 4-byte Folded Spill
        stw r4, 56(r31)                 ; 4-byte Folded Spill
        addi r1, r1, 96
        lwz r0, 8(r1)
        lwz r31, -4(r1)
        mtlr r0

        .align  4
        .indirect_symbol        _puts
        mflr r0
        bcl 20, 31, L_puts$stub$tmp
        mflr r11
        addis r11, r11, ha16(L_puts$lazy_ptr-L_puts$stub$tmp)
        mtlr r0
        lwzu r12, lo16(L_puts$lazy_ptr-L_puts$stub$tmp)(r11)
        mtctr r12
        .section        __DATA,__la_symbol_ptr,lazy_symbol_pointers
        .indirect_symbol        _puts
        .long   dyld_stub_binding_helper

        .section        __TEXT,__cstring,cstring_literals
L_.str:                                 ; @.str
        .asciz   "Hello, world!\n"

and attempting to use llvm-mc:
% /Volumes/Isolde/builds/LLVM/gcc40-cmake-build/bin/llvm-mc
-triple=powerpc-apple-darwin8 hello-puts.s 
        .section        __TEXT,__text,regular,pure_instructions
hello-puts.s:1:2: error: unrecognized machine type
        .machine ppc7400
hello-puts.s:1:2: error: unknown directive
        .machine ppc7400
        .section        __TEXT,__textcoal_nt,coalesced,pure_instructions
        .section        __TEXT,__text,regular,pure_instructions
        .globl  _main
        .align  4

hello-puts.s:9:7: error: invalid operand for instruction
        mflr r0

hello-puts.s:10:6: error: invalid operand for instruction
        stw r31, -4(r1)

I've already taken a stab at accepting rX on memory operands with the following
diff --git a/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
index 3c677cc..e49cf08 100644
--- a/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
+++ b/lib/Target/PowerPC/AsmParser/PPCAsmParser.cpp
@@ -26,6 +26,8 @@
 #include "llvm/Support/TargetRegistry.h"
 #include "llvm/Support/raw_ostream.h"

+#define        ALLOW_DARWIN_ASM_SYNTAX                 1
 using namespace llvm;

 namespace {
@@ -1158,7 +1160,14 @@ ParseOperand(SmallVectorImpl<MCParsedAsmOperand*>
&Operands) {
           IntVal < 0 || IntVal > 31)
         return Error(S, "invalid register number");
+    case AsmToken::Identifier: // e.g. r31
+      unsigned RegNo2;
+      if (MatchRegisterName(Parser.getTok(), RegNo2, IntVal))
+        return Error(S, "invalid register name");
+      Parser.Lex(); // Eat the identifier token.
+      break;
       return Error(S, "invalid memory operand");

but I wouldn't know how to proceed from here.
How difficult would this project be?

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130724/a8e4613d/attachment.html>

More information about the llvm-bugs mailing list