Skip to content

Commit

Permalink
#212: unphi
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 25, 2023
1 parent 4f3a40e commit 70bb9b7
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ You can also do many other things with `eoc` commands
* `dataize` dataizes a single object from the executable binary
* `test` dataizes all visible unit tests

There are also commands that help manipulate with XMIR and EO sources (some of them are not implemented as of yet):
There are also commands that help manipulate with XMIR and EO sources
(the list is not completed, while some of them are not implemented as of yet):

* `audit` inspects all required packages and reports their status
* `foreign` inspects all objects found in the program after `assemble` step
* `sodg` generates SODG from XMIR, further rederable as XML or [Dot](https://en.wikipedia.org/wiki/DOT_%28graph_description_language%29)
* `phi` generates PHI files from XMIR
* `unphi` generates XMIR files from PHI files
* <del>`translate` converts Java/C++/Python/etc. program to EO program</del>
* <del>`demu` removes `cage` and `memory` objects</del>
* <del>`dejump` removes `goto` objects</del>
Expand Down
52 changes: 52 additions & 0 deletions src/commands/unphi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

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

/**
* Command to convert .PHI files into .XMIR files.
* @param {Hash} opts - All options
* @return {Promise} of assemble task
*/
module.exports = function(opts) {
const input = path.resolve(opts.target, 'phi');
console.debug('Reading from %s', input);
const output = path.resolve(opts.target, 'unphi');
console.debug('Writing into %s', output);
return mvnw(
['eo:phi-to-xmir']
.concat(flags(opts))
.concat(
[
`-DunphiInputDir=${input}`,
`-DunphiOutputDir=${output}`,
]
),
opts.target, opts.batch
).then((r) => {
console.info('PHI files converted into XMIR files at %s', output);
return r;
});
};
8 changes: 8 additions & 0 deletions src/eoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const parse = require('./commands/parse');
const assemble = require('./commands/assemble');
const sodg = require('./commands/sodg');
const phi = require('./commands/phi');
const unphi = require('./commands/unphi');
const register = require('./commands/register');
const verify = require('./commands/verify');
const transpile = require('./commands/transpile');
Expand Down Expand Up @@ -159,6 +160,13 @@ program.command('phi')
}
});

program.command('unphi')
.description('Generate XMIR files from PHI files')
.action((str, opts) => {
clear(str);
unphi(program.opts());
});

program.command('verify')
.description('Verify XMIR files and fail if any issues inside')
.action((str, opts) => {
Expand Down
51 changes: 51 additions & 0 deletions test/commands/test_unphi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2022-2023 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

const fs = require('fs');
const path = require('path');
const {runSync, assertFilesExist} = require('../helpers');

describe('unphi', function() {
it('converts PHI files to XMIR files', function(done) {
home = path.resolve('temp/test-unphi/simple');
fs.rmSync(home, {recursive: true, force: true});
fs.mkdirSync(path.resolve(home, 'target/phi'), {recursive: true});
fs.writeFileSync(path.resolve(home, 'target/phi/app.phi'), '{ app ↦ ⟦ ⟧ }');
const stdout = runSync([
'unphi',
'--verbose',
'--track-optimization-steps',
'--parser=0.34.1',
'--hash=1d605bd872f27494551e9dd2341b9413d0d96d89',
'-t', path.resolve(home, 'target'),
]);
assertFilesExist(
stdout, home,
[
'target/unphi/app.xmir',
]
);
done();
});
});

0 comments on commit 70bb9b7

Please sign in to comment.