~ubuntu-branches/ubuntu/oneiric/clif/oneiric

« back to all changes in this revision

Viewing changes to pso.c

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bunk
  • Date: 2002-01-25 14:05:49 UTC
  • Revision ID: james.westby@ubuntu.com-20020125140549-v5mmddxqlcrgzhd2
Tags: upstream-0.93
ImportĀ upstreamĀ versionĀ 0.93

Show diffs side-by-side

added added

removed removed

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