Skip to content

Commit 1647b5b

Browse files
authored
Add .h.in to C (#7227)
* support dynamically created header file from line 4256 (iirc) we know linguist does recognize dynamically created files * add CEN64's common.h.in
1 parent 1e9a19e commit 1647b5b

File tree

2 files changed

+214
-0
lines changed

2 files changed

+214
-0
lines changed

lib/linguist/languages.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ C:
759759
- ".c"
760760
- ".cats"
761761
- ".h"
762+
- ".h.in"
762763
- ".idc"
763764
interpreters:
764765
- tcc

samples/C/common.h.in

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
//
2+
// common.h: Common definitions and such.
3+
//
4+
// CEN64: Cycle-Accurate Nintendo 64 Emulator.
5+
// Copyright (C) 2015, Tyler J. Stachecki.
6+
//
7+
// This file is subject to the terms and conditions defined in
8+
// 'LICENSE', which is part of this source code package.
9+
//
10+
11+
#ifndef __common_h__
12+
#define __common_h__
13+
14+
#define tostring(s) #s
15+
#define stringify(s) tostring(s)
16+
17+
#ifdef _MSC_VER
18+
#define inline _inline
19+
#endif
20+
21+
#ifndef __cplusplus
22+
#include <assert.h>
23+
#include <stddef.h>
24+
#include <stdlib.h>
25+
#include <stdint.h>
26+
#include <stdio.h>
27+
#include <string.h>
28+
#else
29+
#include <cassert>
30+
#include <cstddef>
31+
#include <cstdlib>
32+
#include <cstdint>
33+
#include <cstdio>
34+
#include <cstring>
35+
#endif
36+
37+
#ifndef _MSC_VER
38+
#ifndef __cplusplus
39+
#include <stdbool.h>
40+
#else
41+
#include <cstdbool>
42+
#endif
43+
44+
#else
45+
typedef char bool;
46+
#define false 0
47+
#define true 1
48+
#endif
49+
50+
#ifdef __llvm__
51+
#define CEN64_COMPILER "llvm-" stringify(__clang_major__)"." \
52+
stringify(__clang_minor__)"." stringify(__clang_patchlevel__)
53+
#elif defined(__GNUC__)
54+
#define CEN64_COMPILER "gcc-" stringify(__GNUC__)"." \
55+
stringify(__GNUC_MINOR__)"." stringify(__GNUC_PATCHLEVEL__)
56+
#elif defined(_MSC_VER)
57+
#if _MSC_VER < 1300
58+
#define CEN64_COMPILER "MSVC 6.0"
59+
#elif _MSC_VER < 1500
60+
#define CEN64_COMPILER "MSVC 2005"
61+
#elif _MSC_VER < 1600
62+
#define CEN64_COMPILER "MSVC 2008"
63+
#elif _MSC_VER < 1700
64+
#define CEN64_COMPILER "MSVC 2010"
65+
#elif _MSC_VER < 1800
66+
#define CEN64_COMPILER "MSVC 2012"
67+
#elif _MSC_VER < 1900
68+
#define CEN64_COMPILER "MSVC 2013"
69+
#elif _MSC_VER < 2000
70+
#define CEN64_COMPILER "MSVC 2014"
71+
#else
72+
#define CEN64_COMPILER "MSVC"
73+
#endif
74+
#else
75+
#define CEN64_COMPILER "Unknown"
76+
#endif
77+
78+
#cmakedefine CEN64_ARCH_DIR "@CEN64_ARCH_DIR@"
79+
#cmakedefine CEN64_ARCH_SUPPORT "@CEN64_ARCH_SUPPORT@"
80+
81+
#define CACHE_LINE_SIZE 64
82+
83+
// Define cen64_align().
84+
#ifdef _MSC_VER
85+
#define cen64_align(decl, value) __declspec(align(value)) decl
86+
87+
#elif (defined __GNUC__)
88+
#define cen64_align(decl, value) decl __attribute__ ((aligned(value)))
89+
90+
#else
91+
#define cen64_align(decl, value) decl value
92+
#endif
93+
94+
// Define cen64_cold and cen64_hot.
95+
#ifdef __GNUC__
96+
#define cen64_cold __attribute__((cold))
97+
#define cen64_hot __attribute__((hot))
98+
#else
99+
#define cen64_cold
100+
#define cen64_hot
101+
#endif
102+
103+
// Define cen64_flatten.
104+
#ifdef __GNUC__
105+
#define cen64_flatten __attribute__((flatten))
106+
#else
107+
#define cen64_flatten
108+
#endif
109+
110+
// Define likely()/unlikely().
111+
#ifdef __GNUC__
112+
#define likely(expr) __builtin_expect(!!(expr), !0)
113+
#define unlikely(expr) __builtin_expect(!!(expr), 0)
114+
115+
#else
116+
#define likely(expr) expr
117+
#define unlikely(expr) expr
118+
#endif
119+
120+
// Define unused().
121+
#ifdef __GNUC__
122+
#define unused(decl) __attribute__((unused)) decl
123+
#else
124+
#define unused(decl) decl
125+
#endif
126+
127+
// Byte order swap functions.
128+
#ifdef BIG_ENDIAN_HOST
129+
#define WORD_ADDR_XOR 0
130+
#else
131+
#define WORD_ADDR_XOR 4
132+
#endif
133+
134+
#ifndef _MSC_VER
135+
#ifdef BIG_ENDIAN_HOST
136+
#define htonll(x) (x)
137+
#define ntohll(x) (x)
138+
#else
139+
#ifndef __APPLE__
140+
#define htonll(x) __builtin_bswap64(x)
141+
#define ntohll(x) __builtin_bswap64(x)
142+
#endif
143+
#endif
144+
#endif
145+
146+
#ifdef __GNUC__
147+
__attribute__((pure))
148+
#endif
149+
static inline uint32_t byteswap_32(uint32_t word) {
150+
#ifdef BIG_ENDIAN_HOST
151+
return word;
152+
#elif defined(_MSC_VER)
153+
return _byteswap_ulong(word);
154+
#elif defined(__GNUC__)
155+
return __builtin_bswap32(word);
156+
#else
157+
return
158+
(((((word) >> 24) & 0x000000FF) | \
159+
(((word) >> 8) & 0x0000FF00) | \
160+
(((word) << 8) & 0x00FF0000) | \
161+
(((word) << 24) & 0xFF000000));
162+
#endif
163+
}
164+
165+
#ifdef __GNUC__
166+
__attribute__((pure))
167+
#endif
168+
static inline uint16_t byteswap_16(uint16_t hword) {
169+
#ifdef BIG_ENDIAN_HOST
170+
return hword;
171+
#elif defined(_MSC_VER)
172+
return _byteswap_ushort(hword);
173+
#elif defined(__GNUC__)
174+
return __builtin_bswap16(hword);
175+
#else
176+
return
177+
((((hword) >> 8) & 0x00FF) | \
178+
(((hword) << 8) & 0xFF00));
179+
#endif
180+
}
181+
182+
// Return from simulation function.
183+
struct bus_controller;
184+
185+
#ifdef __GNUC__
186+
__attribute__ ((noreturn))
187+
#endif
188+
void cen64_return(struct bus_controller *bus)
189+
;
190+
191+
#cmakedefine DEBUG_MMIO_REGISTER_ACCESS
192+
#ifdef DEBUG_MMIO_REGISTER_ACCESS
193+
#ifndef __cplusplus
194+
#include <stdio.h>
195+
#else
196+
#include <cstdio>
197+
#endif
198+
#define debug_mmio_read(what, mnemonic, val) printf(#what": READ [%s]: 0x%.8X\n", mnemonic, val)
199+
#define debug_mmio_write(what, mnemonic, val, dqm) printf(#what": WRITE [%s]: 0x%.8X/0x%.8X\n", mnemonic, val, dqm)
200+
#else
201+
#define debug_mmio_read(what, mnemonic, val) do {} while (0)
202+
#define debug_mmio_write(what, mnemonic, val, dqm) do {} while (0)
203+
#endif
204+
205+
#cmakedefine VR4300_BUSY_WAIT_DETECTION
206+
207+
#include "common/debug.h"
208+
209+
// Common/shared LUT with one-hot semantics.
210+
// Returns index (0-based) of hot bit, or -1.
211+
extern const int8_t cen64_one_hot_lut[256];
212+
213+
#endif

0 commit comments

Comments
 (0)