summaryrefslogtreecommitdiff
path: root/05
diff options
context:
space:
mode:
Diffstat (limited to '05')
-rw-r--r--05/.gitignore1
-rw-r--r--05/codegen.b9
-rw-r--r--05/main.b42
-rw-r--r--05/main.c29
-rw-r--r--05/tcc-0.9.25/config.h2
-rw-r--r--05/tcc-0.9.25/libtcc.c4
-rw-r--r--05/tcc-0.9.25/tcc.h7
-rw-r--r--05/tcc-0.9.25/tccpp.c5
-rw-r--r--05/util.b6
9 files changed, 79 insertions, 26 deletions
diff --git a/05/.gitignore b/05/.gitignore
index f4c3e60..fe7b7ab 100644
--- a/05/.gitignore
+++ b/05/.gitignore
@@ -1 +1,2 @@
in04
+address_map.txt
diff --git a/05/codegen.b b/05/codegen.b
index f06f69e..4d2ca1b 100644
--- a/05/codegen.b
+++ b/05/codegen.b
@@ -2580,6 +2580,15 @@ function generate_statement
local c
local d
+ if codegen_second_pass == 0 goto skip_addrmap_write
+ d = code_output - output_file_data
+ fputx32(address_map_fd, d)
+ fputc(address_map_fd, ':)
+ fputc(address_map_fd, 32)
+ fprint_statement_location(address_map_fd, statement)
+ fputc(address_map_fd, 10)
+ :skip_addrmap_write
+
prev_continue_refs = continue_refs
prev_break_refs = break_refs
diff --git a/05/main.b b/05/main.b
index f8f032e..8e040d8 100644
--- a/05/main.b
+++ b/05/main.b
@@ -77,7 +77,8 @@ global function_param_names
global function_param_has_no_name
; ident list of number of bytes of stack space needed by local variables in each function
global functions_required_stack_space
-
+; a map from pc addresses to program locations will be outputted to this file
+global address_map_fd
#include util.b
#include idents.b
@@ -123,13 +124,19 @@ function types_init
*8ptypes_bytes_used = p - types
return
-function print_token_location
+function fprint_token_location
+ argument fd
argument token
token += 2
- print_filename(*2token)
+ fprint_filename(fd, *2token)
token += 2
- putc(':)
- putn(*4token)
+ fputc(fd, ':)
+ fputn(fd, *4token)
+ return
+
+function print_token_location
+ argument token
+ fprint_token_location(1, token)
return
function print_statement_location
@@ -137,15 +144,28 @@ function print_statement_location
; statements & tokens have the same format for locations!
print_token_location(statement)
return
+
+function fprint_statement_location
+ argument fd
+ argument statement
+ ; statements & tokens have the same format for locations!
+ fprint_token_location(fd, statement)
+ return
; accepts EITHER file index OR pointer to filename
-function print_filename
+function fprint_filename
+ argument fd
argument file
if file ] 65535 goto print_filename_string
file = file_get(file)
; (fallthrough)
:print_filename_string
- puts(file)
+ fputs(fd, file)
+ return
+
+function print_filename
+ argument file
+ fprint_filename(1, file)
return
; accepts EITHER file index OR pointer to filename
@@ -328,11 +348,15 @@ function main
debug_puts(.str_parsing)
parse_tokens(tokens)
+
+ address_map_fd = open_w(.str_addrmap_filename, 420)
+
generate_code()
p = output_file_data + RODATA_ADDR
munmap(output_file_data, RWDATA_END)
close(output_fd)
+ close(address_map_fd)
;ident_list_printx64(global_variables)
;puts(.str_types_bytes_used)
@@ -340,6 +364,10 @@ function main
exit(0)
+:str_addrmap_filename
+ string address_map.txt
+ byte 0
+
:str_types_bytes_used
string types_bytes_used:
byte 32
diff --git a/05/main.c b/05/main.c
index 34b15fb..0eee651 100644
--- a/05/main.c
+++ b/05/main.c
@@ -1,17 +1,18 @@
-#define _STDLIB_DEBUG
-#include <math.h>
-#include <stdio.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <float.h>
-#include <setjmp.h>
+/* #define _STDLIB_DEBUG */
+/* #include <math.h> */
+/* #include <stdio.h> */
+/* #include <signal.h> */
+/* #include <stdlib.h> */
+/* #include <string.h> */
+/* #include <time.h> */
+/* #include <float.h> */
+/* #include <setjmp.h> */
+/* */
-int main(int argc, char **argv) {
- jmp_buf test;
- setjmp(test);
- longjmp(test, 5);
- return 0;
+char *p = "a";
+char s[] = "hello\0there";
+
+int _main(int argc, char **argv) {
+ return s;
}
diff --git a/05/tcc-0.9.25/config.h b/05/tcc-0.9.25/config.h
index abc985d..7e4096c 100644
--- a/05/tcc-0.9.25/config.h
+++ b/05/tcc-0.9.25/config.h
@@ -1,7 +1,7 @@
#ifndef CONFIG_TCCDIR
# define CONFIG_TCCDIR "/usr/local/lib/tcc-bootstrap"
#endif
-#define TCC_VERSION "0.9.27"
+#define TCC_VERSION "0.9.25"
#define CONFIG_TCC_STATIC 1
#define TCC_TARGET_X86_64 1
#define CONFIG_TCC_ELFINTERP "/XXX"
diff --git a/05/tcc-0.9.25/libtcc.c b/05/tcc-0.9.25/libtcc.c
index f842f27..3311357 100644
--- a/05/tcc-0.9.25/libtcc.c
+++ b/05/tcc-0.9.25/libtcc.c
@@ -2178,7 +2178,7 @@ typedef struct FlagDef {
const char *name;
} FlagDef;
-static const FlagDef warning_defs[] = {
+static FlagDef warning_defs[] = {
{ 0, 0, "unsupported" },
{ 0, 0, "write-strings" },
{ 0, 0, "error" },
@@ -2235,7 +2235,7 @@ int tcc_set_warning(TCCState *s, const char *warning_name, int value)
}
}
-static const FlagDef flag_defs[] = {
+static FlagDef flag_defs[] = {
{ 0, 0, "unsigned-char" },
{ 0, FD_INVERT, "signed-char" },
{ 0, FD_INVERT, "common" },
diff --git a/05/tcc-0.9.25/tcc.h b/05/tcc-0.9.25/tcc.h
index 4070249..b4789da 100644
--- a/05/tcc-0.9.25/tcc.h
+++ b/05/tcc-0.9.25/tcc.h
@@ -37,6 +37,13 @@
#include <signal.h>
#include <setjmp.h>
#include <time.h>
+#ifdef __GNUC__
+#include <inttypes.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <fcntl.h>
+#endif
#ifdef _WIN32
#include <windows.h>
diff --git a/05/tcc-0.9.25/tccpp.c b/05/tcc-0.9.25/tccpp.c
index ff17d8b..9ae2a1e 100644
--- a/05/tcc-0.9.25/tccpp.c
+++ b/05/tcc-0.9.25/tccpp.c
@@ -20,7 +20,7 @@
static const char tcc_keywords[] =
-#define DEF(id, str) str "\0"
+#define DEF(id, str) str "\n"
#include "tcctok.h"
#undef DEF
;
@@ -862,6 +862,7 @@ static inline void define_push(int v, int macro_type, int *str, Sym *first_arg)
s = sym_push2(&define_stack, v, macro_type, (long)str);
s->next = first_arg;
+
table_ident[v - TOK_IDENT]->sym_define = s;
}
@@ -2883,7 +2884,7 @@ void preprocess_new()
r = p;
for(;;) {
c = *r++;
- if (c == '\0')
+ if (c == '\n')
break;
}
ts = tok_alloc(p, r - p - 1);
diff --git a/05/util.b b/05/util.b
index 42b6342..af1a31d 100644
--- a/05/util.b
+++ b/05/util.b
@@ -541,6 +541,12 @@ function putx32ln
fputx32(1, n)
fputc(1, 10)
return
+function fputx32ln
+ argument fd
+ argument n
+ fputx32(fd, n)
+ fputc(fd, 10)
+ return
function putn
argument n