25 #include "pips_config.h"
40 #include "constants.h"
119 string simpler_file_name =
pips_basename(input_file_name, PP_C_ED);
123 pips_debug(1,
"Open compilation unit \"%s\"\n", input_file_name);
170 C_FILE_SUFFIX
"\".\n"
171 "Not supported yet.\n",
180 free(simpler_file_name);
210 unsigned long long up_to_offset,
214 while(((
unsigned) ftell(source)) < up_to_offset) {
222 fputc(c, destination);
227 if ((next_c = fgetc(source)) ==
'\n') {
228 fputc(next_c, destination);
231 putc(next_c, stderr);
235 ungetc(next_c, source);
238 if (c != EOF && c !=
'\n') {
241 fputc(
'\n', destination);
247 while(isspace(c = fgetc(source))) {
250 fputc(c, destination);
263 unsigned long long last_offset) {
264 pips_debug(2,
"append to compilation unit up-to line %d (from %d) or offset %llu\n",
267 if (last_offset != 0) {
269 pips_debug(2,
"copying to compilation unit file up to offset %llu, we are at currently at offset %lu\n",
278 pips_assert(
"last_line is positive", last_line >= 0);
279 pips_assert(
"if last_line is strictly less than current_input_line, then last_line is 0",
320 filepath[strlen(filepath)-1] !=
'c';
340 int user_first_line,
bool is_static_p)
344 string unambiguous_module_file_name;
345 const char* unambiguous_module_name = is_static_p?
354 FILE * fm = fopen(main_list,
"a");
356 fprintf(stderr,
"fopen(\"%s\", ...) failed\n", main_list);
368 if(!(first_line > 0 && first_line <= last_line)) {
369 pips_user_error(
"Definition of function %s starts at line %d and ends a t line %d\n"
370 "PIPS assumes the function definition to start on a new line "
371 "after the function signature\n",
module_name, first_line, last_line);
373 pips_assert(
"current_compilation_unit_name is defined",
382 unambiguous_module_file_name
389 unambiguous_module_file_name
394 pips_debug(1,
"Begin for %s module \"%s\" from line %d to line %d (offset [%zd-%zd]) in compilation unit %s towards %s\n",
395 is_static_p?
"static" :
"global",
397 first_line, last_line, first_offset, last_offset,
399 unambiguous_module_file_name);
401 if((mfd=fopen(unambiguous_module_file_name,
"r"))!=NULL) {
404 "Copy in file %s from input file %s is ignored\n"
405 "Check source code with a compiler or set property %s\n",
407 unambiguous_module_file_name,
409 "PIPS_CHECK_FORTRAN");
411 else if((mfd=fopen(unambiguous_module_file_name,
"w"))==NULL) {
414 unambiguous_module_file_name);
417 pips_assert(
"The module file descriptor is defined", mfd!=NULL);
438 if(*p==
'.' && *(p+1)==
'/')
440 fprintf(mfd,
"# %d \"%s\"\n", user_first_line,
443 if (first_offset == 0 && last_offset == 0) {
444 pips_debug(2,
"copying to module file lines [%d-%d]\n",
457 pips_debug(2,
"copying to module file offset [%zd-%zd]\n",
458 first_offset, last_offset);
476 if( (where = strstr(signature,
"static") ) &&
477 isspace(where[
sizeof(
"static")-1]) &&
478 ( where == signature || isspace(where[-1]) )
485 else if ( (where = strstr(signature,
"extern") ) &&
486 isspace(where[
sizeof(
"extern")-1]) &&
487 ( where == signature || isspace(where[-1]) )
511 free(unambiguous_module_file_name);
523 pips_debug(2,
"Add typedef name \"%s\" to hash table\n", scoped_type_name);
524 if(strcmp(type_name,
"v1")==0) {
658 return "cannot open file";
677 error_message =
"PIPS preprocessor parser error";
681 error_message = NULL;
685 if(error_message==NULL) {
695 return error_message;
float a2sf[2] __attribute__((aligned(16)))
USER generates a user error (i.e., non fatal) by printing the given MSG according to the FMT.
@ any_exception_error
catch all
static list module_name_list
Kind of useless since a file is used to mimic fsplit.
void csplit_close_compilation_unit()
void init_module_name_list()
void csplit_error_handler()
Close open files and reset variables.
void csplit_copy(const char *module_name, string signature, int first_line, int last_line, size_t first_offset, size_t last_offset, int user_first_line, bool is_static_p)
Create the module directory and file, copy the definition of the module and add the module name to th...
static string splitc_input_file_name
File management.
void reset_current_input_line(void)
In file just above.
string current_file_name
Split a C file into one file per module (function or procedure) plus.
static string current_compilation_unit_file_name
static FILE * compilation_unit_file
includes FILE_SEP_STRING as a suffix.
static FILE * module_list_file
Compilation unit.
void csplit_open_compilation_unit(string input_file_name)
Disambiguate the compilation unit base name (special character to avoid conflicts with function names...
void reset_module_name_list()
string csplit(char *dir_name, char *file_name, FILE *out)
static string current_compilation_unit_name
static FILE * splitc_in_append
The FILE descriptor used to generate the compilation unit:
void preprocessor_init_keyword_typedef_table()
void csplit_close_files(string file_name)
static string current_workspace_name
string get_splitc_input_file_name(void)
char * current_include_file_path
used to keep track of include level
void error_reset_module_name_list()
No checking, to be called from a (future) error handling module.
void keep_track_of_typedef(string type_name)
void csplit_append_to_compilation_unit(int last_line, unsigned long long last_offset)
Copy the input file to the compilation unit between the function declarations up to the current funct...
static bool path_header_p(const char *filepath)
void copy_between_2_fd_up_to_offset(FILE *source, FILE *destination, unsigned long long up_to_offset, bool greedy_spaces __attribute__((__unused__)))
Copy data from on file to another up to an offset.
static int current_input_line
const char * module_name(const char *s)
Return the module part of an entity name.
FILE * safe_fopen(const char *filename, const char *what)
int safe_fclose(FILE *stream, const char *filename)
char * pips_basename(char *fullpath, char *suffix)
bool get_bool_property(const string)
FC 2015-07-20: yuk, moved out to prevent an include cycle dependency include "properties....
#define list_undefined_p(c)
Return if a list is undefined.
#define NIL
The empty list (nil in Lisp)
void gen_free_list(list l)
free the spine of the list
#define list_undefined
Undefined list definition :-)
void hash_put(hash_table htp, const void *key, const void *val)
This functions stores a couple (key,val) in the hash table pointed to by htp.
#define pips_debug
these macros use the GNU extensions that allow variadic macros, including with an empty list.
#define pips_assert(what, predicate)
common macros, two flavors depending on NDEBUG
string concatenate(const char *,...)
Return the concatenation of the given strings.
#define same_string_p(s1, s2)
#define string_undefined_p(s)
#define MAIN_FILE_NAMES
Name of the file containing the names of the main procedures.
void MakeTypedefStack()
Define some functions from the .l or .y since cproto cannot dig them out:
void reset_csplit_line_number()
Reinitialise global position numbers for a new file.
void ForceResetTypedefStack(void)
void reset_preprocessor_scope_stack(void)
string preprocessor_current_initial_file_name
The digestion of a user file by PIPS begins here.
string get_preprocessor_current_scope(void)
void init_preprocessor_scope_stack(void)
void free_keyword_typedef_table(void)
hash_table make_keyword_typedef_table(int)
hash_table keyword_typedef_table
Because of typedefs, the C lexers need help to decide if a character string such as toto is a type na...
int fprintf()
test sc_min : ce test s'appelle par : programme fichier1.data fichier2.data ...
#define TK_BUILTIN_VA_ARG
The structure used to build lists in NewGen.