Permalink
Browse files

Initial checkin.

  • Loading branch information...
rui314 committed Feb 28, 2012
0 parents commit 3764b2071b9601067b81976d80175a0851d0f209
Showing with 58 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +16 −0 8cc.c
  3. +4 −0 Makefile
  4. +9 −0 driver.c
  5. +26 −0 test.sh
@@ -0,0 +1,3 @@
8cc
*.o
*.tmp
16 8cc.c
@@ -0,0 +1,16 @@
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
int val;
if (scanf("%d", &val) == EOF) {
perror("scanf");
exit(1);
}
printf("\t.text\n\t"
".global mymain\n"
"mymain:\n\t"
"mov $%d, %%eax\n\t"
"ret\n", val);
return 0;
}
@@ -0,0 +1,4 @@
8cc: 8cc.o
clean:
rm -f 8cc *.o tmp.*
@@ -0,0 +1,9 @@
#include <stdio.h>
extern int mymain(void);
int main(int argc, char **argv) {
int val = mymain();
printf("%d\n", val);
return 0;
}
26 test.sh
@@ -0,0 +1,26 @@
#!/bin/bash
function test {
expected="$1"
expr="$2"
echo "$expr" | ./8cc > tmp.s
if [ ! $? ]; then
echo "Failed to compile $expr"
exit
fi
gcc -o tmp.out driver.c tmp.s || exit
result="`./tmp.out`"
if [ "$result" != "$expected" ]; then
echo "Test failed: $expected expected but got $result"
exit
fi
}
make -s 8cc
test 0 0
test 42 42
rm -f tmp.out tmp.s
echo "All tests passed"

0 comments on commit 3764b20

Please sign in to comment.