mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-23 03:51:02 +00:00
Cleanup
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "revive",
|
||||
"version": "1.0.0",
|
||||
"description": "Revive compiler",
|
||||
"main": "run_revive.js",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"deasync": "^0.1.15",
|
||||
"solc": "^0.8.28"
|
||||
},
|
||||
"scripts": {
|
||||
"init": "cp -r ../target/wasm32-unknown-emscripten/release/resolc.{js,wasm} .",
|
||||
"test": "npm run init && node run_revive.js"
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
import solc from 'solc';
|
||||
|
||||
// Import the Emscripten module
|
||||
import ModuleFactory from './resolc.js';
|
||||
|
||||
async function runCompiler() {
|
||||
const Module = await ModuleFactory();
|
||||
Module.solc = solc;
|
||||
|
||||
// Create input Solidity source code
|
||||
const input = `
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8;
|
||||
contract Baseline {
|
||||
function baseline() public payable {}
|
||||
}`;
|
||||
|
||||
// Write the input Solidity code to the Emscripten file system
|
||||
Module.FS.writeFile('./input.sol', input);
|
||||
|
||||
// Compile the Solidity source code
|
||||
Module.callMain(['./input.sol', '-O3','--bin']);
|
||||
}
|
||||
|
||||
runCompiler().catch(err => {
|
||||
console.error('Error:', err);
|
||||
});
|
||||
@@ -1,49 +0,0 @@
|
||||
import { readFileSync } from 'fs';
|
||||
import { fileURLToPath } from 'url';
|
||||
import path from 'path';
|
||||
import vm from 'vm';
|
||||
import { createRequire } from 'module';
|
||||
const require = createRequire(import.meta.url);
|
||||
|
||||
// Import the Emscripten module
|
||||
import ModuleFactory from './resolc.mjs';
|
||||
|
||||
async function initializeSolc() {
|
||||
// Load soljson.js
|
||||
const soljsonPath = path.join('./', 'soljson.js');
|
||||
const soljsonCode = readFileSync(soljsonPath, 'utf8');
|
||||
|
||||
// Create a new VM context and run soljson.js in it
|
||||
const soljsonContext = { Module: {} };
|
||||
vm.createContext(soljsonContext); // Create a new context
|
||||
vm.runInContext(soljsonCode, soljsonContext); // Execute soljson.js in the new context
|
||||
|
||||
// Return the initialized soljson module
|
||||
return soljsonContext.Module;
|
||||
}
|
||||
|
||||
async function runCompiler() {
|
||||
const soljson = await initializeSolc();
|
||||
const Module = await ModuleFactory();
|
||||
|
||||
// Expose soljson in the Module context
|
||||
Module.soljson = soljson;
|
||||
|
||||
// Create input Solidity source code
|
||||
const input = `
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8;
|
||||
contract Baseline {
|
||||
function baseline() public payable {}
|
||||
}`;
|
||||
|
||||
// Write the input Solidity code to the Emscripten file system
|
||||
Module.FS.writeFile('./input.sol', input);
|
||||
|
||||
// Compile the Solidity source code
|
||||
Module.callMain(['./input.sol', '-O3','--bin']);
|
||||
}
|
||||
|
||||
runCompiler().catch(err => {
|
||||
console.error('Error:', err);
|
||||
});
|
||||
-111
File diff suppressed because one or more lines are too long
@@ -1,11 +1,11 @@
|
||||
mergeInto(LibraryManager.library, {
|
||||
soljson_compile: function(inputPtr, inputLen) {
|
||||
var inputJson = UTF8ToString(inputPtr, inputLen);
|
||||
var output = Module.soljson.cwrap('solidity_compile', 'string', ['string'])(inputJson);
|
||||
const inputJson = UTF8ToString(inputPtr, inputLen);
|
||||
const output = Module.solc.compile(inputJson)
|
||||
return stringToNewUTF8(output)
|
||||
},
|
||||
soljson_version: function() {
|
||||
var version = Module.soljson.cwrap("solidity_version", "string", [])();
|
||||
var version = Module.solc.version();
|
||||
return stringToNewUTF8(version)
|
||||
},
|
||||
resolc_compile: function(inputPtr, inputLen) {
|
||||
|
||||
+2
-2
@@ -1,9 +1,9 @@
|
||||
// worker.js
|
||||
// nodejs version
|
||||
const { parentPort } = require('worker_threads');
|
||||
import { parentPort } from 'worker_threads';
|
||||
|
||||
parentPort.on('message', async (inputJson) => {
|
||||
const { default: ModuleFactory } = await import('./resolc.mjs');
|
||||
const { default: ModuleFactory } = await import('./resolc.js');
|
||||
const newModule = await ModuleFactory();
|
||||
|
||||
// Create a virtual file for stdin
|
||||
|
||||
Reference in New Issue
Block a user