"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.libmovevm = exports.libcompiler = void 0;
const ref_napi_1 = __importDefault(require("@eleccookie/ref-napi"));
const ffi_napi_1 = __importDefault(require("@eleccookie/ffi-napi"));
const path = __importStar(require("path"));
const types_1 = require("../types");
let compilerName;
let movevmName;
if (process.platform == 'darwin') {
    // macOS
    compilerName = 'libcompiler.dylib';
    movevmName = 'libmovevm.dylib';
}
else if (process.platform == 'linux' && process.arch == 'arm64') {
    // linux arm64
    compilerName = 'libcompiler.aarch64.so';
    movevmName = 'libmovevm.aarch64.so';
}
else if (process.platform == 'linux' && process.arch == 'x64') {
    // linux x64
    compilerName = 'libcompiler.x86_64.so';
    movevmName = 'libmovevm.x86_64.so';
}
else {
    // unsupported platform/architecture
    throw new Error(`${process.platform}/${process.arch} not supported`);
}
// Load the libcompiler library and define its FFI function signatures
exports.libcompiler = ffi_napi_1.default.Library(path.resolve(__dirname, `../../library/${compilerName}`), {
    create_new_move_package: [
        types_1.UnmanagedVectorType,
        [
            types_1.UnmanagedVectorPtr,
            types_1.ByteSliceViewType,
            types_1.ByteSliceViewType,
            types_1.ByteSliceViewType,
            ref_napi_1.default.types.bool,
        ],
    ],
    clean_move_package: [
        types_1.UnmanagedVectorType,
        [
            types_1.UnmanagedVectorPtr,
            types_1.ByteSliceViewType,
            ref_napi_1.default.types.bool,
            ref_napi_1.default.types.bool,
            ref_napi_1.default.types.bool,
        ],
    ],
    build_move_package: [
        types_1.UnmanagedVectorType,
        [types_1.UnmanagedVectorPtr, types_1.ByteSliceViewType],
    ],
    test_move_package: [
        types_1.UnmanagedVectorType,
        [types_1.UnmanagedVectorPtr, types_1.ByteSliceViewType, types_1.ByteSliceViewType],
    ],
});
// load the libmovevm library and define its FFI function signatures
exports.libmovevm = ffi_napi_1.default.Library(path.resolve(__dirname, `../../library/${movevmName}`), {
    read_module_info: [
        types_1.UnmanagedVectorType,
        [types_1.UnmanagedVectorPtr, types_1.ByteSliceViewType],
    ],
    stringify_struct_tag: [
        types_1.UnmanagedVectorType,
        [types_1.UnmanagedVectorPtr, types_1.ByteSliceViewType],
    ],
    parse_struct_tag: [
        types_1.UnmanagedVectorType,
        [types_1.UnmanagedVectorPtr, types_1.ByteSliceViewType],
    ],
    decode_module_bytes: [
        types_1.UnmanagedVectorType,
        [types_1.UnmanagedVectorPtr, types_1.ByteSliceViewType],
    ],
    decode_script_bytes: [
        types_1.UnmanagedVectorType,
        [types_1.UnmanagedVectorPtr, types_1.ByteSliceViewType],
    ],
});
//# sourceMappingURL=vm.js.map