Skip to content

Commit

Permalink
Refractor unnecesary functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cmp831 committed Apr 14, 2021
1 parent c0ea6d3 commit 0b23e1e
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
EMCC=emcc

all: sudoku.cpp
$(EMCC) -O3 -s WASM=1 -o main.js -s EXTRA_EXPORTED_RUNTIME_METHODS='["getValue", "setValue"]' -s EXPORTED_FUNCTIONS="['_calloc', '_returnSudoku', '_initSudoku', '_SolveSudoku']" -s EXPORT_ES6=1 -s MODULARIZE=1 sudoku.cpp
$(EMCC) -O3 -s WASM=1 -o main.js -s EXTRA_EXPORTED_RUNTIME_METHODS='["getValue", "setValue"]' -s EXPORTED_FUNCTIONS="['_calloc', '_SolveSudoku']" -s EXPORT_ES6=1 -s MODULARIZE=1 sudoku.cpp
2 changes: 1 addition & 1 deletion main.js

Large diffs are not rendered by default.

Binary file modified main.wasm
Binary file not shown.
7 changes: 2 additions & 5 deletions sudoku-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,9 @@ Module().then(function (mymod) {
solveBtn.onclick = () => {
let arrPtr = makePtrOfArray(mymod);
let startDate = window.performance.now();
const inputPtr = mymod._initSudoku(arrPtr);
let inputMatrix = getArrayFromPtr(mymod, inputPtr);
let solverResult = mymod._SolveSudoku(inputPtr);
let resultMatrixPtr = mymod._returnSudoku();
let solverResult = mymod._SolveSudoku(arrPtr);
let endDate = window.performance.now();
let resultMatrix = getArrayFromPtr(mymod, resultMatrixPtr);
let resultMatrix = getArrayFromPtr(mymod, arrPtr);
setSudokuGrid(resultMatrix);
alert(`${solverResult ? 'Solved!': 'No results found'} Excecution time: ${(endDate - startDate)} ms`);
}
Expand Down
20 changes: 0 additions & 20 deletions sudoku.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,6 @@ void printGrid(uint32_t **grid)
cout << endl;
}
}

extern "C" {
/* function to return the Sudoku Grid */
EMSCRIPTEN_KEEPALIVE
uint32_t **returnSudoku() {
return grid;
}

EMSCRIPTEN_KEEPALIVE
uint32_t **initSudoku(uint32_t** ptr) {
grid = (uint32_t**)calloc(N, sizeof(*grid));
for(int i = 0; i < N; i++) {
grid[i] = (uint32_t*)calloc(N, sizeof(*grid[i]));
for (int j = 0; j < N; j++) {
grid[i][j] = ptr[i][j];
}
}
return grid;
}
}

// Driver Code
int main()
Expand Down

0 comments on commit 0b23e1e

Please sign in to comment.