// calculate the address referenced by a memory instruction static Int32 MemOpAddr(Int32 PC, Int32 IR) { Int32 op = (IR >> 12) & 15; Boolean idx = ((IR & 0x800) != 0); Boolean ind = ((IR & 0x400) != 0); Boolean map = ((IR & 0x200) != 0); Int32 addr = IR & 511; if (map) { addr |= PC & 0x7e00; } DTag tag = DTag.Indirect; // if instruction is BRU* (non-indexed) and destination is a Call, don't tag this as Indirect if ((op == 9) && (ind) && (!idx) && CTagIs(addr, CTag.Call)) { tag = DTag.None; } while (ind) { DTAG[addr] |= tag; tag = DTag.Indirect; Int32 word = CORE[addr]; ind = ((word & 0x4000) != 0); addr = (word & 0x3fff) | (PC & 0x4000); } return(addr); }
public static int ConvertOffset2Index(DTag dtag, Table table, int current) { int posCount = 0; if (dtag.offset > 0) { for (int i = current + 1; i < table.Size; i++) { if (table.v[i][1] == dtag.pos) { ++posCount; } if (posCount == dtag.offset) { return(i); } } } else { for (int i = current - 1; i >= 0; i--) { if (table.v[i][1] == dtag.pos) { ++posCount; } if (posCount == -dtag.offset) { return(i); } } } return(-1); }
static Boolean DTagIs(DTag tag, DTag flags) { if (flags == DTag.None) { return(tag == flags); } return((tag & flags) == flags); }
public override CoNLLSentence Parse(List <Term> terms) { var table = new Table(); table.v = new string[terms.Count][]; for (int i = 0; i < terms.Count; i++) { var term = terms[i]; var line = new string[4]; table.v[i] = line; line[0] = term.word; line[2] = DependencyUtil.compilePOS(term.nature); line[1] = line[2].Substring(0, 1); } _crfModel.Tag(table); var words = new CoNLLWord[table.Size]; for (int i = 0; i < words.Length; i++) { words[i] = new CoNLLWord(i + 1, table.v[i][0], table.v[i][2], table.v[i][1]); } for (int i = 0; i < table.Size; i++) { var line = table.v[i]; var dtag = new DTag(line[3]); if (dtag.pos.EndsWith("ROOT")) { words[i].HEAD = CoNLLWord.ROOT; } else { var index = ConvertOffset2Index(dtag, table, i); if (index == -1) { words[i].HEAD = CoNLLWord.NULL; } else { words[i].HEAD = words[index]; } } } for (int i = 0; i < words.Length; i++) { words[i].DEPREL = BigramDependencyModel.Get(words[i].NAME, words[i].POSTAG, words[i].HEAD.NAME, words[i].HEAD.POSTAG); } return(new CoNLLSentence(words)); }
static String Label(Int32 addr, Boolean operand, Boolean force) { if ((addr == 0) && (operand) && (!force)) { return("0"); } String num = Octal(addr); if (addr >= 32768) { return((operand) ? String.Concat("'", num) : null); } CTag ctag = CTAG[addr]; if (CTagIs(ctag, CTag.EntryPoint)) { return(String.Concat("E", num, (operand) ? null : ":")); // (E)ntry } if (CTagIs(ctag, CTag.Call)) { return(String.Concat("S", num, (operand) ? null : ":")); // (S)ubroutine } if (CTagIs(ctag, CTag.Branch)) { return(String.Concat("B", num, (operand) ? null : ":")); // (B)ranch target } DTag dtag = DTAG[addr]; if (DTagIs(dtag, DTag.Indirect | DTag.Write)) { return(String.Concat("V", num, (operand) ? null : ":")); // (V)ector } if (DTagIs(dtag, DTag.Indirect)) { return(String.Concat("I", num, (operand) ? null : ":")); // (I)ndirect } if (DTagIs(dtag, DTag.Read | DTag.Write)) { return(String.Concat("D", num, (operand) ? null : ":")); // (D)ata } if (DTagIs(dtag, DTag.Write)) { return(String.Concat("W", num, (operand) ? null : ":")); // (W)rite only } if (DTagIs(dtag, DTag.Read)) { return(String.Concat("R", num, (operand) ? null : ":")); // (R)ead only } return((operand) ? String.Concat("'", num) : null); }
// disassemble a program word static String Disassemble(Int32 addr, Int32 word) { Fragment frag = FindFragment(addr); CTag ctag = CTAG[addr]; DTag dtag = DTAG[addr]; if (CTagIs(ctag, CTag.EntryPoint | CTag.Valid)) { return(DecodeOp(addr, word)); } if ((CTagIs(ctag, CTag.Call)) && (frag != null)) { return("DATA **"); } if (CTagIs(ctag, CTag.Valid) && (frag != null)) { return(DecodeOp(addr, word)); } if (CTagIs(ctag, CTag.Valid) && (frag == null) && DTagIs(dtag, DTag.Read | DTag.Write)) { return(String.Format("DATA {0}", Label(word, true))); } if (CTagIs(ctag, CTag.Valid) && !DTagIs(dtag, DTag.Indirect)) { return(DecodeOp(addr, word)); } if (DTagIs(dtag, DTag.Extended)) { return(String.Format("EAC {0}", Label(word & 0x7fff, true, true))); } if (DTagIs(dtag, DTag.Address) || DTagIs(dtag, DTag.Indirect)) { Boolean idx = ((word & 0x8000) != 0); Boolean ind = ((word & 0x4000) != 0); word &= 0x3fff; if (DTagIs(dtag, DTag.Map1)) { word |= 0x4000; } return(String.Format("DAC{0} {1}{2}", (ind) ? '*' : ' ', Label(word, true), (idx) ? ",1" : null)); } if (DTagIs(dtag, DTag.Immediate)) { return(String.Format("DATA '{0}", Octal(word, 6))); } return(String.Format("DATA {0}", Label(word, true))); }
// calculate the address referenced by an augmented instruction static Int32 AugOpAddr(Int32 addr, Boolean map) { Boolean ind; Int32 PC = (addr - 1) & 0x4000; DTag tag = DTag.None; do { if (map) { DTAG[addr] |= (PC == 0) ? DTag.Map0 : DTag.Map1; } DTAG[addr] |= tag; tag = DTag.Indirect; Int32 word = CORE[addr]; ind = ((word & 0x4000) != 0); addr = word & 0x3fff; if (map) { addr |= PC; } } while (ind); return(addr); }
static Boolean DTagIs(Int32 addr, DTag flags) { return(DTagIs(DTAG[addr], flags)); }