2009-05-05 22:17:11 +04:00
|
|
|
/*
|
|
|
|
* TCC - Tiny C Compiler
|
2015-07-29 23:53:57 +03:00
|
|
|
*
|
2009-05-05 22:17:11 +04:00
|
|
|
* Copyright (c) 2001-2004 Fabrice Bellard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
#ifndef _TCC_H
|
|
|
|
#define _TCC_H
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
2013-02-04 19:08:06 +04:00
|
|
|
# include <unistd.h>
|
|
|
|
# include <sys/time.h>
|
2013-02-06 22:01:07 +04:00
|
|
|
# ifndef CONFIG_TCC_STATIC
|
|
|
|
# include <dlfcn.h>
|
|
|
|
# endif
|
2014-04-04 22:18:39 +04:00
|
|
|
/* XXX: need to define this to use them in non ISOC99 context */
|
|
|
|
extern float strtof (const char *__nptr, char **__endptr);
|
|
|
|
extern long double strtold (const char *__nptr, char **__endptr);
|
2016-10-18 00:24:01 +03:00
|
|
|
|
2014-04-04 22:18:39 +04:00
|
|
|
#else /* on _WIN32: */
|
2013-02-04 19:08:06 +04:00
|
|
|
# include <windows.h>
|
|
|
|
# include <io.h> /* open, close etc. */
|
|
|
|
# include <direct.h> /* getcwd */
|
|
|
|
# ifdef __GNUC__
|
|
|
|
# include <stdint.h>
|
|
|
|
# endif
|
|
|
|
# define inline __inline
|
2016-10-18 00:24:01 +03:00
|
|
|
# define inp next_inp /* inp is an intrinsic on msvc */
|
2014-04-04 22:18:39 +04:00
|
|
|
# define snprintf _snprintf
|
|
|
|
# define vsnprintf _vsnprintf
|
|
|
|
# ifndef __GNUC__
|
|
|
|
# define strtold (long double)strtod
|
|
|
|
# define strtof (float)strtod
|
|
|
|
# define strtoll _strtoi64
|
|
|
|
# define strtoull _strtoui64
|
|
|
|
# endif
|
2013-02-04 19:08:06 +04:00
|
|
|
# ifdef LIBTCC_AS_DLL
|
|
|
|
# define LIBTCCAPI __declspec(dllexport)
|
|
|
|
# define PUB_FUNC LIBTCCAPI
|
|
|
|
# endif
|
2016-04-13 06:29:24 +03:00
|
|
|
# ifdef _MSC_VER
|
|
|
|
# pragma warning (disable : 4244) // conversion from 'uint64_t' to 'int', possible loss of data
|
|
|
|
# pragma warning (disable : 4267) // conversion from 'size_t' to 'int', possible loss of data
|
|
|
|
# pragma warning (disable : 4996) // The POSIX name for this item is deprecated. Instead, use the ISO C and C++ conformant name
|
|
|
|
# pragma warning (disable : 4018) // signed/unsigned mismatch
|
|
|
|
# pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
|
2016-12-19 00:05:42 +03:00
|
|
|
# define ssize_t intptr_t
|
2016-12-20 20:05:33 +03:00
|
|
|
# define __attribute__(x) __declspec x
|
|
|
|
# define aligned align
|
|
|
|
# else
|
2016-04-13 06:29:24 +03:00
|
|
|
# endif
|
2016-10-05 19:34:17 +03:00
|
|
|
# undef CONFIG_TCC_STATIC
|
2009-05-05 22:17:26 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef O_BINARY
|
2013-02-12 22:13:28 +04:00
|
|
|
# define O_BINARY 0
|
2010-09-10 22:55:54 +04:00
|
|
|
#endif
|
|
|
|
|
2014-04-04 22:18:39 +04:00
|
|
|
#ifdef __GNUC__
|
|
|
|
# define NORETURN __attribute__ ((noreturn))
|
|
|
|
#elif defined _MSC_VER
|
|
|
|
# define NORETURN __declspec(noreturn)
|
|
|
|
#else
|
|
|
|
# define NORETURN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# define IS_DIRSEP(c) (c == '/' || c == '\\')
|
|
|
|
# define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
|
|
|
|
# define PATHCMP stricmp
|
|
|
|
#else
|
|
|
|
# define IS_DIRSEP(c) (c == '/')
|
|
|
|
# define IS_ABSPATH(p) IS_DIRSEP(p[0])
|
|
|
|
# define PATHCMP strcmp
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
#define PATHSEP ';'
|
|
|
|
#else
|
|
|
|
#define PATHSEP ':'
|
|
|
|
#endif
|
|
|
|
|
2016-10-18 00:24:01 +03:00
|
|
|
/* -------------------------------------------- */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
|
|
|
/* parser debug */
|
2013-02-17 03:48:51 +04:00
|
|
|
/* #define PARSE_DEBUG */
|
2009-05-05 22:17:26 +04:00
|
|
|
/* preprocessor debug */
|
2013-02-17 03:48:51 +04:00
|
|
|
/* #define PP_DEBUG */
|
2009-05-05 22:17:26 +04:00
|
|
|
/* include file debug */
|
2013-02-17 03:48:51 +04:00
|
|
|
/* #define INC_DEBUG */
|
2013-02-08 22:07:11 +04:00
|
|
|
/* memory leak debug */
|
2013-02-17 03:48:51 +04:00
|
|
|
/* #define MEM_DEBUG */
|
2009-05-05 22:17:26 +04:00
|
|
|
/* assembler debug */
|
2013-02-17 03:48:51 +04:00
|
|
|
/* #define ASM_DEBUG */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
|
|
|
/* target selection */
|
2013-02-17 03:48:51 +04:00
|
|
|
/* #define TCC_TARGET_I386 *//* i386 code generator */
|
|
|
|
/* #define TCC_TARGET_ARM *//* ARMv4 code generator */
|
2015-02-13 21:58:31 +03:00
|
|
|
/* #define TCC_TARGET_ARM64 *//* ARMv8 code generator */
|
2013-02-17 03:48:51 +04:00
|
|
|
/* #define TCC_TARGET_C67 *//* TMS320C67xx code generator */
|
|
|
|
/* #define TCC_TARGET_X86_64 *//* x86-64 code generator */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
|
|
|
/* default target is I386 */
|
|
|
|
#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
|
2015-02-13 21:58:31 +03:00
|
|
|
!defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
|
|
|
|
!defined(TCC_TARGET_X86_64)
|
2009-05-05 22:17:26 +04:00
|
|
|
#define TCC_TARGET_I386
|
|
|
|
#endif
|
|
|
|
|
2009-12-20 00:22:43 +03:00
|
|
|
#if !defined(TCC_UCLIBC) && !defined(TCC_TARGET_ARM) && \
|
2015-02-13 21:58:31 +03:00
|
|
|
!defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
|
2015-04-10 15:17:22 +03:00
|
|
|
!defined(CONFIG_USE_LIBGCC)
|
2009-05-05 22:17:26 +04:00
|
|
|
#define CONFIG_TCC_BCHECK /* enable bound checking code */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* define it to include assembler support */
|
2015-02-13 21:58:31 +03:00
|
|
|
#if !defined(TCC_TARGET_ARM) && !defined(TCC_TARGET_ARM64) && \
|
|
|
|
!defined(TCC_TARGET_C67)
|
2009-05-05 22:17:26 +04:00
|
|
|
#define CONFIG_TCC_ASM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* object format selection */
|
|
|
|
#if defined(TCC_TARGET_C67)
|
|
|
|
#define TCC_TARGET_COFF
|
|
|
|
#endif
|
|
|
|
|
2012-03-05 23:15:56 +04:00
|
|
|
/* only native compiler supports -run */
|
|
|
|
#if defined _WIN32 == defined TCC_TARGET_PE
|
|
|
|
# if (defined __i386__ || defined _X86_) && defined TCC_TARGET_I386
|
|
|
|
# define TCC_IS_NATIVE
|
|
|
|
# elif (defined __x86_64__ || defined _AMD64_) && defined TCC_TARGET_X86_64
|
|
|
|
# define TCC_IS_NATIVE
|
|
|
|
# elif defined __arm__ && defined TCC_TARGET_ARM
|
|
|
|
# define TCC_IS_NATIVE
|
2015-02-13 21:58:31 +03:00
|
|
|
# elif defined __aarch64__ && defined TCC_TARGET_ARM64
|
|
|
|
# define TCC_IS_NATIVE
|
2012-03-05 23:15:56 +04:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined TCC_IS_NATIVE && !defined CONFIG_TCCBOOT
|
|
|
|
# define CONFIG_TCC_BACKTRACE
|
|
|
|
#endif
|
|
|
|
|
2011-08-06 18:11:12 +04:00
|
|
|
/* ------------ path configuration ------------ */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2011-08-11 18:55:30 +04:00
|
|
|
#ifndef CONFIG_SYSROOT
|
|
|
|
# define CONFIG_SYSROOT ""
|
|
|
|
#endif
|
2013-02-14 09:53:07 +04:00
|
|
|
#ifndef CONFIG_TCCDIR
|
|
|
|
# define CONFIG_TCCDIR "."
|
|
|
|
#endif
|
|
|
|
#ifndef CONFIG_LDDIR
|
2016-10-18 00:22:21 +03:00
|
|
|
# define CONFIG_LDDIR "lib"
|
2013-02-14 09:53:07 +04:00
|
|
|
#endif
|
2016-10-18 00:22:21 +03:00
|
|
|
#ifdef CONFIG_TRIPLET
|
|
|
|
# define USE_TRIPLET(s) s "/" CONFIG_TRIPLET
|
|
|
|
# define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s
|
2014-01-06 22:56:26 +04:00
|
|
|
#else
|
2016-10-18 00:22:21 +03:00
|
|
|
# define USE_TRIPLET(s) s
|
|
|
|
# define ALSO_TRIPLET(s) s
|
2013-09-07 21:26:36 +04:00
|
|
|
#endif
|
2011-08-11 18:55:30 +04:00
|
|
|
|
2011-08-04 00:26:39 +04:00
|
|
|
/* path to find crt1.o, crti.o and crtn.o */
|
2011-08-06 18:11:12 +04:00
|
|
|
#ifndef CONFIG_TCC_CRTPREFIX
|
2016-10-18 00:22:21 +03:00
|
|
|
# define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
|
2011-08-04 00:26:39 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-11 18:55:30 +04:00
|
|
|
/* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
|
|
|
|
|
2011-08-06 18:11:12 +04:00
|
|
|
/* system include paths */
|
|
|
|
#ifndef CONFIG_TCC_SYSINCLUDEPATHS
|
2011-08-04 00:26:39 +04:00
|
|
|
# ifdef TCC_TARGET_PE
|
2011-08-11 18:55:30 +04:00
|
|
|
# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include;{B}/include/winapi"
|
2013-09-07 21:26:36 +04:00
|
|
|
# else
|
2012-04-18 20:44:39 +04:00
|
|
|
# define CONFIG_TCC_SYSINCLUDEPATHS \
|
2015-11-23 15:50:16 +03:00
|
|
|
"{B}/include" \
|
2016-10-18 00:22:21 +03:00
|
|
|
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
|
|
|
|
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include")
|
2011-08-04 00:26:39 +04:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2011-08-06 18:11:12 +04:00
|
|
|
/* library search paths */
|
|
|
|
#ifndef CONFIG_TCC_LIBPATHS
|
2011-08-04 00:26:39 +04:00
|
|
|
# ifdef TCC_TARGET_PE
|
2014-01-06 22:56:26 +04:00
|
|
|
# define CONFIG_TCC_LIBPATHS "{B}/lib"
|
2011-08-04 00:26:39 +04:00
|
|
|
# else
|
2011-08-06 18:11:12 +04:00
|
|
|
# define CONFIG_TCC_LIBPATHS \
|
2016-10-18 00:22:21 +03:00
|
|
|
ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
|
|
|
|
":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
|
|
|
|
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
|
2011-08-04 00:26:39 +04:00
|
|
|
# endif
|
|
|
|
#endif
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2011-08-06 18:11:12 +04:00
|
|
|
/* name of ELF interpreter */
|
|
|
|
#ifndef CONFIG_TCC_ELFINTERP
|
|
|
|
# if defined __FreeBSD__
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/libexec/ld-elf.so.1"
|
|
|
|
# elif defined __FreeBSD_kernel__
|
2013-02-18 14:41:34 +04:00
|
|
|
# if defined(TCC_TARGET_X86_64)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-kfreebsd-x86-64.so.1"
|
|
|
|
# else
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld.so.1"
|
|
|
|
# endif
|
2014-04-12 09:10:12 +04:00
|
|
|
# elif defined __DragonFly__
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld-elf.so.2"
|
2015-10-11 13:22:41 +03:00
|
|
|
# elif defined __NetBSD__
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/usr/libexec/ld.elf_so"
|
2013-02-18 14:53:00 +04:00
|
|
|
# elif defined __GNU__
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld.so"
|
2015-03-03 17:05:44 +03:00
|
|
|
# elif defined(TCC_TARGET_PE)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "-"
|
|
|
|
# elif defined(TCC_UCLIBC)
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-uClibc.so.0" /* is there a uClibc for x86_64 ? */
|
2015-02-13 21:58:31 +03:00
|
|
|
# elif defined TCC_TARGET_ARM64
|
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-aarch64.so.1"
|
2011-08-06 18:11:12 +04:00
|
|
|
# elif defined(TCC_TARGET_X86_64)
|
2012-05-23 01:44:03 +04:00
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
|
2014-01-07 11:23:54 +04:00
|
|
|
# elif !defined(TCC_ARM_EABI)
|
2012-05-23 01:44:03 +04:00
|
|
|
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
|
2011-08-06 18:11:12 +04:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 11:23:54 +04:00
|
|
|
/* var elf_interp dans *-gen.c */
|
|
|
|
#ifdef CONFIG_TCC_ELFINTERP
|
|
|
|
# define DEFAULT_ELFINTERP(s) CONFIG_TCC_ELFINTERP
|
|
|
|
#else
|
|
|
|
# define DEFAULT_ELFINTERP(s) default_elfinterp(s)
|
|
|
|
#endif
|
|
|
|
|
2016-10-01 22:06:33 +03:00
|
|
|
/* target specific subdir for libtcc1.a */
|
|
|
|
#ifndef TCC_ARCH_DIR
|
|
|
|
# define TCC_ARCH_DIR ""
|
|
|
|
#endif
|
|
|
|
|
2011-08-06 18:11:12 +04:00
|
|
|
/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
|
2016-10-18 00:22:21 +03:00
|
|
|
#define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
|
2011-08-06 18:11:12 +04:00
|
|
|
|
2016-10-18 00:24:01 +03:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
|
|
|
#include "libtcc.h"
|
|
|
|
#include "elf.h"
|
|
|
|
#include "stab.h"
|
|
|
|
|
|
|
|
#if defined(TCC_TARGET_ARM64) || defined(TCC_TARGET_X86_64)
|
|
|
|
# define ELFCLASSW ELFCLASS64
|
|
|
|
# define ElfW(type) Elf##64##_##type
|
|
|
|
# define ELFW(type) ELF##64##_##type
|
|
|
|
# define ElfW_Rel ElfW(Rela)
|
|
|
|
# define SHT_RELX SHT_RELA
|
|
|
|
# define REL_SECTION_FMT ".rela%s"
|
|
|
|
#else
|
|
|
|
# define ELFCLASSW ELFCLASS32
|
|
|
|
# define ElfW(type) Elf##32##_##type
|
|
|
|
# define ELFW(type) ELF##32##_##type
|
|
|
|
# define ElfW_Rel ElfW(Rel)
|
|
|
|
# define SHT_RELX SHT_REL
|
|
|
|
# define REL_SECTION_FMT ".rel%s"
|
|
|
|
#endif
|
|
|
|
/* target address type */
|
|
|
|
#define addr_t ElfW(Addr)
|
|
|
|
|
2013-02-08 22:07:11 +04:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
/* include the target specific definitions */
|
|
|
|
|
|
|
|
#define TARGET_DEFS_ONLY
|
|
|
|
#ifdef TCC_TARGET_I386
|
2015-07-29 23:53:57 +03:00
|
|
|
# include "i386-gen.c"
|
2016-12-05 23:40:59 +03:00
|
|
|
# include "i386-link.c"
|
2013-02-08 22:07:11 +04:00
|
|
|
#endif
|
|
|
|
#ifdef TCC_TARGET_X86_64
|
2015-07-29 23:53:57 +03:00
|
|
|
# include "x86_64-gen.c"
|
2016-12-05 23:40:59 +03:00
|
|
|
# include "x86_64-link.c"
|
2013-02-08 22:07:11 +04:00
|
|
|
#endif
|
|
|
|
#ifdef TCC_TARGET_ARM
|
2015-07-29 23:53:57 +03:00
|
|
|
# include "arm-gen.c"
|
2016-12-05 23:40:59 +03:00
|
|
|
# include "arm-link.c"
|
2013-02-08 22:07:11 +04:00
|
|
|
#endif
|
2015-02-13 21:58:31 +03:00
|
|
|
#ifdef TCC_TARGET_ARM64
|
2015-07-29 23:53:57 +03:00
|
|
|
# include "arm64-gen.c"
|
2016-12-05 23:40:59 +03:00
|
|
|
# include "arm64-link.c"
|
2015-02-13 21:58:31 +03:00
|
|
|
#endif
|
2013-02-08 22:07:11 +04:00
|
|
|
#ifdef TCC_TARGET_C67
|
|
|
|
# include "coff.h"
|
2015-07-29 23:53:57 +03:00
|
|
|
# include "c67-gen.c"
|
2016-12-05 23:40:59 +03:00
|
|
|
# include "c67-link.c"
|
2013-02-08 22:07:11 +04:00
|
|
|
#endif
|
|
|
|
#undef TARGET_DEFS_ONLY
|
|
|
|
|
2011-08-06 18:11:12 +04:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
#define INCLUDE_STACK_SIZE 32
|
|
|
|
#define IFDEF_STACK_SIZE 64
|
|
|
|
#define VSTACK_SIZE 256
|
|
|
|
#define STRING_MAX_SIZE 1024
|
2016-04-17 16:37:23 +03:00
|
|
|
#define TOKSTR_MAX_SIZE 256
|
2009-05-05 22:17:26 +04:00
|
|
|
#define PACK_STACK_SIZE 8
|
|
|
|
|
2016-04-17 16:37:23 +03:00
|
|
|
#define TOK_HASH_SIZE 16384 /* must be a power of two */
|
2009-05-05 22:17:26 +04:00
|
|
|
#define TOK_ALLOC_INCR 512 /* must be a power of two */
|
|
|
|
#define TOK_MAX_SIZE 4 /* token max size in int unit when stored in string */
|
|
|
|
|
|
|
|
/* token symbol management */
|
|
|
|
typedef struct TokenSym {
|
|
|
|
struct TokenSym *hash_next;
|
|
|
|
struct Sym *sym_define; /* direct pointer to define */
|
|
|
|
struct Sym *sym_label; /* direct pointer to label */
|
|
|
|
struct Sym *sym_struct; /* direct pointer to structure */
|
|
|
|
struct Sym *sym_identifier; /* direct pointer to identifier */
|
|
|
|
int tok; /* token number */
|
|
|
|
int len;
|
|
|
|
char str[1];
|
|
|
|
} TokenSym;
|
|
|
|
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
typedef unsigned short nwchar_t;
|
|
|
|
#else
|
|
|
|
typedef int nwchar_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef struct CString {
|
|
|
|
int size; /* size in bytes */
|
|
|
|
void *data; /* either 'char *' or 'nwchar_t *' */
|
|
|
|
int size_allocated;
|
|
|
|
} CString;
|
|
|
|
|
|
|
|
/* type definition */
|
|
|
|
typedef struct CType {
|
|
|
|
int t;
|
|
|
|
struct Sym *ref;
|
|
|
|
} CType;
|
|
|
|
|
|
|
|
/* constant value */
|
|
|
|
typedef union CValue {
|
|
|
|
long double ld;
|
|
|
|
double d;
|
|
|
|
float f;
|
2015-11-17 22:09:35 +03:00
|
|
|
uint64_t i;
|
2015-11-21 14:23:53 +03:00
|
|
|
struct {
|
|
|
|
int size;
|
|
|
|
const void *data;
|
|
|
|
} str;
|
2013-02-08 22:07:11 +04:00
|
|
|
int tab[LDOUBLE_SIZE/4];
|
2009-05-05 22:17:26 +04:00
|
|
|
} CValue;
|
|
|
|
|
|
|
|
/* value on stack */
|
|
|
|
typedef struct SValue {
|
|
|
|
CType type; /* type */
|
|
|
|
unsigned short r; /* register + flags */
|
|
|
|
unsigned short r2; /* second register, used for 'long long'
|
|
|
|
type. If not used, set to VT_CONST */
|
|
|
|
CValue c; /* constant, if VT_CONST */
|
2016-10-06 05:05:30 +03:00
|
|
|
struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST), or if
|
|
|
|
result of unary() for an identifier. */
|
2009-05-05 22:17:26 +04:00
|
|
|
} SValue;
|
|
|
|
|
2014-01-07 17:57:07 +04:00
|
|
|
struct Attribute {
|
|
|
|
unsigned
|
|
|
|
func_call : 3, /* calling convention (0..5), see below */
|
2016-10-09 03:41:34 +03:00
|
|
|
aligned : 5, /* alignment as log2+1 (0 == unspecified) */
|
2014-01-07 17:57:07 +04:00
|
|
|
packed : 1,
|
|
|
|
func_export : 1,
|
|
|
|
func_import : 1,
|
|
|
|
func_args : 5,
|
2017-02-13 20:23:43 +03:00
|
|
|
func_body : 1,
|
2014-01-07 17:57:07 +04:00
|
|
|
mode : 4,
|
|
|
|
weak : 1,
|
2014-04-14 04:53:11 +04:00
|
|
|
visibility : 2,
|
2016-08-07 03:15:34 +03:00
|
|
|
unsigned_enum : 1,
|
|
|
|
fill : 7; // 7 bits left to fit well in union below
|
2014-01-07 17:57:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* GNUC attribute definition */
|
|
|
|
typedef struct AttributeDef {
|
|
|
|
struct Attribute a;
|
|
|
|
struct Section *section;
|
|
|
|
int alias_target; /* token */
|
2015-11-20 13:22:56 +03:00
|
|
|
int asm_label; /* associated asm label */
|
2014-01-07 17:57:07 +04:00
|
|
|
} AttributeDef;
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
/* symbol management */
|
|
|
|
typedef struct Sym {
|
|
|
|
int v; /* symbol token */
|
2016-05-05 11:39:09 +03:00
|
|
|
union {
|
|
|
|
int asm_label; /* associated asm label */
|
|
|
|
int scope; /* scope level for locals */
|
|
|
|
};
|
2014-01-07 17:57:07 +04:00
|
|
|
union {
|
2016-10-06 05:05:30 +03:00
|
|
|
long r; /* associated register or VT_CONST/VT_LOCAL and LVAL type */
|
2014-01-07 17:57:07 +04:00
|
|
|
struct Attribute a;
|
|
|
|
};
|
2009-07-06 23:16:41 +04:00
|
|
|
union {
|
|
|
|
long c; /* associated number */
|
|
|
|
int *d; /* define token stream */
|
|
|
|
};
|
2009-05-05 22:17:26 +04:00
|
|
|
CType type; /* associated type */
|
2009-07-19 00:05:58 +04:00
|
|
|
union {
|
2016-10-06 05:05:30 +03:00
|
|
|
struct Sym *next; /* next related symbol (for fields and anoms) */
|
2009-07-19 00:05:58 +04:00
|
|
|
long jnext; /* next jump label */
|
|
|
|
};
|
2009-05-05 22:17:26 +04:00
|
|
|
struct Sym *prev; /* prev symbol in stack */
|
|
|
|
struct Sym *prev_tok; /* previous symbol for this token */
|
|
|
|
} Sym;
|
|
|
|
|
|
|
|
/* section definition */
|
|
|
|
/* XXX: use directly ELF structure for parameters ? */
|
|
|
|
/* special flag to indicate that the section should not be linked to
|
|
|
|
the other ones */
|
|
|
|
#define SHF_PRIVATE 0x80000000
|
|
|
|
|
2009-05-05 22:30:39 +04:00
|
|
|
/* special flag, too */
|
|
|
|
#define SECTION_ABS ((void *)1)
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
typedef struct Section {
|
|
|
|
unsigned long data_offset; /* current data offset */
|
|
|
|
unsigned char *data; /* section data */
|
|
|
|
unsigned long data_allocated; /* used for realloc() handling */
|
|
|
|
int sh_name; /* elf section name (only used during output) */
|
|
|
|
int sh_num; /* elf section number */
|
|
|
|
int sh_type; /* elf section type */
|
|
|
|
int sh_flags; /* elf section flags */
|
|
|
|
int sh_info; /* elf section info */
|
|
|
|
int sh_addralign; /* elf section alignment */
|
|
|
|
int sh_entsize; /* elf entry size */
|
|
|
|
unsigned long sh_size; /* section size (only used during output) */
|
2013-02-04 19:08:06 +04:00
|
|
|
addr_t sh_addr; /* address at which the section is relocated */
|
2012-03-03 21:10:15 +04:00
|
|
|
unsigned long sh_offset; /* file offset */
|
2009-05-05 22:17:26 +04:00
|
|
|
int nb_hashed_syms; /* used to resize the hash table */
|
|
|
|
struct Section *link; /* link to another section */
|
|
|
|
struct Section *reloc; /* corresponding section for relocation, if any */
|
2016-06-28 16:11:06 +03:00
|
|
|
struct Section *hash; /* hash table for symbols */
|
|
|
|
struct Section *prev; /* previous section on section stack */
|
2009-05-05 22:17:26 +04:00
|
|
|
char name[1]; /* section name */
|
|
|
|
} Section;
|
|
|
|
|
|
|
|
typedef struct DLLReference {
|
|
|
|
int level;
|
|
|
|
void *handle;
|
|
|
|
char name[1];
|
|
|
|
} DLLReference;
|
|
|
|
|
|
|
|
/* -------------------------------------------------- */
|
|
|
|
|
|
|
|
#define SYM_STRUCT 0x40000000 /* struct/union/enum symbol space */
|
|
|
|
#define SYM_FIELD 0x20000000 /* struct/union field symbol space */
|
|
|
|
#define SYM_FIRST_ANOM 0x10000000 /* first anonymous sym */
|
|
|
|
|
|
|
|
/* stored in 'Sym.c' field */
|
|
|
|
#define FUNC_NEW 1 /* ansi function prototype */
|
|
|
|
#define FUNC_OLD 2 /* old function prototype */
|
|
|
|
#define FUNC_ELLIPSIS 3 /* ansi function prototype with ... */
|
|
|
|
|
|
|
|
/* stored in 'Sym.r' field */
|
|
|
|
#define FUNC_CDECL 0 /* standard c call */
|
|
|
|
#define FUNC_STDCALL 1 /* pascal c call */
|
|
|
|
#define FUNC_FASTCALL1 2 /* first param in %eax */
|
|
|
|
#define FUNC_FASTCALL2 3 /* first parameters in %eax, %edx */
|
|
|
|
#define FUNC_FASTCALL3 4 /* first parameter in %eax, %edx, %ecx */
|
|
|
|
#define FUNC_FASTCALLW 5 /* first parameter in %ecx, %edx */
|
|
|
|
|
|
|
|
/* field 'Sym.t' for macros */
|
|
|
|
#define MACRO_OBJ 0 /* object like macro */
|
|
|
|
#define MACRO_FUNC 1 /* function like macro */
|
|
|
|
|
|
|
|
/* field 'Sym.r' for C labels */
|
|
|
|
#define LABEL_DEFINED 0 /* label is defined */
|
|
|
|
#define LABEL_FORWARD 1 /* label is forward defined */
|
|
|
|
#define LABEL_DECLARED 2 /* label is declared but never used */
|
|
|
|
|
|
|
|
/* type_decl() types */
|
|
|
|
#define TYPE_ABSTRACT 1 /* type without variable */
|
|
|
|
#define TYPE_DIRECT 2 /* type with variable */
|
|
|
|
|
|
|
|
#define IO_BUF_SIZE 8192
|
|
|
|
|
|
|
|
typedef struct BufferedFile {
|
|
|
|
uint8_t *buf_ptr;
|
|
|
|
uint8_t *buf_end;
|
2013-01-14 20:34:07 +04:00
|
|
|
int fd;
|
2010-11-25 15:29:15 +03:00
|
|
|
struct BufferedFile *prev;
|
2009-05-05 22:17:26 +04:00
|
|
|
int line_num; /* current line number - here to simplify code */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
int line_ref; /* tcc -E: last printed line */
|
2009-05-05 22:17:26 +04:00
|
|
|
int ifndef_macro; /* #ifndef macro / #endif search */
|
|
|
|
int ifndef_macro_saved; /* saved ifndef_macro */
|
|
|
|
int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
|
2015-11-20 14:05:55 +03:00
|
|
|
int include_next_index; /* next search path */
|
2013-01-06 20:20:44 +04:00
|
|
|
char filename[1024]; /* filename */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
unsigned char unget[4];
|
2014-12-11 04:58:53 +03:00
|
|
|
unsigned char buffer[1]; /* extra size for CH_EOB char */
|
2009-05-05 22:17:26 +04:00
|
|
|
} BufferedFile;
|
|
|
|
|
|
|
|
#define CH_EOB '\\' /* end of buffer or '\0' char in file */
|
|
|
|
#define CH_EOF (-1) /* end of file */
|
|
|
|
|
|
|
|
/* parsing state (used to save parser state to reparse part of the
|
|
|
|
source several times) */
|
|
|
|
typedef struct ParseState {
|
2010-01-14 22:58:03 +03:00
|
|
|
const int *macro_ptr;
|
2009-05-05 22:17:26 +04:00
|
|
|
int line_num;
|
|
|
|
int tok;
|
|
|
|
CValue tokc;
|
|
|
|
} ParseState;
|
|
|
|
|
|
|
|
/* used to record tokens */
|
|
|
|
typedef struct TokenString {
|
|
|
|
int *str;
|
|
|
|
int len;
|
|
|
|
int allocated_len;
|
|
|
|
int last_line_num;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
/* used to chain token-strings with begin/end_macro() */
|
|
|
|
struct TokenString *prev;
|
|
|
|
const int *prev_ptr;
|
|
|
|
char alloc;
|
2009-05-05 22:17:26 +04:00
|
|
|
} TokenString;
|
|
|
|
|
2009-06-29 23:14:53 +04:00
|
|
|
/* inline functions */
|
|
|
|
typedef struct InlineFunc {
|
2016-11-11 20:29:45 +03:00
|
|
|
TokenString *func_str;
|
2009-06-29 23:14:53 +04:00
|
|
|
Sym *sym;
|
|
|
|
char filename[1];
|
|
|
|
} InlineFunc;
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
/* include file cache, used to find files faster and also to eliminate
|
|
|
|
inclusion if the include file is protected by #ifndef ... #endif */
|
|
|
|
typedef struct CachedInclude {
|
|
|
|
int ifndef_macro;
|
2016-10-01 21:03:48 +03:00
|
|
|
int once;
|
2009-05-05 22:17:26 +04:00
|
|
|
int hash_next; /* -1 if none */
|
|
|
|
char filename[1]; /* path specified in #include */
|
|
|
|
} CachedInclude;
|
|
|
|
|
2016-10-01 21:03:48 +03:00
|
|
|
#define CACHED_INCLUDES_HASH_SIZE 32
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2009-05-11 20:45:56 +04:00
|
|
|
#ifdef CONFIG_TCC_ASM
|
|
|
|
typedef struct ExprValue {
|
2016-05-12 00:47:02 +03:00
|
|
|
uint64_t v;
|
2009-05-11 20:45:56 +04:00
|
|
|
Sym *sym;
|
2016-06-29 16:57:32 +03:00
|
|
|
int pcrel;
|
2009-05-11 20:45:56 +04:00
|
|
|
} ExprValue;
|
|
|
|
|
|
|
|
#define MAX_ASM_OPERANDS 30
|
|
|
|
typedef struct ASMOperand {
|
|
|
|
int id; /* GCC 3 optionnal identifier (0 if number only supported */
|
|
|
|
char *constraint;
|
|
|
|
char asm_str[16]; /* computed asm string for operand */
|
|
|
|
SValue *vt; /* C value of the expression */
|
|
|
|
int ref_index; /* if >= 0, gives reference to a output constraint */
|
|
|
|
int input_index; /* if >= 0, gives reference to an input constraint */
|
|
|
|
int priority; /* priority, used to assign registers */
|
|
|
|
int reg; /* if >= 0, register number used for this operand */
|
|
|
|
int is_llong; /* true if double register value */
|
|
|
|
int is_memory; /* true if memory operand */
|
|
|
|
int is_rw; /* for '+' modifier */
|
|
|
|
} ASMOperand;
|
|
|
|
#endif
|
|
|
|
|
2016-11-12 18:16:07 +03:00
|
|
|
/* extra symbol attributes (not in symbol table) */
|
2012-11-04 03:40:05 +04:00
|
|
|
struct sym_attr {
|
2016-12-15 19:01:22 +03:00
|
|
|
unsigned got_offset;
|
|
|
|
unsigned plt_offset;
|
|
|
|
int plt_sym;
|
|
|
|
int dyn_index;
|
2012-11-04 03:40:05 +04:00
|
|
|
#ifdef TCC_TARGET_ARM
|
|
|
|
unsigned char plt_thumb_stub:1;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
struct TCCState {
|
2012-04-18 20:48:26 +04:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
int verbose; /* if true, display some information during compilation */
|
2009-05-05 22:17:26 +04:00
|
|
|
int nostdinc; /* if true, no standard headers are added */
|
|
|
|
int nostdlib; /* if true, no standard libraries are added */
|
|
|
|
int nocommon; /* if true, do not use common symbols for .bss data */
|
2013-02-12 22:13:28 +04:00
|
|
|
int static_link; /* if true, static linking is performed */
|
|
|
|
int rdynamic; /* if true, all symbols are exported */
|
|
|
|
int symbolic; /* if true, resolve symbols in the current module first */
|
|
|
|
int alacarte_link; /* if true, only link in referenced objects from archive */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
|
|
|
|
char *soname; /* as specified on the command line (-soname) */
|
|
|
|
char *rpath; /* as specified on the command line (-Wl,-rpath=) */
|
2010-04-06 00:56:33 +04:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
/* output type, see TCC_OUTPUT_XXX */
|
|
|
|
int output_type;
|
2009-05-05 22:17:26 +04:00
|
|
|
/* output format, see TCC_OUTPUT_FORMAT_xxx */
|
|
|
|
int output_format;
|
|
|
|
|
|
|
|
/* C language options */
|
|
|
|
int char_is_unsigned;
|
|
|
|
int leading_underscore;
|
2015-04-10 06:31:58 +03:00
|
|
|
int ms_extensions; /* allow nested named struct w/o identifier behave like unnamed */
|
2015-04-10 23:44:10 +03:00
|
|
|
int old_struct_init_code; /* use old algorithm to init array in struct when there is no '{' used.
|
|
|
|
Liuux 2.4.26 can't find initrd when compiled with a new algorithm */
|
2015-04-12 15:32:03 +03:00
|
|
|
int dollars_in_identifiers; /* allows '$' char in indentifiers */
|
2016-11-23 00:33:12 +03:00
|
|
|
int ms_bitfields; /* if true, emulate MS algorithm for aligning bitfields */
|
2016-04-03 11:42:15 +03:00
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
/* warning switches */
|
|
|
|
int warn_write_strings;
|
|
|
|
int warn_unsupported;
|
|
|
|
int warn_error;
|
|
|
|
int warn_none;
|
|
|
|
int warn_implicit_function_declaration;
|
|
|
|
|
2009-05-11 20:45:44 +04:00
|
|
|
/* compile with debug symbol (and use them if error during execution) */
|
|
|
|
int do_debug;
|
2009-12-20 00:22:43 +03:00
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
2009-05-11 20:45:44 +04:00
|
|
|
/* compile with built-in memory and bounds checker */
|
|
|
|
int do_bounds_check;
|
2009-12-20 00:22:43 +03:00
|
|
|
#endif
|
2014-01-07 11:23:54 +04:00
|
|
|
#ifdef TCC_TARGET_ARM
|
|
|
|
enum float_abi float_abi; /* float ABI of the generated code*/
|
|
|
|
#endif
|
2013-02-12 22:13:28 +04:00
|
|
|
|
|
|
|
addr_t text_addr; /* address of text section */
|
|
|
|
int has_text_addr;
|
|
|
|
|
2016-12-15 19:01:22 +03:00
|
|
|
unsigned section_align; /* section alignment */
|
2013-02-12 22:13:28 +04:00
|
|
|
|
|
|
|
char *init_symbol; /* symbols to call at load-time (not used currently) */
|
|
|
|
char *fini_symbol; /* symbols to call at unload-time (not used currently) */
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
#ifdef TCC_TARGET_I386
|
|
|
|
int seg_size; /* 32. Can be 16 with i386 assembler (.code16) */
|
|
|
|
#endif
|
2016-10-03 06:20:21 +03:00
|
|
|
#ifdef TCC_TARGET_X86_64
|
|
|
|
int nosse; /* For -mno-sse support. */
|
|
|
|
#endif
|
2013-02-12 22:13:28 +04:00
|
|
|
|
|
|
|
/* array of all loaded dlls (including those referenced by loaded dlls) */
|
|
|
|
DLLReference **loaded_dlls;
|
|
|
|
int nb_loaded_dlls;
|
|
|
|
|
|
|
|
/* include paths */
|
|
|
|
char **include_paths;
|
|
|
|
int nb_include_paths;
|
|
|
|
|
|
|
|
char **sysinclude_paths;
|
|
|
|
int nb_sysinclude_paths;
|
|
|
|
|
|
|
|
/* library paths */
|
|
|
|
char **library_paths;
|
|
|
|
int nb_library_paths;
|
|
|
|
|
|
|
|
/* crt?.o object path */
|
|
|
|
char **crt_paths;
|
|
|
|
int nb_crt_paths;
|
2009-05-11 20:45:44 +04:00
|
|
|
|
2016-06-27 17:40:00 +03:00
|
|
|
/* -include files */
|
|
|
|
char **cmd_include_files;
|
|
|
|
int nb_cmd_include_files;
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
/* error handling */
|
|
|
|
void *error_opaque;
|
|
|
|
void (*error_func)(void *opaque, const char *msg);
|
|
|
|
int error_set_jmp_enabled;
|
|
|
|
jmp_buf error_jmp_buf;
|
|
|
|
int nb_errors;
|
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
/* output file for preprocessing (-E) */
|
|
|
|
FILE *ppfp;
|
2015-03-03 14:19:14 +03:00
|
|
|
enum {
|
|
|
|
LINE_MACRO_OUTPUT_FORMAT_GCC,
|
|
|
|
LINE_MACRO_OUTPUT_FORMAT_NONE,
|
2015-11-19 21:26:47 +03:00
|
|
|
LINE_MACRO_OUTPUT_FORMAT_STD
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
} Pflag; /* -P switch */
|
2016-04-06 18:57:11 +03:00
|
|
|
char dflag; /* -dX value */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
/* for -MD/-MF: collected dependencies for this compilation */
|
|
|
|
char **target_deps;
|
|
|
|
int nb_target_deps;
|
|
|
|
|
|
|
|
/* compilation */
|
2009-05-05 22:17:26 +04:00
|
|
|
BufferedFile *include_stack[INCLUDE_STACK_SIZE];
|
2013-02-12 22:13:28 +04:00
|
|
|
BufferedFile **include_stack_ptr;
|
2009-05-05 22:17:26 +04:00
|
|
|
|
|
|
|
int ifdef_stack[IFDEF_STACK_SIZE];
|
2013-02-12 22:13:28 +04:00
|
|
|
int *ifdef_stack_ptr;
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
/* included files enclosed with #ifndef MACRO */
|
2009-05-05 22:17:26 +04:00
|
|
|
int cached_includes_hash[CACHED_INCLUDES_HASH_SIZE];
|
2013-02-12 22:13:28 +04:00
|
|
|
CachedInclude **cached_includes;
|
|
|
|
int nb_cached_includes;
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
/* #pragma pack stack */
|
2009-05-05 22:17:26 +04:00
|
|
|
int pack_stack[PACK_STACK_SIZE];
|
|
|
|
int *pack_stack_ptr;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
char **pragma_libs;
|
|
|
|
int nb_pragma_libs;
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
/* inline functions are stored as token lists and compiled last
|
|
|
|
only if referenced */
|
2009-06-29 23:14:53 +04:00
|
|
|
struct InlineFunc **inline_fns;
|
|
|
|
int nb_inline_fns;
|
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
/* sections */
|
|
|
|
Section **sections;
|
|
|
|
int nb_sections; /* number of sections, including first dummy section */
|
|
|
|
|
|
|
|
Section **priv_sections;
|
|
|
|
int nb_priv_sections; /* number of private sections */
|
|
|
|
|
|
|
|
/* got & plt handling */
|
|
|
|
Section *got;
|
|
|
|
Section *plt;
|
2009-08-27 11:34:35 +04:00
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
/* temporary dynamic symbol sections (for dll loading) */
|
|
|
|
Section *dynsymtab_section;
|
|
|
|
/* exported dynamic symbol section */
|
|
|
|
Section *dynsym;
|
|
|
|
/* copy of the gobal symtab_section variable */
|
|
|
|
Section *symtab;
|
2016-11-12 18:16:07 +03:00
|
|
|
/* extra attributes (eg. GOT/PLT value) for symtab symbols */
|
|
|
|
struct sym_attr *sym_attrs;
|
|
|
|
int nb_sym_attrs;
|
2013-02-12 22:13:28 +04:00
|
|
|
/* tiny assembler state */
|
|
|
|
Sym *asm_labels;
|
2009-08-27 12:12:13 +04:00
|
|
|
|
|
|
|
#ifdef TCC_TARGET_PE
|
|
|
|
/* PE info */
|
|
|
|
int pe_subsystem;
|
2016-12-12 17:52:45 +03:00
|
|
|
unsigned pe_characteristics;
|
2013-02-12 22:13:28 +04:00
|
|
|
unsigned pe_file_align;
|
|
|
|
unsigned pe_stack_size;
|
|
|
|
# ifdef TCC_TARGET_X86_64
|
2011-07-14 21:09:49 +04:00
|
|
|
Section *uw_pdata;
|
|
|
|
int uw_sym;
|
|
|
|
unsigned uw_offs;
|
2013-02-12 22:13:28 +04:00
|
|
|
# endif
|
2009-08-27 12:12:13 +04:00
|
|
|
#endif
|
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
#ifdef TCC_IS_NATIVE
|
2013-08-29 00:55:05 +04:00
|
|
|
const char *runtime_main;
|
2016-10-19 20:21:27 +03:00
|
|
|
void **runtime_mem;
|
|
|
|
int nb_runtime_mem;
|
2009-07-19 00:05:27 +04:00
|
|
|
#endif
|
2013-02-12 22:13:28 +04:00
|
|
|
|
|
|
|
/* used by main and tcc_parse_args only */
|
2016-10-01 21:04:58 +03:00
|
|
|
struct filespec **files; /* files seen on command line */
|
2013-02-12 22:13:28 +04:00
|
|
|
int nb_files; /* number thereof */
|
|
|
|
int nb_libraries; /* number of libs thereof */
|
2016-10-01 21:46:16 +03:00
|
|
|
int filetype;
|
2013-02-12 22:13:28 +04:00
|
|
|
char *outfile; /* output filename */
|
2016-12-19 00:57:03 +03:00
|
|
|
int cross_target; /* -m32/-m64 */
|
2013-02-12 22:13:28 +04:00
|
|
|
int print_search_dirs; /* option */
|
|
|
|
int option_r; /* option -r */
|
|
|
|
int do_bench; /* option -bench */
|
|
|
|
int gen_deps; /* option -MD */
|
|
|
|
char *deps_outfile; /* option -MF */
|
2016-10-01 21:49:38 +03:00
|
|
|
int option_pthread; /* -pthread option */
|
2009-05-05 22:17:26 +04:00
|
|
|
};
|
|
|
|
|
2016-10-01 21:04:58 +03:00
|
|
|
struct filespec {
|
|
|
|
char type, name[1];
|
|
|
|
};
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
/* The current value can be: */
|
2013-02-12 22:13:28 +04:00
|
|
|
#define VT_VALMASK 0x003f /* mask for value location, register or: */
|
|
|
|
#define VT_CONST 0x0030 /* constant in vc (must be first non register value) */
|
2011-08-06 18:08:03 +04:00
|
|
|
#define VT_LLOCAL 0x0031 /* lvalue, offset on stack */
|
|
|
|
#define VT_LOCAL 0x0032 /* offset on stack */
|
|
|
|
#define VT_CMP 0x0033 /* the value is stored in processor flags (in vc) */
|
|
|
|
#define VT_JMP 0x0034 /* value is the consequence of jmp true (even) */
|
|
|
|
#define VT_JMPI 0x0035 /* value is the consequence of jmp false (odd) */
|
|
|
|
#define VT_REF 0x0040 /* value is pointer to structure rather than address */
|
2009-05-05 22:17:26 +04:00
|
|
|
#define VT_LVAL 0x0100 /* var is an lvalue */
|
|
|
|
#define VT_SYM 0x0200 /* a symbol value is added */
|
|
|
|
#define VT_MUSTCAST 0x0400 /* value must be casted to be correct (used for
|
|
|
|
char/short stored in integer registers) */
|
|
|
|
#define VT_MUSTBOUND 0x0800 /* bound checking must be done before
|
|
|
|
dereferencing value */
|
|
|
|
#define VT_BOUNDED 0x8000 /* value is bounded. The address of the
|
|
|
|
bounding function call point is in vc */
|
|
|
|
#define VT_LVAL_BYTE 0x1000 /* lvalue is a byte */
|
|
|
|
#define VT_LVAL_SHORT 0x2000 /* lvalue is a short */
|
|
|
|
#define VT_LVAL_UNSIGNED 0x4000 /* lvalue is unsigned */
|
|
|
|
#define VT_LVAL_TYPE (VT_LVAL_BYTE | VT_LVAL_SHORT | VT_LVAL_UNSIGNED)
|
|
|
|
|
|
|
|
/* types */
|
2013-02-12 22:13:28 +04:00
|
|
|
#define VT_BTYPE 0x000f /* mask for basic type */
|
|
|
|
#define VT_INT 0 /* integer type */
|
|
|
|
#define VT_BYTE 1 /* signed byte type */
|
|
|
|
#define VT_SHORT 2 /* short type */
|
|
|
|
#define VT_VOID 3 /* void type */
|
|
|
|
#define VT_PTR 4 /* pointer */
|
|
|
|
#define VT_ENUM 5 /* enum definition */
|
|
|
|
#define VT_FUNC 6 /* function type */
|
|
|
|
#define VT_STRUCT 7 /* struct/union definition */
|
|
|
|
#define VT_FLOAT 8 /* IEEE float */
|
|
|
|
#define VT_DOUBLE 9 /* IEEE double */
|
|
|
|
#define VT_LDOUBLE 10 /* IEEE long double */
|
|
|
|
#define VT_BOOL 11 /* ISOC99 boolean type */
|
|
|
|
#define VT_LLONG 12 /* 64 bit integer */
|
|
|
|
#define VT_LONG 13 /* long integer (NEVER USED as type, only
|
|
|
|
during parsing) */
|
2015-07-29 23:57:41 +03:00
|
|
|
#define VT_QLONG 14 /* 128-bit integer. Only used for x86-64 ABI */
|
|
|
|
#define VT_QFLOAT 15 /* 128-bit float. Only used for x86-64 ABI */
|
2013-02-12 22:13:28 +04:00
|
|
|
#define VT_UNSIGNED 0x0010 /* unsigned type */
|
|
|
|
#define VT_ARRAY 0x0020 /* array type (also has VT_PTR) */
|
|
|
|
#define VT_BITFIELD 0x0040 /* bitfield modifier */
|
|
|
|
#define VT_CONSTANT 0x0800 /* const modifier */
|
|
|
|
#define VT_VOLATILE 0x1000 /* volatile modifier */
|
2014-02-06 16:51:47 +04:00
|
|
|
#define VT_DEFSIGN 0x2000 /* signed type */
|
2013-02-12 22:13:28 +04:00
|
|
|
#define VT_VLA 0x00020000 /* VLA type (also has VT_PTR and VT_ARRAY) */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
|
|
|
/* storage */
|
2011-02-05 04:31:27 +03:00
|
|
|
#define VT_EXTERN 0x00000080 /* extern definition */
|
|
|
|
#define VT_STATIC 0x00000100 /* static variable */
|
|
|
|
#define VT_TYPEDEF 0x00000200 /* typedef definition */
|
|
|
|
#define VT_INLINE 0x00000400 /* inline definition */
|
|
|
|
#define VT_IMPORT 0x00004000 /* win32: extern data imported from dll */
|
|
|
|
#define VT_EXPORT 0x00008000 /* win32: data exported from dll */
|
2013-02-12 22:13:28 +04:00
|
|
|
#define VT_WEAK 0x00010000 /* weak symbol */
|
2013-10-02 23:49:55 +04:00
|
|
|
#define VT_TLS 0x00040000 /* thread-local storage */
|
2014-04-14 04:53:11 +04:00
|
|
|
#define VT_VIS_SHIFT 19 /* shift for symbol visibility, overlapping
|
|
|
|
bitfield values, because bitfields never
|
|
|
|
have linkage and hence never have
|
|
|
|
visibility. */
|
|
|
|
#define VT_VIS_SIZE 2 /* We have four visibilities. */
|
|
|
|
#define VT_VIS_MASK (((1 << VT_VIS_SIZE)-1) << VT_VIS_SHIFT)
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2013-10-02 23:49:55 +04:00
|
|
|
#define VT_STRUCT_SHIFT 19 /* shift for bitfield shift values (max: 32 - 2*6) */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2014-04-14 04:53:11 +04:00
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
/* type mask (except storage) */
|
2014-04-14 04:53:11 +04:00
|
|
|
#define VT_STORAGE (VT_EXTERN | VT_STATIC | VT_TYPEDEF | VT_INLINE | VT_IMPORT | VT_EXPORT | VT_WEAK | VT_VIS_MASK)
|
2013-02-12 22:13:28 +04:00
|
|
|
#define VT_TYPE (~(VT_STORAGE))
|
2009-05-05 22:17:26 +04:00
|
|
|
|
|
|
|
/* token values */
|
|
|
|
|
|
|
|
/* warning: the following compare tokens depend on i386 asm code */
|
|
|
|
#define TOK_ULT 0x92
|
|
|
|
#define TOK_UGE 0x93
|
|
|
|
#define TOK_EQ 0x94
|
|
|
|
#define TOK_NE 0x95
|
|
|
|
#define TOK_ULE 0x96
|
|
|
|
#define TOK_UGT 0x97
|
|
|
|
#define TOK_Nset 0x98
|
|
|
|
#define TOK_Nclear 0x99
|
|
|
|
#define TOK_LT 0x9c
|
|
|
|
#define TOK_GE 0x9d
|
|
|
|
#define TOK_LE 0x9e
|
|
|
|
#define TOK_GT 0x9f
|
|
|
|
|
|
|
|
#define TOK_LAND 0xa0
|
|
|
|
#define TOK_LOR 0xa1
|
|
|
|
#define TOK_DEC 0xa2
|
|
|
|
#define TOK_MID 0xa3 /* inc/dec, to void constant */
|
|
|
|
#define TOK_INC 0xa4
|
|
|
|
#define TOK_UDIV 0xb0 /* unsigned division */
|
|
|
|
#define TOK_UMOD 0xb1 /* unsigned modulo */
|
|
|
|
#define TOK_PDIV 0xb2 /* fast division with undefined rounding for pointers */
|
2014-03-29 19:40:54 +04:00
|
|
|
|
|
|
|
/* tokens that carry values (in additional token string space / tokc) --> */
|
|
|
|
#define TOK_CCHAR 0xb3 /* char constant in tokc */
|
|
|
|
#define TOK_LCHAR 0xb4
|
|
|
|
#define TOK_CINT 0xb5 /* number in tokc */
|
|
|
|
#define TOK_CUINT 0xb6 /* unsigned int constant */
|
|
|
|
#define TOK_CLLONG 0xb7 /* long long constant */
|
|
|
|
#define TOK_CULLONG 0xb8 /* unsigned long long constant */
|
|
|
|
#define TOK_STR 0xb9 /* pointer to string in tokc */
|
|
|
|
#define TOK_LSTR 0xba
|
|
|
|
#define TOK_CFLOAT 0xbb /* float constant */
|
|
|
|
#define TOK_CDOUBLE 0xbc /* double constant */
|
|
|
|
#define TOK_CLDOUBLE 0xbd /* long double constant */
|
|
|
|
#define TOK_PPNUM 0xbe /* preprocessor number */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
#define TOK_PPSTR 0xbf /* preprocessor string */
|
|
|
|
#define TOK_LINENUM 0xc0 /* line number info */
|
2014-03-29 19:40:54 +04:00
|
|
|
/* <-- */
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
#define TOK_UMULL 0xc2 /* unsigned 32x32 -> 64 mul */
|
|
|
|
#define TOK_ADDC1 0xc3 /* add with carry generation */
|
|
|
|
#define TOK_ADDC2 0xc4 /* add with carry use */
|
|
|
|
#define TOK_SUBC1 0xc5 /* add with carry generation */
|
|
|
|
#define TOK_SUBC2 0xc6 /* add with carry use */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
#define TOK_ARROW 0xc7
|
|
|
|
#define TOK_DOTS 0xc8 /* three dots */
|
|
|
|
#define TOK_SHR 0xc9 /* unsigned shift right */
|
|
|
|
#define TOK_TWOSHARPS 0xca /* ## preprocessing token */
|
|
|
|
#define TOK_PLCHLDR 0xcb /* placeholder token as defined in C99 */
|
|
|
|
#define TOK_NOSUBST 0xcc /* means following token has already been pp'd */
|
2016-10-31 05:59:31 +03:00
|
|
|
#define TOK_PPJOIN 0xce /* A '##' in the right position to mean pasting */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
|
|
|
#define TOK_SHL 0x01 /* shift left */
|
|
|
|
#define TOK_SAR 0x02 /* signed shift right */
|
2015-07-29 23:53:57 +03:00
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
/* assignement operators : normal operator or 0x80 */
|
|
|
|
#define TOK_A_MOD 0xa5
|
|
|
|
#define TOK_A_AND 0xa6
|
|
|
|
#define TOK_A_MUL 0xaa
|
|
|
|
#define TOK_A_ADD 0xab
|
|
|
|
#define TOK_A_SUB 0xad
|
|
|
|
#define TOK_A_DIV 0xaf
|
|
|
|
#define TOK_A_XOR 0xde
|
|
|
|
#define TOK_A_OR 0xfc
|
|
|
|
#define TOK_A_SHL 0x81
|
|
|
|
#define TOK_A_SAR 0x82
|
|
|
|
|
|
|
|
#ifndef offsetof
|
|
|
|
#define offsetof(type, field) ((size_t) &((type *)0)->field)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef countof
|
|
|
|
#define countof(tab) (sizeof(tab) / sizeof((tab)[0]))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define TOK_EOF (-1) /* end of file */
|
|
|
|
#define TOK_LINEFEED 10 /* line feed */
|
|
|
|
|
|
|
|
/* all identificators and strings have token above that */
|
|
|
|
#define TOK_IDENT 256
|
|
|
|
|
|
|
|
#define DEF_ASM(x) DEF(TOK_ASM_ ## x, #x)
|
2009-12-20 00:08:37 +03:00
|
|
|
#define TOK_ASM_int TOK_INT
|
2016-04-13 10:23:46 +03:00
|
|
|
#define DEF_ASMDIR(x) DEF(TOK_ASMDIR_ ## x, "." #x)
|
|
|
|
#define TOK_ASMDIR_FIRST TOK_ASMDIR_byte
|
|
|
|
#define TOK_ASMDIR_LAST TOK_ASMDIR_section
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2009-12-20 00:08:37 +03:00
|
|
|
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
|
|
|
/* only used for i386 asm opcodes definitions */
|
2009-05-05 22:17:26 +04:00
|
|
|
#define DEF_BWL(x) \
|
|
|
|
DEF(TOK_ASM_ ## x ## b, #x "b") \
|
|
|
|
DEF(TOK_ASM_ ## x ## w, #x "w") \
|
|
|
|
DEF(TOK_ASM_ ## x ## l, #x "l") \
|
|
|
|
DEF(TOK_ASM_ ## x, #x)
|
|
|
|
#define DEF_WL(x) \
|
|
|
|
DEF(TOK_ASM_ ## x ## w, #x "w") \
|
|
|
|
DEF(TOK_ASM_ ## x ## l, #x "l") \
|
|
|
|
DEF(TOK_ASM_ ## x, #x)
|
2009-08-27 11:53:50 +04:00
|
|
|
#ifdef TCC_TARGET_X86_64
|
2009-12-20 00:08:37 +03:00
|
|
|
# define DEF_BWLQ(x) \
|
2009-08-27 11:53:50 +04:00
|
|
|
DEF(TOK_ASM_ ## x ## b, #x "b") \
|
|
|
|
DEF(TOK_ASM_ ## x ## w, #x "w") \
|
|
|
|
DEF(TOK_ASM_ ## x ## l, #x "l") \
|
|
|
|
DEF(TOK_ASM_ ## x ## q, #x "q") \
|
|
|
|
DEF(TOK_ASM_ ## x, #x)
|
2009-12-20 00:08:37 +03:00
|
|
|
# define DEF_WLQ(x) \
|
2009-08-27 11:53:50 +04:00
|
|
|
DEF(TOK_ASM_ ## x ## w, #x "w") \
|
|
|
|
DEF(TOK_ASM_ ## x ## l, #x "l") \
|
|
|
|
DEF(TOK_ASM_ ## x ## q, #x "q") \
|
|
|
|
DEF(TOK_ASM_ ## x, #x)
|
2009-12-20 00:08:37 +03:00
|
|
|
# define DEF_BWLX DEF_BWLQ
|
|
|
|
# define DEF_WLX DEF_WLQ
|
|
|
|
/* number of sizes + 1 */
|
|
|
|
# define NBWLX 5
|
|
|
|
#else
|
|
|
|
# define DEF_BWLX DEF_BWL
|
|
|
|
# define DEF_WLX DEF_WL
|
|
|
|
/* number of sizes + 1 */
|
|
|
|
# define NBWLX 4
|
2009-08-27 11:53:50 +04:00
|
|
|
#endif
|
|
|
|
|
2009-05-05 22:17:26 +04:00
|
|
|
#define DEF_FP1(x) \
|
|
|
|
DEF(TOK_ASM_ ## f ## x ## s, "f" #x "s") \
|
|
|
|
DEF(TOK_ASM_ ## fi ## x ## l, "fi" #x "l") \
|
|
|
|
DEF(TOK_ASM_ ## f ## x ## l, "f" #x "l") \
|
|
|
|
DEF(TOK_ASM_ ## fi ## x ## s, "fi" #x "s")
|
|
|
|
|
|
|
|
#define DEF_FP(x) \
|
|
|
|
DEF(TOK_ASM_ ## f ## x, "f" #x ) \
|
|
|
|
DEF(TOK_ASM_ ## f ## x ## p, "f" #x "p") \
|
|
|
|
DEF_FP1(x)
|
|
|
|
|
2015-01-06 22:59:19 +03:00
|
|
|
#define DEF_ASMTEST(x,suffix) \
|
|
|
|
DEF_ASM(x ## o ## suffix) \
|
|
|
|
DEF_ASM(x ## no ## suffix) \
|
|
|
|
DEF_ASM(x ## b ## suffix) \
|
|
|
|
DEF_ASM(x ## c ## suffix) \
|
|
|
|
DEF_ASM(x ## nae ## suffix) \
|
|
|
|
DEF_ASM(x ## nb ## suffix) \
|
|
|
|
DEF_ASM(x ## nc ## suffix) \
|
|
|
|
DEF_ASM(x ## ae ## suffix) \
|
|
|
|
DEF_ASM(x ## e ## suffix) \
|
|
|
|
DEF_ASM(x ## z ## suffix) \
|
|
|
|
DEF_ASM(x ## ne ## suffix) \
|
|
|
|
DEF_ASM(x ## nz ## suffix) \
|
|
|
|
DEF_ASM(x ## be ## suffix) \
|
|
|
|
DEF_ASM(x ## na ## suffix) \
|
|
|
|
DEF_ASM(x ## nbe ## suffix) \
|
|
|
|
DEF_ASM(x ## a ## suffix) \
|
|
|
|
DEF_ASM(x ## s ## suffix) \
|
|
|
|
DEF_ASM(x ## ns ## suffix) \
|
|
|
|
DEF_ASM(x ## p ## suffix) \
|
|
|
|
DEF_ASM(x ## pe ## suffix) \
|
|
|
|
DEF_ASM(x ## np ## suffix) \
|
|
|
|
DEF_ASM(x ## po ## suffix) \
|
|
|
|
DEF_ASM(x ## l ## suffix) \
|
|
|
|
DEF_ASM(x ## nge ## suffix) \
|
|
|
|
DEF_ASM(x ## nl ## suffix) \
|
|
|
|
DEF_ASM(x ## ge ## suffix) \
|
|
|
|
DEF_ASM(x ## le ## suffix) \
|
|
|
|
DEF_ASM(x ## ng ## suffix) \
|
|
|
|
DEF_ASM(x ## nle ## suffix) \
|
|
|
|
DEF_ASM(x ## g ## suffix)
|
2009-05-05 22:17:26 +04:00
|
|
|
|
2013-02-17 03:48:51 +04:00
|
|
|
#endif /* defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64 */
|
2009-05-05 22:17:26 +04:00
|
|
|
|
|
|
|
enum tcc_token {
|
2015-11-19 21:26:47 +03:00
|
|
|
TOK_LAST = TOK_IDENT - 1
|
|
|
|
#define DEF(id, str) ,id
|
2009-05-05 22:17:26 +04:00
|
|
|
#include "tcctok.h"
|
|
|
|
#undef DEF
|
|
|
|
};
|
|
|
|
|
2016-10-09 21:33:14 +03:00
|
|
|
/* keywords: tok >= TOK_IDENT && tok < TOK_UIDENT */
|
2009-05-05 22:17:26 +04:00
|
|
|
#define TOK_UIDENT TOK_DEFINE
|
|
|
|
|
2016-10-09 21:33:14 +03:00
|
|
|
/* -------------------------------------------- */
|
2009-05-11 20:45:56 +04:00
|
|
|
|
2016-10-09 21:33:14 +03:00
|
|
|
#ifndef PUB_FUNC /* functions used by tcc.c but not in libtcc.h */
|
2011-08-11 18:55:30 +04:00
|
|
|
# define PUB_FUNC
|
|
|
|
#endif
|
2009-12-20 03:53:49 +03:00
|
|
|
|
2011-07-14 20:45:37 +04:00
|
|
|
#ifdef ONE_SOURCE
|
2009-12-20 03:53:49 +03:00
|
|
|
#define ST_INLN static inline
|
|
|
|
#define ST_FUNC static
|
|
|
|
#define ST_DATA static
|
|
|
|
#else
|
|
|
|
#define ST_INLN
|
|
|
|
#define ST_FUNC
|
|
|
|
#define ST_DATA extern
|
|
|
|
#endif
|
|
|
|
|
2016-10-09 21:33:14 +03:00
|
|
|
#ifdef TCC_PROFILE /* profile all functions */
|
|
|
|
# define static
|
|
|
|
#endif
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* ------------ libtcc.c ------------ */
|
|
|
|
|
|
|
|
/* use GNU C extensions */
|
|
|
|
ST_DATA int gnu_ext;
|
|
|
|
/* use Tiny C extensions */
|
|
|
|
ST_DATA int tcc_ext;
|
|
|
|
/* XXX: get rid of this ASAP */
|
|
|
|
ST_DATA struct TCCState *tcc_state;
|
|
|
|
|
|
|
|
/* public functions currently used by the tcc main function */
|
2017-02-08 21:49:28 +03:00
|
|
|
ST_FUNC char *pstrcpy(char *buf, int buf_size, const char *s);
|
|
|
|
ST_FUNC char *pstrcat(char *buf, int buf_size, const char *s);
|
|
|
|
ST_FUNC char *pstrncpy(char *out, const char *in, size_t num);
|
2009-12-20 03:53:49 +03:00
|
|
|
PUB_FUNC char *tcc_basename(const char *name);
|
|
|
|
PUB_FUNC char *tcc_fileextension (const char *name);
|
2015-05-12 11:56:39 +03:00
|
|
|
|
|
|
|
#ifndef MEM_DEBUG
|
2009-12-20 03:53:49 +03:00
|
|
|
PUB_FUNC void tcc_free(void *ptr);
|
|
|
|
PUB_FUNC void *tcc_malloc(unsigned long size);
|
|
|
|
PUB_FUNC void *tcc_mallocz(unsigned long size);
|
|
|
|
PUB_FUNC void *tcc_realloc(void *ptr, unsigned long size);
|
|
|
|
PUB_FUNC char *tcc_strdup(const char *str);
|
2015-05-12 11:56:39 +03:00
|
|
|
#else
|
|
|
|
#define tcc_free(ptr) tcc_free_debug(ptr)
|
|
|
|
#define tcc_malloc(size) tcc_malloc_debug(size, __FILE__, __LINE__)
|
|
|
|
#define tcc_mallocz(size) tcc_mallocz_debug(size, __FILE__, __LINE__)
|
|
|
|
#define tcc_realloc(ptr,size) tcc_realloc_debug(ptr, size, __FILE__, __LINE__)
|
|
|
|
#define tcc_strdup(str) tcc_strdup_debug(str, __FILE__, __LINE__)
|
|
|
|
PUB_FUNC void tcc_free_debug(void *ptr);
|
|
|
|
PUB_FUNC void *tcc_malloc_debug(unsigned long size, const char *file, int line);
|
|
|
|
PUB_FUNC void *tcc_mallocz_debug(unsigned long size, const char *file, int line);
|
|
|
|
PUB_FUNC void *tcc_realloc_debug(void *ptr, unsigned long size, const char *file, int line);
|
|
|
|
PUB_FUNC char *tcc_strdup_debug(const char *str, const char *file, int line);
|
|
|
|
#endif
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
#define free(p) use_tcc_free(p)
|
|
|
|
#define malloc(s) use_tcc_malloc(s)
|
|
|
|
#define realloc(p, s) use_tcc_realloc(p, s)
|
|
|
|
#undef strdup
|
|
|
|
#define strdup(s) use_tcc_strdup(s)
|
2015-05-12 16:07:09 +03:00
|
|
|
PUB_FUNC void tcc_memstats(int bench);
|
2011-08-11 19:07:56 +04:00
|
|
|
PUB_FUNC void tcc_error_noabort(const char *fmt, ...);
|
2014-04-04 22:18:39 +04:00
|
|
|
PUB_FUNC NORETURN void tcc_error(const char *fmt, ...);
|
2011-08-11 19:07:56 +04:00
|
|
|
PUB_FUNC void tcc_warning(const char *fmt, ...);
|
2009-12-20 03:53:49 +03:00
|
|
|
|
|
|
|
/* other utilities */
|
2017-02-13 20:23:43 +03:00
|
|
|
ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_FUNC void dynarray_reset(void *pp, int *n);
|
2016-10-01 21:26:50 +03:00
|
|
|
ST_INLN void cstr_ccat(CString *cstr, int ch);
|
2016-04-17 16:37:23 +03:00
|
|
|
ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_FUNC void cstr_wccat(CString *cstr, int ch);
|
|
|
|
ST_FUNC void cstr_new(CString *cstr);
|
|
|
|
ST_FUNC void cstr_free(CString *cstr);
|
|
|
|
ST_FUNC void cstr_reset(CString *cstr);
|
2009-12-20 03:53:49 +03:00
|
|
|
|
|
|
|
ST_INLN void sym_free(Sym *sym);
|
|
|
|
ST_FUNC Sym *sym_push2(Sym **ps, int v, int t, long c);
|
|
|
|
ST_FUNC Sym *sym_find2(Sym *s, int v);
|
2016-11-06 07:02:11 +03:00
|
|
|
ST_FUNC Sym *sym_push(int v, CType *type, int r, long c);
|
2016-08-15 06:09:31 +03:00
|
|
|
ST_FUNC void sym_pop(Sym **ptop, Sym *b, int keep);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_INLN Sym *struct_find(int v);
|
|
|
|
ST_INLN Sym *sym_find(int v);
|
2016-11-06 07:02:11 +03:00
|
|
|
ST_FUNC Sym *global_identifier_push(int v, int t, long c);
|
2009-12-20 03:53:49 +03:00
|
|
|
|
2010-11-25 15:29:15 +03:00
|
|
|
ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen);
|
2013-01-14 20:34:07 +04:00
|
|
|
ST_FUNC int tcc_open(TCCState *s1, const char *filename);
|
2010-11-25 15:29:15 +03:00
|
|
|
ST_FUNC void tcc_close(void);
|
|
|
|
|
2016-10-01 21:46:16 +03:00
|
|
|
ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags);
|
|
|
|
/* flags: */
|
|
|
|
#define AFF_PRINT_ERROR 0x10 /* print error if file not found */
|
|
|
|
#define AFF_REFERENCED_DLL 0x20 /* load a referenced dll from another dll */
|
|
|
|
#define AFF_PREPROCESS 0x40 /* preprocess file */
|
|
|
|
/* combined with: */
|
2016-10-01 21:54:45 +03:00
|
|
|
#define AFF_TYPE_NONE 0
|
|
|
|
#define AFF_TYPE_C 1
|
|
|
|
#define AFF_TYPE_ASM 2
|
|
|
|
#define AFF_TYPE_ASMPP 3
|
|
|
|
#define AFF_TYPE_BIN 4
|
|
|
|
#define AFF_TYPE_LIB 5
|
|
|
|
#define AFF_TYPE_LIBWH 6
|
|
|
|
/* values from tcc_object_type(...) */
|
|
|
|
#define AFF_BINTYPE_REL 1
|
|
|
|
#define AFF_BINTYPE_DYN 2
|
|
|
|
#define AFF_BINTYPE_AR 3
|
|
|
|
#define AFF_BINTYPE_C67 4
|
|
|
|
|
2016-10-01 21:46:16 +03:00
|
|
|
|
2011-08-06 18:49:30 +04:00
|
|
|
ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
|
2015-05-10 11:37:36 +03:00
|
|
|
|
|
|
|
#ifndef TCC_TARGET_PE
|
2011-08-11 18:55:30 +04:00
|
|
|
ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
|
2015-05-10 11:37:36 +03:00
|
|
|
#endif
|
|
|
|
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
|
|
|
|
PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
|
2011-08-11 18:55:30 +04:00
|
|
|
|
2016-10-18 00:24:01 +03:00
|
|
|
PUB_FUNC void tcc_print_stats(TCCState *s, unsigned total_time);
|
2013-02-12 22:13:28 +04:00
|
|
|
PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv);
|
2013-02-19 15:47:36 +04:00
|
|
|
PUB_FUNC void tcc_set_environment(TCCState *s);
|
2016-10-15 16:55:31 +03:00
|
|
|
#ifdef _WIN32
|
|
|
|
ST_FUNC char *normalize_slashes(char *path);
|
|
|
|
#endif
|
2013-02-19 15:47:36 +04:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* ------------ tccpp.c ------------ */
|
|
|
|
|
|
|
|
ST_DATA struct BufferedFile *file;
|
|
|
|
ST_DATA int ch, tok;
|
|
|
|
ST_DATA CValue tokc;
|
2010-01-14 22:58:03 +03:00
|
|
|
ST_DATA const int *macro_ptr;
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_DATA int parse_flags;
|
|
|
|
ST_DATA int tok_flags;
|
|
|
|
ST_DATA CString tokcstr; /* current parsed string, if any */
|
|
|
|
|
|
|
|
/* display benchmark infos */
|
|
|
|
ST_DATA int total_lines;
|
|
|
|
ST_DATA int total_bytes;
|
|
|
|
ST_DATA int tok_ident;
|
|
|
|
ST_DATA TokenSym **table_ident;
|
|
|
|
|
|
|
|
#define TOK_FLAG_BOL 0x0001 /* beginning of line before */
|
|
|
|
#define TOK_FLAG_BOF 0x0002 /* beginning of file before */
|
|
|
|
#define TOK_FLAG_ENDIF 0x0004 /* a endif was found matching starting #ifdef */
|
|
|
|
#define TOK_FLAG_EOF 0x0008 /* end of file */
|
|
|
|
|
|
|
|
#define PARSE_FLAG_PREPROCESS 0x0001 /* activate preprocessing */
|
|
|
|
#define PARSE_FLAG_TOK_NUM 0x0002 /* return numbers instead of TOK_PPNUM */
|
|
|
|
#define PARSE_FLAG_LINEFEED 0x0004 /* line feed is returned as a
|
|
|
|
token. line feed is also
|
|
|
|
returned at eof */
|
2015-04-27 16:36:58 +03:00
|
|
|
#define PARSE_FLAG_ASM_FILE 0x0008 /* we processing an asm file: '#' can be used for line comment, etc. */
|
2009-12-20 03:53:49 +03:00
|
|
|
#define PARSE_FLAG_SPACES 0x0010 /* next() returns space tokens (for -E) */
|
2015-05-02 15:58:37 +03:00
|
|
|
#define PARSE_FLAG_ACCEPT_STRAYS 0x0020 /* next() returns '\\' token */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
#define PARSE_FLAG_TOK_STR 0x0040 /* return parsed strings instead of TOK_PPSTR */
|
2009-12-20 03:53:49 +03:00
|
|
|
|
2016-08-25 17:40:50 +03:00
|
|
|
/* isidnum_table flags: */
|
|
|
|
#define IS_SPC 1
|
|
|
|
#define IS_ID 2
|
|
|
|
#define IS_NUM 4
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC TokenSym *tok_alloc(const char *str, int len);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
ST_FUNC const char *get_tok_str(int v, CValue *cv);
|
|
|
|
ST_FUNC void begin_macro(TokenString *str, int alloc);
|
|
|
|
ST_FUNC void end_macro(void);
|
2016-08-25 17:40:50 +03:00
|
|
|
ST_FUNC void set_idnum(int c, int val);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void save_parse_state(ParseState *s);
|
|
|
|
ST_FUNC void restore_parse_state(ParseState *s);
|
|
|
|
ST_INLN void tok_str_new(TokenString *s);
|
2016-10-01 21:26:50 +03:00
|
|
|
ST_FUNC TokenString *tok_str_alloc(void);
|
2016-11-11 22:25:13 +03:00
|
|
|
ST_FUNC void tok_str_free(TokenString *s);
|
|
|
|
ST_FUNC void tok_str_free_str(int *str);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void tok_str_add(TokenString *s, int t);
|
|
|
|
ST_FUNC void tok_str_add_tok(TokenString *s);
|
2016-10-01 21:26:50 +03:00
|
|
|
ST_INLN void define_push(int v, int macro_type, int *str, Sym *first_arg);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void define_undef(Sym *s);
|
|
|
|
ST_INLN Sym *define_find(int v);
|
|
|
|
ST_FUNC void free_defines(Sym *b);
|
|
|
|
ST_FUNC Sym *label_find(int v);
|
|
|
|
ST_FUNC Sym *label_push(Sym **ptop, int v, int flags);
|
|
|
|
ST_FUNC void label_pop(Sym **ptop, Sym *slast);
|
|
|
|
ST_FUNC void parse_define(void);
|
|
|
|
ST_FUNC void preprocess(int is_bof);
|
|
|
|
ST_FUNC void next_nomacro(void);
|
|
|
|
ST_FUNC void next(void);
|
|
|
|
ST_INLN void unget_tok(int last_tok);
|
2016-10-18 00:24:01 +03:00
|
|
|
ST_FUNC void preprocess_start(TCCState *s1);
|
|
|
|
ST_FUNC void tccpp_new(TCCState *s);
|
|
|
|
ST_FUNC void tccpp_delete(TCCState *s);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int tcc_preprocess(TCCState *s1);
|
|
|
|
ST_FUNC void skip(int c);
|
2014-04-04 22:18:39 +04:00
|
|
|
ST_FUNC NORETURN void expect(const char *msg);
|
2009-12-20 03:53:49 +03:00
|
|
|
|
2016-10-09 21:33:14 +03:00
|
|
|
/* space exlcuding newline */
|
|
|
|
static inline int is_space(int ch) {
|
|
|
|
return ch == ' ' || ch == '\t' || ch == '\v' || ch == '\f' || ch == '\r';
|
|
|
|
}
|
|
|
|
static inline int isid(int c) {
|
|
|
|
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_';
|
|
|
|
}
|
|
|
|
static inline int isnum(int c) {
|
|
|
|
return c >= '0' && c <= '9';
|
|
|
|
}
|
|
|
|
static inline int isoct(int c) {
|
|
|
|
return c >= '0' && c <= '7';
|
|
|
|
}
|
|
|
|
static inline int toup(int c) {
|
|
|
|
return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c;
|
|
|
|
}
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* ------------ tccgen.c ------------ */
|
|
|
|
|
|
|
|
#define SYM_POOL_NB (8192 / sizeof(Sym))
|
|
|
|
ST_DATA Sym *sym_free_first;
|
|
|
|
ST_DATA void **sym_pools;
|
|
|
|
ST_DATA int nb_sym_pools;
|
|
|
|
|
|
|
|
ST_DATA Sym *global_stack;
|
|
|
|
ST_DATA Sym *local_stack;
|
|
|
|
ST_DATA Sym *local_label_stack;
|
|
|
|
ST_DATA Sym *global_label_stack;
|
|
|
|
ST_DATA Sym *define_stack;
|
2012-04-16 03:13:25 +04:00
|
|
|
ST_DATA CType char_pointer_type, func_old_type, int_type, size_type;
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
ST_DATA SValue __vstack[1+/*to make bcheck happy*/ VSTACK_SIZE], *vtop, *pvtop;
|
Make tcc work after self-compiling with bounds-check enabled
For vstack Fabrice used the trick to initialize vtop to &vstack[-1], so
that on first push, vtop becomes &vstack[0] and a value is also stored
there - everything works.
Except that when tcc is compiled with bounds-checking enabled, vstack - 1
returns INVALID_POINTER and oops...
Let's workaround it with artificial 1 vstack slot which will not be
used, but only serve as an indicator that pointing to &vstack[-1] is ok.
Now, tcc, after being self-compiled with -b works:
$ ./tcc -B. -o tccb -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" tcc.c -ldl
$ cd tests
$ ../tcc -B.. -run tcctest.c >1
$ ../tccb -B.. -run tcctest.c >2
$ diff -u 1 2
and note, tcc's compilation speed is not affected:
$ ./tcc -B. -bench -DONE_SOURCE -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -c tcc.c
before: 8270 idents, 47221 lines, 1527730 bytes, 0.152 s, 309800 lines/s, 10.0 MB/s
after: 8271 idents, 47221 lines, 1527733 bytes, 0.152 s, 310107 lines/s, 10.0 MB/s
But note, that `tcc -b -run tcc` is still broken - for example it crashes
on
$ cat x.c
double get100 () { return 100.0; }
$ ./tcc -B. -b -DTCC_TARGET_I386 -DCONFIG_MULTIARCHDIR=\"i386-linux-gnu\" -run \
-DONE_SOURCE ./tcc.c -B. -c x.c
Runtime error: dereferencing invalid pointer
./tccpp.c:1953: at 0xa7beebdf parse_number() (included from ./libtcc.c, ./tcc.c)
./tccpp.c:3003: by 0xa7bf0708 next() (included from ./libtcc.c, ./tcc.c)
./tccgen.c:4465: by 0xa7bfe348 block() (included from ./libtcc.c, ./tcc.c)
./tccgen.c:4440: by 0xa7bfe212 block() (included from ./libtcc.c, ./tcc.c)
./tccgen.c:5529: by 0xa7c01929 gen_function() (included from ./libtcc.c, ./tcc.c)
./tccgen.c:5767: by 0xa7c02602 decl0() (included from ./libtcc.c, ./tcc.c)
that's because lib/bcheck.c runtime needs more fixes -- see next
patches.
2012-12-01 01:00:23 +04:00
|
|
|
#define vstack (__vstack + 1)
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_DATA int rsym, anon_sym, ind, loc;
|
|
|
|
|
|
|
|
ST_DATA int const_wanted; /* true if constant wanted */
|
|
|
|
ST_DATA int nocode_wanted; /* true if no code generation wanted for an expression */
|
|
|
|
ST_DATA int global_expr; /* true if compound literals must be allocated globally (used during initializers parsing */
|
|
|
|
ST_DATA CType func_vt; /* current function return type (used by return instruction) */
|
2014-01-06 18:27:39 +04:00
|
|
|
ST_DATA int func_var; /* true if current function is variadic */
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_DATA int func_vc;
|
|
|
|
ST_DATA int last_line_num, last_ind, func_ind; /* debug last line number and pc */
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
ST_DATA const char *funcname;
|
2009-12-20 03:53:49 +03:00
|
|
|
|
2016-10-15 16:55:31 +03:00
|
|
|
ST_FUNC void tccgen_start(TCCState *s1);
|
|
|
|
ST_FUNC void tccgen_end(TCCState *s1);
|
2016-10-18 00:24:01 +03:00
|
|
|
ST_FUNC void free_inline_functions(TCCState *s);
|
tccpp: fix issues, add tests
* fix some macro expansion issues
* add some pp tests in tests/pp
* improved tcc -E output for better diff'ability
* remove -dD feature (quirky code, exotic feature,
didn't work well)
Based partially on ideas / researches from PipCet
Some issues remain with VA_ARGS macros (if used in a
rather tricky way).
Also, to keep it simple, the pp doesn't automtically
add any extra spaces to separate tokens which otherwise
would form wrong tokens if re-read from tcc -E output
(such as '+' '=') GCC does that, other compilers don't.
* cleanups
- #line 01 "file" / # 01 "file" processing
- #pragma comment(lib,"foo")
- tcc -E: forward some pragmas to output (pack, comment(lib))
- fix macro parameter list parsing mess from
a3fc54345949535524d01319e1ca6378b7c2c201
a715d7143d9d17da17e67fec6af1c01409a71a31
(some coffee might help, next time ;)
- introduce TOK_PPSTR - to have character constants as
written in the file (similar to TOK_PPNUM)
- allow '\' appear in macros
- new functions begin/end_macro to:
- fix switching macro levels during expansion
- allow unget_tok to unget more than one tok
- slight speedup by using bitflags in isidnum_table
Also:
- x86_64.c : fix decl after statements
- i386-gen,c : fix a vstack leak with VLA on windows
- configure/Makefile : build on windows (MSYS) was broken
- tcc_warning: fflush stderr to keep output order (win32)
2015-05-09 15:29:39 +03:00
|
|
|
ST_FUNC void check_vstack(void);
|
2016-10-18 00:24:01 +03:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_INLN int is_float(int t);
|
2011-08-01 03:10:36 +04:00
|
|
|
ST_FUNC int ieee_finite(double d);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void test_lvalue(void);
|
|
|
|
ST_FUNC void vpushi(int v);
|
|
|
|
ST_FUNC Sym *external_global_sym(int v, CType *type, int r);
|
2016-11-06 07:02:11 +03:00
|
|
|
ST_FUNC void vset(CType *type, int r, long v);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void vswap(void);
|
2009-12-20 22:33:41 +03:00
|
|
|
ST_FUNC void vpush_global_sym(CType *type, int v);
|
2011-12-10 10:22:09 +04:00
|
|
|
ST_FUNC void vrote(SValue *e, int n);
|
2009-12-20 22:33:41 +03:00
|
|
|
ST_FUNC void vrott(int n);
|
2012-03-14 18:39:16 +04:00
|
|
|
ST_FUNC void vrotb(int n);
|
2009-12-20 22:33:41 +03:00
|
|
|
#ifdef TCC_TARGET_ARM
|
|
|
|
ST_FUNC int get_reg_ex(int rc, int rc2);
|
|
|
|
ST_FUNC void lexpand_nr(void);
|
|
|
|
#endif
|
2009-12-20 00:41:26 +03:00
|
|
|
ST_FUNC void vpushv(SValue *v);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void save_reg(int r);
|
tccgen: arm/i386: save_reg_upstack
tccgen.c:gv() when loading long long from lvalue, before
was saving all registers which caused problems in the arm
function call register parameter preparation, as with
void foo(long long y, int x);
int main(void)
{
unsigned int *xx[1], x;
unsigned long long *yy[1], y;
foo(**yy, **xx);
return 0;
}
Now only the modified register is saved if necessary,
as in this case where it is used to store the result
of the post-inc:
long long *p, v, **pp;
v = 1;
p = &v;
p[0]++;
printf("another long long spill test : %lld\n", *p);
i386-gen.c :
- found a similar problem with TOK_UMULL caused by the
vstack juggle in tccgen:gen_opl()
(bug seen only when using EBX as 4th register)
2016-10-04 18:36:51 +03:00
|
|
|
ST_FUNC void save_reg_upstack(int r, int n);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int get_reg(int rc);
|
|
|
|
ST_FUNC void save_regs(int n);
|
2015-02-13 21:58:31 +03:00
|
|
|
ST_FUNC void gaddrof(void);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int gv(int rc);
|
|
|
|
ST_FUNC void gv2(int rc1, int rc2);
|
|
|
|
ST_FUNC void vpop(void);
|
|
|
|
ST_FUNC void gen_op(int op);
|
|
|
|
ST_FUNC int type_size(CType *type, int *a);
|
|
|
|
ST_FUNC void mk_pointer(CType *type);
|
|
|
|
ST_FUNC void vstore(void);
|
|
|
|
ST_FUNC void inc(int post, int c);
|
2016-07-11 17:42:18 +03:00
|
|
|
ST_FUNC void parse_mult_str (CString *astr, const char *msg);
|
2010-09-14 21:17:39 +04:00
|
|
|
ST_FUNC void parse_asm_str(CString *astr);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int lvalue_type(int t);
|
|
|
|
ST_FUNC void indir(void);
|
|
|
|
ST_FUNC void unary(void);
|
|
|
|
ST_FUNC void expr_prod(void);
|
|
|
|
ST_FUNC void expr_sum(void);
|
|
|
|
ST_FUNC void gexpr(void);
|
|
|
|
ST_FUNC int expr_const(void);
|
|
|
|
ST_FUNC void decl(int l);
|
2009-12-20 22:33:41 +03:00
|
|
|
#if defined CONFIG_TCC_BCHECK || defined TCC_TARGET_C67
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC Sym *get_sym_ref(CType *type, Section *sec, unsigned long offset, unsigned long size);
|
|
|
|
#endif
|
2013-04-27 23:39:34 +04:00
|
|
|
#if defined TCC_TARGET_X86_64 && !defined TCC_TARGET_PE
|
2013-04-19 14:08:12 +04:00
|
|
|
ST_FUNC int classify_x86_64_va_arg(CType *ty);
|
|
|
|
#endif
|
2009-12-20 03:53:49 +03:00
|
|
|
|
|
|
|
/* ------------ tccelf.c ------------ */
|
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
#define TCC_OUTPUT_FORMAT_ELF 0 /* default output format: ELF */
|
|
|
|
#define TCC_OUTPUT_FORMAT_BINARY 1 /* binary image output */
|
|
|
|
#define TCC_OUTPUT_FORMAT_COFF 2 /* COFF */
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
#define ARMAG "!<arch>\012" /* For COFF and a.out archives */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
unsigned int n_strx; /* index into string table of name */
|
|
|
|
unsigned char n_type; /* type of symbol */
|
|
|
|
unsigned char n_other; /* misc info (usually empty) */
|
|
|
|
unsigned short n_desc; /* description field */
|
|
|
|
unsigned int n_value; /* value of symbol */
|
|
|
|
} Stab_Sym;
|
|
|
|
|
2016-10-15 16:55:31 +03:00
|
|
|
ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */
|
|
|
|
ST_DATA Section *cur_text_section; /* current section where function code is generated */
|
|
|
|
#ifdef CONFIG_TCC_ASM
|
|
|
|
ST_DATA Section *last_text_section; /* to handle .previous asm directive */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
|
|
|
/* bound check related sections */
|
|
|
|
ST_DATA Section *bounds_section; /* contains global data bound description */
|
|
|
|
ST_DATA Section *lbounds_section; /* contains local data bound description */
|
2016-10-19 20:15:04 +03:00
|
|
|
ST_FUNC void tccelf_bounds_new(TCCState *s);
|
2016-10-15 16:55:31 +03:00
|
|
|
#endif
|
|
|
|
/* symbol sections */
|
|
|
|
ST_DATA Section *symtab_section, *strtab_section;
|
|
|
|
/* debug sections */
|
|
|
|
ST_DATA Section *stab_section, *stabstr_section;
|
|
|
|
|
|
|
|
ST_FUNC void tccelf_new(TCCState *s);
|
|
|
|
ST_FUNC void tccelf_delete(TCCState *s);
|
2016-10-18 00:24:01 +03:00
|
|
|
ST_FUNC void tccelf_stab_new(TCCState *s);
|
|
|
|
|
2016-10-15 16:55:31 +03:00
|
|
|
ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh_flags);
|
|
|
|
ST_FUNC void section_realloc(Section *sec, unsigned long new_size);
|
|
|
|
ST_FUNC void *section_ptr_add(Section *sec, addr_t size);
|
|
|
|
ST_FUNC void section_reserve(Section *sec, unsigned long size);
|
|
|
|
ST_FUNC Section *find_section(TCCState *s1, const char *name);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC Section *new_symtab(TCCState *s1, const char *symtab_name, int sh_type, int sh_flags, const char *strtab_name, const char *hash_name, int hash_sh_flags);
|
|
|
|
|
2016-10-15 16:55:31 +03:00
|
|
|
ST_FUNC void put_extern_sym2(Sym *sym, Section *section, addr_t value, unsigned long size, int can_add_underscore);
|
|
|
|
ST_FUNC void put_extern_sym(Sym *sym, Section *section, addr_t value, unsigned long size);
|
|
|
|
ST_FUNC void greloc(Section *s, Sym *sym, unsigned long offset, int type);
|
|
|
|
ST_FUNC void greloca(Section *s, Sym *sym, unsigned long offset, int type, addr_t addend);
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int put_elf_str(Section *s, const char *sym);
|
2013-02-04 19:08:06 +04:00
|
|
|
ST_FUNC int put_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
|
2016-11-12 18:16:04 +03:00
|
|
|
ST_FUNC int set_elf_sym(Section *s, addr_t value, unsigned long size, int info, int other, int shndx, const char *name);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int find_elf_sym(Section *s, const char *name);
|
|
|
|
ST_FUNC void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, int type, int symbol);
|
2015-03-23 19:24:55 +03:00
|
|
|
ST_FUNC void put_elf_reloca(Section *symtab, Section *s, unsigned long offset, int type, int symbol, addr_t addend);
|
2009-12-20 03:53:49 +03:00
|
|
|
|
|
|
|
ST_FUNC void put_stabs(const char *str, int type, int other, int desc, unsigned long value);
|
|
|
|
ST_FUNC void put_stabs_r(const char *str, int type, int other, int desc, unsigned long value, Section *sec, int sym_index);
|
|
|
|
ST_FUNC void put_stabn(int type, int other, int desc, int value);
|
|
|
|
ST_FUNC void put_stabd(int type, int other, int desc);
|
|
|
|
|
|
|
|
ST_FUNC void relocate_common_syms(void);
|
2016-11-12 18:16:09 +03:00
|
|
|
ST_FUNC void relocate_syms(TCCState *s1, Section *symtab, int do_resolve);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void relocate_section(TCCState *s1, Section *s);
|
|
|
|
|
|
|
|
ST_FUNC void tcc_add_linker_symbols(TCCState *s1);
|
2016-10-01 21:54:45 +03:00
|
|
|
ST_FUNC int tcc_object_type(int fd, ElfW(Ehdr) *h);
|
2013-01-14 20:34:07 +04:00
|
|
|
ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset);
|
|
|
|
ST_FUNC int tcc_load_archive(TCCState *s1, int fd);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void tcc_add_bcheck(TCCState *s1);
|
|
|
|
ST_FUNC void tcc_add_runtime(TCCState *s1);
|
|
|
|
|
2016-12-15 19:01:22 +03:00
|
|
|
ST_FUNC void build_got_entries(TCCState *s1);
|
|
|
|
ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
|
2016-10-08 03:44:17 +03:00
|
|
|
ST_FUNC void squeeze_multi_relocs(Section *sec, size_t oldrelocoffset);
|
|
|
|
|
2013-02-04 19:08:06 +04:00
|
|
|
ST_FUNC addr_t get_elf_sym_addr(TCCState *s, const char *name, int err);
|
2014-01-07 17:57:07 +04:00
|
|
|
#if defined TCC_IS_NATIVE || defined TCC_TARGET_PE
|
2013-02-04 19:08:06 +04:00
|
|
|
ST_FUNC void *tcc_get_symbol_err(TCCState *s, const char *name);
|
|
|
|
#endif
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
#ifndef TCC_TARGET_PE
|
2013-01-14 20:34:07 +04:00
|
|
|
ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int tcc_load_ldscript(TCCState *s1);
|
2016-05-05 15:12:53 +03:00
|
|
|
ST_FUNC uint8_t *parse_comment(uint8_t *p);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void minp(void);
|
|
|
|
ST_INLN void inp(void);
|
|
|
|
ST_FUNC int handle_eob(void);
|
|
|
|
#endif
|
|
|
|
|
2016-12-10 20:22:08 +03:00
|
|
|
/* ------------ xxx-link.c ------------ */
|
|
|
|
|
|
|
|
/* Wether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so
|
|
|
|
that unknown relocation don't create a GOT or PLT entry */
|
|
|
|
enum gotplt_entry {
|
|
|
|
NO_GOTPLT_ENTRY, /* never generate (eg. GLOB_DAT & JMP_SLOT relocs) */
|
|
|
|
BUILD_GOT_ONLY, /* only build GOT (eg. TPOFF relocs) */
|
|
|
|
AUTO_GOTPLT_ENTRY, /* generate if sym is UNDEF */
|
|
|
|
ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */
|
|
|
|
};
|
|
|
|
|
|
|
|
ST_FUNC int code_reloc (int reloc_type);
|
|
|
|
ST_FUNC int gotplt_entry_type (int reloc_type);
|
2016-12-15 19:01:22 +03:00
|
|
|
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
|
|
|
|
ST_FUNC void relocate_init(Section *sr);
|
|
|
|
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val);
|
|
|
|
ST_FUNC void relocate_plt(TCCState *s1);
|
2016-12-10 20:22:08 +03:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* ------------ xxx-gen.c ------------ */
|
|
|
|
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_DATA const int reg_classes[NB_REGS];
|
2013-02-08 22:07:11 +04:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void gsym_addr(int t, int a);
|
|
|
|
ST_FUNC void gsym(int t);
|
|
|
|
ST_FUNC void load(int r, SValue *sv);
|
|
|
|
ST_FUNC void store(int r, SValue *v);
|
2015-07-29 23:57:41 +03:00
|
|
|
ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *align, int *regsize);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void gfunc_call(int nb_args);
|
|
|
|
ST_FUNC void gfunc_prolog(CType *func_type);
|
|
|
|
ST_FUNC void gfunc_epilog(void);
|
|
|
|
ST_FUNC int gjmp(int t);
|
|
|
|
ST_FUNC void gjmp_addr(int a);
|
|
|
|
ST_FUNC int gtst(int inv, int t);
|
2016-09-30 17:29:38 +03:00
|
|
|
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
|
|
|
ST_FUNC void gtst_addr(int inv, int a);
|
|
|
|
#else
|
|
|
|
#define gtst_addr(inv, a) gsym_addr(gtst(inv, 0), a)
|
|
|
|
#endif
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void gen_opi(int op);
|
|
|
|
ST_FUNC void gen_opf(int op);
|
|
|
|
ST_FUNC void gen_cvt_ftoi(int t);
|
|
|
|
ST_FUNC void gen_cvt_ftof(int t);
|
|
|
|
ST_FUNC void ggoto(void);
|
|
|
|
#ifndef TCC_TARGET_C67
|
|
|
|
ST_FUNC void o(unsigned int c);
|
|
|
|
#endif
|
|
|
|
#ifndef TCC_TARGET_ARM
|
|
|
|
ST_FUNC void gen_cvt_itof(int t);
|
|
|
|
#endif
|
2013-04-27 23:39:34 +04:00
|
|
|
ST_FUNC void gen_vla_sp_save(int addr);
|
|
|
|
ST_FUNC void gen_vla_sp_restore(int addr);
|
|
|
|
ST_FUNC void gen_vla_alloc(CType *type, int align);
|
2009-12-20 03:53:49 +03:00
|
|
|
|
2016-10-09 21:33:14 +03:00
|
|
|
static inline uint16_t read16le(unsigned char *p) {
|
2016-10-01 21:26:50 +03:00
|
|
|
return p[0] | (uint16_t)p[1] << 8;
|
|
|
|
}
|
2016-10-09 21:33:14 +03:00
|
|
|
static inline void write16le(unsigned char *p, uint16_t x) {
|
|
|
|
p[0] = x & 255, p[1] = x >> 8 & 255;
|
2016-10-01 21:26:50 +03:00
|
|
|
}
|
2016-10-09 21:33:14 +03:00
|
|
|
static inline uint32_t read32le(unsigned char *p) {
|
|
|
|
return read16le(p) | (uint32_t)read16le(p + 2) << 16;
|
2016-10-01 21:26:50 +03:00
|
|
|
}
|
2016-10-09 21:33:14 +03:00
|
|
|
static inline void write32le(unsigned char *p, uint32_t x) {
|
|
|
|
write16le(p, x), write16le(p + 2, x >> 16);
|
2016-10-01 21:26:50 +03:00
|
|
|
}
|
2016-11-20 16:52:56 +03:00
|
|
|
static inline void add32le(unsigned char *p, int32_t x) {
|
|
|
|
write32le(p, read32le(p) + x);
|
|
|
|
}
|
2016-10-09 21:33:14 +03:00
|
|
|
static inline uint64_t read64le(unsigned char *p) {
|
|
|
|
return read32le(p) | (uint64_t)read32le(p + 4) << 32;
|
2016-10-01 21:26:50 +03:00
|
|
|
}
|
2016-10-09 21:33:14 +03:00
|
|
|
static inline void write64le(unsigned char *p, uint64_t x) {
|
|
|
|
write32le(p, x), write32le(p + 4, x >> 32);
|
2016-10-01 21:26:50 +03:00
|
|
|
}
|
2016-11-20 16:52:56 +03:00
|
|
|
static inline void add64le(unsigned char *p, int64_t x) {
|
|
|
|
write64le(p, read64le(p) + x);
|
|
|
|
}
|
2016-10-01 21:26:50 +03:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* ------------ i386-gen.c ------------ */
|
|
|
|
#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
|
|
|
|
ST_FUNC void g(int c);
|
|
|
|
ST_FUNC void gen_le16(int c);
|
|
|
|
ST_FUNC void gen_le32(int c);
|
2016-09-29 17:57:30 +03:00
|
|
|
ST_FUNC void gen_addr32(int r, Sym *sym, long c);
|
|
|
|
ST_FUNC void gen_addrpc32(int r, Sym *sym, long c);
|
2009-12-20 03:53:49 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_TCC_BCHECK
|
|
|
|
ST_FUNC void gen_bounded_ptr_add(void);
|
|
|
|
ST_FUNC void gen_bounded_ptr_deref(void);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ x86_64-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_X86_64
|
|
|
|
ST_FUNC void gen_addr64(int r, Sym *sym, int64_t c);
|
2013-02-08 22:07:11 +04:00
|
|
|
ST_FUNC void gen_opl(int op);
|
2009-12-20 03:53:49 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ arm-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_ARM
|
2015-03-03 17:16:52 +03:00
|
|
|
#if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
|
2014-01-07 11:23:54 +04:00
|
|
|
ST_FUNC char *default_elfinterp(struct TCCState *s);
|
|
|
|
#endif
|
|
|
|
ST_FUNC void arm_init(struct TCCState *s);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void gen_cvt_itof1(int t);
|
|
|
|
#endif
|
|
|
|
|
2015-02-13 21:58:31 +03:00
|
|
|
/* ------------ arm64-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_ARM64
|
|
|
|
ST_FUNC void gen_cvt_sxtw(void);
|
|
|
|
ST_FUNC void gen_opl(int op);
|
2017-02-08 21:45:31 +03:00
|
|
|
ST_FUNC void gfunc_return(CType *func_type);
|
2015-02-13 21:58:31 +03:00
|
|
|
ST_FUNC void gen_va_start(void);
|
|
|
|
ST_FUNC void gen_va_arg(CType *t);
|
2015-03-08 03:10:44 +03:00
|
|
|
ST_FUNC void gen_clear_cache(void);
|
2015-02-13 21:58:31 +03:00
|
|
|
#endif
|
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* ------------ c67-gen.c ------------ */
|
|
|
|
#ifdef TCC_TARGET_C67
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ tcccoff.c ------------ */
|
|
|
|
|
|
|
|
#ifdef TCC_TARGET_COFF
|
|
|
|
ST_FUNC int tcc_output_coff(TCCState *s1, FILE *f);
|
2013-01-14 20:34:07 +04:00
|
|
|
ST_FUNC int tcc_load_coff(TCCState * s1, int fd);
|
2009-12-20 03:53:49 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ tccasm.c ------------ */
|
|
|
|
ST_FUNC void asm_instr(void);
|
|
|
|
ST_FUNC void asm_global_instr(void);
|
|
|
|
#ifdef CONFIG_TCC_ASM
|
|
|
|
ST_FUNC int find_constraint(ASMOperand *operands, int nb_operands, const char *name, const char **pp);
|
2016-08-26 19:11:19 +03:00
|
|
|
ST_FUNC Sym* get_asm_sym(int name, Sym *csym);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void asm_expr(TCCState *s1, ExprValue *pe);
|
|
|
|
ST_FUNC int asm_int_expr(TCCState *s1);
|
|
|
|
ST_FUNC int tcc_assemble(TCCState *s1, int do_preprocess);
|
|
|
|
/* ------------ i386-asm.c ------------ */
|
|
|
|
ST_FUNC void gen_expr32(ExprValue *pe);
|
2016-06-29 20:22:07 +03:00
|
|
|
#ifdef TCC_TARGET_X86_64
|
|
|
|
ST_FUNC void gen_expr64(ExprValue *pe);
|
|
|
|
#endif
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void asm_opcode(TCCState *s1, int opcode);
|
2016-10-06 05:05:30 +03:00
|
|
|
ST_FUNC int asm_parse_regvar(int t);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
|
|
|
|
ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
|
|
|
|
ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);
|
|
|
|
ST_FUNC void asm_clobber(uint8_t *clobber_regs, const char *str);
|
|
|
|
#endif
|
2013-02-12 22:13:28 +04:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/* ------------ tccpe.c -------------- */
|
|
|
|
#ifdef TCC_TARGET_PE
|
2013-01-14 20:34:07 +04:00
|
|
|
ST_FUNC int pe_load_file(struct TCCState *s1, const char *filename, int fd);
|
2009-12-20 03:53:49 +03:00
|
|
|
ST_FUNC int pe_output_file(TCCState * s1, const char *filename);
|
2013-02-04 19:08:06 +04:00
|
|
|
ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, addr_t value);
|
2016-10-03 13:29:38 +03:00
|
|
|
#ifndef TCC_TARGET_ARM
|
2010-01-14 22:55:51 +03:00
|
|
|
ST_FUNC SValue *pe_getimport(SValue *sv, SValue *v2);
|
2016-10-03 13:29:38 +03:00
|
|
|
#endif
|
2009-12-20 00:40:28 +03:00
|
|
|
#ifdef TCC_TARGET_X86_64
|
|
|
|
ST_FUNC void pe_add_unwind_data(unsigned start, unsigned end, unsigned stack);
|
|
|
|
#endif
|
2014-04-17 19:01:28 +04:00
|
|
|
/* symbol properties stored in Elf32_Sym->st_other */
|
|
|
|
# define ST_PE_EXPORT 0x10
|
|
|
|
# define ST_PE_IMPORT 0x20
|
|
|
|
# define ST_PE_STDCALL 0x40
|
2009-12-20 03:53:49 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* ------------ tccrun.c ----------------- */
|
2013-02-04 19:08:06 +04:00
|
|
|
#ifdef TCC_IS_NATIVE
|
2009-12-20 22:33:41 +03:00
|
|
|
#ifdef CONFIG_TCC_STATIC
|
|
|
|
#define RTLD_LAZY 0x001
|
|
|
|
#define RTLD_NOW 0x002
|
|
|
|
#define RTLD_GLOBAL 0x100
|
|
|
|
#define RTLD_DEFAULT NULL
|
|
|
|
/* dummy function for profiling */
|
|
|
|
ST_FUNC void *dlopen(const char *filename, int flag);
|
|
|
|
ST_FUNC void dlclose(void *p);
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_FUNC const char *dlerror(void);
|
2016-11-13 13:45:55 +03:00
|
|
|
ST_FUNC void *dlsym(void *handle, const char *symbol);
|
2009-12-20 03:53:49 +03:00
|
|
|
#endif
|
2012-04-18 20:43:29 +04:00
|
|
|
#ifdef CONFIG_TCC_BACKTRACE
|
|
|
|
ST_DATA int rt_num_callers;
|
|
|
|
ST_DATA const char **rt_bound_error_msg;
|
|
|
|
ST_DATA void *rt_prog_main;
|
2013-02-12 22:13:28 +04:00
|
|
|
ST_FUNC void tcc_set_num_callers(int n);
|
2012-04-18 20:43:29 +04:00
|
|
|
#endif
|
2016-10-19 20:21:27 +03:00
|
|
|
ST_FUNC void tcc_run_free(TCCState *s1);
|
2013-02-04 19:08:06 +04:00
|
|
|
#endif
|
2012-04-18 20:43:29 +04:00
|
|
|
|
2009-12-20 03:53:49 +03:00
|
|
|
/********************************************************/
|
|
|
|
#undef ST_DATA
|
2011-07-14 20:45:37 +04:00
|
|
|
#ifdef ONE_SOURCE
|
2009-12-20 03:53:49 +03:00
|
|
|
#define ST_DATA static
|
|
|
|
#else
|
|
|
|
#define ST_DATA
|
|
|
|
#endif
|
|
|
|
/********************************************************/
|
|
|
|
#endif /* _TCC_H */
|