pp.h (1363B)
1 #ifndef KIT_PP_H 2 #define KIT_PP_H 3 4 #include <stdint.h> 5 6 #include "lex/lex.h" 7 8 typedef struct Pp Pp; 9 10 /* PP reads the compiler file-IO service for include search. If include search 11 * is configured but file_io is missing, include resolution panics. */ 12 Pp* pp_new(Compiler*); 13 void pp_free(Pp*); 14 15 void pp_add_include_dir(Pp*, const char* dir, int system); 16 void pp_define(Pp*, const char* name, const char* body); /* -D */ 17 void pp_undef(Pp*, const char* name); /* -U */ 18 uint32_t pp_pack_alignment(const Pp*); 19 20 /* Pushes a Lexer onto the include stack. PP takes ownership of the Lexer: 21 * it is closed when the input hits EOF and is popped, or in pp_free if it 22 * is still on the stack. Callers must not call lex_close on a pushed 23 * Lexer. The borrowed source buffer (see lex_open_mem) must outlive 24 * pp_free. */ 25 void pp_push_input(Pp*, Lexer*); 26 void pp_add_include_edge(Pp*, u32 includer_file_id, u32 included_file_id, 27 SrcLoc include_loc, int system); 28 29 /* Streaming. Yields preprocessed tokens (macro-expanded, directives consumed). 30 */ 31 Tok pp_next(Pp*); 32 33 /* Drains pp_next into `out` as preprocessed C source text: token spellings 34 * separated by single spaces where TF_HAS_SPACE is set, with newlines for 35 * TF_AT_BOL transitions. Stops on TOK_EOF. Used by the C driver. */ 36 void pp_emit_text(Pp*, Writer* out); 37 38 #endif