Exemplo n.º 1
0
        internal Assembler()
        {
            _codeBuffer  = new CodeBuffer(this);
            _codeContext = new CodeContext(this);

            if (Constants.X64)
            {
                Zdi = new GpRegister(Cpu.Registers.Rdi);
                Zsi = new GpRegister(Cpu.Registers.Rsi);
                Zbp = new GpRegister(Cpu.Registers.Rbp);
                Zsp = new GpRegister(Cpu.Registers.Rsp);
                Zbx = new GpRegister(Cpu.Registers.Rbx);
                Zdx = new GpRegister(Cpu.Registers.Rdx);
                Zcx = new GpRegister(Cpu.Registers.Rcx);
                Zax = new GpRegister(Cpu.Registers.Rax);
            }
            else
            {
                Zdi = new GpRegister(Cpu.Registers.Edi);
                Zsi = new GpRegister(Cpu.Registers.Esi);
                Zbp = new GpRegister(Cpu.Registers.Ebp);
                Zsp = new GpRegister(Cpu.Registers.Esp);
                Zbx = new GpRegister(Cpu.Registers.Ebx);
                Zdx = new GpRegister(Cpu.Registers.Edx);
                Zcx = new GpRegister(Cpu.Registers.Ecx);
                Zax = new GpRegister(Cpu.Registers.Eax);
            }

            _id                 = _idGenerator++;
            _features          |= AssemblerFeatures.OptimizedAlign;
            _instructionOptions = InstructionOptions.None;
        }
Exemplo n.º 2
0
        public override string ToString()
        {
            var buf = new CodeBuffer();

            Write(buf);

            return(buf.ToString());
        }
Exemplo n.º 3
0
 internal override void GenSlurpBytes(CodeBuffer cb, string b, string s, string l)
 {
     cb.Append("{\n");
     cb.Append("int i = org.apache.hadoop.record.Utils.readVInt(" + b + ", " + s + ");\n"
               );
     cb.Append("int z = org.apache.hadoop.record.Utils.getVIntSize(i);\n");
     cb.Append(s + "+=(z+i); " + l + "-= (z+i);\n");
     cb.Append("}\n");
 }
Exemplo n.º 4
0
 internal override void GenSlurpBytes(CodeBuffer cb, string b, string s, string l)
 {
     cb.Append("{\n");
     cb.Append("if (" + l + "<4) {\n");
     cb.Append("throw new java.io.IOException(\"Float is exactly 4 bytes." + " Provided buffer is smaller.\");\n"
               );
     cb.Append("}\n");
     cb.Append(s + "+=4; " + l + "-=4;\n");
     cb.Append("}\n");
 }
Exemplo n.º 5
0
 // In Binary format, boolean is written as byte. true = 1, false = 0
 internal override void GenSlurpBytes(CodeBuffer cb, string b, string s, string l)
 {
     cb.Append("{\n");
     cb.Append("if (" + l + "<1) {\n");
     cb.Append("throw new java.io.IOException(\"Boolean is exactly 1 byte." + " Provided buffer is smaller.\");\n"
               );
     cb.Append("}\n");
     cb.Append(s + "++; " + l + "--;\n");
     cb.Append("}\n");
 }
Exemplo n.º 6
0
 internal override void GenGetSet(CodeBuffer cb, string fname)
 {
     cb.Append("virtual const " + this.GetType() + "& get" + JType.ToCamelCase(fname)
               + "() const {\n");
     cb.Append("return " + fname + ";\n");
     cb.Append("}\n");
     cb.Append("virtual " + this.GetType() + "& get" + JType.ToCamelCase(fname) + "() {\n"
               );
     cb.Append("return " + fname + ";\n");
     cb.Append("}\n");
 }
Exemplo n.º 7
0
        public override void Write(CodeBuffer buf)
        {
            buf.Append("case ").Append(Exp).AppendLine(" of");
            buf.Indent();
            foreach (var(pred, body) in Cases)
            {
                buf.Append(pred).AppendLine(" ->");
                buf.Indented(() => buf.AppendLine(body));
            }

            buf.DeIndent();
        }
Exemplo n.º 8
0
        public override void Write(CodeBuffer buf)
        {
            buf.AppendLine(Type);

            var headerItems = new List <string>();

            headerItems.Add(Name);
            headerItems.AddRange(Params);
            headerItems.Add("=");
            buf.AppendLine(string.Join(' ', headerItems));
            buf.Indented(() => buf.AppendLine(Body));
        }
