Skip to content

Commit

Permalink
Add support for M1 Mac
Browse files Browse the repository at this point in the history
* wref to issue IUCompilerCourse/public-student-support-code#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
  • Loading branch information
vjspranav committed Mar 26, 2022
1 parent 3847aec commit 1ca96bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion utilities.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 1ca96bf

Please sign in to comment.