-
Notifications
You must be signed in to change notification settings - Fork 892
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Compile an integer to an exectuable that exits with the given number
- Loading branch information
0 parents
commit 0522e2d
Showing
4 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
**/*~ | ||
**/\#* | ||
**/*.o | ||
**/*.s | ||
**/a.out | ||
/tmp* | ||
/chibicc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
CFLAGS=-std=c11 -g -fno-common | ||
|
||
chibicc: main.o | ||
$(CC) -o chibicc main.o $(LDFLAGS) | ||
|
||
test: chibicc | ||
./test.sh | ||
|
||
clean: | ||
rm -f chibicc *.o *~ tmp* | ||
|
||
.PHONY: test clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int main(int argc, char **argv) { | ||
if (argc != 2) { | ||
fprintf(stderr, "%s: invalid number of arguments\n", argv[0]); | ||
return 1; | ||
} | ||
|
||
printf(" .globl main\n"); | ||
printf("main:\n"); | ||
printf(" mov $%d, %%rax\n", atoi(argv[1])); | ||
printf(" ret\n"); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
assert() { | ||
expected="$1" | ||
input="$2" | ||
|
||
./chibicc "$input" > tmp.s || exit | ||
gcc -static -o tmp tmp.s | ||
./tmp | ||
actual="$?" | ||
|
||
if [ "$actual" = "$expected" ]; then | ||
echo "$input => $actual" | ||
else | ||
echo "$input => $expected expected, but got $actual" | ||
exit 1 | ||
fi | ||
} | ||
|
||
assert 0 0 | ||
assert 42 42 | ||
|
||
echo OK |
0522e2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit tree https://github.com/rui314/chibicc/commits/main?after=90d1f7f199cc55b13c7fdb5839d1409806633fdb+300&branch=main
0522e2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a minor typo in your commit message, I think it should be 'executable' instead of 'exectuable'.