Skip to content

Commit

Permalink
fix indent of sample
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Feb 19, 2025
1 parent 2a62b30 commit 0233c99
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions sample/data-code.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,30 @@ static const size_t codeSize = 4096;
*/

struct Generator : public CodeGenerator {
Generator()
Generator()
: CodeGenerator(dataSize + codeSize, DontSetProtectRWE)
{
// data from here
dataTop = const_cast<uint8_t*>(getCurr());
Label d1L, d2L;
L(d1L);
append4B(123000);
append4B(123000);
L(d2L);
append4B(456);
append4B(456);

// set the other data

setSize(dataSize);

// code from here
codeTop = getCurr<uint32_t(*)(uint8_t *data)>();
codeTop = getCurr<uint32_t(*)(uint8_t *data)>();

const Reg &dataTop = a2;
const Reg &dataTop = a2;
mv(dataTop, a0);
lw(a0, dataTop, getOffset(d1L));
lw(a0, dataTop, getOffset(d1L));
lw(a1, dataTop, getOffset(d2L));
add(a0, a0, a1);
ret();
}
ret();
}
uint32_t getOffset(const Label& L) const
{
return L.getAddress() - dataTop;
Expand All @@ -51,12 +50,12 @@ struct Generator : public CodeGenerator {
int main()
try
{
Generator gen;
gen.ready();
Generator gen;
gen.ready();
CodeArray::protect((void*)gen.codeTop, codeSize, CodeArray::PROTECT_RE);
printf("data=%p\n", gen.dataTop);
printf("code=%p\n", gen.codeTop);
printf("exec = %d\n", gen.codeTop(gen.dataTop));
printf("exec = %d\n", gen.codeTop(gen.dataTop));
} catch (std::exception& e) {
printf("err %s\n", e.what());
return 1;
Expand Down

0 comments on commit 0233c99

Please sign in to comment.