@@ -567,6 +567,7 @@ static void error1(int mode, const char *fmt, va_list ap)
567567 BufferedFile * * pf , * f ;
568568 TCCState * s1 = tcc_state ;
569569 CString cs ;
570+ int line = 0 ;
570571
571572 tcc_exit_state (s1 );
572573
@@ -589,6 +590,8 @@ static void error1(int mode, const char *fmt, va_list ap)
589590 }
590591
591592 cstr_new (& cs );
593+ if (fmt [0 ] == '%' && fmt [1 ] == 'i' && fmt [2 ] == ':' )
594+ line = va_arg (ap , int ), fmt += 3 ;
592595 f = NULL ;
593596 if (s1 -> error_set_jmp_enabled ) { /* we're called while parsing a file */
594597 /* use upper file if inline ":asm:" or token ":paste:" */
@@ -599,8 +602,9 @@ static void error1(int mode, const char *fmt, va_list ap)
599602 for (pf = s1 -> include_stack ; pf < s1 -> include_stack_ptr ; pf ++ )
600603 cstr_printf (& cs , "In file included from %s:%d:\n" ,
601604 (* pf )-> filename , (* pf )-> line_num - 1 );
602- cstr_printf (& cs , "%s:%d: " ,
603- f -> filename , f -> line_num - ((tok_flags & TOK_FLAG_BOL ) && !macro_ptr ));
605+ if (0 == line )
606+ line = f -> line_num - ((tok_flags & TOK_FLAG_BOL ) && !macro_ptr );
607+ cstr_printf (& cs , "%s:%d: " , f -> filename , line );
604608 } else if (s1 -> current_filename ) {
605609 cstr_printf (& cs , "%s: " , s1 -> current_filename );
606610 } else {
@@ -818,6 +822,7 @@ LIBTCCAPI TCCState *tcc_new(void)
818822 s -> warn_implicit_function_declaration = 1 ;
819823 s -> warn_discarded_qualifiers = 1 ;
820824 s -> ms_extensions = 1 ;
825+ s -> unwind_tables = 1 ;
821826
822827#ifdef CHAR_IS_UNSIGNED
823828 s -> char_is_unsigned = 1 ;
@@ -999,6 +1004,8 @@ static int tcc_glob_so(TCCState *s1, const char *pattern, char *buf, int size)
9991004}
10001005#endif
10011006
1007+ static int guess_filetype (const char * filename );
1008+
10021009ST_FUNC int tcc_add_file_internal (TCCState * s1 , const char * filename , int flags )
10031010{
10041011 int fd , ret = -1 ;
@@ -1009,6 +1016,9 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
10091016 filename = buf ;
10101017#endif
10111018
1019+ if (0 == (flags & AFF_TYPE_MASK ))
1020+ flags |= guess_filetype (filename );
1021+
10121022 /* ignore binary files with -E */
10131023 if (s1 -> output_type == TCC_OUTPUT_PREPROCESS
10141024 && (flags & AFF_TYPE_BIN ))
@@ -1118,10 +1128,10 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags)
11181128 return ret ;
11191129}
11201130
1121- LIBTCCAPI int tcc_add_file ( TCCState * s , const char * filename )
1131+ static int guess_filetype ( const char * filename )
11221132{
1123- int filetype = s -> filetype ;
1124- if (0 == ( filetype & AFF_TYPE_MASK ) ) {
1133+ int filetype = 0 ;
1134+ if (1 ) {
11251135 /* use a file extension to detect a filetype */
11261136 const char * ext = tcc_fileextension (filename );
11271137 if (ext [0 ]) {
@@ -1140,7 +1150,12 @@ LIBTCCAPI int tcc_add_file(TCCState *s, const char *filename)
11401150 filetype = AFF_TYPE_C ;
11411151 }
11421152 }
1143- return tcc_add_file_internal (s , filename , filetype | AFF_PRINT_ERROR );
1153+ return filetype ;
1154+ }
1155+
1156+ LIBTCCAPI int tcc_add_file (TCCState * s , const char * filename )
1157+ {
1158+ return tcc_add_file_internal (s , filename , s -> filetype | AFF_PRINT_ERROR );
11441159}
11451160
11461161LIBTCCAPI int tcc_add_library_path (TCCState * s , const char * pathname )
@@ -1157,12 +1172,12 @@ static int tcc_add_library_internal(TCCState *s1, const char *fmt,
11571172
11581173 for (i = 0 ; i < nb_paths ; i ++ ) {
11591174 snprintf (buf , sizeof (buf ), fmt , paths [i ], filename );
1160- ret = tcc_add_file_internal (s1 , buf , ( flags & ~AFF_PRINT_ERROR ) | AFF_TYPE_BIN );
1175+ ret = tcc_add_file_internal (s1 , buf , flags & ~AFF_PRINT_ERROR );
11611176 if (ret != FILE_NOT_FOUND )
11621177 return ret ;
11631178 }
11641179 if (flags & AFF_PRINT_ERROR )
1165- tcc_error_noabort ("file '%s' not found" , filename );
1180+ tcc_error_noabort ("library '%s' not found" , filename );
11661181 return FILE_NOT_FOUND ;
11671182}
11681183
@@ -1214,23 +1229,15 @@ LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
12141229 return ret ;
12151230 ++ pp ;
12161231 }
1217- return FILE_NOT_FOUND ;
1218- }
1219-
1220- PUB_FUNC int tcc_add_library_err (TCCState * s1 , const char * libname )
1221- {
1222- int ret = tcc_add_library (s1 , libname );
1223- if (ret == FILE_NOT_FOUND )
1224- tcc_error_noabort ("library '%s' not found" , libname );
1225- return ret ;
1232+ return tcc_add_dll (s , libraryname , AFF_PRINT_ERROR );
12261233}
12271234
12281235/* handle #pragma comment(lib,) */
12291236ST_FUNC void tcc_add_pragma_libs (TCCState * s1 )
12301237{
12311238 int i ;
12321239 for (i = 0 ; i < s1 -> nb_pragma_libs ; i ++ )
1233- tcc_add_library_err (s1 , s1 -> pragma_libs [i ]);
1240+ tcc_add_library (s1 , s1 -> pragma_libs [i ]);
12341241}
12351242
12361243LIBTCCAPI int tcc_add_symbol (TCCState * s1 , const char * name , const void * val )
@@ -1669,6 +1676,9 @@ static const FlagDef options_f[] = {
16691676 { offsetof(TCCState , ms_extensions ), 0 , "ms-extensions" },
16701677 { offsetof(TCCState , dollars_in_identifiers ), 0 , "dollars-in-identifiers" },
16711678 { offsetof(TCCState , test_coverage ), 0 , "test-coverage" },
1679+ { offsetof(TCCState , reverse_funcargs ), 0 , "reverse-funcargs" },
1680+ { offsetof(TCCState , gnu89_inline ), 0 , "gnu89-inline" },
1681+ { offsetof(TCCState , unwind_tables ), 0 , "asynchronous-unwind-tables" },
16721682 { 0 , 0 , NULL }
16731683};
16741684
0 commit comments