Mercurial > hg > CbC > CbC_gcc
comparison gcc/c-decl.c @ 1:caeb520cebed
patch for CbC
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 17 Jul 2009 17:43:54 +0900 |
parents | a06113de4d67 |
children | 27e6f95b2c21 |
comparison
equal
deleted
inserted
replaced
0:a06113de4d67 | 1:caeb520cebed |
---|---|
61 #include "libfuncs.h" | 61 #include "libfuncs.h" |
62 #include "except.h" | 62 #include "except.h" |
63 #include "langhooks-def.h" | 63 #include "langhooks-def.h" |
64 #include "pointer-set.h" | 64 #include "pointer-set.h" |
65 #include "gimple.h" | 65 #include "gimple.h" |
66 #ifndef noCbC | |
67 #include "cbc-tree.h" | |
68 tree cbc_env; | |
69 tree cbc_return_f; | |
70 location_t cbc_return; | |
71 #endif | |
72 | |
66 | 73 |
67 /* In grokdeclarator, distinguish syntactic contexts of declarators. */ | 74 /* In grokdeclarator, distinguish syntactic contexts of declarators. */ |
68 enum decl_context | 75 enum decl_context |
69 { NORMAL, /* Ordinary declaration */ | 76 { NORMAL, /* Ordinary declaration */ |
70 FUNCDEF, /* Function definition */ | 77 FUNCDEF, /* Function definition */ |
2337 } | 2344 } |
2338 | 2345 |
2339 /* Generate an implicit declaration for identifier FUNCTIONID as a | 2346 /* Generate an implicit declaration for identifier FUNCTIONID as a |
2340 function of type int (). */ | 2347 function of type int (). */ |
2341 | 2348 |
2349 #ifndef noCbC | |
2350 tree | |
2351 implicitly_declare (tree functionid, int fun) | |
2352 #else | |
2342 tree | 2353 tree |
2343 implicitly_declare (tree functionid) | 2354 implicitly_declare (tree functionid) |
2355 #endif | |
2344 { | 2356 { |
2345 struct c_binding *b; | 2357 struct c_binding *b; |
2346 tree decl = 0; | 2358 tree decl = 0; |
2347 tree asmspec_tree; | 2359 tree asmspec_tree; |
2348 | 2360 |
2413 return decl; | 2425 return decl; |
2414 } | 2426 } |
2415 } | 2427 } |
2416 | 2428 |
2417 /* Not seen before. */ | 2429 /* Not seen before. */ |
2430 #ifndef noCbC | |
2431 decl = build_decl (FUNCTION_DECL, functionid, | |
2432 fun==RID_CbC_CODE?build_function_type (void_type_node, NULL_TREE):default_function_type); | |
2433 #else | |
2418 decl = build_decl (FUNCTION_DECL, functionid, default_function_type); | 2434 decl = build_decl (FUNCTION_DECL, functionid, default_function_type); |
2435 #endif | |
2419 DECL_EXTERNAL (decl) = 1; | 2436 DECL_EXTERNAL (decl) = 1; |
2420 TREE_PUBLIC (decl) = 1; | 2437 TREE_PUBLIC (decl) = 1; |
2421 C_DECL_IMPLICIT (decl) = 1; | 2438 C_DECL_IMPLICIT (decl) = 1; |
2422 implicit_decl_warning (functionid, 0); | 2439 implicit_decl_warning (functionid, 0); |
2423 asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL); | 2440 asmspec_tree = maybe_apply_renaming_pragma (decl, /*asmname=*/NULL); |
4558 | 4575 |
4559 type = c_build_qualified_type (type, type_quals); | 4576 type = c_build_qualified_type (type, type_quals); |
4560 } | 4577 } |
4561 type_quals = TYPE_UNQUALIFIED; | 4578 type_quals = TYPE_UNQUALIFIED; |
4562 | 4579 |
4563 type = build_function_type (type, arg_types); | 4580 #ifndef noCbC |
4581 if ( declspecs->typespec_word == cts_CbC_code ) | |
4582 { | |
4583 type = build_code_segment_type (type, arg_types); | |
4584 } | |
4585 else | |
4586 #endif | |
4587 { | |
4588 type = build_function_type (type, arg_types); | |
4589 } | |
4590 | |
4564 declarator = declarator->declarator; | 4591 declarator = declarator->declarator; |
4565 | 4592 |
4566 /* Set the TYPE_CONTEXTs for each tagged type which is local to | 4593 /* Set the TYPE_CONTEXTs for each tagged type which is local to |
4567 the formal parameter list of this FUNCTION_TYPE to point to | 4594 the formal parameter list of this FUNCTION_TYPE to point to |
4568 the FUNCTION_TYPE node itself. */ | 4595 the FUNCTION_TYPE node itself. */ |
6070 pushdecl (decl); | 6097 pushdecl (decl); |
6071 | 6098 |
6072 return tree_cons (decl, value, NULL_TREE); | 6099 return tree_cons (decl, value, NULL_TREE); |
6073 } | 6100 } |
6074 | 6101 |
6102 #ifndef noCbC | |
6103 #define CbC_STACK_SIZE (1024 * 8) | |
6104 static void cbc_set_codesegment(tree fndecl){ | |
6105 tree args; | |
6106 tree *nextp; | |
6107 // tree itype; | |
6108 // tree icst; | |
6109 // tree padding_array; | |
6110 // tree list; | |
6111 int padding_size = CbC_STACK_SIZE; | |
6112 | |
6113 //CbC_IS_CODE_SEGMENT(TREE_TYPE(fndecl)) = 1; | |
6114 //CbC_IS_CODE_SEGMENT(fndecl) = 1; | |
6115 | |
6116 nextp = & TYPE_ARG_TYPES (TREE_TYPE (fndecl)); | |
6117 for (args = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); args; | |
6118 args = TREE_CHAIN (args)) | |
6119 { | |
6120 tree type = args ? TREE_VALUE (args) : 0; | |
6121 tree type_size; | |
6122 unsigned int size; | |
6123 | |
6124 if (type == void_type_node) | |
6125 break; | |
6126 | |
6127 type_size = TYPE_SIZE (type); | |
6128 size = TREE_INT_CST_LOW (type_size); | |
6129 padding_size -= size; | |
6130 | |
6131 nextp = & TREE_CHAIN(args); | |
6132 } | |
6133 | |
6134 /* error check. */ | |
6135 if (padding_size<0) | |
6136 { | |
6137 error ("CbC: too many arguments on code segment %qE", fndecl); | |
6138 return ; | |
6139 } | |
6140 else if (padding_size==0) | |
6141 return ; | |
6142 | |
6143 #if 0 | |
6144 /* itype is integer_type that means last index. */ | |
6145 icst = build_int_cst (NULL_TREE, padding_size-1); | |
6146 itype = build_index_type (icst); | |
6147 | |
6148 /* create array_type node. */ | |
6149 padding_array = build_array_type (integer_type_node, itype); | |
6150 | |
6151 /* add array_type to this function's argument list | |
6152 before void_type_node. */ | |
6153 if (!args) | |
6154 args = build_tree_list(NULL_TREE, void_type_node); | |
6155 list = build_tree_list(NULL_TREE, padding_array); | |
6156 TREE_CHAIN(list) = args; | |
6157 *nextp = list; | |
6158 #endif | |
6159 | |
6160 return ; | |
6161 } | |
6162 #endif | |
6163 | |
6075 | 6164 |
6076 /* Create the FUNCTION_DECL for a function definition. | 6165 /* Create the FUNCTION_DECL for a function definition. |
6077 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of | 6166 DECLSPECS, DECLARATOR and ATTRIBUTES are the parts of |
6078 the declaration; they describe the function's name and the type it returns, | 6167 the declaration; they describe the function's name and the type it returns, |
6079 but twisted together in a fashion that parallels the syntax of C. | 6168 but twisted together in a fashion that parallels the syntax of C. |
6118 error message in c_finish_bc_stmt. */ | 6207 error message in c_finish_bc_stmt. */ |
6119 c_break_label = c_cont_label = size_zero_node; | 6208 c_break_label = c_cont_label = size_zero_node; |
6120 | 6209 |
6121 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL, | 6210 decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, true, NULL, |
6122 &attributes, DEPRECATED_NORMAL); | 6211 &attributes, DEPRECATED_NORMAL); |
6212 | |
6213 #ifndef noCbC | |
6214 cbc_return_f = NULL_TREE; | |
6215 cbc_env = NULL_TREE; | |
6216 if ( declspecs->typespec_word == cts_CbC_code ) | |
6217 { | |
6218 cbc_set_codesegment(decl1); | |
6219 //CbC_IS_CODE_SEGMENT(TREE_TYPE(decl1)) = 1; | |
6220 } | |
6221 #endif | |
6123 | 6222 |
6124 /* If the declarator is not suitable for a function definition, | 6223 /* If the declarator is not suitable for a function definition, |
6125 cause a syntax error. */ | 6224 cause a syntax error. */ |
6126 if (decl1 == 0) | 6225 if (decl1 == 0) |
6127 { | 6226 { |
7247 error ("both %<long%> and %<short%> in " | 7346 error ("both %<long%> and %<short%> in " |
7248 "declaration specifiers"); | 7347 "declaration specifiers"); |
7249 else if (specs->typespec_word == cts_void) | 7348 else if (specs->typespec_word == cts_void) |
7250 error ("both %<long%> and %<void%> in " | 7349 error ("both %<long%> and %<void%> in " |
7251 "declaration specifiers"); | 7350 "declaration specifiers"); |
7351 #ifndef noCbC | |
7352 else if (specs->typespec_word == cts_CbC_code) | |
7353 error ("both %<long%> and %<void%> in " | |
7354 "declaration specifiers"); | |
7355 #endif | |
7252 else if (specs->typespec_word == cts_bool) | 7356 else if (specs->typespec_word == cts_bool) |
7253 error ("both %<long%> and %<_Bool%> in " | 7357 error ("both %<long%> and %<_Bool%> in " |
7254 "declaration specifiers"); | 7358 "declaration specifiers"); |
7255 else if (specs->typespec_word == cts_char) | 7359 else if (specs->typespec_word == cts_char) |
7256 error ("both %<long%> and %<char%> in " | 7360 error ("both %<long%> and %<char%> in " |
7276 error ("both %<long%> and %<short%> in " | 7380 error ("both %<long%> and %<short%> in " |
7277 "declaration specifiers"); | 7381 "declaration specifiers"); |
7278 else if (specs->typespec_word == cts_void) | 7382 else if (specs->typespec_word == cts_void) |
7279 error ("both %<short%> and %<void%> in " | 7383 error ("both %<short%> and %<void%> in " |
7280 "declaration specifiers"); | 7384 "declaration specifiers"); |
7385 #ifndef noCbC | |
7386 else if (specs->typespec_word == cts_CbC_code) | |
7387 error ("both %<short%> and %<void%> in " | |
7388 "declaration specifiers"); | |
7389 #endif | |
7281 else if (specs->typespec_word == cts_bool) | 7390 else if (specs->typespec_word == cts_bool) |
7282 error ("both %<short%> and %<_Bool%> in " | 7391 error ("both %<short%> and %<_Bool%> in " |
7283 "declaration specifiers"); | 7392 "declaration specifiers"); |
7284 else if (specs->typespec_word == cts_char) | 7393 else if (specs->typespec_word == cts_char) |
7285 error ("both %<short%> and %<char%> in " | 7394 error ("both %<short%> and %<char%> in " |
7308 error ("both %<signed%> and %<unsigned%> in " | 7417 error ("both %<signed%> and %<unsigned%> in " |
7309 "declaration specifiers"); | 7418 "declaration specifiers"); |
7310 else if (specs->typespec_word == cts_void) | 7419 else if (specs->typespec_word == cts_void) |
7311 error ("both %<signed%> and %<void%> in " | 7420 error ("both %<signed%> and %<void%> in " |
7312 "declaration specifiers"); | 7421 "declaration specifiers"); |
7422 #ifndef noCbC | |
7423 else if (specs->typespec_word == cts_CbC_code) | |
7424 error ("both %<signed%> and %<void%> in " | |
7425 "declaration specifiers"); | |
7426 #endif | |
7313 else if (specs->typespec_word == cts_bool) | 7427 else if (specs->typespec_word == cts_bool) |
7314 error ("both %<signed%> and %<_Bool%> in " | 7428 error ("both %<signed%> and %<_Bool%> in " |
7315 "declaration specifiers"); | 7429 "declaration specifiers"); |
7316 else if (specs->typespec_word == cts_float) | 7430 else if (specs->typespec_word == cts_float) |
7317 error ("both %<signed%> and %<float%> in " | 7431 error ("both %<signed%> and %<float%> in " |
7337 error ("both %<signed%> and %<unsigned%> in " | 7451 error ("both %<signed%> and %<unsigned%> in " |
7338 "declaration specifiers"); | 7452 "declaration specifiers"); |
7339 else if (specs->typespec_word == cts_void) | 7453 else if (specs->typespec_word == cts_void) |
7340 error ("both %<unsigned%> and %<void%> in " | 7454 error ("both %<unsigned%> and %<void%> in " |
7341 "declaration specifiers"); | 7455 "declaration specifiers"); |
7456 #ifndef noCbC | |
7457 else if (specs->typespec_word == cts_CbC_code) | |
7458 error ("both %<unsigned%> and %<void%> in " | |
7459 "declaration specifiers"); | |
7460 #endif | |
7342 else if (specs->typespec_word == cts_bool) | 7461 else if (specs->typespec_word == cts_bool) |
7343 error ("both %<unsigned%> and %<_Bool%> in " | 7462 error ("both %<unsigned%> and %<_Bool%> in " |
7344 "declaration specifiers"); | 7463 "declaration specifiers"); |
7345 else if (specs->typespec_word == cts_float) | 7464 else if (specs->typespec_word == cts_float) |
7346 error ("both %<unsigned%> and %<float%> in " | 7465 error ("both %<unsigned%> and %<float%> in " |
7365 if (!flag_isoc99 && !in_system_header) | 7484 if (!flag_isoc99 && !in_system_header) |
7366 pedwarn (input_location, OPT_pedantic, "ISO C90 does not support complex types"); | 7485 pedwarn (input_location, OPT_pedantic, "ISO C90 does not support complex types"); |
7367 if (specs->typespec_word == cts_void) | 7486 if (specs->typespec_word == cts_void) |
7368 error ("both %<complex%> and %<void%> in " | 7487 error ("both %<complex%> and %<void%> in " |
7369 "declaration specifiers"); | 7488 "declaration specifiers"); |
7489 #ifndef noCbC | |
7490 else if (specs->typespec_word == cts_CbC_code) | |
7491 error ("both %<complex%> and %<void%> in " | |
7492 "declaration specifiers"); | |
7493 #endif | |
7370 else if (specs->typespec_word == cts_bool) | 7494 else if (specs->typespec_word == cts_bool) |
7371 error ("both %<complex%> and %<_Bool%> in " | 7495 error ("both %<complex%> and %<_Bool%> in " |
7372 "declaration specifiers"); | 7496 "declaration specifiers"); |
7373 else if (specs->typespec_word == cts_dfloat32) | 7497 else if (specs->typespec_word == cts_dfloat32) |
7374 error ("both %<complex%> and %<_Decimal32%> in " | 7498 error ("both %<complex%> and %<_Decimal32%> in " |
7467 error ("both %<_Sat%> and %<void%> in " | 7591 error ("both %<_Sat%> and %<void%> in " |
7468 "declaration specifiers"); | 7592 "declaration specifiers"); |
7469 else | 7593 else |
7470 specs->typespec_word = cts_void; | 7594 specs->typespec_word = cts_void; |
7471 return specs; | 7595 return specs; |
7596 #ifndef noCbC | |
7597 case RID_CbC_CODE: | |
7598 if (specs->long_p) | |
7599 error ("both %<long%> and %<void%> in " | |
7600 "declaration specifiers"); | |
7601 else if (specs->short_p) | |
7602 error ("both %<short%> and %<void%> in " | |
7603 "declaration specifiers"); | |
7604 else if (specs->signed_p) | |
7605 error ("both %<signed%> and %<void%> in " | |
7606 "declaration specifiers"); | |
7607 else if (specs->unsigned_p) | |
7608 error ("both %<unsigned%> and %<void%> in " | |
7609 "declaration specifiers"); | |
7610 else if (specs->complex_p) | |
7611 error ("both %<complex%> and %<void%> in " | |
7612 "declaration specifiers"); | |
7613 else | |
7614 specs->typespec_word = cts_CbC_code; | |
7615 return specs; | |
7616 #endif | |
7472 case RID_BOOL: | 7617 case RID_BOOL: |
7473 if (specs->long_p) | 7618 if (specs->long_p) |
7474 error ("both %<long%> and %<_Bool%> in " | 7619 error ("both %<long%> and %<_Bool%> in " |
7475 "declaration specifiers"); | 7620 "declaration specifiers"); |
7476 else if (specs->short_p) | 7621 else if (specs->short_p) |
7821 | 7966 |
7822 /* Now compute the actual type. */ | 7967 /* Now compute the actual type. */ |
7823 switch (specs->typespec_word) | 7968 switch (specs->typespec_word) |
7824 { | 7969 { |
7825 case cts_void: | 7970 case cts_void: |
7971 #ifndef noCbC | |
7972 case cts_CbC_code: | |
7973 #endif | |
7826 gcc_assert (!specs->long_p && !specs->short_p | 7974 gcc_assert (!specs->long_p && !specs->short_p |
7827 && !specs->signed_p && !specs->unsigned_p | 7975 && !specs->signed_p && !specs->unsigned_p |
7828 && !specs->complex_p); | 7976 && !specs->complex_p); |
7829 specs->type = void_type_node; | 7977 specs->type = void_type_node; |
7830 break; | 7978 break; |