]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - gmqcc.h
Initial platform / compiler specific code refactoring.
[xonotic/gmqcc.git] / gmqcc.h
diff --git a/gmqcc.h b/gmqcc.h
index fcf7d836c8e94a55f70c92456e1015f9c86da26d..75f70a5b7a1896004f048b051998999e6a65f80c 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -24,6 +24,7 @@
 #ifndef GMQCC_HDR
 #define GMQCC_HDR
 #include <stdarg.h>
+#include <time.h>  /* TODO: remove this? */
 #include <stdio.h> /* TODO: remove this */
 
 /*
@@ -35,7 +36,7 @@
 #endif /*! _MSC_VER */
 
 #define GMQCC_VERSION_MAJOR 0
-#define GMQCC_VERSION_MINOR 3
+#define GMQCC_VERSION_MINOR 4
 #define GMQCC_VERSION_PATCH 0
 #define GMQCC_VERSION_BUILD(J,N,P) (((J)<<16)|((N)<<8)|(P))
 #define GMQCC_VERSION \
@@ -332,7 +333,6 @@ void *stat_mem_allocate  (size_t, size_t, const char *);
 bool  util_filexists     (const char *);
 bool  util_strupper      (const char *);
 bool  util_strdigit      (const char *);
-void  util_debug         (const char *, const char *, ...);
 void  util_endianswap    (void *,  size_t, unsigned int);
 
 size_t util_strtocmd         (const char *, char *, size_t);
@@ -344,18 +344,8 @@ uint16_t util_crc16(uint16_t crc, const char *data, size_t len);
 void     util_seed(uint32_t);
 uint32_t util_rand(void);
 
-/*
- * String functions (formatting, copying, concatenating, errors). These are wrapped
- * to use the MSVC _safe_ versions when using MSVC, plus some implementations of
- * these are non-conformant or don't exist such as asprintf and snprintf, which are
- * not supported in C90, but do exist in C99.
- */
-int         util_vasprintf(char **ret, const char *fmt, va_list);
-int         util_asprintf (char **ret, const char *fmt, ...);
-int         util_snprintf (char *src,  size_t bytes, const char *format, ...);
-char       *util_strcat   (char *dest, const char *src);
-char       *util_strncpy  (char *dest, const char *src, size_t num);
-const char *util_strerror (int num);
+int      util_vasprintf(char **ret, const char *fmt, va_list);
+int      util_asprintf (char **ret, const char *fmt, ...);
 
 /*
  * A flexible vector implementation: all vector pointers contain some
@@ -471,6 +461,18 @@ int            fs_dir_close   (DIR *);
 struct dirent *fs_dir_read    (DIR *);
 
 
+int platform_vsnprintf(char *buffer, size_t bytes, const char *format, va_list arg);
+int platform_sscanf(const char *str, const char *format, ...);
+const struct tm *platform_localtime(const time_t *timer);
+const char *platform_ctime(const time_t *timer);
+char *platform_strncat(char *dest, const char *src, size_t num);
+const char *platform_tmpnam(char *str);
+const char *platform_getenv(char *var);
+int platform_snprintf(char *src, size_t bytes, const char *format, ...);
+char *platform_strcat(char *dest, const char *src);
+char *platform_strncpy(char *dest, const char *src, size_t num);
+const char *platform_strerror(int err);
+
 /*===================================================================*/
 /*=========================== correct.c =============================*/
 /*===================================================================*/
@@ -713,11 +715,24 @@ enum {
     VINSTR_PHI,
     VINSTR_JUMP,
     VINSTR_COND,
+
     /* A never returning CALL.
      * Creating this causes IR blocks to be marked as 'final'.
      * No-Return-Call
      */
-    VINSTR_NRCALL
+    VINSTR_NRCALL,
+
+    /* Emulated instructions. */
+    VINSTR_BITAND_V, /* BITAND_V must be the first emulated bitop */
+    VINSTR_BITAND_VF,
+    VINSTR_BITOR_V,
+    VINSTR_BITOR_VF,
+    VINSTR_BITXOR,
+    VINSTR_BITXOR_V,
+    VINSTR_BITXOR_VF,
+    VINSTR_CROSS,
+    VINSTR_NEG_F,
+    VINSTR_NEG_V
 };
 
 /* TODO: elide */
@@ -731,6 +746,7 @@ typedef uint32_t qcuint_t;
 typedef struct {
     prog_section_statement_t *statements;
     int                      *linenums;
+    int                      *columnnums;
     prog_section_def_t       *defs;
     prog_section_field_t     *fields;
     prog_section_function_t  *functions;
@@ -742,6 +758,16 @@ typedef struct {
     qcint_t                   string_cached_empty;
 } code_t;
 
+/*
+ * A shallow copy of a lex_file to remember where which ast node
+ * came from.
+ */
+typedef struct {
+    const char *file;
+    size_t      line;
+    size_t      column;
+} lex_ctx_t;
+
 /*
  * code_write          -- writes out the compiled file
  * code_init           -- prepares the code file
@@ -756,18 +782,9 @@ code_t   *code_init          (void);
 void      code_cleanup       (code_t *);
 uint32_t  code_genstring     (code_t *, const char *string);
 qcint_t   code_alloc_field   (code_t *, size_t qcsize);
-void      code_push_statement(code_t *, prog_section_statement_t *stmt, int linenum);
+void      code_push_statement(code_t *, prog_section_statement_t *stmt, lex_ctx_t ctx);
 void      code_pop_statement (code_t *);
 
-/*
- * A shallow copy of a lex_file to remember where which ast node
- * came from.
- */
-typedef struct {
-    const char *file;
-    size_t      line;
-    size_t      column;
-} lex_ctx_t;
 
 /*===================================================================*/
 /*============================ con.c ================================*/
@@ -974,16 +991,11 @@ typedef uint32_t longbit;
 #endif
 
 /*===================================================================*/
-/*=========================== utf8lib.c =============================*/
+/*============================= utf8.c ==============================*/
 /*===================================================================*/
-typedef uint32_t uchar_t;
-
-bool    u8_analyze (const char *_s, size_t *_start, size_t *_len, uchar_t *_ch, size_t _maxlen);
-size_t  u8_strlen  (const char*);
-size_t  u8_strnlen (const char*, size_t);
-uchar_t u8_getchar (const char*, const char**);
-uchar_t u8_getnchar(const char*, const char**, size_t);
-int     u8_fromchar(uchar_t w,   char *to,     size_t maxlen);
+typedef long utf8ch_t;
+int utf8_from(char *, utf8ch_t);
+int utf8_to(utf8ch_t *, const unsigned char *, size_t);
 
 /*===================================================================*/
 /*============================= opts.c ==============================*/