-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3f1251
commit 2fa30c6
Showing
28 changed files
with
949 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/lua5.4 | ||
|
||
-- This scripts generates a snippet of solidity code to be inserted | ||
-- in the EmulatorhConstants.sol file. | ||
|
||
local cartesi = require("cartesi") | ||
|
||
local function hex(n) | ||
return string.format("%x", n) | ||
end | ||
|
||
local function hexstring(hash) | ||
return (string.gsub(hash, ".", function(c) return string.format("%02x", string.byte(c)) end)) | ||
end | ||
|
||
local out = io.stdout | ||
|
||
out:write(' uint64 constant UARCH_CYCLE_ADDRESS = 0x' .. hex(cartesi.machine.get_csr_address("uarch_cycle")) .. ';\n') | ||
out:write(' uint64 constant UARCH_HALT_FLAG_ADDRESS = 0x' .. hex(cartesi.machine.get_csr_address("uarch_halt_flag")) .. ';\n') | ||
out:write(' uint64 constant UARCH_PC_ADDRESS = 0x' .. hex(cartesi.machine.get_csr_address("uarch_pc")) .. ';\n') | ||
out:write(' uint64 constant UARCH_X0_ADDRESS = 0x' .. hex(cartesi.machine.get_uarch_x_address(0)) .. ';\n') | ||
out:write(' uint64 constant UARCH_SHADOW_START_ADDRESS = 0x' .. hex(cartesi.UARCH_SHADOW_START_ADDRESS) .. ';\n') | ||
out:write(' uint64 constant UARCH_SHADOW_LENGTH = 0x' .. hex(cartesi.UARCH_SHADOW_LENGTH) .. ';\n') | ||
out:write(' uint64 constant UARCH_RAM_START_ADDRESS = 0x' .. hex(cartesi.UARCH_RAM_START_ADDRESS) .. ';\n') | ||
out:write(' uint64 constant UARCH_RAM_LENGTH = 0x' .. hex(cartesi.UARCH_RAM_LENGTH) .. ';\n') | ||
out:write(' uint64 constant UARCH_STATE_START_ADDRESS = 0x' .. hex(cartesi.UARCH_STATE_START_ADDRESS) .. ';\n') | ||
out:write(' uint8 constant UARCH_STATE_LOG2_SIZE = ' .. cartesi.UARCH_STATE_LOG2_SIZE .. ';\n') | ||
out:write(' bytes32 constant UARCH_PRISTINE_STATE_HASH = 0x' .. hexstring(cartesi.UARCH_PRISTINE_STATE_HASH) .. ';\n') | ||
out:write(' uint64 constant UARCH_ECALL_FN_HALT = ' .. cartesi.UARCH_ECALL_FN_HALT .. ';\n') | ||
out:write(' uint64 constant UARCH_ECALL_FN_PUTCHAR = ' .. cartesi.UARCH_ECALL_FN_PUTCHAR .. ';\n') | ||
out:write(' uint64 constant IFLAGS_ADDRESS = 0x' .. hex(cartesi.machine.get_csr_address("iflags")) .. ';\n') | ||
out:write(' uint64 constant HTIF_FROMHOST_ADDRESS = 0x' .. hex(cartesi.machine.get_csr_address("htif_fromhost")) .. ';\n') | ||
out:write(' uint32 constant TREE_LOG2_WORD_SIZE = 0x' .. hex(cartesi.TREE_LOG2_WORD_SIZE) .. ';\n') | ||
out:write(' uint32 constant TREE_WORD_SIZE = uint32(1) << TREE_LOG2_WORD_SIZE;\n') | ||
out:write(' uint64 constant PMA_CMIO_RX_BUFFER_START = 0x'.. hex(cartesi.PMA_CMIO_RX_BUFFER_START) .. ';\n') | ||
out:close() | ||
|
||
out:close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
SED=${SED:-"sed"} | ||
EMULATOR_DIR=${EMULATOR_DIR:-"../emulator"} | ||
CPP_RESET_PATH=${EMULATOR_DIR}"/src/send-cmio-response.cpp" | ||
|
||
TEMPLATE_FILE="./templates/SendCmioResponse.sol.template" | ||
TARGET_FILE="src/SendCmioResponse.sol" | ||
COMPAT_FILE="src/EmulatorCompat.sol" | ||
CONSTANTS_FILE="src/EmulatorConstants.sol" | ||
KEYWORD_START="START OF AUTO-GENERATED CODE" | ||
KEYWORD_END="END OF AUTO-GENERATED CODE" | ||
|
||
# get function names from EmulatorCompat.sol | ||
COMPAT_FNS=`cat $COMPAT_FILE | grep -o "function [^(]*(" | $SED "s/function//g" | $SED "s/(//g"` | ||
COMPAT_FNS=`echo $COMPAT_FNS | $SED -E "s/( |\n)/|/g"` | ||
|
||
# get constant names from EmulatorConstants.sol | ||
CONSTANTS=`cat $CONSTANTS_FILE | grep -E -o 'constant\s+[^ ]*' | $SED -E "s/constant//g; s/ //g" | tr '\n' '|' | sed "s/.$//"` | ||
|
||
# grab head and tail of the template | ||
start=`cat "$TEMPLATE_FILE" | grep "$KEYWORD_START" -n | grep -Eo "[0-9]*"` | ||
end=`cat "$TEMPLATE_FILE" | grep "$KEYWORD_END" -n | grep -Eo "[0-9]*"` | ||
total=`wc -l "$TEMPLATE_FILE" | grep -Eo "[0-9]*"` | ||
let last=total-end+1 | ||
|
||
h=`head -n $start $TEMPLATE_FILE` | ||
t=`tail -n -$last $TEMPLATE_FILE` | ||
|
||
cpp_src=`cat "$CPP_RESET_PATH"` | ||
pattern="namespace cartesi \{(.*)\}" | ||
[[ $cpp_src =~ $pattern ]] | ||
|
||
# replace cpp specific syntaxes with solidity ones | ||
cpp_src=`echo "${BASH_REMATCH[1]}" \ | ||
| $SED "/Explicit instantiatio/d" \ | ||
| $SED "/template/d" \ | ||
| $SED "s/machine_merkle_tree::get_log2_word_size()/TREE_LOG2_WORD_SIZE/g" \ | ||
| $SED -E "s/($COMPAT_FNS)/EmulatorCompat.\1/g" \ | ||
| $SED "s/writeMemoryWithPadding(a, PMA_CMIO_RX_BUFFER_START, data, dataLength, writeLengthLog2Size);/a.writeRegion(Memory.regionFromPhysicalAddress(PMA_CMIO_RX_BUFFER_START.toPhysicalAddress(),Memory.alignedSizeFromLog2(uint8(writeLengthLog2Size - TREE_LOG2_WORD_SIZE))),dataHash);"/g \ | ||
| $SED -E "s/($CONSTANTS)([^a-zA-Z])/EmulatorConstants.\1\2/g" \ | ||
| $SED "s/void send_cmio_response(STATE_ACCESS &a, uint16 reason, bytes data, uint32 dataLength) {/function sendCmioResponse(AccessLogs.Context memory a, uint16 reason, bytes32 dataHash, uint32 dataLength) internal pure {/" \ | ||
| $SED "s/writeMemoryWithPadding(a, PMA_CMIO_RX_BUFFER_START, data, dataLength, writeLengthLog2Size);/a.writeRegion(Memory.regionFromPhysicalAddress(PMA_CMIO_RX_BUFFER_START.toPhysicalAddress(),Memory.alignedSizeFromLog2(writeLengthLog2Size)),dataHash);"/g \ | ||
| $SED "s/const uint64/uint64/g" \ | ||
| $SED "s/const uint32/uint32/g" \ | ||
| $SED "/^$/N;/^\n$/D" | ||
` | ||
|
||
# compose the solidity file from all components | ||
echo -e "$h" "\n\n$h_src" > $TARGET_FILE | ||
echo "$cpp_src" >> $TARGET_FILE | ||
echo -e "\n$t" >> $TARGET_FILE |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.