void EmitInstructions(List <Instruction> ins, AssemblyWriter writer) { // Write out code for (int i = 0; i < ins.Count; i++) { var xOp = ins[i]; if (xOp == null) { continue; } if (xOp.Emit) { string prefix = "\t\t\t"; if (xOp is Label) { var xLabel = (Label)xOp; writer.WriteLine(); prefix = "\t\t"; writer.Write(prefix); xLabel.WriteText(this, writer); writer.WriteLine(); } else { writer.Write(prefix); xOp.WriteText(this, writer); writer.WriteLine(); } } } }
public void EmitDecl(AssemblyWriter asmw, string varname) { asmw.WriteLine(varname + ": ISTRUC "+ Name); foreach (StructVar sv in Vars) { asmw.WriteLine("AT " + Name + "." + sv.Name + ", " + (sv.IsByte?"DB":"DW") + " 0"); } asmw.WriteLine("IEND"); }
public void Emit(AssemblyWriter asmw) { asmw.WriteLine("struc " + Name); foreach (StructVar sv in Vars) { sv.Emit(asmw); } asmw.WriteLine(".size:"); asmw.WriteLine("endstruc"); }
public void Emit(AssemblyWriter asmw) { if (!IsStruct) { asmw.WriteLine("." + Name + ": " + (IsByte?"RESB":"RESW") + " " + Size.ToString()); } else { asmw.WriteLine("." + Name + ": " + "RESB " + Type + ".size"); } }
public virtual void EmitFinalize(AssemblyWriter writer) { if (IsBootLoader) { writer.WriteLine("________________VATU__BOOTLOADER_SIGNATURE:"); writer.WriteLine("times 510 - ($-$$) db 0"); writer.WriteLine("dw 0xaa55"); } if (!IsLibrary) { writer.WriteLine("PROGRAM_END:"); } }
public virtual void EmitPrepare(AssemblyWriter writer) { // Emit writer.WriteLine("bits 16"); if (!IsLibrary) { writer.WriteLine("PROGRAM_ORG:"); } else { writer.WriteLine("extern PROGRAM_ORG"); writer.WriteLine("extern PROGRAM_END"); } // INT Install if (IsFlat) { EmitInterruptInstallCode(writer); } //// define //foreach (StructElement xMember in mStructs) //{ // xMember.Emit(writer); // writer.WriteLine(); //} // alloc vars if (!IsFlat) { writer.WriteLine(";section .bss"); } foreach (KeyValuePair <string, StructElement> p in DeclaredStructVars) { p.Value.EmitAlloc(writer, p.Key); writer.WriteLine(); } writer.WriteLine(); // define globals foreach (string ex in Globals) { writer.WriteLine("global\t" + ex); } writer.WriteLine(); }
public override void WriteText(AsmContext aAssembler, AssemblyWriter aOutput) { if (IsGlobal) { aOutput.Write("global "); aOutput.WriteLine(QualifiedName); } aOutput.Write(QualifiedName); aOutput.Write(":"); if (Comment.Length > 0) { aOutput.Write(" ;"); aOutput.Write(Comment); } }
void EmitInterruptInstallCode(AssemblyWriter writer) { if (!string.IsNullOrEmpty(EntryPoint)) { writer.WriteLine("global ___vatu_entry"); writer.WriteLine("___vatu_entry:"); } if (IsFlat) { writer.WriteLine("FINIT ; Initialize's the floating point unit"); } foreach (Instruction inst in mDefInstructions) { writer.Write("\t"); inst.WriteText(this, writer); writer.WriteLine(); } if (!IsLibrary) { interrupt_name = "______INSTALL_INTERRUPTS"; } else if (IsLibrary) { interrupt_name = "______INSTALL_INTERRUPTS_" + DateTime.Now.ToFileTimeUtc().ToString(); } if (!string.IsNullOrEmpty(EntryPoint)) { if (IsInterruptOverload && Interrupts.Count > 0) { writer.WriteLine("\t\tcall " + interrupt_name); } writer.Write("\t\tjmp " + EntryPoint); } writer.WriteLine(); }
public override void WriteText(AsmContext ec, AssemblyWriter aOutput) { if (RawAsm != null) { aOutput.WriteLine(RawAsm); return; } if (Labels != null) { aOutput.Write(Name); foreach (string lb in Labels) { aOutput.WriteLine(" dw " + lb); } aOutput.WriteLine(); return; } if (ReferenceName != null) { aOutput.Write(Name); aOutput.Write(" dw " + ReferenceName); aOutput.WriteLine(); return; } if (FloatValue.HasValue) { aOutput.Write(Name); aOutput.Write(" dd " + FloatValue.ToString().Replace(",", ".")); aOutput.WriteLine(); return; } if (StrVal != null) { if (IsGlobal) { aOutput.Write("global "); aOutput.WriteLine(Name); } if (string.IsNullOrEmpty(StrVal)) { aOutput.Write(Name); aOutput.Write(" times 256 db 0"); return; } aOutput.Write(Name); aOutput.Write(" db "); //foreach (char c in StrVal) //{ // if (c == '\r' || c == '\n') // { // if (!string.IsNullOrEmpty(last)) // strdecl+= "\"" + last + "\", "; // strdecl += b[i].ToString(); // strdecl += ","; // last = ""; // } // else last += c + ""; // i++; //} //if (!string.IsNullOrEmpty(last)) // strdecl += "\"" + last + "\""; //else strdecl = strdecl.Remove(strdecl.Length - 1, 1); if (!verbatim) { StringHelper.WriteNormalizedString(StrVal, aOutput); } else { aOutput.Write("\"" + StringHelper.StringFromVerbatimLiteral(StrVal) + "\""); } if (!StrConst) { aOutput.WriteLine(); aOutput.Write("\t\t times " + (255 - StrVal.Length).ToString() + " db 0"); } else { aOutput.Write(",0"); } return; } if (RawDefaultValue != null) { if (RawDefaultValue.Length == 0) { aOutput.Write(Name); aOutput.Write(":"); return; } if ((from item in RawDefaultValue group item by item into i select i).Count() > 1 || RawDefaultValue.Length < 10) { if (IsGlobal) { aOutput.Write("global "); aOutput.WriteLine(Name); } aOutput.Write(Name); aOutput.Write(" db "); for (int i = 0; i < (RawDefaultValue.Length - 1); i++) { aOutput.Write(RawDefaultValue[i]); aOutput.Write(", "); } aOutput.Write(RawDefaultValue.Last()); } else { //aOutputWriter.WriteLine("TIMES 0x50000 db 0"); if (IsGlobal) { aOutput.Write("global "); aOutput.WriteLine(Name); } aOutput.Write(Name); aOutput.Write(": TIMES "); aOutput.Write(RawDefaultValue.Length); aOutput.Write(" db "); aOutput.Write(RawDefaultValue[0]); } return; } if (UntypedDefaultValue != null) { StringBuilder xSB = new StringBuilder(); if (IsGlobal) { aOutput.Write("global "); aOutput.WriteLine(Name); } aOutput.Write(Name); aOutput.Write(" dw "); Func <object, string> xGetTextForItem = delegate(object aItem) { var xElementRef = aItem as ElementReference; if (xElementRef == null) { return((aItem ?? 0).ToString()); } else { if (xElementRef.Offset == 0) { return(xElementRef.Name); } return(xElementRef.Name + " + " + xElementRef.Offset); } }; for (int i = 0; i < (UntypedDefaultValue.Length - 1); i++) { aOutput.Write(xGetTextForItem(UntypedDefaultValue[i])); aOutput.Write(", "); } aOutput.Write(xGetTextForItem(UntypedDefaultValue.Last())); return; } throw new Exception("Situation unsupported!"); }
public virtual void Emit(AssemblyWriter writer) { // Optimize Optimize(); // prepare emit EmitPrepare(writer); // Write out readonly if (!IsFlat) { writer.WriteLine(";section .rodata"); } foreach (DataMember xMember in mCDataMembers) { writer.Write("\t"); if (xMember.IsComment) { writer.Write(xMember.Name); } else { xMember.WriteText(this, writer); } writer.WriteLine(); } writer.WriteLine(); // Write out data declarations if (!IsFlat) { writer.WriteLine(";section .data"); } foreach (DataMember xMember in mDataMembers) { writer.Write("\t"); if (xMember.IsComment) { writer.Write(xMember.Name); } else { xMember.WriteText(this, writer); } writer.WriteLine(); } // declare vars writer.WriteLine(); foreach (KeyValuePair <string, StructElement> p in DeclaredStructVars) { p.Value.EmitDecl(writer, p.Key); writer.WriteLine(); } writer.WriteLine(); if (!IsFlat) { writer.WriteLine(";section .text"); } if (!IsFlat) { // define externs foreach (string ex in Externals) { writer.WriteLine("extern\t" + ex); } writer.WriteLine(); } if (!IsFlat) { EmitInterruptInstallCode(writer); } if (IsInterruptOverload && Interrupts.Count > 0) { InstallINTInstruction iit = new InstallINTInstruction(Interrupts, interrupt_name); writer.WriteLine(); writer.Write("\t\t"); iit.WriteText(this, writer); } // Emit Code EmitInstructions(mInstructions, writer); EmitInstructions(AnonymousInstructions, writer); // Emit Finalize EmitFinalize(writer); }
public void EmitAlloc(AssemblyWriter asmw, string varname) { asmw.WriteLine(varname + ": RESB "+ Name + ".size"); }