📄 grant.c
字号:
case INTEGER_CST: return result; case REAL_CST: return result; case STRING_CST: return result; case CONSTRUCTOR: val = TREE_OPERAND (val, 1); if (type != NULL && TREE_CODE (type) == SET_TYPE && CH_BOOLS_TYPE_P (type)) /* It's a bitstring. */ return result; else { /* It's some kind of tuple */ if (type != NULL_TREE) { mode_string = get_type_selective (type, all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); } if (val == NULL_TREE || TREE_CODE (val) == ERROR_MARK) return result; else if (TREE_CODE (val) != TREE_LIST) goto fail; else { for ( ; ; ) { tree lo_val = TREE_PURPOSE (val); tree hi_val = TREE_VALUE (val); MYSTRING *val_string; if (lo_val != NULL_TREE) { val_string = decode_constant_selective (lo_val, all_decls); if (val_string->len) APPEND (result, val_string->str); FREE (val_string); } val_string = decode_constant_selective (hi_val, all_decls); if (val_string->len) { MAYBE_NEWLINE (result); APPEND (result, val_string->str); } FREE (val_string); val = TREE_CHAIN (val); if (val == NULL_TREE) break; } } } return result; case COMPONENT_REF: { mode_string = decode_constant_selective (TREE_OPERAND (init, 0), all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); return result; } fail: error ("decode_constant_selective: mode and value mismatch"); break; default: error ("decode_constant_selective: cannot decode this mode"); break; } return result;}/* Assuming DECL is an ALIAS_DECL, return its prefix rename clause. */static MYSTRING *decode_prefix_rename (decl) tree decl;{ MYSTRING *result = newstring (""); if (DECL_OLD_PREFIX (decl) || DECL_NEW_PREFIX (decl)) { APPEND (result, "("); if (DECL_OLD_PREFIX (decl)) APPEND (result, IDENTIFIER_POINTER (DECL_OLD_PREFIX (decl))); APPEND (result, "->"); if (DECL_NEW_PREFIX (decl)) APPEND (result, IDENTIFIER_POINTER (DECL_NEW_PREFIX (decl))); APPEND (result, ")!"); } if (DECL_POSTFIX_ALL (decl)) APPEND (result, "ALL"); else APPEND (result, IDENTIFIER_POINTER (DECL_POSTFIX (decl))); return result;}static MYSTRING *decode_decl (decl) tree decl;{ MYSTRING *result = newstring (""); MYSTRING *mode_string; tree type; switch ((enum chill_tree_code)TREE_CODE (decl)) { case VAR_DECL: case BASED_DECL: APPEND (result, "DCL "); APPEND (result, IDENTIFIER_POINTER (DECL_NAME (decl))); APPEND (result, " "); mode_string = get_type (TREE_TYPE (decl)); APPEND (result, mode_string->str); FREE (mode_string); if ((enum chill_tree_code)TREE_CODE (decl) == BASED_DECL) { APPEND (result, " BASED ("); APPEND (result, IDENTIFIER_POINTER (DECL_ABSTRACT_ORIGIN (decl))); APPEND (result, ")"); } break; case TYPE_DECL: if (CH_DECL_SIGNAL (decl)) { /* this is really a signal */ tree fields = TYPE_FIELDS (TREE_TYPE (decl)); tree signame = DECL_NAME (decl); tree sigdest; APPEND (result, "SIGNAL "); APPEND (result, IDENTIFIER_POINTER (signame)); if (IDENTIFIER_SIGNAL_DATA (signame)) { APPEND (result, " = ("); for ( ; fields != NULL_TREE; fields = TREE_CHAIN (fields)) { MYSTRING *mode_string; mode_string = get_type (TREE_TYPE (fields)); APPEND (result, mode_string->str); FREE (mode_string); if (TREE_CHAIN (fields) != NULL_TREE) APPEND (result, ", "); } APPEND (result, ")"); } sigdest = IDENTIFIER_SIGNAL_DEST (signame); if (sigdest != NULL_TREE) { APPEND (result, " TO "); APPEND (result, IDENTIFIER_POINTER (DECL_NAME (sigdest))); } } else { /* avoid defining a mode as itself */ if (CH_NOVELTY (TREE_TYPE (decl)) == decl) APPEND (result, "NEWMODE "); else APPEND (result, "SYNMODE "); APPEND (result, IDENTIFIER_POINTER (DECL_NAME (decl))); APPEND (result, " = "); mode_string = decode_mode (TREE_TYPE (decl)); APPEND (result, mode_string->str); FREE (mode_string); } break; case FUNCTION_DECL: { tree args; type = TREE_TYPE (decl); args = TYPE_ARG_TYPES (type); APPEND (result, IDENTIFIER_POINTER (DECL_NAME (decl))); if (CH_DECL_PROCESS (decl)) APPEND (result, ": PROCESS ("); else APPEND (result, ": PROC ("); args = TYPE_ARG_TYPES (type); mode_string = print_proc_tail (type, args, 1); APPEND (result, mode_string->str); FREE (mode_string); /* generality */ if (CH_DECL_GENERAL (decl)) APPEND (result, " GENERAL"); if (CH_DECL_SIMPLE (decl)) APPEND (result, " SIMPLE"); if (DECL_INLINE (decl)) APPEND (result, " INLINE"); if (CH_DECL_RECURSIVE (decl)) APPEND (result, " RECURSIVE"); APPEND (result, " END"); } break; case FIELD_DECL: APPEND (result, IDENTIFIER_POINTER (DECL_NAME (decl))); APPEND (result, " "); mode_string = get_type (TREE_TYPE (decl)); APPEND (result, mode_string->str); FREE (mode_string); if (DECL_INITIAL (decl) != NULL_TREE) { mode_string = decode_layout (DECL_INITIAL (decl)); APPEND (result, mode_string->str); FREE (mode_string); }#if 0 if (is_forbidden (DECL_NAME (decl), forbid)) APPEND (result, " FORBID");#endif break; case CONST_DECL: if (DECL_INITIAL (decl) == NULL_TREE || TREE_CODE (DECL_INITIAL (decl)) == ERROR_MARK) break; APPEND (result, "SYN "); APPEND (result, IDENTIFIER_POINTER (DECL_NAME (decl))); APPEND (result, " "); mode_string = get_type (TREE_TYPE (decl)); APPEND (result, mode_string->str); FREE (mode_string); APPEND (result, " = "); mode_string = decode_constant (DECL_INITIAL (decl)); APPEND (result, mode_string->str); FREE (mode_string); break; case ALIAS_DECL: /* If CH_DECL_GRANTED, decl was granted into this scope, and so wasn't in the source code. */ if (!CH_DECL_GRANTED (decl)) { static int restricted = 0; if (DECL_SEIZEFILE (decl) != use_seizefile_name && DECL_SEIZEFILE (decl)) { use_seizefile_name = DECL_SEIZEFILE (decl); restricted = use_seizefile_name == NULL_TREE ? 0 : CH_USE_SEIZEFILE_RESTRICTED (use_seizefile_name); if (! restricted) grant_use_seizefile (IDENTIFIER_POINTER (use_seizefile_name)); mark_use_seizefile_written (use_seizefile_name); } if (! restricted) { APPEND (result, "SEIZE "); mode_string = decode_prefix_rename (decl); APPEND (result, mode_string->str); FREE (mode_string); } } break; default: APPEND (result, "----- not implemented ------"); break; } return (result);}static MYSTRING *decode_decl_selective (decl, all_decls) tree decl; tree all_decls;{ MYSTRING *result = newstring (""); MYSTRING *mode_string; tree type; if (CH_ALREADY_GRANTED (decl)) /* do nothing */ return result; CH_ALREADY_GRANTED (decl) = 1; switch ((int)TREE_CODE (decl)) { case VAR_DECL: case BASED_DECL: mode_string = get_type_selective (TREE_TYPE (decl), all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); if ((enum chill_tree_code)TREE_CODE (decl) == BASED_DECL) { mode_string = decode_mode_selective (DECL_ABSTRACT_ORIGIN (decl), all_decls); if (mode_string->len) PREPEND (result, mode_string->str); FREE (mode_string); } break; case TYPE_DECL: if (CH_DECL_SIGNAL (decl)) { /* this is really a signal */ tree fields = TYPE_FIELDS (TREE_TYPE (decl)); tree signame = DECL_NAME (decl); tree sigdest; if (IDENTIFIER_SIGNAL_DATA (signame)) { for ( ; fields != NULL_TREE; fields = TREE_CHAIN (fields)) { MYSTRING *mode_string; mode_string = get_type_selective (TREE_TYPE (fields), all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); } } sigdest = IDENTIFIER_SIGNAL_DEST (signame); if (sigdest != NULL_TREE) { mode_string = decode_mode_selective (DECL_NAME (sigdest), all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); } } else { /* avoid defining a mode as itself */ mode_string = decode_mode_selective (TREE_TYPE (decl), all_decls); APPEND (result, mode_string->str); FREE (mode_string); } break; case FUNCTION_DECL: { tree args; type = TREE_TYPE (decl); args = TYPE_ARG_TYPES (type); args = TYPE_ARG_TYPES (type); mode_string = print_proc_tail_selective (type, args, all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); } break; case FIELD_DECL: mode_string = get_type_selective (TREE_TYPE (decl), all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); break; case CONST_DECL: if (DECL_INITIAL (decl) == NULL_TREE || TREE_CODE (DECL_INITIAL (decl)) == ERROR_MARK) break; mode_string = get_type_selective (TREE_TYPE (decl), all_decls); if (mode_string->len) APPEND (result, mode_string->str); FREE (mode_string); mode_string = decode_constant_selective (DECL_INITIAL (decl), all_decls); if (mode_string->len) { MAYBE_NEWLINE (result); APPEND (result, mode_string->str); } FREE (mode_string); break; } MAYBE_NEWLINE (result); return (result);}static voidglobalize_decl (decl) tree decl;{ if (!TREE_PUBLIC (decl) && DECL_NAME (decl) && (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL)) { extern FILE *asm_out_file; extern char *first_global_object_name; char *name = XSTR (XEXP (DECL_RTL (decl), 0), 0); if (!first_global_object_name) first_global_object_name = name + (name[0] == '*'); ASM_GLOBALIZE_LABEL (asm_out_file, name); }}static voidgrant_one_decl (decl) tree decl;{ MYSTRING *result; if (DECL_SOURCE_LINE (decl) == 0) return; result = decode_decl (decl); if (result->len) { APPEND (result, ";\n"); APPEND (gstring, result->str); } FREE (result);}static voidgrant_one_decl_selective (decl, all_decls) tree decl; tree all_decls;{ MYSTRING *result; MYSTRING *fixups; tree d = DECL_ABSTRACT_ORIGIN (decl); if (CH_ALREADY_GRANTED (d)) /* already done */ return; result = decode_decl (d); if (!result->len) { /* nothing to do */ FREE (result); return; } APPEND (result, ";\n"); /* now process all undefined items in the decl */ fixups = decode_decl_selective (d, all_decls); if (fixups->len) { PREPEND (result, fixups->str); } FREE (fixups); /* we have finished a decl */ APPEND (selective_gstring, result->str); FREE (result);}static intcompare_memory_file (fname, buf) char *fname; char *buf;{ FILE *fb; int c; /* check if we have something to write */ if (!buf || !strlen (buf)) return (0); if ((fb = fopen (fname, "r")) == NULL) return (1); while ((c = getc (fb)) != EOF) { if (c != *buf++) { fclose (fb); return (1); } } fclose (fb); return (*buf ? 1 : 0);}voidwrite_grant_file (){ FILE *fb; /* We only write out the grant file if it has changed, to avoid changing its time-stamp and triggering an unnecessary 'make' action. Return if no change. */ if (gstring == NULL || !spec_module_generated || !compare_memory_file (grant_file_name, gstring->str)) return; fb = fopen (grant_file_name, "w"); if (fb == NULL) pfatal_with_name (grant_file_name); /* write file. Due to problems with record sizes on VAX/VMS write string to '\n' */#ifdef VMS /* do it this way for VMS, cause of problems with record sizes */ p = gstring->str; while (*p) { p1 = strchr (p, '\n'); c = *++p1; *p1 = '\0'; fprintf (fb, "%s", p); *p1 = c; p = p1; }#else /* faster way to write */ if (write (fileno (fb), gstring->s
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -