/// <summary> /// Loads library into the address space. /// </summary> /// <param name="lib">The name of the library.</param> /// <returns></returns> protected bool load(string lib) { if (string.IsNullOrWhiteSpace(lib)) { throw new ArgumentNullException(nameof(lib)); } if (Library.IsActive) { throw new LoaderException($"Module '{Library.module}' should be unloaded before new loading '{lib}'."); } Library = loadLibrary(lib); if (Library.handle == IntPtr.Zero) { // TODO: clarify specific error throw new LoadLibException($"Failed loading '{Library.module}'. Possible incorrect architecture or missing file or its dependencies. https://github.com/3F/Conari/issues/4", true); } PE = new PEFile(Library.module); AfterLoad(this, new DataArgs <Link>(Library)); return(true); }
private void loadFileButton_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { var ipe = new IPE(ofd.FileName); List <string> binary = ipe.ParseFile(); myCPU.setNumInstLeft(binary.Count); //for (int i = 0; i < binary.Count; i++) //{ // Console.WriteLine("parser at " + i + ": " + binary[i]); // } List <Int16> finBinary = convert(binary); //ipe.createBinaryTextFile(binary); createBinaryFile(finBinary); myCPU.setBinary(binary); myCPU.setBinary16(finBinary); myCPU.setLabelLocationMap(ipe.getLabelLocationMap()); mainMemory.setLabelLocationMap(ipe.getLabelLocationMap()); myCPU.getMainMemory().InitializeCache(); foreach (KeyValuePair <string, int> kvp in ipe.getLabelLocationMap()) { //Console.WriteLine("Key = {0}, Value = {1}", kvp.Key, kvp.Value); } // for (int i = 0; i < ipe.getLabelLocationMap().Count; i++) // { // Console.WriteLine("map key: " + ipe.getLabelLocationMap().Keys[i]) // } // Console.WriteLine("map.keys: " + ipe.getLabelLocationMap()); //Console.WriteLine("map.value: " + ipe.getLabelLocationMap().Values); myCPU.PC = 0; myCPU.finished = false; ipe.broken = false; } catch (Exception err) { System.Windows.Forms.MessageBox.Show(err.Message); } } } }
private void loadFileButton_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { var ipe = new IPE(ofd.FileName); ipe.ParseFile(); } catch (Exception err) { // show a dialog with error } } } }
private void loadFileButton_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialog()) { if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { resetGUI(); string fileName = Path.GetFileNameWithoutExtension(ofd.FileName); this.fileNameLabel.Text = fileName + ".s"; var ipe = new IPE(ofd.FileName); List <string> assemblyLines = ipe.ParseFile(); if (assemblyLines.Count == 0) { return; } short[] binaryLines = ipe.AssemblytoBinary(assemblyLines); string tempFileName = Path.GetDirectoryName(ofd.FileName) + "\\" + fileName + ".out"; Debug.WriteLine("\nOutput to file: " + tempFileName); ipe.WriteBinarytoFile(binaryLines, tempFileName); //Write out the binary instructions to a file binaryLines = ipe.readBinaryFromFile(tempFileName); //Read in the binary and load to memory Memory.setBinaryInstructions(binaryLines.ToList()); //Load the binary we just read from file into Memory currentInstructionLabel.Text = Memory.getAssemblyInstructions().ElementAt(0); this.setPipelineValuesToView(); //not sure if this is needed totalInstructionCountLabel.Text = (Memory.getAssemblyInstructions().Count).ToString(); instructionCount = 1; currInstructionCountLabel.Text = (this.myCPU.PC + 1).ToString(); } catch (Exception err) { // show a dialog with error MessageBox.Show(err.Message); resetGUI(); } } } }
/// <summary> /// Loads library into the address space. /// </summary> /// <param name="lib">The name of the library.</param> /// <returns></returns> protected bool load(string lib) { if (Library.IsActive) { throw new LoaderException($"The library '{Library.LibName}' should be unloaded before new loading '{lib}'."); } if (String.IsNullOrWhiteSpace(lib)) { throw new ArgumentException("The library name cannot be null or empty.", "lib"); } Library = loadLibrary(lib); if (Library.Handle == IntPtr.Zero) { throw new LoadLibException($"Failed loading '{Library.LibName}': Check used architecture or existence of file. https://github.com/3F/Conari/issues/4", true); } PE = new PEFile(Library.LibName); AfterLoad(this, new DataArgs <Link>(Library)); return(true); }