Symbol.xcc
Benoit Dupont de Dinechin (Benoit.Dupont-de-Dinechin@st.com).
Copyright 2002 - 2007 STMicroelectronics. Copyright 1995 - 1998 Commissariat a l'Energie Atomique.
This program is free software; you can redistribute it and/or modify it under the terms of either (at your option): the GNU General Public License (GPL) version 2; the GNU Lesser General Public License (LGPL) version 2.1; any later version of these licences as published by the Free Software Foundation.
Symbol_Factory— IndexedFactory for Symbol(s).
extern IndexedFactory_ Symbol_Factory[1];
SymbolClass— Enumerates the Symbol Classes.
typedef enum { SymbolClass__UNDEF, // Symbol class is undefined. SymbolClass_VAR, // Symbol is a data variable. SymbolClass_FUNC, // Symbol is a function address. SymbolClass_CONST, // Symbol is a constant value. SymbolClass_PREG, // Symbol is a pseudo register. SymbolClass_BLOCK, // Symbol is a base symbol for a block. SymbolClass__COUNT } enum_SymbolClass; typedef uint8_t SymbolClass;
SymbolStore— Enumerates the Symbol Store Classes.
typedef enum { SymbolStore__UNDEF, // Symbol sclass is undefined. SymbolStore_AUTO, // Symbol is automatic. SymbolStore_FORMAL, // Symbol is a formal parameter. SymbolStore_FORMAL_REF, // Symbol is a formal ref parameter. SymbolStore_PSTATIC, // Symbol is PU static. SymbolStore_FSTATIC, // Symbol is file static. SymbolStore_COMMON, // Symbol is common. SymbolStore_EXTERN, // Symbol is unallocated data or text. SymbolStore_UGLOBAL, // Symbol is uninitialized global data. SymbolStore_DGLOBAL, // Symbol is defined global data. SymbolStore_TEXT, // Symbol is an executable code. SymbolStore_REG, // Symbol is a register variable. SymbolStore__COUNT } enum_SymbolStore; typedef uint8_t SymbolStore;
SymbolExport— Enumerates the Symbol Export Classes.
typedef enum { SymbolExport__UNDEF, // Symbol export is undefined. SymbolExport_LOCAL, // Default for static (not exported) // may have address taken. SymbolExport_LOCAL_INTERNAL, // Static that do not have address // passed out of .out/.so. SymbolExport_GLOBAL_INTERNAL, // Exported, but only visible and used // within .out/.so. SymbolExport_GLOBAL_HIDDEN, // Exported, but only visible // within .out/.so, however may be // used outside by address taken. SymbolExport_GLOBAL_PROTECTED, // Exported, not preemptible. SymbolExport_GLOBAL_PREEMPTIBLE, // Exported and preemptible. SymbolExport__COUNT } enum_SymbolExport; typedef uint8_t SymbolExport;
SymbolFlag— Enumerates the Symbol flags.
typedef enum { SymbolFlag_Resolved = 0x01, // Symbol is resolved } enum_SymbolFlag; typedef uint8_t SymbolFlags;
SymbolUnion_— Union for the variant part of Symbol.
union SymbolUnion_ { void *POINTER; // Client pointer. struct Procedure_ *PROCEDURE; // The Procedure if Symbol of a Procedure. }; typedef union SymbolUnion_ SymbolUnion_, *SymbolUnion;
Symbol -- Implement a symbol.
struct Symbol_ { //@args uint32_t index, String name Indexed_ __; // A Symbol ISA Indexed. //@access IDENTITY Indexed_IDENTITY(Symbol____(this)) //@access INDEX Indexed_INDEX(Symbol____(this)) //@mutate INDEX Indexed__INDEX(Symbol____(this)) ImmediateValue VALUE; // The resolved value of this Symbol. String NAME; // The Symbol name. SymbolUnion_ UNION_; //@access POINTER (Symbol_UNION_(this).POINTER) //@mutate POINTER (&Symbol_UNION_(this).POINTER) //@access PROCEDURE (Symbol_UNION_(this).PROCEDURE) //@mutate PROCEDURE (&Symbol_UNION_(this).PROCEDURE) struct Procedure_ *PROCEDURE; // The Procedure SymbolClass CLASS; // The symbol class SymbolStore STORE; // The symbol store class. SymbolExport EXPORT; // The symbol export class SymbolFlags FLAGS; // This Symbol flags. //@access isResolved ((Symbol_flags(this) & SymbolFlag_Resolved) != 0) uint64_t SIZE; // The symbol size uint64_t BASEOFFSET; // Positive offset from start of base symbol. uint32_t BASEINDEX; // The identity of the base symbol if any else INDEX. NativeType NATIVETYPE; // The symbol machine type if scalar };
Symbol_value— This Symbol value.
static inline ImmediateValue Symbol_value(const_Symbol this) { return Symbol_VALUE(this); }
Symbol_setValue— Set this Symbol value.
static inline void Symbol_setValue(Symbol this, ImmediateValue value) { *Symbol__VALUE(this) = value; }
Symbol_identity— This Symbol identity.
static inline uint32_t Symbol_identity(const_Symbol this) { return Symbol_IDENTITY(this); }
Symbol_index— This Symbol index.
static inline uint32_t Symbol_index(const_Symbol this) { return Symbol_INDEX(this); }
Symbol_name— This Symbol name.
static inline const char * Symbol_name(const_Symbol this) { return Symbol_NAME(this); }
Symbol_class— This Symbol SymbolClass.
static inline SymbolClass Symbol_class(const_Symbol this) { return Symbol_CLASS(this); }
Symbol_class— Set this Symbol SymbolClass.
static inline void Symbol_setClass(Symbol this, SymbolClass sclass) { *Symbol__CLASS(this) = sclass; }
Symbol_store— This Symbol SymbolStore.
static inline SymbolStore Symbol_store(const_Symbol this) { return Symbol_STORE(this); }
Symbol_setStore— Set this Symbol SymbolStore.
static inline void Symbol_setStore(Symbol this, SymbolStore sstore) { *Symbol__STORE(this) = sstore; }
Symbol_export— This Symbol SymbolExport.
static inline SymbolExport Symbol_export(const_Symbol this) { return Symbol_EXPORT(this); }
Symbol_setExport— Set this Symbol SymbolExport.
static inline void Symbol_setExport(Symbol this, SymbolExport sexport) { *Symbol__EXPORT(this) = sexport; }
Symbol_setClasses— Set the classes (CLASS, STORE, EXPORT) for the symbol.
static inline void Symbol_setClasses(Symbol this, SymbolClass sclass, SymbolStore sstore, SymbolExport sexport) { *Symbol__CLASS(this) = sclass; *Symbol__STORE(this) = sstore; *Symbol__EXPORT(this) = sexport; }
Symbol_flags— This Symbol flags.
static inline SymbolFlags Symbol_flags(const_Symbol this) { return Symbol_FLAGS(this); }
Symbol_setFlags— Set this Symbol flags.
static inline void Symbol_setFlags(Symbol this, SymbolFlags flags) { *Symbol__FLAGS(this) |= flags; }
Symbol_clearFlags— Reset this Symbol flags.
static inline void Symbol_clearFlags(Symbol this, SymbolFlags flags) { *Symbol__FLAGS(this) &= ~flags; }
Symbol_isSpill— Test if this Symbol is for spilling.
Currently no distinction between a spill symbol and an auto variable.
static inline bool Symbol_isSpill(const_Symbol symbol) { return Symbol_CLASS(symbol) == SymbolClass_VAR && Symbol_STORE(symbol) == SymbolStore_AUTO && Symbol_EXPORT(symbol) == SymbolExport_LOCAL; }
Symbol_isRoot— Returns true if the symbol is a root symbol.
A symbol which is not root is a leaf symbol. A root symbol does not need to be allocated.
static inline bool Symbol_isRoot(const_Symbol this) { SymbolClass sclass = Symbol_class(this); // Only VAR and CONST are leaf symbol. return !(sclass == SymbolClass_VAR || sclass == SymbolClass_CONST); }
Symbol_isAllocated— Returns true if the symbol is allocated: * the symbol is a root or * the symbol is a leaf and as a base root symbol
static inline bool Symbol_isAllocated(const_Symbol this) { return Symbol_isRoot(this) || Symbol_BASEINDEX(this) != Symbol_INDEX(this); }
Symbol_isTyped— Returns true if the symbol should be typed: * the symbol is var, const or a preg
static inline bool Symbol_isTyped(const_Symbol this) { return Symbol_class(this) == SymbolClass_VAR || Symbol_class(this) == SymbolClass_CONST || Symbol_class(this) == SymbolClass_PREG; }
Symbol_hasSize— Returns true if the symbol have a size: * the symbol is block, var, const or preg
static inline bool Symbol_hasSize(const_Symbol this) { return Symbol_class(this) == SymbolClass_BLOCK || Symbol_class(this) == SymbolClass_VAR || Symbol_class(this) == SymbolClass_CONST || Symbol_class(this) == SymbolClass_PREG; }
Symbol_nativeType— This Symbol machine type.
Only used for symbol with scalar types. If nativeType == NATIVETYPE_UNKNOWN the symbol is of unknown or non scalar type.
static inline NativeType Symbol_nativeType(const_Symbol this) { return Symbol_NATIVETYPE(this); }
Symbol_setNativeType— Set this Symbol basic type.
static inline void Symbol_setNativeType(Symbol this, NativeType nativeType) { Except_REQUIRE(Symbol_isTyped(this)); Except_REQUIRE(nativeType != NativeType__UNDEF); *Symbol__NATIVETYPE(this) = nativeType; *Symbol__SIZE(this) = NativeType_sizeOf(nativeType); }
Symbol_size— This Symbol size.
static inline uint64_t Symbol_size(const_Symbol this) { return Symbol_SIZE(this); }
Symbol_setSize— Set this Symbol size.
static inline void Symbol_setSize(Symbol this, uint64_t size) { Except_ENSURE(Symbol_hasSize(this)); *Symbol__SIZE(this) = size; }
Symbol_baseIndex— This Symbol base index.
static inline uint32_t Symbol_baseIndex(const_Symbol this) { return Symbol_BASEINDEX(this); }
Symbol_baseIndex— Set this Symbol base index.
static inline void Symbol_setBaseIndex(Symbol this, uint32_t baseIndex) { *Symbol__BASEINDEX(this) = baseIndex; }
Symbol_baseOffset— This Symbol base offset.
The offset is a positive value that locates the symbol into its base symbol container. If the symbol does not have a container base, then the offset is always 0.
static inline uint64_t Symbol_baseOffset(const_Symbol this) { return Symbol_BASEOFFSET(this); }
Symbol_baseOffset— Set this Symbol base offset.
static inline void Symbol_setBaseOffset(Symbol this, uint64_t offset) { *Symbol__BASEOFFSET(this) = offset; }
SymbolTable— Symbol table for Symbol(s).
struct SymbolTable_ { //@args Memory memory, int32_t estimate StringStore_ STRINGS_; //@access STRINGS SymbolTable__STRINGS_(this) HTable_ HTABLE_; //@access HTABLE SymbolTable__HTABLE_(this) //@access MEMORY HTable_memory(SymbolTable_HTABLE(this)) uint32_t INDEXGEN; // The number used for generated Symbol keys. const char *PREFIX; // The prefix used for generated Symbol names. };
SymbolTable_memory— This SymbolTable Memory
static inline Memory SymbolTable_memory(SymbolTable this) { return SymbolTable_MEMORY(this); }
SymbolTable_strings— This SymbolTable StringStore
static inline StringStore SymbolTable_strings(SymbolTable this) { return SymbolTable_STRINGS(this); }
SymbolTable_prefix— This SymbolTable name prefix.
static inline const char * SymbolTable_prefix(SymbolTable this) { return SymbolTable_PREFIX(this); }
SymbolTable_setPrefix— Set this SymbolTable name prefix.
static inline void SymbolTable_setPrefix(SymbolTable this, const char *prefix) { StringStore strings = SymbolTable_STRINGS(this); *SymbolTable__PREFIX(this) = StringStore_S(strings, prefix); }
SymbolTable_htable— For use by SymbolTable_FOREACH_Symbol.
static inline HTable SymbolTable_htable(SymbolTable this) { return SymbolTable_HTABLE(this); }
SymbolTable_search— Search this SymbolTable by index.
static inline Symbol SymbolTable_search(SymbolTable this, uint32_t index) { HTableKey key = (HTableKey)index; HTable htable = SymbolTable_htable(this); return HTable_search(htable, key); }
SymbolTable_insert— Insert a new symbol into this SymbolTable.
- Return
- NULL if a symbol with this
index
already exists.
Symbol SymbolTable_insert(SymbolTable this, uint32_t index, const char *name);
SymbolTable_lookup— Lookup a new symbol into this SymbolTable.
Symbol SymbolTable_lookup(SymbolTable this, uint32_t index, const char *name);
SymbolTable_makeSymbol— Make a new anonymous symbol.
The index generated for the new symbol has the 8 low bits cleared, to ensure they will not collide with any cgir_sym passed in.
Symbol SymbolTable_makeSymbol(SymbolTable this, const char *name);
SymbolTable_getBaseSymbol— Get the Symbol base of a symbol.
Always return a valid symbol. A symbol base may be the symbol itself if the symbol is self contained, in this case the symbol baseOffset is always 0. Otherwise the symbol base is a symbol of class SymbolClass_BLOCK that is a container for this symbol, in this case the symbol baseOffset locates this symbol into the container block symbol. Only one level of symbol container is allowed. Thus a symbol of class SymbolClass_BLOCK has no base other than itself.
static inline Symbol SymbolTable_getBaseSymbol(SymbolTable this, Symbol symbol) { Symbol base = NULL; if (Symbol_BASEINDEX(symbol) == Symbol_INDEX(symbol)) { Except_CHECK(Symbol_BASEOFFSET(symbol) == 0); base = symbol; } base = SymbolTable_search(this, Symbol_BASEINDEX(symbol)); Except_ENSURE(base != NULL); return base; }