Skip to content

Commit ad9b3a0

Browse files
authored
cgen: reduce empty lines in default C prelude stored in cheaders.v (#25396)
1 parent 11edca1 commit ad9b3a0

1 file changed

Lines changed: 0 additions & 66 deletions

File tree

‎vlib/v/gen/c/cheaders.v‎

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -57,65 +57,54 @@ const c_common_macros = '
5757
// Due to a tcc bug, the length of an array needs to be specified, but GCC crashes if it is...
5858
#define EMPTY_ARRAY_OF_ELEMS(x,n) (x[])
5959
#define TCCSKIP(x) x
60-
6160
#define __NOINLINE __attribute__((noinline))
6261
#define __IRQHANDLER __attribute__((interrupt))
63-
6462
#define __V_architecture 0
6563
#if defined(__x86_64__) || defined(_M_AMD64)
6664
#define __V_amd64 1
6765
#undef __V_architecture
6866
#define __V_architecture 1
6967
#endif
70-
7168
#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
7269
#define __V_arm64 1
7370
#undef __V_architecture
7471
#define __V_architecture 2
7572
#endif
76-
7773
#if defined(__arm__) || defined(_M_ARM)
7874
#define __V_arm32 1
7975
#undef __V_architecture
8076
#define __V_architecture 3
8177
#endif
82-
8378
#if defined(__riscv) && __riscv_xlen == 64
8479
#define __V_rv64 1
8580
#undef __V_architecture
8681
#define __V_architecture 4
8782
#endif
88-
8983
#if defined(__riscv) && __riscv_xlen == 32
9084
#define __V_rv32 1
9185
#undef __V_architecture
9286
#define __V_architecture 5
9387
#endif
94-
9588
#if defined(__i386__) || defined(_M_IX86)
9689
#define __V_x86 1
9790
#undef __V_architecture
9891
#define __V_architecture 6
9992
#endif
100-
10193
#if defined(__s390x__)
10294
#define __V_s390x 1
10395
#undef __V_architecture
10496
#define __V_architecture 7
10597
#endif
106-
10798
#if defined(__powerpc64__) && defined(__LITTLE_ENDIAN__)
10899
#define __V_ppc64le 1
109100
#undef __V_architecture
110101
#define __V_architecture 8
111102
#endif
112-
113103
#if defined(__loongarch64)
114104
#define __V_loongarch64 1
115105
#undef __V_architecture
116106
#define __V_architecture 9
117107
#endif
118-
119108
// Using just __GNUC__ for detecting gcc, is not reliable because other compilers define it too:
120109
#ifdef __GNUC__
121110
#define __V_GCC__
@@ -129,15 +118,13 @@ const c_common_macros = '
129118
#ifdef __clang__
130119
#undef __V_GCC__
131120
#endif
132-
133121
#ifdef _MSC_VER
134122
#undef __V_GCC__
135123
#undef EMPTY_STRUCT_DECLARATION
136124
#undef E_STRUCT
137125
#define EMPTY_STRUCT_DECLARATION unsigned char _dummy_pad
138126
#define E_STRUCT 0
139127
#endif
140-
141128
#ifndef _WIN32
142129
#if defined __has_include
143130
#if __has_include (<execinfo.h>)
@@ -148,7 +135,6 @@ const c_common_macros = '
148135
#endif
149136
#endif
150137
#endif
151-
152138
#ifdef __TINYC__
153139
#define _Atomic volatile
154140
#undef EMPTY_STRUCT_DECLARATION
@@ -167,12 +153,10 @@ const c_common_macros = '
167153
// #include <byteswap.h>
168154
int tcc_backtrace(const char *fmt, ...);
169155
#endif
170-
171156
// Use __offsetof_ptr instead of __offset_of, when you *do* have a valid pointer, to avoid UB:
172157
#ifndef __offsetof_ptr
173158
#define __offsetof_ptr(ptr,PTYPE,FIELDNAME) ((size_t)((byte *)&((PTYPE *)ptr)->FIELDNAME - (byte *)ptr))
174159
#endif
175-
176160
// for __offset_of
177161
#ifndef __offsetof
178162
#if defined(__TINYC__) || defined(_MSC_VER)
@@ -181,7 +165,6 @@ const c_common_macros = '
181165
#define __offsetof(st, m) __builtin_offsetof(st, m)
182166
#endif
183167
#endif
184-
185168
#if defined(_WIN32) || defined(__CYGWIN__)
186169
#define VV_EXP extern __declspec(dllexport)
187170
#define VV_LOC static
@@ -207,19 +190,16 @@ const c_common_macros = '
207190
#define VV_LOC static
208191
#endif
209192
#endif
210-
211193
#ifdef __cplusplus
212194
#include <utility>
213195
#define _MOV std::move
214196
#else
215197
#define _MOV
216198
#endif
217-
218199
// tcc does not support has_include properly yet, turn it off completely
219200
#if defined(__TINYC__) && defined(__has_include)
220201
#undef __has_include
221202
#endif
222-
223203
//likely and unlikely macros
224204
#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__)
225205
#define _likely_(x) __builtin_expect(x,1)
@@ -319,15 +299,12 @@ const c_helper_macros = '//============================== HELPER C MACROS ======
319299
// optimized way to compare literal strings
320300
#define _SLIT_EQ(sptr, slen, lit) (slen == sizeof("" lit)-1 && !builtin__vmemcmp(sptr, "" lit, slen))
321301
#define _SLIT_NE(sptr, slen, lit) (slen != sizeof("" lit)-1 || builtin__vmemcmp(sptr, "" lit, slen))
322-
323302
// take the address of an rvalue
324303
#define ADDR(type, expr) (&((type[]){expr}[0]))
325-
326304
// copy something to the heap
327305
#define HEAP(type, expr) ((type*)builtin__memdup((void*)&((type[]){expr}[0]), sizeof(type)))
328306
#define HEAP_noscan(type, expr) ((type*)builtin__memdup_noscan((void*)&((type[]){expr}[0]), sizeof(type)))
329307
#define HEAP_align(type, expr, align) ((type*)builtin__memdup_align((void*)&((type[]){expr}[0]), sizeof(type), align))
330-
331308
#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); builtin__array_push_many(arr, tmp.data, tmp.len);}
332309
#define _PUSH_MANY_noscan(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); builtin__array_push_many_noscan(arr, tmp.data, tmp.len);}
333310
'
@@ -339,17 +316,14 @@ typedef int (*qsort_callback_func)(const void*, const void*);
339316
#include <stdio.h> // TODO: remove all these includes, define all function signatures and types manually
340317
#include <stdlib.h>
341318
#include <string.h>
342-
343319
#include <stdarg.h> // for va_list
344-
345320
#ifdef __TERMUX__
346321
#if defined __BIONIC_AVAILABILITY_GUARD && __BIONIC_AVAILABILITY_GUARD(28)
347322
#else
348323
void * aligned_alloc(size_t alignment, size_t size) { return malloc(size); }
349324
#endif
350325
#endif
351326
//================================== GLOBALS =================================*/
352-
int load_so(byteptr);
353327
void _vinit(int ___argc, voidptr ___argv);
354328
void _vcleanup(void);
355329
#ifdef _WIN32
@@ -360,57 +334,46 @@ void _vcleanup(void);
360334
#endif
361335
#define sigaction_size sizeof(sigaction);
362336
#define _ARR_LEN(a) ( (sizeof(a)) / (sizeof(a[0])) )
363-
364-
void v_free(voidptr ptr);
365-
366337
#if INTPTR_MAX == INT32_MAX
367338
#define TARGET_IS_32BIT 1
368339
#elif INTPTR_MAX == INT64_MAX
369340
#define TARGET_IS_64BIT 1
370341
#else
371342
#error "The environment is not 32 or 64-bit."
372343
#endif
373-
374344
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ || defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN || defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
375345
#define TARGET_ORDER_IS_BIG 1
376346
#elif defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ || defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__THUMBEL__) || defined(__AARCH64EL__) || defined(_MIPSEL) || defined(__MIPSEL) || defined(__MIPSEL__) || defined(_M_AMD64) || defined(_M_ARM64) || defined(_M_X64) || defined(_M_IX86)
377347
#define TARGET_ORDER_IS_LITTLE 1
378348
#else
379349
#error "Unknown architecture endianness"
380350
#endif
381-
382351
#ifndef _WIN32
383352
#include <ctype.h>
384353
#include <locale.h> // tolower
385354
#include <sys/time.h>
386355
#include <unistd.h> // sleep
387356
extern char **environ;
388357
#endif
389-
390358
#if defined(__CYGWIN__) && !defined(_WIN32)
391359
#error Cygwin is not supported, please use MinGW or Visual Studio.
392360
#endif
393-
394361
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__) || defined(__vinix__) || defined(__serenity__) || defined(__sun) || defined(__plan9__)
395362
#include <sys/types.h>
396363
#include <sys/wait.h> // os__wait uses wait on nix
397364
#endif
398-
399365
#ifdef __OpenBSD__
400366
#include <sys/types.h>
401367
#include <sys/resource.h>
402368
#include <sys/wait.h> // os__wait uses wait on nix
403369
#endif
404-
405370
#ifdef __FreeBSD__
406371
#include <signal.h>
407372
#include <execinfo.h>
408373
#endif
409-
410374
#ifdef __NetBSD__
411375
#include <sys/wait.h> // os__wait uses wait on nix
412376
#endif
413-
414377
#ifdef _WIN32
415378
#define WINVER 0x0600
416379
#ifdef _WIN32_WINNT
@@ -427,23 +390,19 @@ void v_free(voidptr ptr);
427390
#define UNICODE
428391
#endif
429392
#include <windows.h>
430-
431393
#include <io.h> // _waccess
432394
#include <direct.h> // _wgetcwd
433395
#ifdef V_USE_SIGNAL_H
434396
#include <signal.h> // signal and SIGSEGV for segmentation fault handler
435397
#endif
436-
437398
#ifdef _MSC_VER
438399
// On MSVC these are the same (as long as /volatile:ms is passed)
439400
#define _Atomic volatile
440-
441401
// MSVC cannot parse some things properly
442402
#undef __NOINLINE
443403
#undef __IRQHANDLER
444404
#define __NOINLINE __declspec(noinline)
445405
#define __IRQHANDLER __declspec(naked)
446-
447406
#include <dbghelp.h>
448407
#pragma comment(lib, "Dbghelp")
449408
#endif
@@ -454,7 +413,6 @@ void v_free(voidptr ptr);
454413
#define pthread_rwlockattr_setkind_np(a, b)
455414
#endif
456415
#endif
457-
458416
#if defined(__MINGW32__) || defined(__MINGW64__) || (defined(_WIN32) && defined(__TINYC__))
459417
#undef PRId64
460418
#undef PRIi64
@@ -469,7 +427,6 @@ void v_free(voidptr ptr);
469427
#define PRIx64 "llx"
470428
#define PRIX64 "llX"
471429
#endif
472-
473430
#ifdef _VFREESTANDING
474431
#undef _VFREESTANDING
475432
#endif
@@ -511,9 +468,7 @@ typedef unsigned char* byteptr;
511468
typedef void* voidptr;
512469
typedef char* charptr;
513470
typedef u8 array_fixed_byte_300 [300];
514-
515471
typedef struct sync__Channel* chan;
516-
517472
#ifndef CUSTOM_DEFINE_no_bool
518473
#ifndef __cplusplus
519474
#ifndef bool
@@ -539,61 +494,49 @@ typedef void (*MapFreeFn)(voidptr);
539494
const c_bare_headers = c_helper_macros + c_unsigned_comparison_functions + c_common_macros +
540495
'
541496
#define _VFREESTANDING
542-
543497
typedef long unsigned int size_t;
544-
545498
// Memory allocation related headers
546499
void *malloc(size_t size);
547500
void *calloc(size_t nitems, size_t size);
548501
void *realloc(void *ptr, size_t size);
549502
void *memcpy(void *dest, void *src, size_t n);
550503
void *memset(void *s, int c, size_t n);
551504
void *memmove(void *dest, void *src, size_t n);
552-
553505
// varargs implementation, TODO: works on tcc and gcc, but is very unportable and hacky
554506
typedef __builtin_va_list va_list;
555507
#define va_start(a, b) __builtin_va_start(a, b)
556508
#define va_end(a) __builtin_va_end(a)
557509
#define va_arg(a, b) __builtin_va_arg(a, b)
558510
#define va_copy(a, b) __builtin_va_copy(a, b)
559-
560511
//================================== GLOBALS =================================*/
561-
int load_so(byteptr);
562512
void _vinit(int ___argc, voidptr ___argv);
563513
void _vcleanup();
564514
#define sigaction_size sizeof(sigaction);
565515
#define _ARR_LEN(a) ( (sizeof(a)) / (sizeof(a[0])) )
566-
567-
void v_free(voidptr ptr);
568516
voidptr builtin__memdup(voidptr src, isize size);
569-
570517
'
571518

