File tree Expand file tree Collapse file tree 12 files changed +149
-97
lines changed Expand file tree Collapse file tree 12 files changed +149
-97
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export ARM_EXEC
1414arm-specific-defs = \
1515 $(Q )$(PRINTF ) \
1616 "/* target: ARM */\n$\
17+ \# pragma once\n$\
1718 \#define ARCH_PREDEFINED \"__arm__\" /* defined by GNU C and RealView */\n$\
1819 \#define ELF_MACHINE 0x28 /* up to ARMv7/Aarch32 */\n$\
1920 \#define ELF_FLAGS 0x5000200\n$\
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ export RISCV_EXEC
1010riscv-specific-defs = \
1111 $(Q )$(PRINTF ) \
1212 "/* target: RISCV */\n$\
13+ \# pragma once\n$\
1314 \#define ARCH_PREDEFINED \"__riscv\" /* Older versions of the GCC toolchain defined __riscv__ */\n$\
1415 \#define ELF_MACHINE 0xf3\n$\
1516 \#define ELF_FLAGS 0\n$\
Original file line number Diff line number Diff line change 88/* Translate IR to target machine code */
99
1010#include "arm.c"
11+ #include "defs.h"
12+ #include "globals.c"
1113
1214void update_elf_offset (ph2_ir_t * ph2_ir )
1315{
Original file line number Diff line number Diff line change 2626 * the current instruction.
2727 */
2828
29+ #include "defs.h"
30+
2931/* opcode */
3032typedef enum {
3133 arm_and = 0 ,
Original file line number Diff line number Diff line change 55 * file "LICENSE" for information on usage and redistribution of this file.
66 */
77
8- #ifndef SHECC_DEFS_H
9- #define SHECC_DEFS_H
8+ #pragma once
9+
10+ #include <stdbool.h>
1011
1112/* definitions */
1213
@@ -78,6 +79,89 @@ typedef struct {
7879 arena_block_t * head ;
7980} arena_t ;
8081
82+ /* lexer tokens */
83+ typedef enum {
84+ T_start , /* FIXME: it was intended to start the state machine. */
85+ T_numeric ,
86+ T_identifier ,
87+ T_comma , /* , */
88+ T_string , /* null-terminated string */
89+ T_char ,
90+ T_open_bracket , /* ( */
91+ T_close_bracket , /* ) */
92+ T_open_curly , /* { */
93+ T_close_curly , /* } */
94+ T_open_square , /* [ */
95+ T_close_square , /* ] */
96+ T_asterisk , /* '*' */
97+ T_divide , /* / */
98+ T_mod , /* % */
99+ T_bit_or , /* | */
100+ T_bit_xor , /* ^ */
101+ T_bit_not , /* ~ */
102+ T_log_and , /* && */
103+ T_log_or , /* || */
104+ T_log_not , /* ! */
105+ T_lt , /* < */
106+ T_gt , /* > */
107+ T_le , /* <= */
108+ T_ge , /* >= */
109+ T_lshift , /* << */
110+ T_rshift , /* >> */
111+ T_dot , /* . */
112+ T_arrow , /* -> */
113+ T_plus , /* + */
114+ T_minus , /* - */
115+ T_minuseq , /* -= */
116+ T_pluseq , /* += */
117+ T_asteriskeq , /* *= */
118+ T_divideeq , /* /= */
119+ T_modeq , /* %= */
120+ T_lshifteq , /* <<= */
121+ T_rshifteq , /* >>= */
122+ T_xoreq , /* ^= */
123+ T_oreq , /* |= */
124+ T_andeq , /* &= */
125+ T_eq , /* == */
126+ T_noteq , /* != */
127+ T_assign , /* = */
128+ T_increment , /* ++ */
129+ T_decrement , /* -- */
130+ T_question , /* ? */
131+ T_colon , /* : */
132+ T_semicolon , /* ; */
133+ T_eof , /* end-of-file (EOF) */
134+ T_ampersand , /* & */
135+ T_return ,
136+ T_if ,
137+ T_else ,
138+ T_while ,
139+ T_for ,
140+ T_do ,
141+ T_typedef ,
142+ T_enum ,
143+ T_struct ,
144+ T_sizeof ,
145+ T_elipsis , /* ... */
146+ T_switch ,
147+ T_case ,
148+ T_break ,
149+ T_default ,
150+ T_continue ,
151+ /* C pre-processor directives */
152+ T_cppd_include ,
153+ T_cppd_define ,
154+ T_cppd_undef ,
155+ T_cppd_error ,
156+ T_cppd_if ,
157+ T_cppd_elif ,
158+ T_cppd_else ,
159+ T_cppd_endif ,
160+ T_cppd_ifdef ,
161+ T_cppd_ifndef ,
162+ T_cppd_pragma
163+ } token_t ;
164+
81165/* builtin types */
82166typedef enum {
83167 TYPE_void = 0 ,
@@ -466,5 +550,3 @@ typedef struct {
466550 var_t * var ;
467551 int polluted ;
468552} regfile_t ;
469-
470- #endif
Original file line number Diff line number Diff line change 55 * file "LICENSE" for information on usage and redistribution of this file.
66 */
77
8+ #pragma once
89#include <stdbool.h>
910#include <stdlib.h>
1011
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+
1127/* Global objects */
1228
1329block_list_t BLOCKS ;
@@ -58,6 +74,8 @@ int constants_idx = 0;
5874
5975source_t * SOURCE ;
6076
77+ hashmap_t * INCLUSION_MAP ;
78+
6179/* ELF sections */
6280
6381char * elf_code ;
@@ -911,6 +929,7 @@ void global_init()
911929 PH2_IR_FLATTEN = malloc (MAX_IR_INSTR * sizeof (ph2_ir_t * ));
912930 LABEL_LUT = malloc (MAX_LABEL * sizeof (label_lut_t ));
913931 SOURCE = create_source (MAX_SOURCE );
932+ INCLUSION_MAP = hashmap_create (16 );
914933 ALIASES = malloc (MAX_ALIASES * sizeof (alias_t ));
915934 CONSTANTS = malloc (MAX_CONSTANTS * sizeof (constant_t ));
916935
@@ -943,6 +962,7 @@ void global_release()
943962 free (PH2_IR_FLATTEN );
944963 free (LABEL_LUT );
945964 source_release (SOURCE );
965+ hashmap_free (INCLUSION_MAP );
946966 free (ALIASES );
947967 free (CONSTANTS );
948968
Original file line number Diff line number Diff line change 77
88#include <stdbool.h>
99
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"
10312
10413bool is_whitespace (char c )
10514{
@@ -223,6 +132,8 @@ token_t lex_token_internal(bool aliasing)
223132 return T_cppd_else ;
224133 if (!strcmp (token_str , "#endif" ))
225134 return T_cppd_endif ;
135+ if (!strcmp (token_str , "#pragma" ))
136+ return T_cppd_pragma ;
226137 error ("Unknown directive" );
227138 }
228139
Original file line number Diff line number Diff line change 66 */
77
88#include <stdbool.h>
9+ #include <stdio.h>
910#include <stdlib.h>
1011
12+ #include "../config"
13+ #include "defs.h"
14+ #include "globals.c"
15+
1116/* C language syntactic analyzer */
1217int global_var_idx = 0 ;
1318int global_label_idx = 0 ;
@@ -513,6 +518,10 @@ bool read_preproc_directive()
513518 cppd_control_flow_skip_lines ();
514519 return true;
515520 }
521+ if (lex_accept_internal (T_cppd_pragma , false)) {
522+ lex_expect (T_identifier );
523+ return true;
524+ }
516525
517526 return false;
518527}
@@ -3399,6 +3408,10 @@ void load_source_file(char *file)
33993408
34003409 for (;;) {
34013410 if (!fgets (buffer , MAX_LINE_LEN , f )) {
3411+ break ;
3412+ }
3413+ if (!strncmp (buffer , "#pragma once" , 12 ) &&
3414+ hashmap_contains (INCLUSION_MAP , file )) {
34023415 fclose (f );
34033416 return ;
34043417 }
@@ -3419,6 +3432,8 @@ void load_source_file(char *file)
34193432 SOURCE -> size += strlen (buffer );
34203433 }
34213434 }
3435+
3436+ hashmap_put (INCLUSION_MAP , file , calloc (sizeof (char ), 1 ));
34223437 fclose (f );
34233438}
34243439
Original file line number Diff line number Diff line change 55 * file "LICENSE" for information on usage and redistribution of this file.
66 */
77
8+ #include <stdbool.h>
9+
10+ #include "defs.h"
11+ #include "globals.c"
12+
813bool is_fusible_insn (ph2_ir_t * ph2_ir )
914{
1015 switch (ph2_ir -> op ) {
Original file line number Diff line number Diff line change 1212 * dead variable and does NOT wrtie it back to the stack.
1313 */
1414
15+ #include <stdbool.h>
16+
17+ #include "defs.h"
18+ #include "globals.c"
19+
1520/* Aligns size to nearest multiple of 4, this meets
1621 * ARMv7's alignment requirement.
1722 *
You can’t perform that action at this time.
0 commit comments