1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
/*
Clif - A C-like Interpreter Framework
Copyright (C) 1998, L. Koren
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
struct var_s
{
char *adr;
int offset;
char *name;
};
#include <stdio.h>
#include "allocx.h"
#include "flags.h"
#include "global.h"
#include "pso.h"
#include "tables.h"
#include "type.h"
#include "struct.h"
#include "comp_maint.h"
#include "instr.h"
#include "geninstr.h"
/* Lookup in tables of local variables, if the variable is not found
in the table of global variables. Setting of addresses for code
generation. */
void
lookup_tables (var_name, variable)
char *var_name;
struct var_s variable[];
{
struct ident_tab_loc *loc_var;
if (NULL == (loc_var = point_loc (var_name)))
{
struct ident_tab *var;
var = point (var_name);
if (NULL == var)
COMPILE_ONLY;
if ((STRUCT_P(var->type)
|| UNION_P(var->type))
&& -1 == add_to_ident_list ())
COMPILE_ONLY;
variable[++set].adr = var->adr;
variable[set].name = var_name;
variable[set].offset = 0;
type_com[set] = var->type;
}
else
{
/* Address is non NULL only if the
local variable is declared static. */
if (NULL != loc_var->adr)
{
variable[set].offset = 0;
variable[set].adr = loc_var->adr;
variable[set].name = var_name;
}
else
{
/* First part of the offset is set in the
point_loc function. */
variable[set].offset += loc_var->offset;
variable[set].adr = NULL;
variable[set].name = var_name;
}
type_com[set] = loc_var->type;
}
if (NULL == type_com[set]->output)
type_ac[set] = type_com[set]->attribute.arit_class;
else if (LOCAL_P(type_com[set])
|| REMOTE_P(type_com[set]))
{
type_ac[set] =
type_com[set]->output->attribute.arit_class;
proc_name_text[++proc] = text;
}
else if (ARRAY_P(type_com[set]))
{
type_ac[set] =
type_com[set]->output->attribute.arit_class;
array_subscript (type_com[set]->input);
}
else if (POINTER_P(type_com[set]))
type_ac[set] = LONG_AC | INTEGER;
kodp4 = kodp;
if (0 < variable[set].offset)
{
if (call_by_value)
{
if (ARRAY_P(type_com[set]))
{
GEN_PUSHArr(variable[set].offset);
}
else
{
GEN_PUSHAr(variable[set].offset);
}
}
else if (call_by_reference)
{
GEN_PUSHArr(variable[set].offset);
}
GENCODE;
}
else if (0 > variable[set].offset)
{
GEN_PUSHAr(variable[set].offset); GENCODE;
}
else if (! LOCAL_P(type_com[set])
&& ! REMOTE_P(type_com[set]))
{
GEN_PUSHA(variable[set].adr); GENCODE;
}
}
/* The typedef structure (only the beginning part) is copied, if
any non simple part was inserted, i.e. pointer, function, array,
struct, etc. */
void
typedef_copy (type)
struct internal_type *type;
{
typeh[type_spec_count] = (struct internal_type *)
allocate (sizeof(struct internal_type),
scope_level > PERM ? BLOCK : PERM);
init_zero ((char *)typeh[type_spec_count],
sizeof(struct internal_type));
typeh[type_spec_count]->attribute.function_class =
SIMPLE;
typeh[type_spec_count]->attribute.type_qualifier =
UNDEF_TQ;
typeh[type_spec_count]->attribute.arit_class =
UNUSED_AC;
typeh[type_spec_count]->attribute.storage_class_specifier =
TYPEDEF_SC;
typeh[type_spec_count]->output = type;
}
|