]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/new6a/a.y
[dev.cc] cmd/new5a etc, cmd/internal/asm: edit to produce working Go code
[gostls13.git] / src / cmd / new6a / a.y
index 29011c7ffb05e478fd875918bc51f584132d6fde..f9217a00cd37ca2500a7cd8ceb8c76eeeacebae8 100644 (file)
 // THE SOFTWARE.
 
 %{
-#include <u.h>
-#include <stdio.h>     /* if we don't, bison will, and a.h re-#defines getc */
-#include <libc.h>
-#include "a.h"
-#include "../../runtime/funcdata.h"
+package main
+
+import (
+       "cmd/internal/asm"
+       "cmd/internal/obj"
+       "cmd/internal/obj/x86"
+)
 %}
-%union {
-       Sym     *sym;
-       vlong   lval;
-       double  dval;
-       char    sval[8];
-       Addr    addr;
-       Addr2   addr2;
+
+%union {
+       sym *asm.Sym
+       lval int64
+       dval float64
+       sval string
+       addr obj.Addr
+       addr2 Addr2
 }
+
 %left  '|'
 %left  '^'
 %left  '&'
 prog:
 |      prog 
        {
-               stmtline = lineno;
+               stmtline = asm.Lineno;
        }
        line
 
 line:
        LNAME ':'
        {
-               $1 = labellookup($1);
-               if($1->type == LLAB && $1->value != pc)
-                       yyerror("redeclaration of %s (%s)", $1->labelname, $1->name);
-               $1->type = LLAB;
-               $1->value = pc;
+               $1 = asm.LabelLookup($1);
+               if $1.Type == LLAB && $1.Value != int64(asm.PC) {
+                       yyerror("redeclaration of %s (%s)", $1.Labelname, $1.Name);
+               }
+               $1.Type = LLAB;
+               $1.Value = int64(asm.PC)
        }
        line
 |      ';'
@@ -87,34 +92,35 @@ line:
 inst:
        LNAME '=' expr
        {
-               $1->type = LVAR;
-               $1->value = $3;
+               $1.Type = LVAR;
+               $1.Value = $3;
        }
 |      LVAR '=' expr
        {
-               if($1->value != $3)
-                       yyerror("redeclaration of %s", $1->name);
-               $1->value = $3;
-       }
-|      LTYPE0 nonnon   { outcode($1, &$2); }
-|      LTYPE1 nonrem   { outcode($1, &$2); }
-|      LTYPE2 rimnon   { outcode($1, &$2); }
-|      LTYPE3 rimrem   { outcode($1, &$2); }
-|      LTYPE4 remrim   { outcode($1, &$2); }
-|      LTYPER nonrel   { outcode($1, &$2); }
-|      LTYPED spec1    { outcode($1, &$2); }
-|      LTYPET spec2    { outcode($1, &$2); }
-|      LTYPEC spec3    { outcode($1, &$2); }
-|      LTYPEN spec4    { outcode($1, &$2); }
-|      LTYPES spec5    { outcode($1, &$2); }
-|      LTYPEM spec6    { outcode($1, &$2); }
-|      LTYPEI spec7    { outcode($1, &$2); }
-|      LTYPEXC spec8   { outcode($1, &$2); }
-|      LTYPEX spec9    { outcode($1, &$2); }
-|      LTYPERT spec10  { outcode($1, &$2); }
-|      LTYPEG spec11   { outcode($1, &$2); }
-|      LTYPEPC spec12  { outcode($1, &$2); }
-|      LTYPEF spec13   { outcode($1, &$2); }
+               if $1.Value != $3 {
+                       yyerror("redeclaration of %s", $1.Name);
+               }
+               $1.Value = $3;
+       }
+|      LTYPE0 nonnon   { outcode(int($1), &$2); }
+|      LTYPE1 nonrem   { outcode(int($1), &$2); }
+|      LTYPE2 rimnon   { outcode(int($1), &$2); }
+|      LTYPE3 rimrem   { outcode(int($1), &$2); }
+|      LTYPE4 remrim   { outcode(int($1), &$2); }
+|      LTYPER nonrel   { outcode(int($1), &$2); }
+|      LTYPED spec1    { outcode(int($1), &$2); }
+|      LTYPET spec2    { outcode(int($1), &$2); }
+|      LTYPEC spec3    { outcode(int($1), &$2); }
+|      LTYPEN spec4    { outcode(int($1), &$2); }
+|      LTYPES spec5    { outcode(int($1), &$2); }
+|      LTYPEM spec6    { outcode(int($1), &$2); }
+|      LTYPEI spec7    { outcode(int($1), &$2); }
+|      LTYPEXC spec8   { outcode(int($1), &$2); }
+|      LTYPEX spec9    { outcode(int($1), &$2); }
+|      LTYPERT spec10  { outcode(int($1), &$2); }
+|      LTYPEG spec11   { outcode(int($1), &$2); }
+|      LTYPEPC spec12  { outcode(int($1), &$2); }
+|      LTYPEF spec13   { outcode(int($1), &$2); }
 
 nonnon:
        {
@@ -186,22 +192,22 @@ spec1:    /* DATA */
        nam '/' con ',' imm
        {
                $$.from = $1;
-               $$.from.scale = $3;
+               $$.from.Scale = int8($3);
                $$.to = $5;
        }
 
 spec2: /* TEXT */
        mem ',' imm2
        {
-               settext($1.sym);
+               asm.Settext($1.Sym);
                $$.from = $1;
                $$.to = $3;
        }
 |      mem ',' con ',' imm2
        {
-               settext($1.sym);
+               asm.Settext($1.Sym);
                $$.from = $1;
-               $$.from.scale = $3;
+               $$.from.Scale = int8($3);
                $$.to = $5;
        }
 
@@ -231,9 +237,10 @@ spec5:     /* SHL/SHR */
        {
                $$.from = $1;
                $$.to = $3;
-               if($$.from.index != D_NONE)
+               if $$.from.Index != x86.D_NONE {
                        yyerror("dp shift with lhs index");
-               $$.from.index = $5;
+               }
+               $$.from.Index = uint8($5);
        }
 
 spec6: /* MOVW/MOVL */
@@ -246,9 +253,10 @@ spec6:     /* MOVW/MOVL */
        {
                $$.from = $1;
                $$.to = $3;
-               if($$.to.index != D_NONE)
+               if $$.to.Index != x86.D_NONE {
                        yyerror("dp move with lhs index");
-               $$.to.index = $5;
+               }
+               $$.to.Index = uint8($5);
        }
 
 spec7:
@@ -273,7 +281,7 @@ spec8:      /* CMPPS/CMPPD */
        {
                $$.from = $1;
                $$.to = $3;
-               $$.to.offset = $5;
+               $$.to.Offset = $5;
        }
 
 spec9: /* shufl */
@@ -281,9 +289,10 @@ spec9:     /* shufl */
        {
                $$.from = $3;
                $$.to = $5;
-               if($1.type != D_CONST)
+               if $1.Type_ != x86.D_CONST {
                        yyerror("illegal constant");
-               $$.to.offset = $1.offset;
+               }
+               $$.to.Offset = $1.Offset;
        }
 
 spec10:        /* RET/RETF */
@@ -306,15 +315,16 @@ spec11:   /* GLOBL */
 |      mem ',' con ',' imm
        {
                $$.from = $1;
-               $$.from.scale = $3;
+               $$.from.Scale = int8($3);
                $$.to = $5;
        }
 
-spec12:        /* PCDATA */
+spec12:        /* asm.PCDATA */
        rim ',' rim
        {
-               if($1.type != D_CONST || $3.type != D_CONST)
-                       yyerror("arguments to PCDATA must be integer constants");
+               if $1.Type_ != x86.D_CONST || $3.Type_ != x86.D_CONST {
+                       yyerror("arguments to asm.PCDATA must be integer constants");
+               }
                $$.from = $1;
                $$.to = $3;
        }
@@ -322,10 +332,12 @@ spec12:   /* PCDATA */
 spec13:        /* FUNCDATA */
        rim ',' rim
        {
-               if($1.type != D_CONST)
+               if $1.Type_ != x86.D_CONST {
                        yyerror("index for FUNCDATA must be integer constant");
-               if($3.type != D_EXTERN && $3.type != D_STATIC)
+               }
+               if $3.Type_ != x86.D_EXTERN && $3.Type_ != x86.D_STATIC {
                        yyerror("value for FUNCDATA must be symbol reference");
+               }
                $$.from = $1;
                $$.to = $3;
        }
@@ -356,110 +368,111 @@ rel:
        con '(' LPC ')'
        {
                $$ = nullgen;
-               $$.type = D_BRANCH;
-               $$.offset = $1 + pc;
+               $$.Type_ = x86.D_BRANCH;
+               $$.Offset = $1 + int64(asm.PC);
        }
 |      LNAME offset
        {
-               $1 = labellookup($1);
+               $1 = asm.LabelLookup($1);
                $$ = nullgen;
-               if(pass == 2 && $1->type != LLAB)
-                       yyerror("undefined label: %s", $1->labelname);
-               $$.type = D_BRANCH;
-               $$.offset = $1->value + $2;
+               if asm.Pass == 2 && $1.Type != LLAB {
+                       yyerror("undefined label: %s", $1.Labelname);
+               }
+               $$.Type_ = x86.D_BRANCH;
+               $$.Offset = $1.Value + $2;
        }
 
 reg:
        LBREG
        {
                $$ = nullgen;
-               $$.type = $1;
+               $$.Type_ = int16($1);
        }
 |      LFREG
        {
                $$ = nullgen;
-               $$.type = $1;
+               $$.Type_ = int16($1);
        }
 |      LLREG
        {
                $$ = nullgen;
-               $$.type = $1;
+               $$.Type_ = int16($1);
        }
 |      LMREG
        {
                $$ = nullgen;
-               $$.type = $1;
+               $$.Type_ = int16($1);
        }
 |      LSP
        {
                $$ = nullgen;
-               $$.type = D_SP;
+               $$.Type_ = x86.D_SP;
        }
 |      LSREG
        {
                $$ = nullgen;
-               $$.type = $1;
+               $$.Type_ = int16($1);
        }
 |      LXREG
        {
                $$ = nullgen;
-               $$.type = $1;
+               $$.Type_ = int16($1);
        }
 imm2:
        '$' con2
        {
                $$ = nullgen;
-               $$.type = D_CONST;
-               $$.offset = $2;
+               $$.Type_ = x86.D_CONST;
+               $$.Offset = $2;
        }
 
 imm:
        '$' con
        {
                $$ = nullgen;
-               $$.type = D_CONST;
-               $$.offset = $2;
+               $$.Type_ = x86.D_CONST;
+               $$.Offset = $2;
        }
 |      '$' nam
        {
                $$ = $2;
-               $$.index = $2.type;
-               $$.type = D_ADDR;
+               $$.Index = uint8($2.Type_);
+               $$.Type_ = x86.D_ADDR;
                /*
-               if($2.type == D_AUTO || $2.type == D_PARAM)
+               if($2.Type_ == x86.D_AUTO || $2.Type_ == x86.D_PARAM)
                        yyerror("constant cannot be automatic: %s",
-                               $2.sym->name);
+                               $2.sym.Name);
                 */
        }
 |      '$' LSCONST
        {
                $$ = nullgen;
-               $$.type = D_SCONST;
-               memcpy($$.u.sval, $2, sizeof($$.u.sval));
+               $$.Type_ = x86.D_SCONST;
+               $$.U.Sval = ($2+"\x00\x00\x00\x00\x00\x00\x00\x00")[:8]
        }
 |      '$' LFCONST
        {
                $$ = nullgen;
-               $$.type = D_FCONST;
-               $$.u.dval = $2;
+               $$.Type_ = x86.D_FCONST;
+               $$.U.Dval = $2;
        }
 |      '$' '(' LFCONST ')'
        {
                $$ = nullgen;
-               $$.type = D_FCONST;
-               $$.u.dval = $3;
+               $$.Type_ = x86.D_FCONST;
+               $$.U.Dval = $3;
        }
 |      '$' '(' '-' LFCONST ')'
        {
                $$ = nullgen;
-               $$.type = D_FCONST;
-               $$.u.dval = -$4;
+               $$.Type_ = x86.D_FCONST;
+               $$.U.Dval = -$4;
        }
 |      '$' '-' LFCONST
        {
                $$ = nullgen;
-               $$.type = D_FCONST;
-               $$.u.dval = -$3;
+               $$.Type_ = x86.D_FCONST;
+               $$.U.Dval = -$3;
        }
 
 mem:
@@ -470,79 +483,79 @@ omem:
        con
        {
                $$ = nullgen;
-               $$.type = D_INDIR+D_NONE;
-               $$.offset = $1;
+               $$.Type_ = x86.D_INDIR+x86.D_NONE;
+               $$.Offset = $1;
        }
 |      con '(' LLREG ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+$3;
-               $$.offset = $1;
+               $$.Type_ = int16(x86.D_INDIR+$3);
+               $$.Offset = $1;
        }
 |      con '(' LSP ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+D_SP;