Exemplo n.º 9
0
 internal override void GenCompareBytes(CodeBuffer cb)
 {
     cb.Append("{\n");
     cb.Append("int i1 = org.apache.hadoop.record.Utils.readVInt(b1, s1);\n");
     cb.Append("int i2 = org.apache.hadoop.record.Utils.readVInt(b2, s2);\n");
     cb.Append("if (i1 != i2) {\n");
     cb.Append("return ((i1-i2) < 0) ? -1 : 0;\n");
     cb.Append("}\n");
     cb.Append("int z1 = org.apache.hadoop.record.Utils.getVIntSize(i1);\n");
     cb.Append("int z2 = org.apache.hadoop.record.Utils.getVIntSize(i2);\n");
     cb.Append("s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n");
     cb.Append("}\n");
 }
Exemplo n.º 10
0
 // In Binary format, boolean is written as byte. true = 1, false = 0
 internal override void GenCompareBytes(CodeBuffer cb)
 {
     cb.Append("{\n");
     cb.Append("if (l1<1 || l2<1) {\n");
     cb.Append("throw new java.io.IOException(\"Boolean is exactly 1 byte." + " Provided buffer is smaller.\");\n"
               );
     cb.Append("}\n");
     cb.Append("if (b1[s1] != b2[s2]) {\n");
     cb.Append("return (b1[s1]<b2[s2])? -1 : 0;\n");
     cb.Append("}\n");
     cb.Append("s1++; s2++; l1--; l2--;\n");
     cb.Append("}\n");
 }
Exemplo n.º 11
0
        public override void Write(CodeBuffer buf)
        {
            for (var i = 0; i < Exprs.Count; i++)
            {
                var expr = Exprs[i];
                if (i == 0)
                {
                    buf.AppendLine(expr.ToString());
                    continue;
                }

                buf.Append("|> ").AppendLine(expr);
            }
        }
Exemplo n.º 12
0
 internal override void GenCompareBytes(CodeBuffer cb)
 {
     cb.Append("{\n");
     cb.Append("int i1 = org.apache.hadoop.record.Utils.readVInt(b1, s1);\n");
     cb.Append("int i2 = org.apache.hadoop.record.Utils.readVInt(b2, s2);\n");
     cb.Append("int z1 = org.apache.hadoop.record.Utils.getVIntSize(i1);\n");
     cb.Append("int z2 = org.apache.hadoop.record.Utils.getVIntSize(i2);\n");
     cb.Append("s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n");
     cb.Append("int r1 = org.apache.hadoop.record.Utils.compareBytes(b1,s1,i1,b2,s2,i2);\n"
               );
     cb.Append("if (r1 != 0) { return (r1<0)?-1:0; }\n");
     cb.Append("s1+=i1; s2+=i2; l1-=i1; l1-=i2;\n");
     cb.Append("}\n");
 }
Exemplo n.º 13
0
 internal override void GenCompareBytes(CodeBuffer cb)
 {
     cb.Append("{\n");
     cb.Append("if (l1<8 || l2<8) {\n");
     cb.Append("throw new java.io.IOException(\"Double is exactly 8 bytes." + " Provided buffer is smaller.\");\n"
               );
     cb.Append("}\n");
     cb.Append("double d1 = org.apache.hadoop.record.Utils.readDouble(b1, s1);\n");
     cb.Append("double d2 = org.apache.hadoop.record.Utils.readDouble(b2, s2);\n");
     cb.Append("if (d1 != d2) {\n");
     cb.Append("return ((d1-d2) < 0) ? -1 : 0;\n");
     cb.Append("}\n");
     cb.Append("s1+=8; s2+=8; l1-=8; l2-=8;\n");
     cb.Append("}\n");
 }
Exemplo n.º 14
0
 internal override void GenCompareBytes(CodeBuffer cb)
 {
     cb.Append("{\n");
     cb.Append("if (l1<4 || l2<4) {\n");
     cb.Append("throw new java.io.IOException(\"Float is exactly 4 bytes." + " Provided buffer is smaller.\");\n"
               );
     cb.Append("}\n");
     cb.Append("float f1 = org.apache.hadoop.record.Utils.readFloat(b1, s1);\n");
     cb.Append("float f2 = org.apache.hadoop.record.Utils.readFloat(b2, s2);\n");
     cb.Append("if (f1 != f2) {\n");
     cb.Append("return ((f1-f2) < 0) ? -1 : 0;\n");
     cb.Append("}\n");
     cb.Append("s1+=4; s2+=4; l1-=4; l2-=4;\n");
     cb.Append("}\n");
 }
