Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input Type always set to Assembly on startup #356

Open
federicovilla55 opened this issue Apr 6, 2024 · 0 comments
Open

Input Type always set to Assembly on startup #356

federicovilla55 opened this issue Apr 6, 2024 · 0 comments

Comments

@federicovilla55
Copy link
Contributor

I have noticed that each time I open a C file in the Ripes GUI, after I save it and open it again, the same file appears in the Source Code section of the Editor tab, but the Input Type is always set to Assembly.


The Ripes.config file, which saves the settings of Ripes, contains the parameter input_type which stores an integer representing an element of the enumeration:

enum SourceType {
/** Assembly text */
Assembly,
/** C text */
C,
/** Flat binary external file */
FlatBinary,
/** Executable files not compiled from within ripes */
ExternalELF,
/** Executable files compiled within ripes */
InternalELF
};

When I close the simulator with a C file open in the editor tab, the field input_type = 1 is saved in the Ripes.config, indicating that the last opened file (whose source code is in the sourcecode field of the Ripes.config file) was a C file.

The problem is the next time Ripes is opened, that value is changed in input_type = 0, which means that the file is always considered an Assembly.

Looking at the code, the option input_type is modified by the method EditTab::sourceTypeChanged() and is set as follows:

Ripes/src/edittab.cpp

Lines 255 to 276 in 8780873

if (m_ui->setAssemblyInput->isChecked()) {
m_currentSourceType = SourceType::Assembly;
} else if (m_ui->setCInput->isChecked()) {
// Ensure that we have a validated C compiler available
if (!CCManager::get().hasValidCC()) {
QMessageBox::warning(this, "Error",
"No C compiler set.\n\nProvide a path to a valid C "
"compiler under:\n Edit->Settings->Editor");
// Re-enable assembly input
m_ui->setAssemblyInput->setChecked(true);
return;
} else {
m_currentSourceType = SourceType::C;
}
}
// Notify the source type change to the code editor
m_ui->codeEditor->setSourceType(
m_currentSourceType, ProcessorHandler::getAssembler()->getOpcodes());
// And store in settings
RipesSettings::setValue(RIPES_SETTING_INPUT_TYPE, m_currentSourceType);

So when opening the simulator the input type is set as default as m_ui->setCInput has not been checked yet.

In the EditTab constructor before the m_ui are toggled the following methods are called:

Ripes/src/edittab.cpp

Lines 112 to 113 in 8780873

sourceTypeChanged();
enableEditor();

Those methods (that have a direct or indirect call to the method sourceTypeChanged()) change the input type to Assembly.

I suppose that those methods should not modify the input type, as it should be done in the constructor a few lines after:

Ripes/src/edittab.cpp

Lines 127 to 139 in 8780873

switch (RipesSettings::value(RIPES_SETTING_INPUT_TYPE).toInt()) {
case SourceType::Assembly: {
m_ui->setAssemblyInput->toggle();
break;
}
case SourceType::C: {
m_ui->setCInput->toggle();
break;
}
default:
break;
}
}


My proposal for the problem:

  • Move the switch to set the input type in the line following the statement to set the source code in the editor:
EditTab::EditTab(QToolBar *toolbar, QWidget *parent){
  // ...
  m_ui->codeEditor->document()->setPlainText(
      RipesSettings::value(RIPES_SETTING_SOURCECODE).toString());

  switch (RipesSettings::value(RIPES_SETTING_INPUT_TYPE).toInt()) {
  case SourceType::Assembly: {
    m_ui->setAssemblyInput->toggle();
    break;
  }
  case SourceType::C: {
    m_ui->setCInput->toggle();
    break;
  }
  default:
    break;
  }
  // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant