Skip to content

Commit

Permalink
#207: phi works
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 22, 2023
1 parent f45c9aa commit c503b0c
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/up.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
- run: apt-get -y install jq
- run: sudo apt-get -y install jq
- run: curl https://api.github.com/repos/objectionary/eo/releases/latest --silent | jq -r .tag_name > eo-version.txt
- uses: peter-evans/create-pull-request@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@
"mocha": "10.2.0"
},
"scripts": {
"test": "mocha --timeout 1200000 --files test/**/*.js"
"test": "mocha --timeout 1200000"
}
}
16 changes: 2 additions & 14 deletions src/commands/assemble.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,15 @@
*/

const path = require('path');
const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');

/**
* Command to assemble .XMIR files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
return mvnw([
'eo:assemble',
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.trackOptimizationSteps ? '-Deo.trackOptimizationSteps' : '',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
`-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`,
`-Deo.placedFormat=csv`,
], opts.target, opts.batch).then((r) => {
return mvnw(['eo:assemble'].concat(flags(opts)), opts.target, opts.batch).then((r) => {
console.info('EO program assembled in %s', path.resolve(opts.target));
return r;
});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

const mvnw = require('../mvnw');
const {mvnw} = require('../mvnw');

/**
* Command to audit all packages.
Expand Down
15 changes: 2 additions & 13 deletions src/commands/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');
const path = require('path');

/**
Expand All @@ -32,18 +32,7 @@ const path = require('path');
*/
module.exports = function(opts) {
const target = path.resolve(opts.target);
return mvnw([
'compiler:compile',
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Dmaven.compiler.source=1.8`,
`-Dmaven.compiler.target=1.8`,
`-Deo.targetDir=${target}`,
`-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`,
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
], opts.target, opts.batch).then((r) => {
return mvnw(['compiler:compile'].concat(flags(opts)), opts.target, opts.batch).then((r) => {
console.info('Java .class files compiled into %s', target);
return r;
});
Expand Down
11 changes: 2 additions & 9 deletions src/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');
const path = require('path');

/**
Expand All @@ -31,14 +31,7 @@ const path = require('path');
* @return {Promise} of link task
*/
module.exports = function(opts) {
return mvnw([
'jar:jar',
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
'-Deo.version=' + opts.parser,
], opts.target, opts.batch).then((r) => {
return mvnw(['jar:jar'].concat(flags(opts)), opts.target, opts.batch).then((r) => {
console.info('Executable JAR created at %s', path.resolve(opts.target, 'eoc.jar'));
return r;
});
Expand Down
13 changes: 2 additions & 11 deletions src/commands/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,15 @@
*/

const path = require('path');
const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');

/**
* Command to parse EO into .XMIR files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
return mvnw([
'eo:parse',
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
], opts.target, opts.batch).then((r) => {
return mvnw(['eo:parse'].concat(flags(opts)), opts.target, opts.batch).then((r) => {
console.info('EO sources parsed in %s', path.resolve(opts.target));
return r;
});
Expand Down
20 changes: 12 additions & 8 deletions src/commands/phi.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@
*/

const path = require('path');
const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');

/**
* Command to convert .XMIR files into .PHI files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
return mvnw([
'eo:phi',
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
], opts.target, opts.batch).then((r) => {
return mvnw(
['eo:xmir-to-phi']
.concat(flags(opts))
.concat(
[
`-DphiInputDir=${path.resolve(opts.target, '2-optimize')}`,
`-DphiOutputDir=${path.resolve(opts.target, 'phi')}`,
]
),
opts.target, opts.batch
).then((r) => {
console.info('XMIR files converted into PHI files at %s', path.resolve(opts.target));
return r;
});
Expand Down
12 changes: 2 additions & 10 deletions src/commands/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');
const path = require('path');

/**
Expand All @@ -32,15 +32,7 @@ const path = require('path');
*/
module.exports = function(opts) {
const foreign = path.resolve(opts.target, 'eo-foreign.json');
return mvnw([
'eo:register',
'-Deo.version=' + opts.parser,
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.sourcesDir=${path.resolve(opts.sources)}`,
], opts.target, opts.batch).then((r) => {
return mvnw(['eo:register'].concat(flags(opts)), opts.target, opts.batch).then((r) => {
console.info('EO objects registered in %s', foreign);
return r;
});
Expand Down
11 changes: 2 additions & 9 deletions src/commands/sodg.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,15 @@
*/

const path = require('path');
const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');

/**
* Generate SODG files from XMIR.
* @param {Hash} opts - All options
* @return {Promise} of sodg task
*/
module.exports = function(opts) {
const argv = [
'eo:sodg',
'-Deo.version=' + opts.parser,
opts.verbose ? '' : '--quiet',
opts.verbose ? '--errors' : '',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
];
const argv = ['eo:sodg'].concat(flags(opts));
argv.push('-Deo.sodgIncludes=' + opts.include);
if (opts.exclude) {
argv.push('-Deo.sodgExcludes=' + opts.exclude);
Expand Down
12 changes: 2 additions & 10 deletions src/commands/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@
* SOFTWARE.
*/

const mvnw = require('../mvnw');
const path = require('path');
const {mvnw} = require('../mvnw');

/**
* Command to run all available unit tests.
* @param {Hash} opts - All options
* @return {Promise} of compile task
*/
module.exports = function(opts) {
return mvnw([
'surefire:test',
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
'-Deo.version=' + opts.parser,
`-Deo.targetDir=${path.resolve(opts.target)}`,
]);
return mvnw(['surefire:test'].concat(flags(opts)));
};
12 changes: 2 additions & 10 deletions src/commands/transpile.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* SOFTWARE.
*/

const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');
const path = require('path');

/**
Expand All @@ -32,15 +32,7 @@ const path = require('path');
*/
module.exports = function(opts) {
const sources = path.resolve(opts.target, 'generated-sources');
return mvnw([
'eo:transpile',
'-Deo.version=' + opts.parser,
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.generatedDir=${sources}`,
], opts.target, opts.batch).then((r) => {
return mvnw(['eo:transpile'].concat(flags(opts)), opts.target, opts.batch).then((r) => {
console.info('Java sources generated in %s', sources);
return r;
});
Expand Down
13 changes: 2 additions & 11 deletions src/commands/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,15 @@
*/

const path = require('path');
const mvnw = require('../mvnw');
const {mvnw, flags} = require('../mvnw');

/**
* Command to verify .XMIR files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
return mvnw([
'eo:verify',
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
], opts.target, opts.batch).then((r) => {
return mvnw(['eo:verify'].concat(flags(opts)), opts.target, opts.batch).then((r) => {
console.info('EO program verified in %s', path.resolve(opts.target));
return r;
});
Expand Down
14 changes: 14 additions & 0 deletions src/eoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const clean = require('./commands/clean');
const parse = require('./commands/parse');
const assemble = require('./commands/assemble');
const sodg = require('./commands/sodg');
const phi = require('./commands/phi');
const register = require('./commands/register');
const verify = require('./commands/verify');
const transpile = require('./commands/transpile');
Expand Down Expand Up @@ -145,6 +146,19 @@ program.command('sodg')
}
});

program.command('phi')
.description('Generate PHI files from XMIR')
.action((str, opts) => {
clear(str);
if (program.opts().alone == undefined) {
register(program.opts())
.then((r) => assemble(program.opts()))
.then((r) => phi(program.opts()));
} else {
phi(program.opts());
}
});

program.command('verify')
.description('Verify XMIR files and fail if any issues inside')
.action((str, opts) => {
Expand Down
24 changes: 23 additions & 1 deletion src/mvnw.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,36 @@ let target;
let running = false;
let beginning;

/**
* Prepare options for Maven.
* @param {Hash} opts - Opts provided to the "eoc"
* @return {Array} of Maven options
*/
module.exports.flags = function(opts) {
return [
'-Deo.version=' + opts.parser,
'-Deo.hash=' + (opts.hash ? opts.hash : opts.parser),
opts.verbose ? '--errors' : '',
opts.verbose ? '' : '--quiet',
opts.debug ? '--debug' : '',
`-Deo.sourcesDir=${path.resolve(opts.sources)}`,
`-Deo.targetDir=${path.resolve(opts.target)}`,
`-Deo.outputDir=${path.resolve(opts.target, 'classes')}`,
`-Deo.generatedDir=${path.resolve(opts.target, 'generated-sources')}`,
`-Deo.placed=${path.resolve(opts.target, 'eo-placed.csv')}`,
`-Deo.placedFormat=csv`,
opts.trackOptimizationSteps ? '-Deo.trackOptimizationSteps' : '',
];
};

/**
* Run mvnw with provided commands.
* @param {Hash} args - All arguments to pass to it
* @param {String} tgt - Path to the target directory
* @param {Boolean} batch - Is it batch mode (TRUE) or interactive (FALSE)?
* @return {Promise} of maven execution task
*/
module.exports = function(args, tgt, batch) {
module.exports.mvnw = function(args, tgt, batch) {
return new Promise((resolve, reject) => {
target = tgt;
phase = args[0];
Expand Down
9 changes: 5 additions & 4 deletions test/commands/test_phi.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
* SOFTWARE.
*/

const assert = require('assert');
const fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');
Expand All @@ -32,19 +31,21 @@ describe('phi', function() {
home = path.resolve('temp/test-phi/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'src'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'src/simple.eo'), '[] > simple\n');
fs.writeFileSync(path.resolve(home, 'src/phi.eo'), '[] > phi\n');
const stdout = runSync([
'phi',
'--verbose',
'--track-optimization-steps',
'--parser=0.34.1',
'--hash=1d605bd872f27494551e9dd2341b9413d0d96d89',
'-s', path.resolve(home, 'src'),
'-t', path.resolve(home, 'target'),
]);
assertFilesExist(
stdout, home,
[
'target/2-optimize/simple.xmir',
'target/phi/simple.phi',
'target/2-optimize/phi.xmir',
'target/phi/phi.phi',
]
);
done();
Expand Down
Loading

0 comments on commit c503b0c

Please sign in to comment.