working (?) tcc build

This commit is contained in:
pommicket 2022-02-17 17:38:52 -05:00
parent e900dd8d6f
commit e94266df3d
9 changed files with 79 additions and 26 deletions

1
05/.gitignore vendored
View file

@ -1 +1,2 @@
in04 in04
address_map.txt

View file

@ -2580,6 +2580,15 @@ function generate_statement
local c local c
local d 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_continue_refs = continue_refs
prev_break_refs = break_refs prev_break_refs = break_refs

View file

@ -77,7 +77,8 @@ global function_param_names
global function_param_has_no_name global function_param_has_no_name
; ident list of number of bytes of stack space needed by local variables in each function ; ident list of number of bytes of stack space needed by local variables in each function
global functions_required_stack_space 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 util.b
#include idents.b #include idents.b
@ -123,13 +124,19 @@ function types_init
*8ptypes_bytes_used = p - types *8ptypes_bytes_used = p - types
return return
function print_token_location function fprint_token_location
argument fd
argument token argument token
token += 2 token += 2
print_filename(*2token) fprint_filename(fd, *2token)
token += 2 token += 2
putc(':) fputc(fd, ':)
putn(*4token) fputn(fd, *4token)
return
function print_token_location
argument token
fprint_token_location(1, token)
return return
function print_statement_location function print_statement_location
@ -138,14 +145,27 @@ function print_statement_location
print_token_location(statement) print_token_location(statement)
return 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 ; accepts EITHER file index OR pointer to filename
function print_filename function fprint_filename
argument fd
argument file argument file
if file ] 65535 goto print_filename_string if file ] 65535 goto print_filename_string
file = file_get(file) file = file_get(file)
; (fallthrough) ; (fallthrough)
:print_filename_string :print_filename_string
puts(file) fputs(fd, file)
return
function print_filename
argument file
fprint_filename(1, file)
return return
; accepts EITHER file index OR pointer to filename ; accepts EITHER file index OR pointer to filename
@ -328,11 +348,15 @@ function main
debug_puts(.str_parsing) debug_puts(.str_parsing)
parse_tokens(tokens) parse_tokens(tokens)
address_map_fd = open_w(.str_addrmap_filename, 420)
generate_code() generate_code()
p = output_file_data + RODATA_ADDR p = output_file_data + RODATA_ADDR
munmap(output_file_data, RWDATA_END) munmap(output_file_data, RWDATA_END)
close(output_fd) close(output_fd)
close(address_map_fd)
;ident_list_printx64(global_variables) ;ident_list_printx64(global_variables)
;puts(.str_types_bytes_used) ;puts(.str_types_bytes_used)
@ -340,6 +364,10 @@ function main
exit(0) exit(0)
:str_addrmap_filename
string address_map.txt
byte 0
:str_types_bytes_used :str_types_bytes_used
string types_bytes_used: string types_bytes_used:
byte 32 byte 32

View file

@ -1,17 +1,18 @@
#define _STDLIB_DEBUG /* #define _STDLIB_DEBUG */
#include <math.h> /* #include <math.h> */
#include <stdio.h> /* #include <stdio.h> */
#include <signal.h> /* #include <signal.h> */
#include <stdlib.h> /* #include <stdlib.h> */
#include <string.h> /* #include <string.h> */
#include <time.h> /* #include <time.h> */
#include <float.h> /* #include <float.h> */
#include <setjmp.h> /* #include <setjmp.h> */
/* */
int main(int argc, char **argv) { char *p = "a";
jmp_buf test; char s[] = "hello\0there";
setjmp(test);
longjmp(test, 5); int _main(int argc, char **argv) {
return 0; return s;
} }

View file

@ -1,7 +1,7 @@
#ifndef CONFIG_TCCDIR #ifndef CONFIG_TCCDIR
# define CONFIG_TCCDIR "/usr/local/lib/tcc-bootstrap" # define CONFIG_TCCDIR "/usr/local/lib/tcc-bootstrap"
#endif #endif
#define TCC_VERSION "0.9.27" #define TCC_VERSION "0.9.25"
#define CONFIG_TCC_STATIC 1 #define CONFIG_TCC_STATIC 1
#define TCC_TARGET_X86_64 1 #define TCC_TARGET_X86_64 1
#define CONFIG_TCC_ELFINTERP "/XXX" #define CONFIG_TCC_ELFINTERP "/XXX"

View file

@ -2178,7 +2178,7 @@ typedef struct FlagDef {
const char *name; const char *name;
} FlagDef; } FlagDef;
static const FlagDef warning_defs[] = { static FlagDef warning_defs[] = {
{ 0, 0, "unsupported" }, { 0, 0, "unsupported" },
{ 0, 0, "write-strings" }, { 0, 0, "write-strings" },
{ 0, 0, "error" }, { 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, 0, "unsigned-char" },
{ 0, FD_INVERT, "signed-char" }, { 0, FD_INVERT, "signed-char" },
{ 0, FD_INVERT, "common" }, { 0, FD_INVERT, "common" },

View file

@ -37,6 +37,13 @@
#include <signal.h> #include <signal.h>
#include <setjmp.h> #include <setjmp.h>
#include <time.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 #ifdef _WIN32
#include <windows.h> #include <windows.h>

View file

@ -20,7 +20,7 @@
static const char tcc_keywords[] = static const char tcc_keywords[] =
#define DEF(id, str) str "\0" #define DEF(id, str) str "\n"
#include "tcctok.h" #include "tcctok.h"
#undef DEF #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 = sym_push2(&define_stack, v, macro_type, (long)str);
s->next = first_arg; s->next = first_arg;
table_ident[v - TOK_IDENT]->sym_define = s; table_ident[v - TOK_IDENT]->sym_define = s;
} }
@ -2883,7 +2884,7 @@ void preprocess_new()
r = p; r = p;
for(;;) { for(;;) {
c = *r++; c = *r++;
if (c == '\0') if (c == '\n')
break; break;
} }
ts = tok_alloc(p, r - p - 1); ts = tok_alloc(p, r - p - 1);

View file

@ -541,6 +541,12 @@ function putx32ln
fputx32(1, n) fputx32(1, n)
fputc(1, 10) fputc(1, 10)
return return
function fputx32ln
argument fd
argument n
fputx32(fd, n)
fputc(fd, 10)
return
function putn function putn
argument n argument n