File tree 12 files changed +149
-97
lines changed
12 files changed +149
-97
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export ARM_EXEC
14
14
arm-specific-defs = \
15
15
$(Q )$(PRINTF ) \
16
16
"/* target: ARM */\n$\
17
+ \# pragma once\n$\
17
18
\#define ARCH_PREDEFINED \"__arm__\" /* defined by GNU C and RealView */\n$\
18
19
\#define ELF_MACHINE 0x28 /* up to ARMv7/Aarch32 */\n$\
19
20
\#define ELF_FLAGS 0x5000200\n$\
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export RISCV_EXEC
10
10
riscv-specific-defs = \
11
11
$(Q )$(PRINTF ) \
12
12
"/* target: RISCV */\n$\
13
+ \# pragma once\n$\
13
14
\#define ARCH_PREDEFINED \"__riscv\" /* Older versions of the GCC toolchain defined __riscv__ */\n$\
14
15
\#define ELF_MACHINE 0xf3\n$\
15
16
\#define ELF_FLAGS 0\n$\
Original file line number Diff line number Diff line change 8
8
/* Translate IR to target machine code */
9
9
10
10
#include "arm.c"
11
+ #include "defs.h"
12
+ #include "globals.c"
11
13
12
14
void update_elf_offset (ph2_ir_t * ph2_ir )
13
15
{
Original file line number Diff line number Diff line change 26
26
* the current instruction.
27
27
*/
28
28
29
+ #include "defs.h"
30
+
29
31
/* opcode */
30
32
typedef enum {
31
33
arm_and = 0 ,
Original file line number Diff line number Diff line change 5
5
* file "LICENSE" for information on usage and redistribution of this file.
6
6
*/
7
7
8
- #ifndef SHECC_DEFS_H
9
- #define SHECC_DEFS_H
8
+ #pragma once
9
+ #include <stdbool.h>
10
10
11
11
/* definitions */
12
12
40
40
#define MAX_NESTING 128
41
41
#define MAX_OPERAND_STACK_SIZE 32
42
42
#define MAX_ANALYSIS_STACK_SIZE 800
43
+ #define MAX_INCLUSIONS 16
43
44
44
45
/* Default capacities for common data structures */
45
46
/* Default arena size is initialized with 256 KiB */
@@ -92,6 +93,89 @@ typedef struct {
92
93
hashmap_node_t * * buckets ;
93
94
} hashmap_t ;
94
95
96
+ /* lexer tokens */
97
+ typedef enum {
98
+ T_start , /* FIXME: it was intended to start the state machine. */
99
+ T_numeric ,
100
+ T_identifier ,
101
+ T_comma , /* , */
102
+ T_string , /* null-terminated string */
103
+ T_char ,
104
+ T_open_bracket , /* ( */
105
+ T_close_bracket , /* ) */
106
+ T_open_curly , /* { */
107
+ T_close_curly , /* } */
108
+ T_open_square , /* [ */
109
+ T_close_square , /* ] */
110
+ T_asterisk , /* '*' */
111
+ T_divide , /* / */
112
+ T_mod , /* % */
113
+ T_bit_or , /* | */
114
+ T_bit_xor , /* ^ */
115
+ T_bit_not , /* ~ */
116
+ T_log_and , /* && */
117
+ T_log_or , /* || */
118
+ T_log_not , /* ! */
119
+ T_lt , /* < */
120
+ T_gt , /* > */
121
+ T_le , /* <= */
122
+ T_ge , /* >= */
123
+ T_lshift , /* << */
124
+ T_rshift , /* >> */
125
+ T_dot , /* . */
126
+ T_arrow , /* -> */
127
+ T_plus , /* + */
128
+ T_minus , /* - */
129
+ T_minuseq , /* -= */
130
+ T_pluseq , /* += */
131
+ T_asteriskeq , /* *= */
132
+ T_divideeq , /* /= */
133
+ T_modeq , /* %= */
134
+ T_lshifteq , /* <<= */
135
+ T_rshifteq , /* >>= */
136
+ T_xoreq , /* ^= */
137
+ T_oreq , /* |= */
138
+ T_andeq , /* &= */
139
+ T_eq , /* == */
140
+ T_noteq , /* != */
141
+ T_assign , /* = */
142
+ T_increment , /* ++ */
143
+ T_decrement , /* -- */
144
+ T_question , /* ? */
145
+ T_colon , /* : */
146
+ T_semicolon , /* ; */
147
+ T_eof , /* end-of-file (EOF) */
148
+ T_ampersand , /* & */
149
+ T_return ,
150
+ T_if ,
151
+ T_else ,
152
+ T_while ,
153
+ T_for ,
154
+ T_do ,
155
+ T_typedef ,
156
+ T_enum ,
157
+ T_struct ,
158
+ T_sizeof ,
159
+ T_elipsis , /* ... */
160
+ T_switch ,
161
+ T_case ,
162
+ T_break ,
163
+ T_default ,
164
+ T_continue ,
165
+ /* C pre-processor directives */
166
+ T_cppd_include ,
167
+ T_cppd_define ,
168
+ T_cppd_undef ,
169
+ T_cppd_error ,
170
+ T_cppd_if ,
171
+ T_cppd_elif ,
172
+ T_cppd_else ,
173
+ T_cppd_endif ,
174
+ T_cppd_ifdef ,
175
+ T_cppd_ifndef ,
176
+ T_cppd_pragma
177
+ } token_t ;
178
+
95
179
/* builtin types */
96
180
typedef enum {
97
181
TYPE_void = 0 ,
@@ -467,5 +551,3 @@ typedef struct {
467
551
var_t * var ;
468
552
int polluted ;
469
553
} regfile_t ;
470
-
471
- #endif
Original file line number Diff line number Diff line change 5
5
* file "LICENSE" for information on usage and redistribution of this file.
6
6
*/
7
7
8
+ #pragma once
8
9
#include <stdbool.h>
9
10
#include <stdlib.h>
10
11
12
+ #include "defs.h"
13
+
14
+ /* Lexer */
15
+ char token_str [MAX_TOKEN_LEN ];
16
+ token_t next_token ;
17
+ char next_char ;
18
+ bool skip_newline = true;
19
+
20
+ bool preproc_match ;
21
+
22
+ /* Point to the first character after where the macro has been called. It is
23
+ * needed when returning from the macro body.
24
+ */
25
+ int macro_return_idx ;
26
+
11
27
/* Global objects */
12
28
13
29
block_list_t BLOCKS ;
@@ -58,6 +74,8 @@ int constants_idx = 0;
58
74
59
75
source_t * SOURCE ;
60
76
77
+ hashmap_t * INCLUSION_MAP ;
78
+
61
79
/* ELF sections */
62
80
63
81
char * elf_code ;
@@ -968,6 +986,7 @@ void global_init()
968
986
PH2_IR_FLATTEN = malloc (MAX_IR_INSTR * sizeof (ph2_ir_t * ));
969
987
LABEL_LUT = malloc (MAX_LABEL * sizeof (label_lut_t ));
970
988
SOURCE = create_source (MAX_SOURCE );
989
+ INCLUSION_MAP = hashmap_create (MAX_INCLUSIONS );
971
990
ALIASES = malloc (MAX_ALIASES * sizeof (alias_t ));
972
991
CONSTANTS = malloc (MAX_CONSTANTS * sizeof (constant_t ));
973
992
@@ -1000,6 +1019,7 @@ void global_release()
1000
1019
free (PH2_IR_FLATTEN );
1001
1020
free (LABEL_LUT );
1002
1021
source_release (SOURCE );
1022
+ hashmap_free (INCLUSION_MAP );
1003
1023
free (ALIASES );
1004
1024
free (CONSTANTS );
1005
1025
Original file line number Diff line number Diff line change 7
7
8
8
#include <stdbool.h>
9
9
10
- /* lexer tokens */
11
- typedef enum {
12
- T_start , /* FIXME: it was intended to start the state machine. */
13
- T_numeric ,
14
- T_identifier ,
15
- T_comma , /* , */
16
- T_string , /* null-terminated string */
17
- T_char ,
18
- T_open_bracket , /* ( */
19
- T_close_bracket , /* ) */
20
- T_open_curly , /* { */
21
- T_close_curly , /* } */
22
- T_open_square , /* [ */
23
- T_close_square , /* ] */
24
- T_asterisk , /* '*' */
25
- T_divide , /* / */
26
- T_mod , /* % */
27
- T_bit_or , /* | */
28
- T_bit_xor , /* ^ */
29
- T_bit_not , /* ~ */
30
- T_log_and , /* && */
31
- T_log_or , /* || */
32
- T_log_not , /* ! */
33
- T_lt , /* < */
34
- T_gt , /* > */
35
- T_le , /* <= */
36
- T_ge , /* >= */
37
- T_lshift , /* << */
38
- T_rshift , /* >> */
39
- T_dot , /* . */
40
- T_arrow , /* -> */
41
- T_plus , /* + */
42
- T_minus , /* - */
43
- T_minuseq , /* -= */
44
- T_pluseq , /* += */
45
- T_asteriskeq , /* *= */
46
- T_divideeq , /* /= */
47
- T_modeq , /* %= */
48
- T_lshifteq , /* <<= */
49
- T_rshifteq , /* >>= */
50
- T_xoreq , /* ^= */
51
- T_oreq , /* |= */
52
- T_andeq , /* &= */
53
- T_eq , /* == */
54
- T_noteq , /* != */
55
- T_assign , /* = */
56
- T_increment , /* ++ */
57
- T_decrement , /* -- */
58
- T_question , /* ? */
59
- T_colon , /* : */
60
- T_semicolon , /* ; */
61
- T_eof , /* end-of-file (EOF) */
62
- T_ampersand , /* & */
63
- T_return ,
64
- T_if ,
65
- T_else ,
66
- T_while ,
67
- T_for ,
68
- T_do ,
69
- T_typedef ,
70
- T_enum ,
71
- T_struct ,
72
- T_sizeof ,
73
- T_elipsis , /* ... */
74
- T_switch ,
75
- T_case ,
76
- T_break ,
77
- T_default ,
78
- T_continue ,
79
- /* C pre-processor directives */
80
- T_cppd_include ,
81
- T_cppd_define ,
82
- T_cppd_undef ,
83
- T_cppd_error ,
84
- T_cppd_if ,
85
- T_cppd_elif ,
86
- T_cppd_else ,
87
- T_cppd_endif ,
88
- T_cppd_ifdef ,
89
- T_cppd_ifndef
90
- } token_t ;
91
-
92
- char token_str [MAX_TOKEN_LEN ];
93
- token_t next_token ;
94
- char next_char ;
95
- bool skip_newline = true;
96
-
97
- bool preproc_match ;
98
-
99
- /* Point to the first character after where the macro has been called. It is
100
- * needed when returning from the macro body.
101
- */
102
- int macro_return_idx ;
10
+ #include "defs.h"
11
+ #include "globals.c"
103
12
104
13
bool is_whitespace (char c )
105
14
{
@@ -223,6 +132,8 @@ token_t lex_token_internal(bool aliasing)
223
132
return T_cppd_else ;
224
133
if (!strcmp (token_str , "#endif" ))
225
134
return T_cppd_endif ;
135
+ if (!strcmp (token_str , "#pragma" ))
136
+ return T_cppd_pragma ;
226
137
error ("Unknown directive" );
227
138
}
228
139
Original file line number Diff line number Diff line change 6
6
*/
7
7
8
8
#include <stdbool.h>
9
+ #include <stdio.h>
9
10
#include <stdlib.h>
10
11
12
+ #include "../config"
13
+ #include "defs.h"
14
+ #include "globals.c"
15
+
11
16
/* C language syntactic analyzer */
12
17
int global_var_idx = 0 ;
13
18
int global_label_idx = 0 ;
@@ -513,6 +518,10 @@ bool read_preproc_directive()
513
518
cppd_control_flow_skip_lines ();
514
519
return true;
515
520
}
521
+ if (lex_accept_internal (T_cppd_pragma , false)) {
522
+ lex_expect (T_identifier );
523
+ return true;
524
+ }
516
525
517
526
return false;
518
527
}
@@ -3399,6 +3408,10 @@ void load_source_file(char *file)
3399
3408
3400
3409
for (;;) {
3401
3410
if (!fgets (buffer , MAX_LINE_LEN , f )) {
3411
+ break ;
3412
+ }
3413
+ if (!strncmp (buffer , "#pragma once" , 12 ) &&
3414
+ hashmap_contains (INCLUSION_MAP , file )) {
3402
3415
fclose (f );
3403
3416
return ;
3404
3417
}
@@ -3419,6 +3432,8 @@ void load_source_file(char *file)
3419
3432
SOURCE -> size += strlen (buffer );
3420
3433
}
3421
3434
}
3435
+
3436
+ hashmap_put (INCLUSION_MAP , file , NULL );
3422
3437
fclose (f );
3423
3438
}
3424
3439
Original file line number Diff line number Diff line change 5
5
* file "LICENSE" for information on usage and redistribution of this file.
6
6
*/
7
7
8
+ #include <stdbool.h>
9
+
10
+ #include "defs.h"
11
+ #include "globals.c"
12
+
8
13
bool is_fusible_insn (ph2_ir_t * ph2_ir )
9
14
{
10
15
switch (ph2_ir -> op ) {
Original file line number Diff line number Diff line change 12
12
* dead variable and does NOT wrtie it back to the stack.
13
13
*/
14
14
15
+ #include <stdbool.h>
16
+
17
+ #include "defs.h"
18
+ #include "globals.c"
19
+
15
20
/* Aligns size to nearest multiple of 4, this meets
16
21
* ARMv7's alignment requirement.
17
22
*
Original file line number Diff line number Diff line change 7
7
8
8
/* Translate IR to target machine code */
9
9
10
+ #include "defs.h"
11
+ #include "globals.c"
10
12
#include "riscv.c"
11
13
12
14
void update_elf_offset (ph2_ir_t * ph2_ir )
You can’t perform that action at this time.
0 commit comments