public string DataDeclaration(SOCRecord record) { if (record.Depth == 0) { if (record.Width == 1) { return($"reg {record.HardwareName};"); } else { return($"reg [{record.Width - 1} : 0] {record.HardwareName};"); } } else { if (record.Width == 1) { return($"reg {record.HardwareName}[0 : {record.Depth}];"); } else { return($"reg [{record.Width - 1} : 0] {record.HardwareName}[0 : {record.Depth - 1}];"); } } }
public List <SOCRecord> ToSOCRecords(uint seg, IEnumerable <SOCResourceCPPModel> source) { var socRecords = new List <SOCRecord>(); foreach (var d in source) { var segment = d.Address; if (segment == 0) { segment = seg; seg++; } var templatesMap = new Dictionary <Type, string>() { { typeof(byte), "memory8" }, { typeof(sbyte), "memory8" }, { typeof(ushort), "memory16" }, { typeof(short), "memory16" }, { typeof(int), "memory32" }, { typeof(uint), "memory32" }, }; if (d.Length > 0 && !templatesMap.ContainsKey(d.Type)) { throw new Exception($"No template found for {d.Type}"); } var template = d.Length > 0 ? templatesMap[d.Type] : "register"; var rec = new SOCRecord() { SegmentBits = 12, SoftwareName = d.Name, HardwareName = d.Name, DataType = d.Type, Depth = (uint)d.Length, Segment = segment, Template = template, }; socRecords.Add(rec); } return(socRecords); }
public string DataControl( SOCRecord record, IntegrationTemplates templates) { if (string.IsNullOrWhiteSpace(record.Template)) { throw new Exception($"No hardware template specified for '{record.HardwareName}'"); } if (!templates.Templates.ContainsKey(record.Template)) { throw new Exception($"Template '{record.Template}' was not provided"); } var map = new Dictionary <string, string>(); map["NAME"] = record.HardwareName; map["SEG"] = record.Segment.ToString("X2"); map["be_3"] = record.Width > 24 ? "" : "//"; map["be_2"] = record.Width > 16 ? "" : "//"; map["be_1"] = record.Width > 8 ? "" : "//"; map["be_0"] = record.Width > 0 ? "" : "//"; map["WIDTH"] = record.Width.ToString(); map["HIGH"] = (record.Width - 1).ToString(); map["SEG_WIDTH"] = record.SegmentBits.ToString(); map["SEG_END"] = (32 - record.SegmentBits).ToString(); var template = templates.Templates[record.Template]; foreach (var pair in map) { var token = $"{{{pair.Key}}}"; template = template.Replace(token, pair.Value); } return(template); }