mirror of
https://github.com/pezkuwichain/revive.git
synced 2026-06-14 04:11:03 +00:00
Cleanup
This commit is contained in:
+1
-1
@@ -14,4 +14,4 @@ artifacts
|
|||||||
tmp
|
tmp
|
||||||
package-lock.json
|
package-lock.json
|
||||||
/*.html
|
/*.html
|
||||||
/build
|
/js/resolc.*
|
||||||
|
|||||||
+2
-2
@@ -10,7 +10,7 @@ mkdir -p ${INSTALL_DIR}
|
|||||||
# Build LLVM, clang
|
# Build LLVM, clang
|
||||||
LLVM_SRC_PREFIX=${PWD}/llvm-project
|
LLVM_SRC_PREFIX=${PWD}/llvm-project
|
||||||
LLVM_SRC_DIR=${LLVM_SRC_PREFIX}/llvm
|
LLVM_SRC_DIR=${LLVM_SRC_PREFIX}/llvm
|
||||||
LLVM_BUILD_DIR=${PWD}/build/llvm
|
LLVM_BUILD_DIR=${LLVM_SRC_PREFIX}/build/llvm
|
||||||
if [ ! -d ${LLVM_BUILD_DIR} ] ; then
|
if [ ! -d ${LLVM_BUILD_DIR} ] ; then
|
||||||
mkdir -p ${LLVM_BUILD_DIR}
|
mkdir -p ${LLVM_BUILD_DIR}
|
||||||
fi
|
fi
|
||||||
@@ -33,7 +33,7 @@ cmake --install ${LLVM_BUILD_DIR}
|
|||||||
|
|
||||||
# Build compiler builtins
|
# Build compiler builtins
|
||||||
COMPILER_RT_SRC_DIR=${LLVM_SRC_PREFIX}/compiler-rt
|
COMPILER_RT_SRC_DIR=${LLVM_SRC_PREFIX}/compiler-rt
|
||||||
COMPILER_RT_BUILD_DIR=${PWD}/build/compiler-rt
|
COMPILER_RT_BUILD_DIR=${LLVM_SRC_PREFIX}/build/compiler-rt
|
||||||
if [ ! -d ${COMPILER_RT_BUILD_DIR} ] ; then
|
if [ ! -d ${COMPILER_RT_BUILD_DIR} ] ; then
|
||||||
mkdir -p ${COMPILER_RT_BUILD_DIR}
|
mkdir -p ${COMPILER_RT_BUILD_DIR}
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -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, {
|
mergeInto(LibraryManager.library, {
|
||||||
soljson_compile: function(inputPtr, inputLen) {
|
soljson_compile: function(inputPtr, inputLen) {
|
||||||
var inputJson = UTF8ToString(inputPtr, inputLen);
|
const inputJson = UTF8ToString(inputPtr, inputLen);
|
||||||
var output = Module.soljson.cwrap('solidity_compile', 'string', ['string'])(inputJson);
|
const output = Module.solc.compile(inputJson)
|
||||||
return stringToNewUTF8(output)
|
return stringToNewUTF8(output)
|
||||||
},
|
},
|
||||||
soljson_version: function() {
|
soljson_version: function() {
|
||||||
var version = Module.soljson.cwrap("solidity_version", "string", [])();
|
var version = Module.solc.version();
|
||||||
return stringToNewUTF8(version)
|
return stringToNewUTF8(version)
|
||||||
},
|
},
|
||||||
resolc_compile: function(inputPtr, inputLen) {
|
resolc_compile: function(inputPtr, inputLen) {
|
||||||
|
|||||||
+2
-2
@@ -1,9 +1,9 @@
|
|||||||
// worker.js
|
// worker.js
|
||||||
// nodejs version
|
// nodejs version
|
||||||
const { parentPort } = require('worker_threads');
|
import { parentPort } from 'worker_threads';
|
||||||
|
|
||||||
parentPort.on('message', async (inputJson) => {
|
parentPort.on('message', async (inputJson) => {
|
||||||
const { default: ModuleFactory } = await import('./resolc.mjs');
|
const { default: ModuleFactory } = await import('./resolc.js');
|
||||||
const newModule = await ModuleFactory();
|
const newModule = await ModuleFactory();
|
||||||
|
|
||||||
// Create a virtual file for stdin
|
// Create a virtual file for stdin
|
||||||
|
|||||||
+4
-2
@@ -2,9 +2,11 @@
|
|||||||
"name": "root",
|
"name": "root",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test:cli": "npm run test -w crates/solidity/src/tests/cli-tests"
|
"test:cli": "npm run test -w crates/solidity/src/tests/cli-tests",
|
||||||
|
"test:revive": "npm run test -w js"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
"crates/solidity/src/tests/cli-tests"
|
"crates/solidity/src/tests/cli-tests",
|
||||||
|
"js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user