Support local register variables

Similar to GCC a local asm register variable enforces the use of a
specified register in asm operands (and doesn't otherwise
matter).  Works only if the variable is directly mentioned as
operand.  For that we now generally store a backpointer from
an SValue to a Sym when the SValue was the result of unary()
parsing a symbol identifier.
This commit is contained in:
Michael Matz
2016-10-06 04:05:30 +02:00
parent 3bc9c325c5
commit f081acbfba
4 changed files with 58 additions and 6 deletions

8
tcc.h
View File

@ -372,7 +372,8 @@ typedef struct SValue {
unsigned short r2; /* second register, used for 'long long'
type. If not used, set to VT_CONST */
CValue c; /* constant, if VT_CONST */
struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST) */
struct Sym *sym; /* symbol, if (VT_SYM | VT_CONST), or if
result of unary() for an identifier. */
} SValue;
struct Attribute {
@ -407,7 +408,7 @@ typedef struct Sym {
int scope; /* scope level for locals */
};
union {
long r; /* associated register */
long r; /* associated register or VT_CONST/VT_LOCAL and LVAL type */
struct Attribute a;
};
union {
@ -416,7 +417,7 @@ typedef struct Sym {
};
CType type; /* associated type */
union {
struct Sym *next; /* next related symbol */
struct Sym *next; /* next related symbol (for fields and anoms) */
long jnext; /* next jump label */
};
struct Sym *prev; /* prev symbol in stack */
@ -1542,6 +1543,7 @@ ST_FUNC void gen_expr32(ExprValue *pe);
ST_FUNC void gen_expr64(ExprValue *pe);
#endif
ST_FUNC void asm_opcode(TCCState *s1, int opcode);
ST_FUNC int asm_parse_regvar(int t);
ST_FUNC void asm_compute_constraints(ASMOperand *operands, int nb_operands, int nb_outputs, const uint8_t *clobber_regs, int *pout_reg);
ST_FUNC void subst_asm_operand(CString *add_str, SValue *sv, int modifier);
ST_FUNC void asm_gen_code(ASMOperand *operands, int nb_operands, int nb_outputs, int is_output, uint8_t *clobber_regs, int out_reg);