Skip to content

Commit

Permalink
Change test bench
Browse files Browse the repository at this point in the history
  • Loading branch information
eecheng87 committed Oct 15, 2020
1 parent 9e04dcd commit 7c944b1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,18 @@ int fib(int n) fib: Reserve stack frame for function

1. Any non-zero value is NOT treated as logical truth by all ops.
That is, the expression `0 == strcmp(ptr, "hello")` is not equivalent to `!strcmp(ptr, "hello")`.
2. Global variable initialization is not supported.
Therefore, you can not initialize a global such as `int i = [expr]`.
3. Dereference is incomplete. Consider `int x = 5; int *ptr = &x;` and it is forbidden to use `*ptr`.
2. Dereference is incomplete. Consider `int x = 5; int *ptr = &x;` and it is forbidden to use `*ptr`.
However, it is valid to use `ptr[0]`, which behaves the same of `*ptr`.
4. The support of varying number of function arguments is incomplete. No `<stdarg.h>` can be used.
3. The support of varying number of function arguments is incomplete. No `<stdarg.h>` can be used.
Alternatively, check the implementation `printf` in source `lib/c.c` for `var_arg`.
5. The memory region allocated by `malloc` can not be released. In fact, there is no `free` function.
4. The memory region allocated by `malloc` can not be released. In fact, there is no `free` function.
Memory allocator should be introduced in embedded libc implementation.
6. If you attempt to return values in `main` function, the value will not be reserved after the
5. If you attempt to return values in `main` function, the value will not be reserved after the
program exited. You have to modify the `return` statement to `exit` call. Check the test items in
file `tests/driver.sh` for details.
7. The C front-end is a bit dirty because there is no effective AST.
8. No function pointer is supported.
6. The C front-end is a bit dirty because there is no effective AST.
7. No function pointer is supported.
8. ELF lacks of .bss and .rodata section

## License

Expand Down
Binary file added bench
Binary file not shown.
5 changes: 5 additions & 0 deletions src/cfront.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,12 +1314,17 @@ int read_global_assignment(char *token)
var_t *var = find_global_var(token);
if (var) {
char buffer[10];
int isneg = 0;
/* global initialization must be constant */
/* TODO: support rvalue as expression e.g. int a = 3 + 2; */
if (lex_accept(T_minus))
isneg = 1;
if (lex_peek(T_numeric, buffer))
var->init_val = read_numeric_constant(buffer);
else
error("Invalid value after assignment");
if (isneg)
var->init_val = -1 * var->init_val;
lex_expect(T_numeric);
lex_expect(T_semicolon);

Expand Down
10 changes: 10 additions & 0 deletions tests/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ int main() {
}
EOF

# global initialization
try_ 41 << EOF
int a = 44;
int b = -3;
int main()
{
exit(a + b);
}
EOF

# conditional operator
# expr 10 "1 ? 10 : 5"
# expr 25 "0 ? 10 : 25"
Expand Down
13 changes: 0 additions & 13 deletions tests/global.c

This file was deleted.

0 comments on commit 7c944b1

Please sign in to comment.