1
// Inferno utils/8c/sgen.c
2
// http://code.google.com/p/inferno-os/source/browse/utils/8c/sgen.c
4
// Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved.
5
// Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net)
6
// Portions Copyright © 1997-1999 Vita Nuova Limited
7
// Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuova.com)
8
// Portions Copyright © 2004,2006 Bruce Ellis
9
// Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net)
10
// Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others
11
// Portions Copyright © 2009 The Go Authors. All rights reserved.
13
// Permission is hereby granted, free of charge, to any person obtaining a copy
14
// of this software and associated documentation files (the "Software"), to deal
15
// in the Software without restriction, including without limitation the rights
16
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
// copies of the Software, and to permit persons to whom the Software is
18
// furnished to do so, subject to the following conditions:
20
// The above copyright notice and this permission notice shall be included in
21
// all copies or substantial portions of the Software.
23
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
34
gtext(Sym *s, int32 stkoff)
39
if(!(textflag & NOSPLIT))
41
else if(stkoff >= 128)
42
yyerror("stack frame too large for NOSPLIT function");
44
gpseudo(ATEXT, s, nodconst(stkoff));
45
p->to.type = D_CONST2;
64
/* welcome to commute */
72
if(r->complex > l->complex) {
83
if(!typechlp[n->type->etype])
86
if(n->op == OASHL && n->right->op == OCONST){
94
* calculate addressability as follows
95
* NAME ==> 10/11 name+value(SB/SP)
96
* REGISTER ==> 12 register
99
* &(10) ==> 13 $name+value(SB)
100
* &(11) ==> 1 $name+value(SP)
101
* (13) + (20) ==> 13 fold constants
102
* (1) + (20) ==> 1 fold constants
103
* *(13) ==> 10 back to name
104
* *(1) ==> 11 back to name
106
* (20) * (X) ==> 7 multiplier in indexing
107
* (X,7) + (13,1) ==> 8 adder in indexing (addresses)
108
* (8) ==> &9(OINDEX) index, almost addressable
109
* 100 extern register
111
* calculate complexity (number of registers)
132
if(n->class == CPARAM || n->class == CAUTO)
160
if(n->type->etype != TIND)
173
l->xoffset += r->vconst;
184
/* l is the base, r is the index */
206
/* r is the base, l is the index */
211
if(n->addable == 8 && !side(n)) {
213
l = new1(OINDEX, idx.basetree, idx.regtree);
214
l->scale = idx.scale;
216
l->complex = l->right->complex;
217
l->type = l->left->type;
274
r->type = types[TINT];
288
r->type = types[TINT];
299
r->type = types[TINT];
354
n->complex = l->complex;
356
if(r->complex == n->complex)
357
n->complex = r->complex+1;
359
if(r->complex > n->complex)
360
n->complex = r->complex;
386
if(r->complex >= l->complex) {
387
n->complex = l->complex + 3;
388
if(r->complex > n->complex)
389
n->complex = r->complex;
391
n->complex = r->complex + 3;
392
if(l->complex > n->complex)
393
n->complex = l->complex;
403
if(r->complex >= l->complex) {
404
n->complex = l->complex + 2;
405
if(r->complex > n->complex)
406
n->complex = r->complex;
408
n->complex = r->complex + 2;
409
if(l->complex > n->complex)
410
n->complex = l->complex;
419
* immediate operators, make const on right
421
if(l->op == OCONST) {
438
* compare operators, make const on left
440
if(r->op == OCONST) {
443
n->op = invrel[relindex(n->op)];
459
if(l->addable == 1 || l->addable == 13 || r->complex > l->complex) {
465
if(l->addable != 7) {
469
if(l->right->addable == 20) {
470
idx.regtree = l->left;
471
idx.scale = 1 << l->right->vconst;
473
if(l->left->addable == 20) {
474
idx.regtree = l->right;
475
idx.scale = 1 << l->left->vconst;
477
diag(n, "bad index");
481
print("scale = %d\n", idx.scale);
482
prtree(idx.regtree, "index");
483
prtree(idx.basetree, "base");