Exemplo n.º 15
0
 public override void Write(CodeBuffer buf)
 {
     buf.Append("type ").Append(Name).AppendLine(" =");
     buf.Indented(() => {
         for (var i = 0; i < Alternatives.Count; i++)
         {
             var altName = Alternatives[i];
             if (i > 0)
             {
                 buf.Append("| ").AppendLine(altName);
             }
             else
             {
                 buf.Indented(() => buf.AppendLine(altName));
             }
         }
     });
 }
Exemplo n.º 16
0
        public override void Write(CodeBuffer buf)
        {
            buf.Append("type alias ").Append(Name).AppendLine(" =");
            buf.Indented(() => {
                var i = 0;
                foreach (var field in Fields)
                {
                    if (i == 0)
                    {
                        buf.Append("{ ");
                    }
                    else
                    {
                        buf.Append(", ");
                    }

                    buf.Append(field.Key).Append(" : ").AppendLine(field.Value);
                    i++;
                }

                buf.AppendLine("}");
            });
        }
Exemplo n.º 17
0
 internal override void GenHashCode(CodeBuffer cb, string fname)
 {
     cb.Append(Consts.RioPrefix + "ret = Float.floatToIntBits(" + fname + ");\n");
 }
Exemplo n.º 18
0
 internal override void GenClone(CodeBuffer cb, string fname)
 {
     cb.Append(Consts.RioPrefix + "other." + fname + " = (" + this.GetType() + ") this."
               + fname + ".clone();\n");
 }
Exemplo n.º 19
0
 public override void Write(CodeBuffer buf)
 {
     buf.Append("( ");
     buf.Append(Elements.ConvertAll(e => e.ToString()).Join(", "));
     buf.Append(" )");
 }
Exemplo n.º 20
0
            internal override void GenHashCode(CodeBuffer cb, string fname)
            {
                string tmp = "Double.doubleToLongBits(" + fname + ")";

                cb.Append(Consts.RioPrefix + "ret = (int)(" + tmp + "^(" + tmp + ">>>32));\n");
            }
Exemplo n.º 21
0
 public override void Write(CodeBuffer buf)
 {
     buf.Append(Rator).Append(" ").Append(string.Join(' ', Rands.ConvertAll(n => $"({n})")));
 }
Exemplo n.º 22
0
 internal override void GenEquals(CodeBuffer cb, string fname, string peer)
 {
     cb.Append(Consts.RioPrefix + "ret = " + fname + ".equals(" + peer + ");\n");
 }
Exemplo n.º 23
0
 public override void Write(CodeBuffer buf)
 {
     buf.Append(Name);
 }
Exemplo n.º 24
0
 internal override void GenHashCode(CodeBuffer cb, string fname)
 {
     cb.Append(Consts.RioPrefix + "ret = (" + fname + ")?0:1;\n");
 }
Exemplo n.º 25
0
 internal override void GenCompareTo(CodeBuffer cb, string fname, string other)
 {
     cb.Append(Consts.RioPrefix + "ret = (" + fname + " == " + other + ")? 0 : (" + fname
               + "?1:-1);\n");
 }
Exemplo n.º 26
0
 public override void Write(CodeBuffer buf)
 {
     buf.AppendLine($"(\\{string.Join(' ', Params)} ->");
     buf.Indented(() => buf.AppendLine(Body));
     buf.AppendLine(")");
 }
Exemplo n.º 27
0
 public override void Write(CodeBuffer buf)
 {
     buf.Append($"\"{Content}\"");
 }
Exemplo n.º 28
0
 internal override void GenHashCode(CodeBuffer cb, string fname)
 {
     cb.Append(Consts.RioPrefix + "ret = (int) (" + fname + "^(" + fname + ">>>32));\n"
               );
 }
Exemplo n.º 29
0
 internal override void GenClone(CodeBuffer cb, string fname)
 {
     cb.Append(Consts.RioPrefix + "other." + fname + " = this." + fname + ";\n");
 }
Exemplo n.º 30
0
 public abstract void Write(CodeBuffer buf);