private static uint ExtractData(Expression src, Dictionary<string, LabelOffset> label_offsets, out bool fits, string cur_label, int cur_offset, int field_len, bool is_lit) { if (src is IntegerOperand) { int i = ((IntegerOperand)src).val; return build_imm(i, field_len, out fits, is_lit); } else if (src is RegisterOperand) { RegisterOperand r = src as RegisterOperand; if (regs.ContainsKey(r.val.ToUpper())) { fits = true; return (uint)regs[r.val.ToUpper()]; } else { string label = r.val; if (label_offsets.ContainsKey(label)) { if (label_offsets[label].Section != cur_section) throw new NotImplementedException(); int v = label_offsets[label].Offset; return build_imm(v, field_len, out fits, is_lit); } else throw new Exception("Undefined label: " + r.val); } } fits = true; return 0; }
private static Expression EvaluateOperand(Expression src, Dictionary<string, LabelOffset> label_offsets, Section cur_section) { if (src == null) return null; MakeState s = new MakeState(label_offsets, cur_section); // ExpandComplex already uses operands if (src is Operand) return src; var v = src.Evaluate(s); switch(v.Type) { case Expression.EvalResult.ResultType.Register: return new RegisterOperand { val = v.strval }; case Expression.EvalResult.ResultType.Int: return new IntegerOperand { val = v.intval }; case Expression.EvalResult.ResultType.Relocation: return v.relocval; default: throw new NotImplementedException(); } }