Skip to content

Commit

Permalink
fix: repair SuperscalarConfigModal layout (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxcabe authored Mar 20, 2024
1 parent e9c9cf6 commit 050b27c
Show file tree
Hide file tree
Showing 11 changed files with 713 additions and 699 deletions.
8 changes: 5 additions & 3 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"config": {
"name": "Options",
"superescalar": "Configure Superescalar Machine",
"superescalar": "Configure Superscalar Machine",
"vliw": "Configure VLIW Machine",
"options": "Options",
"content": "Load content Memory - Registers"
Expand Down Expand Up @@ -68,7 +68,9 @@
}
},
"superescalarModal": {
"name": "Configuration",
"name": "Superscalar Configuration",
"functionalUnits": "Functional Units",
"parameters": "Parameters",
"warning": "Execution will restart once configuration changes",
"latency": "Latency",
"quantity": "Quantity",
Expand Down Expand Up @@ -159,7 +161,7 @@
"read": "Read more",
"home": "Home",
"project": "Project",
"superescalar": "Superescalar",
"superescalar": "Superscalar",
"superescalar_description": "Simulate the operation of a superscalar machine executing your code step by step!",
"go": "Go",
"vliw": "VLIW",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/es/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
}
},
"superescalarModal": {
"name": "Configuración",
"name": "Configuración Superescalar",
"functionalUnits": "Unidades Funcionales",
"parameters": "Parámetros",
"warning": "La ejecución será reiniciada tras modificar la configuración",
"latency": "Latencia",
"quantity": "Cantidad",
Expand Down
10 changes: 5 additions & 5 deletions src/core/Common/Machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ export class Machine {
}
}

