Skip to content

Commit

Permalink
feature: optim level for easy-riscv, fix: disabling printf_chk in cla…
Browse files Browse the repository at this point in the history
…ssroom
  • Loading branch information
sylefeb committed Dec 3, 2024
1 parent 4985bda commit 8c2772e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion learn-silice/classroom/soc_wave_player/firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $(PRGS): %: %.o $(OBJS)
$(ARCH)-objdump --disassemble code.elf > code.s

%.o : %.c
$(CC) -fno-builtin -fno-unroll-loops $(DEFINES) -Os -fno-stack-protector -fno-pic -march=rv32i -mabi=ilp32 -c $< -o $@
$(CC) -U_FORTIFY_SOURCE -fno-builtin -fno-unroll-loops $(DEFINES) -Os -fno-stack-protector -fno-pic -march=rv32i -mabi=ilp32 -c $< -o $@

%.o : %.s
$(AS) -march=rv32i -mabi=ilp32 $< -o $@
Expand Down
28 changes: 27 additions & 1 deletion src/RISCVSynthesizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,31 @@ int RISCVSynthesizer::stackSize(siliceParser::RiscvContext *riscv) const

// -------------------------------------------------

std::string RISCVSynthesizer::optimizationLevel(siliceParser::RiscvContext *riscv) const
{
if (riscv->riscvModifiers() != nullptr) {
for (auto m : riscv->riscvModifiers()->riscvModifier()) {
if (m->IDENTIFIER()->getText() == "O") {
if (m->STRING() == nullptr) {
if (m->NUMBER() == nullptr) {
reportError(sourceloc(riscv), "[RISCV] optimization level should be a number of a string.");
} else {
return m->NUMBER()->getText();
}
} else {
string level = m->STRING()->getText();
level = level.substr(1, level.length() - 2); // remove '"' and '"'
return level;
}
}
}
}
// optional, return default size if not found
return "s";
}

// -------------------------------------------------

std::string RISCVSynthesizer::coreName(siliceParser::RiscvContext *riscv) const
{
if (riscv->riscvModifiers() != nullptr) {
Expand Down Expand Up @@ -383,6 +408,7 @@ string RISCVSynthesizer::generateSiliceCode(siliceParser::RiscvContext *riscv) c
code << "$$memsz = " << memorySize(riscv)/4 << nxl;
code << "$$external = " << justHigherPow2(memorySize(riscv))-2 << nxl;
code << "$$arch = '" << archName(riscv) << '\'' << nxl;
code << "$$O = '" << optimizationLevel(riscv) << '\'' << nxl;
code << "$$algorithm_name = '" << riscv->IDENTIFIER()->getText() << "'" << nxl;
code << "$$dofile('" << normalizePath(CONFIG.keyValues()["libraries_path"]) + "/riscv/riscv-compile.lua')" << nxl;
code << "$$meminit = data_bram" << nxl;
Expand Down Expand Up @@ -410,7 +436,7 @@ RISCVSynthesizer::RISCVSynthesizer(siliceParser::RiscvContext *riscv)
// compute stack start
int stack_start = memorySize(riscv);
// get stack size
int stack_size = stackSize(riscv);
int stack_size = stackSize(riscv);
// compile from inline source
siliceParser::CblockContext *cblock = riscv->cblock();
sl_assert(cblock != nullptr);
Expand Down
2 changes: 2 additions & 0 deletions src/RISCVSynthesizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ namespace Silice
int memorySize(siliceParser::RiscvContext *riscv) const;
/// \brief returns the user-given stack size (if any, 0 otherwise)
int stackSize(siliceParser::RiscvContext *riscv) const;
/// \brief returns the user-given optimization level
std::string optimizationLevel(siliceParser::RiscvContext *riscv) const;
/// \brief returns the user-given core name (if any, default core selection otherwise)
std::string coreName(siliceParser::RiscvContext *riscv) const;
/// \brief returns the user-given architecture variant (defaults to rv32i otherwise)
Expand Down

0 comments on commit 8c2772e

Please sign in to comment.