}
}
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+ /* TODO */
+ return 1;
+}
+
/**
* swap the primary and secondary registers
*/
output_decimal(num);
}
+static void describe_access(SYMBOL *sym)
+{
+ if (sym->storage == LSTATIC)
+ print_label(sym->offset);
+ else if (sym->storage == AUTO || sym->storage == DEFAUTO) {
+ output_number(sym->offset - stkp);
+ output_string(",s");
+ } else
+ output_string(sym->name);
+ newline();
+}
+
/**
* fetch a static memory cell into the primary register
* @param sym
void gen_get_memory(SYMBOL *sym) {
if ((sym->identity != POINTER) && (sym->type == CCHAR)) {
output_with_tab("ldb ");
- output_string(sym->name);
- newline ();
+ describe_access(sym);
output_line("sex");
} else if ((sym->identity != POINTER) && (sym->type == UCHAR)) {
output_with_tab("ldb ");
- output_string(sym->name);
- newline();
+ describe_access(sym);
output_line("clr a");
} else {
output_with_tab ("ldd ");
- output_string(sym->name);
- newline ();
+ describe_access(sym);
}
}
* @param sym
*/
void gen_put_memory(SYMBOL *sym) {
- if ((sym->identity != POINTER) && (sym->type & CCHAR)) {
+ if ((sym->identity != POINTER) && (sym->type & CCHAR))
output_with_tab ("stb ");
- output_string(sym->name);
- } else {
+ else
output_with_tab("std ");
- output_string(sym->name);
- }
- newline ();
+ describe_access(sym);
}
/**
}
}
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+ /* Never indirect, use s relative because our CPU rocks */
+ return 0;
+}
+
/**
* swap the primary and secondary registers
*/
}
}
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+ /* FIXME: TODO - we can avoid indirecting LSTATIC */
+ return 1;
+}
+
+
/**
* swap the primary and secondary registers
*/
output_byte(')');
}
+static void describe_access(SYMBOL *sym)
+{
+ output_byte('(');
+ if (sym->storage == LSTATIC) {
+ print_label(sym->offset);
+ } else if (sym->storage == AUTO || sym->storage == DEFAUTO) {
+ output_number(sym->offset);
+ output_string("+fp");
+ } else
+ output_string(sym->name);
+ output_byte(')');
+ newline();
+}
+
/**
* fetch a static memory cell into the primary register
* @param sym
*/
void gen_get_memory(SYMBOL *sym) {
- if ((sym->identity != POINTER) && (sym->type == CCHAR)) {
+ if ((sym->identity != POINTER) && (sym->type == CCHAR))
output_with_tab ("loadsb r1 ");
- output_bracketed(sym->name);
- newline ();
- } else if ((sym->identity != POINTER) && (sym->type == UCHAR)) {
+ else if ((sym->identity != POINTER) && (sym->type == UCHAR))
output_with_tab("loadub r1 ");
- output_bracketed(sym->name);
- newline();
- } else {
+ else
output_with_tab ("load r1 ");
- output_bracketed(sym->name);
- newline ();
- }
+ describe_access(sym);
}
/**
* @param sym
*/
void gen_put_memory(SYMBOL *sym) {
- if ((sym->identity != POINTER) && (sym->type & CCHAR)) {
+ if ((sym->identity != POINTER) && (sym->type & CCHAR))
output_with_tab ("storeb r1 ");
- output_bracketed(sym->name);
- } else {
+ else
output_with_tab("store r1 ");
- output_bracketed(sym->name);
- }
- newline ();
+ describe_access(sym);
}
/**
}
}
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+ return 0;
+}
+
/**
* swap the primary and secondary registers
*/
output_decimal(num);
}
+static void output_number_signed(int num)
+{
+ if (num > 0)
+ output_byte('+');
+ else
+ output_decimal(num);
+}
+
static void output_bracketed(char *p)
{
output_byte('(');
output_byte(')');
}
+static void describe_access(SYMBOL *sym)
+{
+ if (sym->storage == LSTATIC) {
+ output_byte('(');
+ print_label(sym->offset);
+ output_byte(')');
+ } else if (sym->storage == AUTO || sym->storage == DEFAUTO) {
+ output_string("(ix");
+ output_number_signed(sym->offset - stkp);
+ output_byte(')');
+ } else
+ output_string(sym->name);
+ newline();
+}
+
+
/**
* fetch a static memory cell into the primary register
* @param sym
}
}
+/**
+ * platform level analysis of whether a symbol access needs to be
+ * direct or indirect (globals are always direct)
+ */
+int gen_indirected(SYMBOL *s)
+{
+ if (s->storage == LSTATIC)
+ return 0;
+/* if (abs(s->offset) < 124 && (s->type == CCHAR || s->type == UCHAR))
+ return 0; */
+ return 1;
+}
+
/**
* swap the primary and secondary registers
*/
return(0);
}
if (symname (sname)) {
- if ((symbol_table_idx = find_locale(sname)) > -1) {
- symbol = &symbol_table[symbol_table_idx];
+ int local = 1;
+ symbol_table_idx = find_locale(sname);
+ if (symbol_table_idx == -1) {
+ local = 0;
+ symbol_table_idx = find_global(sname);
+ /* Only valid undeclared name is a function reference */
+ if (symbol_table_idx == -1) {
+ blanks();
+ if (ch() != '(')
+ error("undeclared variable");
+ symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC);
+ symbol = &symbol_table[symbol_table_idx];
+ lval->symbol = symbol;
+ lval->indirect = 0;
+ return 0;
+ }
+ }
+ symbol = &symbol_table[symbol_table_idx];
+
+ if (local && gen_indirected(symbol)) {
reg = gen_get_locale(symbol);
lval->symbol = symbol;
lval->indirect = symbol->type;
}
return FETCH | reg;
}
- if ((symbol_table_idx = find_global(sname)) > -1) {
- symbol = &symbol_table[symbol_table_idx];
- if (symbol->identity != FUNCTION) {
- lval->symbol = symbol;
- lval->indirect = 0;
- if (symbol->type == STRUCT) {
- lval->tagsym = &tag_table[symbol->tagidx];
- }
- if (symbol->identity != ARRAY &&
- (symbol->identity != VARIABLE || symbol->type != STRUCT)) {
- if (symbol->identity == POINTER) {
- lval->ptr_type = symbol->type;
- }
- return FETCH | HL_REG;
+ /* Globals and anything we can directly access */
+ if (symbol->identity != FUNCTION) {
+ lval->symbol = symbol;
+ lval->indirect = 0;
+ if (symbol->type == STRUCT) {
+ lval->tagsym = &tag_table[symbol->tagidx];
+ }
+ if (symbol->identity != ARRAY &&
+ (symbol->identity != VARIABLE || symbol->type != STRUCT)) {
+ if (symbol->identity == POINTER) {
+ lval->ptr_type = symbol->type;
}
+ return FETCH | HL_REG;
+ }
+
+ if (symbol->storage == LSTATIC)
+ gen_get_locale(symbol);
+ else {
gen_immediate();
output_string(symbol->name);
newline();
- lval->indirect = symbol->type;
- lval->ptr_type = symbol->type;
- return 0;
}
+ lval->indirect = symbol->type;
+ lval->ptr_type = symbol->type;
+ return 0;
}
- blanks();
- if (ch() != '(')
- error("undeclared variable");
- symbol_table_idx = add_global(sname, FUNCTION, CINT, 0, PUBLIC);
- symbol = &symbol_table[symbol_table_idx];
- lval->symbol = symbol;
- lval->indirect = 0;
- return 0;
}
lval->symbol = 0;
lval->indirect = 0;
extern void gen_get_memory(SYMBOL *sym);
extern int gen_get_locale(SYMBOL *sym);
extern void gen_put_memory(SYMBOL *sym);
+extern int gen_indirected(SYMBOL *sym);
extern void gen_put_indirect(char typeobj);
extern void gen_get_indirect(char typeobj, int reg);
extern void gen_swap(void);