private Expression MakeValueExpression(Value value, DataType dt) { var c = value as Constant; if (c != null) { if (c.Value == null) { var w = PrimitiveType.CreateWord(dt.Size); var v = IrConstant.Create(w, 0); v.DataType = w; return(v); } else { return(IrConstant.Create(dt, Convert.ToInt64(c.Value))); } } var l = value as Literal; if (l != null) { if (l.Type == TokenType.HexInteger) { var ptr = dt as Pointer; var val = Convert.ToInt64(l.Value, 16); if (ptr != null) { return(Address.Create(ptr, (ulong)val)); } return(IrConstant.Create(dt, val)); } throw new NotImplementedException(); } var local = value as LocalId; if (local != null) { return(m.GetLocalId(local.Name)); } var global = value as GlobalId; if (global != null) { return(builder.Globals[global.Name]); } var get = value as GetElementPtrExpr; if (get != null) { return(GetElementPtr(get.PointerType, get.Pointer, get.Indices)); } throw new NotImplementedException(string.Format("MakeValueExpression: {0} {1}", value.GetType().Name, value.ToString() ?? "(null)")); }
private Expression MakeValueExpression(Value value, DataType dt) { switch (value) { case Constant c: if (c.Value == null) { var w = PrimitiveType.CreateWord(dt.BitSize); var v = IrConstant.Create(w, 0); v.DataType = w; return(v); } else { return(IrConstant.Create(dt, Convert.ToInt64(c.Value))); } case Literal l: if (l.Type == TokenType.HexInteger) { var val = Convert.ToInt64(l.Value, 16); if (dt is Pointer ptr) { return(Address.Create(ptr, (ulong)val)); } return(IrConstant.Create(dt, val)); } throw new NotImplementedException(); case LocalId local: return(m.GetLocalId(local.Name)); case GlobalId global: return(builder.Globals[global.Name]); case GetElementPtrExpr get: return(GetElementPtr(get.PointerType, get.Pointer, get.Indices)); } throw new NotImplementedException(string.Format("MakeValueExpression: {0} {1}", value.GetType().Name, value.ToString() ?? "(null)")); }