-               $$.offset = $1;
+               $$.Type_ = int16(x86.D_INDIR+x86.D_SP);
+               $$.Offset = $1;
        }
 |      con '(' LSREG ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+$3;
-               $$.offset = $1;
+               $$.Type_ = int16(x86.D_INDIR+$3);
+               $$.Offset = $1;
        }
 |      con '(' LLREG '*' con ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+D_NONE;
-               $$.offset = $1;
-               $$.index = $3;
-               $$.scale = $5;
-               checkscale($$.scale);
+               $$.Type_ = int16(x86.D_INDIR+x86.D_NONE);
+               $$.Offset = $1;
+               $$.Index = uint8($3);
+               $$.Scale = int8($5);
+               checkscale($$.Scale);
        }
 |      con '(' LLREG ')' '(' LLREG '*' con ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+$3;
-               $$.offset = $1;
-               $$.index = $6;
-               $$.scale = $8;
-               checkscale($$.scale);
+               $$.Type_ = int16(x86.D_INDIR+$3);
+               $$.Offset = $1;
+               $$.Index = uint8($6);
+               $$.Scale = int8($8);
+               checkscale($$.Scale);
        }
 |      con '(' LLREG ')' '(' LSREG '*' con ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+$3;
-               $$.offset = $1;
-               $$.index = $6;
-               $$.scale = $8;
-               checkscale($$.scale);
+               $$.Type_ = int16(x86.D_INDIR+$3);
+               $$.Offset = $1;
+               $$.Index = uint8($6);
+               $$.Scale = int8($8);
+               checkscale($$.Scale);
        }
 |      '(' LLREG ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+$2;
