forked from dllaurence/Nil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c_defs.c
74 lines (63 loc) · 2.26 KB
/
c_defs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**********************************************************************
* c_defs.c
*
* Compute C language-specific constructs.
*
; Copyright 2009-2010 by Dustin Laurence. Distributed under the terms of
; the LGPLv3.
;
**********************************************************************/
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
#define BUFSIZE 1024
char* strupper(char* str)
{
static char buffer[BUFSIZE];
int i;
for(i=0;(str[i]!='\0'&&i<(BUFSIZE-1));i++) buffer[i] = toupper(str[i]);
buffer[i] = '\0';
return buffer; // =8-O
}
int
main(int argc, char *argv[])
{
puts("#ifndef C_DEFS_LLH");
puts("#define C_DEFS_LLH");
putchar('\n');
puts(";**********************************************************************");
puts("; THIS FILE IS AUTOMATICALLY GENERATED BY c_defs. DO NOT EDIT; CHANGE");
puts("; THE SOURCE CODE IN c_defs.c.");
puts(";**********************************************************************");
putchar('\n');
puts(";**********************************************************************");
puts("; c_defs.llh");
putchar('\n');
puts("; Make C language quantities visible in LLVM code.");
putchar('\n');
puts(";**********************************************************************");
putchar('\n');
puts("; C and unix types");
// LLVM's unit of size is the bit, not the byte as in C
// CHAR_BIT is already defined for us--yes, there are computers whose bytes
// are not octets. Somewhere. Maybe even still running.
#define bitsof(type) (sizeof(type)*CHAR_BIT)
#define IMPORT_TYPE(type) \
(printf("%%c_%s = type i%d\n", #type, bitsof(type)), \
printf("#define C_%s_SIZEOF %d\n", strupper(#type), sizeof(type)), \
printf("#define C_%s_BITSOF %d\n", strupper(#type), bitsof(type)), \
putchar('\n'))
IMPORT_TYPE(char);
IMPORT_TYPE(int);
IMPORT_TYPE(long);
IMPORT_TYPE(intptr_t);
IMPORT_TYPE(size_t);
puts("; C stdio constants");
printf("#define C_EOF %d\n", EOF);
printf("#define C_STDIN_FD %d\n", fileno(stdin));
printf("#define C_STDOUT_FD %d\n", fileno(stdout));
printf("#define C_STDERR_FD %d\n", fileno(stderr));
putchar('\n');
puts("#endif");
return 0;
}