public changeFunctionalUnitNumber(type: FunctionalUnitType, number: number) {
if (number == 0) {
public changeFunctionalUnitNumber(type: FunctionalUnitType, num: number) {
if (num === 0) {
return;
}

let currentLatency = this.functionalUnit[type][0].latency;
this.functionalUnit[type] = new Array(number);
for (let i = 0; i < number; i++) {
const currentLatency = this.functionalUnit[type][0].latency;
this.functionalUnit[type] = new Array(num);
for (let i = 0; i < num; i++) {
this.functionalUnit[type][i] = new FunctionalUnit(type, currentLatency);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/Superescalar/Superescalar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ export class Superescalar extends Machine {
}
}

public changeFunctionalUnitNumber(type: FunctionalUnitType, number: number) {
super.changeFunctionalUnitNumber(type, number);
public changeFunctionalUnitNumber(type: FunctionalUnitType, num: number) {
super.changeFunctionalUnitNumber(type, num);

// Update the number of alu mem units acortding to the number of memory units
if (type === FunctionalUnitType.MEMORY) {
let currentLatency = this.aluMem[0].latency;
this._aluMem = new Array(number);
for (let j = 0; j < number; j++) {
this._aluMem = new Array(num);
for (let j = 0; j < num; j++) {
this.aluMem[j] = new FunctionalUnit(
FunctionalUnitType.INTEGERSUM,
currentLatency
Expand Down
1 change: 0 additions & 1 deletion src/integration/superescalar-integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ export class SuperescalarIntegration extends MachineIntegration {

saveSuperConfig = (superConfig) => {
// TODO: enforce this through a unique map so that we can overwrite the config directly

this.superescalar.changeFunctionalUnitNumber(FunctionalUnitType.INTEGERSUM, +superConfig.integerSumQuantity);
this.superescalar.changeFunctionalUnitLatency(FunctionalUnitType.INTEGERSUM, +superConfig.integerSumLatency);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import RegisterTabComponent from './tab/RegistersTabComponent';
import StatsTabComponent from './tab/StatsTabComponent';

import LoadModalComponent from "./modal/LoadModalComponent";
import SuperescalarConfigModalComponent from "./modal/SuperescalarConfigModalComponent";
import SuperescalarConfigModalComponent from "./modal/SuperescalarConfigModal";
import SuperescalarLoadContentModalComponent from "./modal/SuperescalarLoadContentModalComponent";

import OptionsModalComponent from "./modal/OptionsModalComponent";
Expand Down
145 changes: 72 additions & 73 deletions src/interface/components/Superescalar/modal/OptionsModalComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,82 +1,81 @@
import * as React from 'react';
import { Modal, Button } from 'react-bootstrap';
import { withTranslation } from 'react-i18next';
import { bindActionCreators } from 'redux';
import { toggleOptionsModal } from '../../../actions/modals';
import { connect } from 'react-redux';
import SuperescalarIntegration from '../../../../integration/superescalar-integration';
import type * as React from "react";
import { Alert, Button, Modal } from "react-bootstrap";
import { type WithTranslation, withTranslation } from "react-i18next";
import { type Dispatch, type UnknownAction, bindActionCreators } from "redux";
import { toggleOptionsModal } from "../../../actions/modals";
import { connect } from "react-redux";

class OptionsModalComponent extends React.Component<any, any> {
const mapStateToProps = (state) => {
return {
isOptionsModalOpen: state.Ui.isOptionsModalOpen,
};
};

constructor(public props: any) {
super(props);

this.close = this.close.bind(this);
this.setOptions = this.setOptions.bind(this);
this.handleChange = this.handleChange.bind(this);
this.state = {
cacheFailPercentage: 0
}
}
function mapDispatchToProps(dispatch: Dispatch<UnknownAction>) {
return { actions: bindActionCreators({ toggleOptionsModal }, dispatch) };
}

close() {
this.props.actions.toggleOptionsModal(false);
};
export type OptionsModalProps = WithTranslation &
ReturnType<typeof mapStateToProps> &
ReturnType<typeof mapDispatchToProps>;

handleChange(event) {
let newState = {...this.state};
newState.cacheFailPercentage = event.target.value;
this.setState(newState);
}
export const OptionsModalComponent: React.FC = ({
actions,
isOptionsModalOpen,
t,
}: OptionsModalProps) => {
const cacheFailPercentage = 0;

setOptions() {
// SuperescalarIntegration.setOptions(this.state.cacheFailPercentage);
this.close();
}
const close = () => {
actions.toggleOptionsModal(false);
};

render() {
return (
<Modal show={this.props.isOptionsModalOpen} onHide={this.close}>
<Modal.Header closeButton>
<Modal.Title>{this.props.t('optionsModal.title')}</Modal.Title>
</Modal.Header>
<Modal.Body>
<form className='form form-horizontal'>
<div className='form-group'>
<div className='col-sm-4'>
<label htmlFor='cacheFailPercentage' className='control-label'>{this.props.t('optionsModal.cacheFault')}
</label>
</div>
<div className='col-sm-8'>
<input
className='form-control'
name='cacheFailPercentage'
type='number'
min='0'
max='100'
value={this.state.cacheFailPercentage}
onChange={this.handleChange}
/>
</div>
</div>
</form>
</Modal.Body>
<Modal.Footer>
<Button onClick={this.close}>{this.props.t('commonButtons.close')}</Button>
<Button className='btn btn-primary' onClick={this.setOptions}>{this.props.t('commonButtons.save')}</Button>
</Modal.Footer>
</Modal>);
}
}
const handleChange = (event) => {
// setState({ ...state, cacheFailPercentage: event.target.value });
};

const mapStateToProps = state => {
return {
isOptionsModalOpen: state.Ui.isOptionsModalOpen,
}
}
const setOptions = () => {
close();
};

function mapDispatchToProps(dispatch) {
return { actions: bindActionCreators({toggleOptionsModal}, dispatch)};
}
return (
<Modal show={isOptionsModalOpen} onHide={close}>
<Modal.Header closeButton>
<Modal.Title>{t("optionsModal.title")}</Modal.Title>
</Modal.Header>
<Modal.Body>
<form className="form form-horizontal">
<div className="form-group">
<div className="col-sm-4">
<label htmlFor="cacheFailPercentage" className="control-label">
{t("optionsModal.cacheFault")}
</label>
</div>
<div className="col-sm-8">
<input
className="form-control"
name="cacheFailPercentage"
type="number"
min="0"
max="100"
value={cacheFailPercentage}
onChange={handleChange}
/>
</div>
</div>
</form>
</Modal.Body>
<Modal.Footer>
<Button onClick={close}>{t("commonButtons.close")}</Button>
<Button className="btn btn-primary" onClick={setOptions}>
{t("commonButtons.save")}
</Button>
</Modal.Footer>
</Modal>
);
};

export default connect(mapStateToProps, mapDispatchToProps)(withTranslation()(OptionsModalComponent));
export default connect(
mapStateToProps,
mapDispatchToProps,
)(withTranslation()(OptionsModalComponent));
Loading

0 comments on commit 050b27c

Please sign in to comment.