+               $$.Type_ = int16(x86.D_INDIR+$2);
        }
 |      '(' LSP ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+D_SP;
+               $$.Type_ = int16(x86.D_INDIR+x86.D_SP);
        }
 |      '(' LLREG '*' con ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+D_NONE;
-               $$.index = $2;
-               $$.scale = $4;
-               checkscale($$.scale);
+               $$.Type_ = int16(x86.D_INDIR+x86.D_NONE);
+               $$.Index = uint8($2);
+               $$.Scale = int8($4);
+               checkscale($$.Scale);
        }
 |      '(' LLREG ')' '(' LLREG '*' con ')'
        {
                $$ = nullgen;
-               $$.type = D_INDIR+$2;
-               $$.index = $5;
-               $$.scale = $7;
-               checkscale($$.scale);
+               $$.Type_ = int16(x86.D_INDIR+$2);
+               $$.Index = uint8($5);
+               $$.Scale = int8($7);
+               checkscale($$.Scale);
        }
 
 nmem:
@@ -553,25 +566,25 @@ nmem:
 |      nam '(' LLREG '*' con ')'
        {
                $$ = $1;
-               $$.index = $3;
-               $$.scale = $5;
-               checkscale($$.scale);
+               $$.Index = uint8($3);
+               $$.Scale = int8($5);
+               checkscale($$.Scale);
        }
 
 nam:
        LNAME offset '(' pointer ')'
        {
                $$ = nullgen;
-               $$.type = $4;
-               $$.sym = linklookup(ctxt, $1->name, 0);
-               $$.offset = $2;
+               $$.Type_ = int16($4);
+               $$.Sym = obj.Linklookup(asm.Ctxt, $1.Name, 0);
+               $$.Offset = $2;
        }
 |      LNAME '<' '>' offset '(' LSB ')'
        {
                $$ = nullgen;
-               $$.type = D_STATIC;
-               $$.sym = linklookup(ctxt, $1->name, 1);
-               $$.offset = $4;
+               $$.Type_ = x86.D_STATIC;
+               $$.Sym = obj.Linklookup(asm.Ctxt, $1.Name, 1);
+               $$.Offset = $4;
        }
 
 offset:
