Skip to content

Commit

Permalink
Try to fix MSVC compiler error
Browse files Browse the repository at this point in the history
  • Loading branch information
raccog committed Nov 3, 2023
1 parent 1dc105b commit 00d8dd7
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 56 deletions.
16 changes: 8 additions & 8 deletions src/isa/pseudoinstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ using PseudoExpandFunc = std::function<Result<std::vector<LineTokens>>(

template <typename PseudoInstrImpl>
struct PseudoInstruction : public PseudoInstructionBase {
constexpr static unsigned ExpectedTokens =
1 + PseudoInstrImpl::Fields::NumFields();
constexpr static unsigned ExpectedTokens() {
return 1 + PseudoInstrImpl::Fields::NumFields();
}
QString name() const override {
return QString(PseudoInstrImpl::Name.data());
}
Result<std::vector<LineTokens>> expand(const TokenizedSrcLine &line,
SymbolMap &symbols) const override {
if (line.tokens.length() != PseudoInstrImpl::ExpectedTokens) {
return Error(line,
"Instruction '" + name() + "' expects " +
QString::number(PseudoInstrImpl::ExpectedTokens - 1) +
" arguments, but got " +
QString::number(line.tokens.length() - 1));
if (line.tokens.length() != ExpectedTokens()) {
return Error(line, "Instruction '" + name() + "' expects " +
QString::number(ExpectedTokens() - 1) +
" arguments, but got " +
QString::number(line.tokens.length() - 1));
}

return PseudoInstrImpl::expander(*this, line, symbols);
Expand Down
1 change: 0 additions & 1 deletion src/isa/rv_c_ext.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "pseudoinstruction.h"
#include "rv_i_ext.h"
#include "rvisainfo_common.h"

namespace Ripes {
Expand Down
47 changes: 47 additions & 0 deletions src/isa/rv_i_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,53 @@ struct Bgeu : public Instr<Bgeu, Funct3::BGEU> {

namespace TypePseudo {

template <unsigned tokenIndex>
struct PseudoReg : public Ripes::PseudoReg<tokenIndex, RV_GPRInfo> {};

template <typename PseudoInstrImpl>
struct PseudoInstrLoad : public PseudoInstruction<PseudoInstrImpl> {
struct Fields : public FieldSet<PseudoReg, PseudoImm> {};

static Result<std::vector<LineTokens>>
expander(const PseudoInstruction<PseudoInstrImpl> &,
const TokenizedSrcLine &line, const SymbolMap &) {
LineTokensVec v;
v.push_back(LineTokens() << Token("auipc") << line.tokens.at(1)
<< Token(line.tokens.at(2), "%pcrel_hi"));
v.push_back(LineTokens()
<< QString(PseudoInstrImpl::Name.data()) << line.tokens.at(1)
<< Token(QString("(%1 + 4) ").arg(line.tokens.at(2)),
"%pcrel_lo")
<< line.tokens.at(1));
return v;
}
};

template <typename PseudoInstrImpl>
struct PseudoInstrStore : public PseudoInstruction<PseudoInstrImpl> {
struct Fields : public FieldSet<PseudoReg, PseudoImm, PseudoReg> {};

static Result<std::vector<LineTokens>>
expander(const PseudoInstruction<PseudoInstrImpl> &,
const TokenizedSrcLine &line, const SymbolMap &) {
bool canConvert;
getImmediate(line.tokens.at(2), canConvert);
if (canConvert) {
return Result<std::vector<LineTokens>>(
Error(0, "Unused; will fallback to non-pseudo op sw"));
}
LineTokensVec v;
v.push_back(LineTokens() << Token("auipc") << line.tokens.at(3)
<< Token(line.tokens.at(2), "%pcrel_hi"));
v.push_back(LineTokens()
<< QString(PseudoInstrImpl::Name.data()) << line.tokens.at(1)
<< Token(QString("(%1 + 4)").arg(line.tokens.at(2)),
"%pcrel_lo")
<< line.tokens.at(3));
return Result<std::vector<LineTokens>>(v);
}
};

struct Lb : public PseudoInstrLoad<Lb> {
constexpr static std::string_view Name = "lb";
};
Expand Down
47 changes: 0 additions & 47 deletions src/isa/rvisainfo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,53 +259,6 @@ struct RegRd : public GPR_Reg<RegRd<tokenIndex>, tokenIndex, BitRange<7, 11>> {
constexpr static std::string_view Name = "rd";
};

template <unsigned tokenIndex>
struct PseudoReg : public Ripes::PseudoReg<tokenIndex, RV_GPRInfo> {};

template <typename PseudoInstrImpl>
struct PseudoInstrLoad : public PseudoInstruction<PseudoInstrImpl> {
struct Fields : public FieldSet<PseudoReg, PseudoImm> {};

static Result<std::vector<LineTokens>>
expander(const PseudoInstruction<PseudoInstrImpl> &,
const TokenizedSrcLine &line, const SymbolMap &) {
LineTokensVec v;
v.push_back(LineTokens() << Token("auipc") << line.tokens.at(1)
<< Token(line.tokens.at(2), "%pcrel_hi"));
v.push_back(LineTokens()
<< QString(PseudoInstrImpl::Name.data()) << line.tokens.at(1)
<< Token(QString("(%1 + 4) ").arg(line.tokens.at(2)),
"%pcrel_lo")
<< line.tokens.at(1));
return v;
}
};

template <typename PseudoInstrImpl>
struct PseudoInstrStore : public PseudoInstruction<PseudoInstrImpl> {
struct Fields : public FieldSet<PseudoReg, PseudoImm, PseudoReg> {};

static Result<std::vector<LineTokens>>
expander(const PseudoInstruction<PseudoInstrImpl> &,
const TokenizedSrcLine &line, const SymbolMap &) {
bool canConvert;
getImmediate(line.tokens.at(2), canConvert);
if (canConvert) {
return Result<std::vector<LineTokens>>(
Error(0, "Unused; will fallback to non-pseudo op sw"));
}
LineTokensVec v;
v.push_back(LineTokens() << Token("auipc") << line.tokens.at(3)
<< Token(line.tokens.at(2), "%pcrel_hi"));
v.push_back(LineTokens()
<< QString(PseudoInstrImpl::Name.data()) << line.tokens.at(1)
<< Token(QString("(%1 + 4)").arg(line.tokens.at(2)),
"%pcrel_lo")
<< line.tokens.at(3));
return Result<std::vector<LineTokens>>(v);
}
};

}; // namespace RVISA

} // namespace Ripes

0 comments on commit 00d8dd7

Please sign in to comment.