572519
const c_wyhash_headers = '
573520
// ============== wyhash ==============
574521
#ifndef wyhash_final_version_3
575522
#define wyhash_final_version_3
576-
577523
#ifndef WYHASH_CONDOM
578524
// protections that produce different results:
579525
// 1: normal valid behavior
580526
// 2: extra protection against entropy loss (probability=2^-63), aka. "blind multiplication"
581527
#define WYHASH_CONDOM 1
582528
#endif
583-
584529
#ifndef WYHASH_32BIT_MUM
585530
// 0: normal version, slow on 32 bit systems
586531
// 1: faster on 32 bit systems but produces different results, incompatible with wy2u0k function
587532
#define WYHASH_32BIT_MUM 0
588533
#endif
589-
590534
// includes
591535
#include <stdint.h>
592536
#if defined(_MSC_VER) && defined(_M_X64)
593537
#include <intrin.h>
594538
#pragma intrinsic(_umul128)
595539
#endif
596-
597540
// 128bit multiply function
598541
static inline uint64_t _wyrot(uint64_t x) { return (x>>32)|(x<<32); }
599542
static inline void _wymum(uint64_t *A, uint64_t *B){
@@ -630,10 +573,8 @@ static inline void _wymum(uint64_t *A, uint64_t *B){
630573
#endif
631574
#endif
632575
}
633-
634576
// multiply and xor mix function, aka MUM
635577
static inline uint64_t _wymix(uint64_t A, uint64_t B){ _wymum(&A,&B); return A^B; }
636-
637578
// endian macros
638579
#ifndef WYHASH_LITTLE_ENDIAN
639580
#ifdef TARGET_ORDER_IS_LITTLE
@@ -642,7 +583,6 @@ static inline uint64_t _wymix(uint64_t A, uint64_t B){ _wymum(&A,&B); return A^B
642583
#define WYHASH_LITTLE_ENDIAN 0
643584
#endif
644585
#endif
645-
646586
// read functions
647587
#if (WYHASH_LITTLE_ENDIAN)
648588
static inline uint64_t _wyr8(const uint8_t *p) { uint64_t v; memcpy(&v, p, 8); return v;}
@@ -690,26 +630,20 @@ static inline uint64_t wyhash(const void *key, size_t len, uint64_t seed, const
690630
}
691631
// the default secret parameters
692632
static const uint64_t _wyp[4] = {0xa0761d6478bd642f, 0xe7037ed1a0b428db, 0x8ebc6af09c88c6e3, 0x589965cc75374cc3};
693-
694633
// a useful 64bit-64bit mix function to produce deterministic pseudo random numbers that can pass BigCrush and PractRand
695634
static inline uint64_t wyhash64(uint64_t A, uint64_t B){ A^=0xa0761d6478bd642f; B^=0xe7037ed1a0b428db; _wymum(&A,&B); return _wymix(A^0xa0761d6478bd642f,B^0xe7037ed1a0b428db);}
696-
697635
// the wyrand PRNG that pass BigCrush and PractRand
698636
static inline uint64_t wyrand(uint64_t *seed){ *seed+=0xa0761d6478bd642f; return _wymix(*seed,*seed^0xe7037ed1a0b428db);}
699-
700637
#ifndef __vinix__
701638
// convert any 64 bit pseudo random numbers to uniform distribution [0,1). It can be combined with wyrand, wyhash64 or wyhash.
702639
static inline double wy2u01(uint64_t r){ const double _wynorm=1.0/(1ull<<52); return (r>>12)*_wynorm;}
703-
704640
// convert any 64 bit pseudo random numbers to APPROXIMATE Gaussian distribution. It can be combined with wyrand, wyhash64 or wyhash.
705641
static inline double wy2gau(uint64_t r){ const double _wynorm=1.0/(1ull<<20); return ((r&0x1fffff)+((r>>21)&0x1fffff)+((r>>42)&0x1fffff))*_wynorm-3.0;}
706642
#endif
707-
708643
#if(!WYHASH_32BIT_MUM)
709644
// fast range integer random number generation on [0,k) credit to Daniel Lemire. May not work when WYHASH_32BIT_MUM=1. It can be combined with wyrand, wyhash64 or wyhash.
710645
static inline uint64_t wy2u0k(uint64_t r, uint64_t k){ _wymum(&r,&k); return k; }
711646
#endif
712647
#endif
713-
714648
#define _IN_MAP(val, m) builtin__map_exists(m, val)
715649
'

0 commit comments

Comments
 (0)