Compile time macro trouble.
Kai Nacke via digitalmars-d-ldc
digitalmars-d-ldc at puremagic.com
Sun Mar 13 07:43:27 PDT 2016
On Sunday, 13 March 2016 at 06:15:34 UTC, Taylor Hillegeist wrote:
>
> So here: https://dlang.org/pretod.html
> there is a lovely section about how doing normal functions is
> basically a processor macro.
>
> The C Preprocessor Way:
> #define X(i) ((i) = (i) / 3)
>
> The D Way:
> int X(ref int i) { return i = i / 3; }
>
> However I am running into troubles with the truthfulness of
> this on LDC for thumb cortex-m0plus.
>
> MKL25Z.d
> line 5243:
> uint32_t SIM_SOPT2_TPMSRC(uint32_t x) {return ((x <<
> SIM_SOPT2_TPMSRC_SHIFT) & SIM_SOPT2_TPMSRC_MASK);}
>
> start.d
> line 28: int value = SIM_SOPT2_TPMSRC(1);
> 0x0000046E 2001 MOVS r0,#0x01
> 0x00000470 9004 STR r0,[sp,#0x10]
> 0x00000472 F000F8ED BL.W MKL25Z4.SIM_SOPT2_TPMSRC
> (0x00000650) //branch to crap
> 0x00000476 9005 STR r0,[sp,#0x14]
> ...
> 0x00000650 B082 DCW 0xB082 < the crap
> 0x00000652 4601 DCW 0x4601
> 0x00000654 9001 DCW 0x9001
> 0x00000656 0600 DCW 0x0600
> 0x00000658 2203 DCW 0x2203
>
> Is this an error on ldc's part or do i need to do something
> more to get the correct result?
>
> I compiled with:
> ldc2.exe -output-o -march=thumb -mcpu=cortex-m0plus
> -mtriple=arm-linux -g -c main.d start.d MKL25Z4.d
> and linked with:
> arm-unknown-linux-gnueabi-ld.exe -T mkl25z4.ld --gc-sections
> start.o MKL25Z4.o main.o -o ldoutput.elf
>
>
> And yes there is a little bit of information missing i've
> uploaded some files here.
>
> https://github.com/taylorh140/DLANG_FRDM_KL25Z
>
> I'm just trying to get more comfortable with working on
> microcontrollers with d. The good news is that I got a simple
> example running. An led blinking three colors! I would like
> advice on the best way to handle direct interaction with
> registers, but maybe that's best for another post.
Hi Taylor,
I compiled your code to assembly. I get in start.s:
.loc 1 28 5
movs r0, #1
str r0, [sp, #16]
bl _D7MKL25Z416SIM_SOPT2_TPMSRCFkZk
and in MKL25Z4.s:
_D7MKL25Z416SIM_SOPT2_TPMSRCFkZk:
.Lfunc_begin197:
.loc 1 5245 0
.fnstart
.cfi_startproc
.loc 1 5245 10 prologue_end
sub sp, #8
.Ltmp966:
.cfi_def_cfa_offset 8
Looks good so far (except for the missing inlining). I did not
try to link.
BTW: Which version do you use? I used current vesion from
ltsmaster:
LDC - the LLVM D compiler (c936f8):
based on DMD v2.068.2 and LLVM 3.7.1
Default target: armv7a-hardfloat-linux-gnueabi
Host CPU: krait
http://dlang.org - http://wiki.dlang.org/LDC
Regards,
Kai
More information about the digitalmars-d-ldc
mailing list