Skip to content

Instantly share code, notes, and snippets.

@jsnyder
Created July 26, 2011 23:13
Show Gist options
  • Save jsnyder/1108326 to your computer and use it in GitHub Desktop.
Save jsnyder/1108326 to your computer and use it in GitHub Desktop.
LLVM/Clang now builds for Cortex-M3?
~> cat test.c
int main()
{
int i = 0;
int j = 0;
for( i = 0; i < 100; i++ )
j += i;
return 1;
}
Clang:
~> clang -ccc-host-triple armv7m-none-eabi -mthumb -S -o - test.c
.syntax unified
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 44, 1
.file "test.c"
.text
.globl main
.align 2
.type main,%function
.code 16
.thumb_func
main:
sub sp, #12
movs r0, #0
str r0, [sp, #8]
str r0, [sp, #4]
str r0, [sp]
str r0, [sp, #4]
.LBB0_1:
ldr r0, [sp, #4]
cmp r0, #99
bgt .LBB0_4
b .LBB0_2
.LBB0_2:
ldr r0, [sp, #4]
ldr r1, [sp]
add r0, r1
str r0, [sp]
ldr r0, [sp, #4]
adds r0, #1
str r0, [sp, #4]
b .LBB0_1
.LBB0_4:
movs r0, #1
add sp, #12
bx lr
.Ltmp0:
.size main, .Ltmp0-main
GCC:
~> arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -S -o - test.c
.syntax unified
.cpu cortex-m3
.fpu softvfp
.eabi_attribute 20, 1
.eabi_attribute 21, 1
.eabi_attribute 23, 3
.eabi_attribute 24, 1
.eabi_attribute 25, 1
.eabi_attribute 26, 1
.eabi_attribute 30, 6
.eabi_attribute 18, 4
.thumb
.file "test.c"
.text
.align 2
.global main
.thumb
.thumb_func
.type main, %function
main:
@ args = 0, pretend = 0, frame = 8
@ frame_needed = 1, uses_anonymous_args = 0
@ link register save eliminated.
push {r7}
sub sp, sp, #12
add r7, sp, #0
mov r3, #0
str r3, [r7, #4]
mov r3, #0
str r3, [r7, #0]
mov r3, #0
str r3, [r7, #4]
b .L2
.L3:
ldr r2, [r7, #0]
ldr r3, [r7, #4]
adds r3, r2, r3
str r3, [r7, #0]
ldr r3, [r7, #4]
add r3, r3, #1
str r3, [r7, #4]
.L2:
ldr r3, [r7, #4]
cmp r3, #99
ble .L3
mov r3, #1
mov r0, r3
add r7, r7, #12
mov sp, r7
pop {r7}
bx lr
.size main, .-main
.ident "GCC: (GNU) 4.5.1"
@errordeveloper
Copy link

but that's using armv7m-none-eabi-gcc as a back-end, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment