Skip to content

Commit

Permalink
Use awk to rewrite compile.lua
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Sep 11, 2024
1 parent 7ca37f9 commit db805ce
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tests/benchmark/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ define debug
endef

define compile-run
$(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | lua $(ROOT_DIR)/../../tools/compile.lua | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc
$(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc
$(CKB-DEBUGGER) --read-file $(ROOT_DIR)/../../build/$(1).bc --bin $(BIN_PATH) -- -r | tee $(ROOT_DIR)/benchmark.txt
endef

Expand Down
4 changes: 2 additions & 2 deletions tests/ckb_js_tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ build/testdata_fs_modules.bin: test_data/fs_module/main.js test_data/fs_module/f

fs_bytecode:
mkdir -p ../../build/bytecode
$(CKB_DEBUGGER) --read-file test_data/fs_module/main.js --bin $(BIN_PATH) -- -c | lua $(ROOT_DIR)/../../tools/compile.lua | xxd -r -p > ../../build/bytecode/main.bc
$(CKB_DEBUGGER) --read-file test_data/fs_module/fib_module.js --bin $(BIN_PATH) -- -c | lua $(ROOT_DIR)/../../tools/compile.lua | xxd -r -p > ../../build/bytecode/fib_module.bc
$(CKB_DEBUGGER) --read-file test_data/fs_module/main.js --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > ../../build/bytecode/main.bc
$(CKB_DEBUGGER) --read-file test_data/fs_module/fib_module.js --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > ../../build/bytecode/fib_module.bc
cd ../../build/bytecode && lua ../../tools/fs.lua pack ../../build/testdata_fs_modules_bc.bin main.bc fib_module.bc
$(CKB_DEBUGGER) --max-cycles $(MAX_CYCLES) --read-file ../../build/testdata_fs_modules_bc.bin --bin $(BIN_PATH) -- -f -r 2>&1 | fgrep 'Run result: 0'

Expand Down
2 changes: 1 addition & 1 deletion tests/examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ define debug
endef

define compile-run
$(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | lua $(ROOT_DIR)/../../tools/compile.lua | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc
$(CKB-DEBUGGER) --read-file $(ROOT_DIR)/$(1) --bin $(BIN_PATH) -- -c | awk -f $(ROOT_DIR)/../../tools/compile.awk | xxd -r -p > $(ROOT_DIR)/../../build/$(1).bc
$(CKB-DEBUGGER) --read-file $(ROOT_DIR)/../../build/$(1).bc --bin $(BIN_PATH) -- -r | fgrep 'Run result: 0'
endef

Expand Down
14 changes: 14 additions & 0 deletions tools/compile.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/awk -f

{
# Check if the line starts with "Script log: "
if ($0 ~ /^Script log: /) {
# Remove "Script log: " from the line
line_data = gensub(/^Script log: /, "", "g")

# If the remaining line is not empty, print it
if (line_data != "") {
print line_data
}
}
}
8 changes: 0 additions & 8 deletions tools/compile.lua

This file was deleted.

0 comments on commit db805ce

Please sign in to comment.