# HG changeset patch # User Nobuyasu Oshiro # Date 1324753482 -32400 # Node ID 99e7b6776dd1e40b7559ba03139aed564b6682da # Parent 3356a4c26abc95f7e4e8d2b49b9a7cdb855f9b5e implemeted __rectype expression. add CbC-exanples/fact-rectype.s diff -r 3356a4c26abc -r 99e7b6776dd1 CbC-examples/fact-rectype.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CbC-examples/fact-rectype.c Sun Dec 25 04:04:42 2011 +0900 @@ -0,0 +1,32 @@ +#include +#define __environment _CbC_environment +#define __return _CbC_return + +__code factorial(int n, int result, __rectype *print, __rectype *exit1, void *envp) +{ + if(n<0) { + print("#0008:err %dn",n); + goto (*exit1)(0, envp); + } + if (n==0) + goto (*print)(n,result,print,exit1, envp); + else { + result *= n; + n--; + goto factorial(n, result, print,exit1, envp); + } +} + +__code print(int n, int result, __rectype *print ,__rectype *exit1 ,void *envp); + +int main(int argc, char *argv[]) { + int n; + n = 10; + goto factorial(n,1,print,__return,__environment); +} + + +__code print(int n, int result, __rectype *print ,__rectype *exit1,void *envp){ + printf("#0032:%d = %d\n", n, result); + goto (*exit1)(0,envp); +} diff -r 3356a4c26abc -r 99e7b6776dd1 gcc/c-decl.c --- a/gcc/c-decl.c Tue Dec 20 19:03:56 2011 +0900 +++ b/gcc/c-decl.c Sun Dec 25 04:04:42 2011 +0900 @@ -5636,6 +5636,12 @@ } case cdk_pointer: { +#ifndef noCbC + if ( declspecs->typespec_word == cts_CbC_rec ) + { + type = build_code_segment_type (type, NULL_TREE); + } +#endif /* Merge any constancy or volatility into the target type for the pointer. */ @@ -8892,6 +8898,10 @@ error_at (loc, ("both % and % in " "declaration specifiers")); + else if (specs->typespec_word == cts_CbC_rec) + error_at (loc, + ("both % and % in " + "declaration specifiers")); #endif else if (specs->typespec_word == cts_int128) error_at (loc, @@ -8939,6 +8949,10 @@ error_at (loc, ("both % and % in " "declaration specifiers")); + else if (specs->typespec_word == cts_CbC_rec) + error_at (loc, + ("both % and % in " + "declaration specifiers")); #endif else if (specs->typespec_word == cts_int128) error_at (loc, @@ -8990,6 +9004,10 @@ error_at (loc, ("both % and % in " "declaration specifiers")); + else if (specs->typespec_word == cts_CbC_rec) + error_at (loc, + ("both % and % in " + "declaration specifiers")); #endif else if (specs->typespec_word == cts_bool) error_at (loc, @@ -9033,6 +9051,10 @@ error_at (loc, ("both % and % in " "declaration specifiers")); + else if (specs->typespec_word == cts_CbC_rec) + error_at (loc, + ("both % and % in " + "declaration specifiers")); #endif else if (specs->typespec_word == cts_bool) error_at (loc, @@ -9075,6 +9097,10 @@ error_at (loc, ("both % and % in " "declaration specifiers")); + else if (specs->typespec_word == cts_CbC_rec) + error_at (loc, + ("both % and % in " + "declaration specifiers")); #endif else if (specs->typespec_word == cts_bool) error_at (loc, @@ -9237,22 +9263,51 @@ #ifndef noCbC case RID_CbC_CODE: if (specs->long_p) - error ("both % and % in " - "declaration specifiers"); - else if (specs->short_p) - error ("both % and % in " - "declaration specifiers"); - else if (specs->signed_p) - error ("both % and % in " - "declaration specifiers"); - else if (specs->unsigned_p) - error ("both % and % in " - "declaration specifiers"); - else if (specs->complex_p) - error ("both % and % in " - "declaration specifiers"); + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else if (specs->short_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else if (specs->signed_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else if (specs->unsigned_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else if (specs->complex_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); else - specs->typespec_word = cts_CbC_code; + specs->typespec_word = cts_CbC_code; + return specs; + case RID_CbC_REC: + if (specs->long_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else if (specs->short_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else if (specs->signed_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else if (specs->unsigned_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else if (specs->complex_p) + error_at (loc, + ("both % and %<_Bool%> in " + "declaration specifiers")); + else + specs->typespec_word = cts_CbC_rec; return specs; #endif case RID_BOOL: @@ -9676,6 +9731,7 @@ case cts_void: #ifndef noCbC case cts_CbC_code: + case cts_CbC_rec: #endif gcc_assert (!specs->long_p && !specs->short_p && !specs->signed_p && !specs->unsigned_p diff -r 3356a4c26abc -r 99e7b6776dd1 gcc/c-family/c-common.c --- a/gcc/c-family/c-common.c Tue Dec 20 19:03:56 2011 +0900 +++ b/gcc/c-family/c-common.c Sun Dec 25 04:04:42 2011 +0900 @@ -423,6 +423,7 @@ #ifndef noCbC /* CbC project */ { "__code", RID_CbC_CODE, 0 }, + { "__rectype", RID_CbC_REC, 0}, #endif { "__builtin_choose_expr", RID_CHOOSE_EXPR, D_CONLY }, { "__builtin_offsetof", RID_OFFSETOF, 0 }, diff -r 3356a4c26abc -r 99e7b6776dd1 gcc/c-family/c-common.h --- a/gcc/c-family/c-common.h Tue Dec 20 19:03:56 2011 +0900 +++ b/gcc/c-family/c-common.h Sun Dec 25 04:04:42 2011 +0900 @@ -157,7 +157,7 @@ #ifndef noCbC /* Continuation based C */ - RID_CbC_CODE, RID_CbC_ENV, RID_CbC_RET, + RID_CbC_CODE, RID_CbC_ENV, RID_CbC_RET,RID_CbC_REC, #endif /* Named address support, mapping the keyword to a particular named address number. Named address space 0 is reserved for the generic address. If diff -r 3356a4c26abc -r 99e7b6776dd1 gcc/c-parser.c --- a/gcc/c-parser.c Tue Dec 20 19:03:56 2011 +0900 +++ b/gcc/c-parser.c Sun Dec 25 04:04:42 2011 +0900 @@ -654,7 +654,8 @@ case RID_ACCUM: case RID_SAT: #ifndef noCbC - case RID_CbC_CODE: + case RID_CbC_CODE: + case RID_CbC_REC: #endif return true; default: @@ -2097,30 +2098,31 @@ c_parser_consume_token (parser); break; #ifndef noCbC - case RID_CbC_CODE: - if (!typespec_ok) - goto out; - attrs_ok = true; - seen_type = true; - if (c_dialect_objc ()) - parser->objc_need_raw_identifier = true; - t.kind = ctsk_resword; - t.spec = c_parser_peek_token (parser)->value; - declspecs_add_type (loc, specs, t); - - /* - attrs = get_identifier("fastcall"); - attrs = build_tree_list(attrs, NULL_TREE); - declspecs_add_attrs(specs, attrs); - */ - if(!TARGET_64BIT) { - attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); - /*attrs = build_tree_list (get_identifier("noreturn"), attrs);*/ - declspecs_add_attrs(specs, attrs); + case RID_CbC_CODE: + case RID_CbC_REC: + if (!typespec_ok) + goto out; + attrs_ok = true; + seen_type = true; + if (c_dialect_objc ()) + parser->objc_need_raw_identifier = true; + t.kind = ctsk_resword; + t.spec = c_parser_peek_token (parser)->value; + declspecs_add_type (loc, specs, t); + + /* + attrs = get_identifier("fastcall"); + attrs = build_tree_list(attrs, NULL_TREE); + declspecs_add_attrs(specs, attrs); + */ + if(!TARGET_64BIT) { + attrs = build_tree_list (get_identifier("fastcall"), NULL_TREE); + /*attrs = build_tree_list (get_identifier("noreturn"), attrs);*/ + declspecs_add_attrs(specs, attrs); } - - c_parser_consume_token (parser); - break; + + c_parser_consume_token (parser); + break; #endif case RID_ENUM: if (!typespec_ok) @@ -6167,12 +6169,12 @@ decl_attributes (&tlab, NULL_TREE, 0); add_stmt (build_stmt (loc, LABEL_EXPR, tlab)); - tree ret = c_finish_return (loc, retval, retval); /*tree ret = c_finish_return (retval);*/ - /* + tree ret = c_finish_return (loc, retval, retval); //tree ret = c_finish_return (retval); TREE_USED(ret) = 1; tree if_body = c_end_compound_stmt (loc, cstmt, true); TREE_SIDE_EFFECTS (cstmt) = 1; c_finish_if_stmt (loc, cond, if_body, NULL_TREE, false); + */ cond = integer_zero_node; @@ -6775,13 +6777,12 @@ build_decl (location, VAR_DECL, get_identifier ("retval"), TREE_TYPE (TREE_TYPE (current_function_decl))); TREE_STATIC (decl_cond) = 1; - - /* use thread-local */ - //DECL_TLS_MODEL (decl_cond) = decl_default_tls_model (decl_cond); - // DECL_TLS_MODEL (decl_cond) = TLS_MODEL_REAL; - - /* Linux: TLS_MODEL_LOCAL_EXEC OS X: TlS_MODE_REAL */ - DECL_TLS_MODEL (decl_cond) = TLS_MODEL_LOCAL_EXEC; + TREE_USED (decl_cond) = 1; + + /* Use thread-local */ + DECL_TLS_MODEL (decl_cond) = decl_default_tls_model (decl_cond); + DECL_NONLOCAL (decl_cond) = 1; + // DECL_READ_P (decl_cond) = 1; //DECL_ARTIFICIAL (decl_cond) = 1; // pushdecl (decl_cond); add_stmt (build_stmt(location, DECL_EXPR, pushdecl (decl_cond))); @@ -6789,6 +6790,7 @@ /* define nested function. */ decl = cbc_finish_nested_function (location, label, decl_cond); + TREE_USED(decl) = 1; /* define if-ed goto label and return statement. */ cbc_finish_labeled_goto (location, label, decl_cond); diff -r 3356a4c26abc -r 99e7b6776dd1 gcc/c-tree.h --- a/gcc/c-tree.h Tue Dec 20 19:03:56 2011 +0900 +++ b/gcc/c-tree.h Sun Dec 25 04:04:42 2011 +0900 @@ -201,6 +201,7 @@ cts_double, #ifndef noCbC cts_CbC_code, + cts_CbC_rec, #endif cts_dfloat32, cts_dfloat64,