@@ -534,6 +534,44 @@ class BackendARM64 : CompilerBackend {
534534 output ~= format(" %s:\n " , symbol);
535535 output ~= " str lr, [x20, #-8]!\n " ;
536536
537+ // allocate parameters
538+ size_t paramSize;
539+ foreach (ref type ; node.paramTypes) {
540+ if (! TypeExists(type)) {
541+ Error(node.error, " Type '%s' doesn't exist" , type);
542+ }
543+
544+ paramSize += GetType(type).size;
545+ }
546+ if (paramSize > 0 ) {
547+ output ~= format(" sub x20, x20, #%d\n " , paramSize);
548+ foreach (ref var ; variables) {
549+ var.offset += paramSize;
550+ }
551+
552+ size_t offset;
553+ foreach (i, ref type ; node.paramTypes) {
554+ auto param = node.params[i];
555+ Variable var;
556+
557+ var.name = param;
558+ var.type = GetType(type);
559+ var.offset = cast (uint ) offset;
560+ offset += var.Size();
561+ variables ~= var;
562+ }
563+
564+ // copy data to parameters
565+ output ~= format(" sub x9, x19, #%d\n " , paramSize);
566+ output ~= " mov x10, x20\n " ;
567+ output ~= format(" mov x11, #%d\n " , paramSize);
568+ output ~= " 1:\n " ;
569+ output ~= " ldrb w12, [x9], #1\n " ;
570+ output ~= " strb w12, [x10], #1\n " ;
571+ output ~= " subs x11, x11, #1\n " ;
572+ output ~= " bne 1b\n " ;
573+ }
574+
537575 foreach (ref inode ; node.nodes) {
538576 compiler.CompileNode(inode);
539577 }
0 commit comments