From 0163a536dc4d9596099685c17fe8f7434ffe2a4d Mon Sep 17 00:00:00 2001 From: vjspranav Date: Thu, 10 Mar 2022 18:52:11 +0530 Subject: [PATCH] Add support for M1 Mac * wref to issue https://github.com/IUCompilerCourse/public-student-support-code/issues/13 * We do this with the help of inbuilt arch command "Rosetta 2", For now Rosetta is here to stay * and we can make use of it's capabilities to compile x86 instructions on arm machine --- Makefile | 9 +++++++++ utilities.rkt | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index bf018f0..6ba2e03 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,15 @@ CC = gcc RACKET = racket RM = rm +UNAME_S := $(shell uname -s) +UNAME_P := $(shell uname -p) +ifeq ($(UNAME_S),Darwin) + ifeq ($(UNAME_P),arm) + $(info M1 MacOSX detected) + CC := arch -x86_64 $(CC) + endif +endif + runtime.o: runtime.c runtime.h $(CC) -c -g -std=c99 runtime.c diff --git a/utilities.rkt b/utilities.rkt index 021d09e..42b9d78 100644 --- a/utilities.rkt +++ b/utilities.rkt @@ -2244,6 +2244,14 @@ Changelog: (close-output-port out) result)])) +(define (get-arch) + (match (system-type 'arch) + [ 'aarch64 + (match (system-type 'os) + [ 'macosx "arch -x86_64 "] + [ else "" ])] + [ else "" ])) + (define (compiler-tests-suite name typechecker passes test-family test-nums) (let ([compiler (compile-file typechecker passes)]) (make-test-suite @@ -2258,7 +2266,7 @@ Changelog: (test-case "typecheck" (check-false typechecks "Expected expression to fail typechecking")) (if (not typechecks) (fail "Expected expression to typecheck") (test-case "code generation" - (let ([gcc-output (system (format "gcc -g -march=x86-64 -std=c99 runtime.o ./tests/~a.s -o ./tests/~a.out" test-name test-name))]) + (let ([gcc-output (system (format (string-append (get-arch) "gcc -g -std=c99 runtime.o ./tests/~a.s -o ./tests/~a.out") test-name test-name))]) (if (not gcc-output) (fail "Failed during assembly") (let ([input (if (file-exists? (format "./tests/~a.in" test-name)) (format " < ./tests/~a.in" test-name)