public static void TranslateToC(HLProgram program) { // Program file string emulatorPath = Properties.Settings.Default.EmulatorPath; string cCode = Translator.Translate(program); string templateFullPath = System.IO.Path.Combine(emulatorPath, "MCEmulator", EmulatorTemplate); string outputFullPath = System.IO.Path.Combine(emulatorPath, "MCEmulator", EmulatorOutputFile); CodeGenerator.GenerateCSource(templateFullPath, outputFullPath, cCode); // Main file and COM Port if (Properties.Settings.Default.EmulatorComPort == "") { throw new ComPortException(); } else { string mainTemplateFullPath = System.IO.Path.Combine(emulatorPath, "MCEmulator", MainTemplate); string mainOutputFullPath = System.IO.Path.Combine(emulatorPath, "MCEmulator", MainOutput); string mainStr = File.ReadAllText(mainTemplateFullPath); // COM1 is the 0th int comNo = Int32.Parse(Properties.Settings.Default.EmulatorComPort.Substring(3)) - 1; mainStr = mainStr.Replace("/**change_com_port**/", (comNo.ToString())); File.WriteAllText(mainOutputFullPath, mainStr); } }
/// <summary> /// Get the sub-program specified by a range. /// </summary> /// <param name="startIndex">the index of the first Instruction.</param> /// <param name="endIndex">the index of the last Instruction.</param> /// <returns></returns> public HLProgram SubProgram(int startIndex, int endIndex) { HLProgram hlp = new HLProgram(); for (int i = startIndex; i <= endIndex; i++) { hlp.Add(program[i]); } return(hlp); }
/// <summary> /// Validate a program. /// </summary> /// <param name="program">program is the input of test program</param> public static void ValidateProgram(HLProgram program) { currentLine = 0; Validator.program = program; foreach (Instruction ins in program) { ValidateInstruction(ins); currentLine++; } }
/// <summary> /// Translate high-level program /// </summary> /// <param name="program">High level igp program input</param> /// <returns>C code of igp program</returns> public static string Translate(HLProgram program) { StringBuilder cBuilder = new StringBuilder(); foreach (Instruction ins in program.GetInstructionList()) { // The instruction itself as comment cBuilder.AppendLine("//" + ins.ToString()); cBuilder.AppendLine(TranslateInstruction(ins)); } return(cBuilder.ToString()); }
/// <summary> /// Get the completed IF or LOOP block. /// </summary> /// <param name="ifLoopIns">The starting IF or LOOP instruction.</param> /// <returns>The completed IF or LOOP block.</returns> public static HLProgram GetDefaultIfLoopBlock(Instruction ifLoopIns) { HLProgram result = new HLProgram(); result.Add(ifLoopIns); if (ifLoopIns.opcode == Instruction.IF) { result.Add(Instruction.CreatDefaultFromOpcode(Instruction.ELSE)); result.Add(Instruction.CreatDefaultFromOpcode(Instruction.END_IF)); } else if (ifLoopIns.opcode == Instruction.LOOP) { result.Add(Instruction.CreatDefaultFromOpcode(Instruction.END_LOOP)); } return(result); }
// For debugging private void programList_ProgramChanged() { HLProgram program = programList.Program; textBoxSource.Text = program.ToString(); }
private void buttonRefreshSource_Click(object sender, RoutedEventArgs e) { HLProgram program = programList.Program; textBoxSource.Text = program.ToString(); }
public void Add(HLProgram subProgram) { program.AddRange(subProgram.program); }
public void Insert(int index, HLProgram subProgram) { program.InsertRange(index, subProgram.program); }