-
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
Marcos Pernambuco Motta
committed
Nov 26, 2023
1 parent
a7aeb1a
commit fdc384b
Showing
23 changed files
with
293 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ test/uarch-log | |
test/UArchReplay_*.t.sol | ||
src/UArchConstants.sol | ||
src/UArchStep.sol | ||
src/UArchReset.sol | ||
.DS_Store |
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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
#!/bin/bash | ||
|
||
SED=${SED:-"sed"} | ||
|
||
for i in test/uarch-log/rv64ui*; do | ||
BASE=`basename $i .json | sed "s/-/_/g"` | ||
BASE=`basename $i .json | $SED "s/-/_/g"` | ||
cp templates/UArchReplay.t.sol.template test/UArchReplay_$BASE.t.sol | ||
sed -i "s/@X@/$BASE/g" test/UArchReplay_$BASE.t.sol | ||
$SED -i "s/@X@/$BASE/g" test/UArchReplay_$BASE.t.sol | ||
P=`basename $i` | ||
sed -i "s/@PATH@/$P/g" test/UArchReplay_$BASE.t.sol | ||
$SED -i "s/@PATH@/$P/g" test/UArchReplay_$BASE.t.sol | ||
done |
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,30 @@ | ||
#!/usr/bin/lua5.4 | ||
|
||
-- This scripts generates a snipet of solidity code to be inserted | ||
-- in the UarchConstants.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 UCYCLE = 0x' .. hex(cartesi.machine.get_csr_address("uarch_cycle")) .. ';\n') | ||
out:write(' uint64 constant UHALT = 0x' .. hex(cartesi.machine.get_csr_address("uarch_halt_flag")) .. ';\n') | ||
out:write(' uint64 constant UPC = 0x' .. hex(cartesi.machine.get_csr_address("uarch_pc")) .. ';\n') | ||
out:write(' uint64 constant UX0 = 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 RESET_POSITION = 0x' .. hex(cartesi.UARCH_STATE_START_ADDRESS) .. ';\n') | ||
out:write(' uint8 constant RESET_ALIGNED_SIZE = ' .. cartesi.UARCH_STATE_LOG2_SIZE .. ';\n') | ||
out:write(' bytes32 constant PRESTINE_STATE = 0x' .. hexstring(cartesi.UARCH_PRISTINE_STATE_HASH) .. ';\n') | ||
|
||
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,39 @@ | ||
#!/bin/bash | ||
SED=${SED:-"sed"} | ||
EMULATOR_DIR=${EMULATOR_DIR:-"../emulator"} | ||
CPP_RESET_PATH=${EMULATOR_DIR}"/src/uarch-reset-state.cpp" | ||
|
||
TEMPLATE_FILE="./templates/UArchReset.sol.template" | ||
TARGET_FILE="src/UArchReset.sol" | ||
COMPAT_FILE="src/UArchCompat.sol" | ||
KEYWORD_START="START OF AUTO-GENERATED CODE" | ||
KEYWORD_END="END OF AUTO-GENERATED CODE" | ||
|
||
# get function names from UArchCompat.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"` | ||
|
||
# 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 -E "s/($COMPAT_FNS)/UArchCompat.\1/g" \ | ||
| $SED "s/void uarch_reset_state(UarchState &a) {/function reset(AccessLogs.Context memory a) internal pure {/"` | ||
|
||
# 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright Cartesi and individual authors (see AUTHORS) | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
/// @title UArchReset | ||
/// @notice Reset microarchitecture to pristine state | ||
/// @dev This file is generated from templates/UArchReset.sol.template, one should not modify the content directly | ||
|
||
pragma solidity ^0.8.0; | ||
|
||
import "./UArchCompat.sol"; | ||
|
||
library UArchReset { | ||
// START OF AUTO-GENERATED CODE | ||
|
||
function reset(AccessLogs.Context memory a) internal pure { | ||
UArchCompat.resetState(a); | ||
} | ||
|
||
// END OF AUTO-GENERATED CODE | ||
} |
Oops, something went wrong.