@@ -591,7 +604,7 @@ pointer:
        LSB
 |      LSP
        {
-               $$ = D_AUTO;
+               $$ = x86.D_AUTO;
        }
 |      LFP
 
@@ -599,7 +612,7 @@ con:
        LCONST
 |      LVAR
        {
-               $$ = $1->value;
+               $$ = $1.Value;
        }
 |      '-' con
        {
@@ -611,7 +624,7 @@ con:
        }
 |      '~' con
        {
-               $$ = ~$2;
+               $$ = ^$2;
        }
 |      '(' expr ')'
        {
@@ -621,23 +634,19 @@ con:
 con2:
        LCONST
        {
-               $$ = ($1 & 0xffffffffLL) +
-                       ((vlong)ArgsSizeUnknown << 32);
+               $$ = int64(uint64($1 & 0xffffffff) + (obj.ArgsSizeUnknown<<32))
        }
 |      '-' LCONST
        {
-               $$ = (-$2 & 0xffffffffLL) +
-                       ((vlong)ArgsSizeUnknown << 32);
+               $$ = int64(uint64(-$2 & 0xffffffff) + (obj.ArgsSizeUnknown<<32))
        }
 |      LCONST '-' LCONST
        {
-               $$ = ($1 & 0xffffffffLL) +
-                       (($3 & 0xffffLL) << 32);
+               $$ = ($1 & 0xffffffff) + (($3 & 0xffff) << 32);
        }
 |      '-' LCONST '-' LCONST
        {
-               $$ = (-$2 & 0xffffffffLL) +
-                       (($4 & 0xffffLL) << 32);
+               $$ = (-$2 & 0xffffffff) + (($4 & 0xffff) << 32);
        }
 
 expr:
@@ -664,11 +673,11 @@ expr:
        }
 |      expr '<' '<' expr
        {
-               $$ = $1 << $4;
+               $$ = $1 << uint($4);
        }
 |      expr '>' '>' expr
        {
-               $$ = $1 >> $4;
+               $$ = $1 >> uint($4);
        }
 |      expr '&' expr
        {