gen-zam: Fix clang-tidy and pre-commit warnings

This commit is contained in:
Tim Wojtulewicz 2025-08-14 10:36:57 -07:00
parent a2f4f2adc3
commit 32522307d9
2 changed files with 21 additions and 21 deletions

View file

@ -1,10 +1,12 @@
// See the file "COPYING" in the toplevel directory for copyright. // See the file "COPYING" in the main distribution directory for copyright.
#include "Gen-ZAM.h" #include "Gen-ZAM.h"
#include <ctype.h> #include <cctype>
#include <cstring> #include <cstring>
#include <map>
#include <regex> #include <regex>
#include <set>
using namespace std; using namespace std;
@ -654,7 +656,7 @@ void ZAM_OpTemplate::BuildInstruction(const OCVec& oc, const string& params, con
Emit("z = GenInst(" + op + ", " + params + ");"); Emit("z = GenInst(" + op + ", " + params + ");");
} }
static bool skippable_ot(ZAM_OperandClass oc) { static bool skippable_op_type(ZAM_OperandClass oc) {
return oc == ZAM_OC_EVENT_HANDLER || oc == ZAM_OC_AUX || oc == ZAM_OC_LIST; return oc == ZAM_OC_EVENT_HANDLER || oc == ZAM_OC_AUX || oc == ZAM_OC_LIST;
} }
@ -677,7 +679,7 @@ string ZAM_OpTemplate::ExpandParams(const OCVec& oc, string eval, const vector<s
need_target = false; need_target = false;
} }
while ( oc_size > 0 && skippable_ot(oc[oc_size - 1]) ) while ( oc_size > 0 && skippable_op_type(oc[oc_size - 1]) )
--oc_size; --oc_size;
auto max_param = oc_size; auto max_param = oc_size;
@ -869,11 +871,11 @@ void ZAM_OpTemplate::StartDesc(const string& op_code, const string& oc_str) {
Emit("\"\","); Emit("\"\",");
else { else {
string ots; string ots;
for ( auto ot : op_types ) { for ( auto typ : op_types ) {
if ( ot == ZAM_TYPE_DEFAULT ) if ( typ == ZAM_TYPE_DEFAULT )
ots += "X"; ots += "X";
else else
ots += expr_name_types[ot]; ots += expr_name_types[typ];
} }
Emit("\"" + ots + "\", "); Emit("\"" + ots + "\", ");
@ -2217,8 +2219,8 @@ void ZAMGen::GenMacros() {
} }
} }
string ZAMGen::GenOpCode(const ZAM_OpTemplate* ot, const string& suffix, ZAM_InstClass zc) { string ZAMGen::GenOpCode(const ZAM_OpTemplate* op_templ, const string& suffix, ZAM_InstClass zc) {
auto op = "OP_" + ot->CanonicalName() + suffix; auto op = "OP_" + op_templ->CanonicalName() + suffix;
static unordered_set<string> known_opcodes; static unordered_set<string> known_opcodes;
@ -2237,16 +2239,16 @@ string ZAMGen::GenOpCode(const ZAM_OpTemplate* ot, const string& suffix, ZAM_Ins
// ... the "flavor" of how it treats its first operand ... // ... the "flavor" of how it treats its first operand ...
auto op_comment = ",\t// " + op; auto op_comment = ",\t// " + op;
auto op1_always_read = (zc == ZIC_FIELD || zc == ZIC_COND); auto op1_always_read = (zc == ZIC_FIELD || zc == ZIC_COND);
auto flavor = op1_always_read ? "OP1_READ" : ot->GetOp1Flavor(); auto flavor = op1_always_read ? "OP1_READ" : op_templ->GetOp1Flavor();
Emit(Op1Flavor, flavor + op_comment); Emit(Op1Flavor, flavor + op_comment);
// ... whether it has side effects ... // ... whether it has side effects ...
auto se = ot->HasSideEffects() ? "true" : "false"; auto se = op_templ->HasSideEffects() ? "true" : "false";
Emit(OpSideEffects, se + op_comment); Emit(OpSideEffects, se + op_comment);
// ... and the switch case that maps the enum to a string // ... and the switch case that maps the enum to a string
// representation. // representation.
auto name = ot->BaseName(); auto name = op_templ->BaseName();
transform(name.begin(), name.end(), name.begin(), ::tolower); transform(name.begin(), name.end(), name.begin(), ::tolower);
name += suffix; name += suffix;
transform(name.begin(), name.end(), name.begin(), under_to_dash); transform(name.begin(), name.end(), name.begin(), under_to_dash);
@ -2408,7 +2410,7 @@ bool ZAMGen::ParseTemplate() {
const auto& op_name = words[1]; const auto& op_name = words[1];
// We track issues with the wrong number of template arguments // We track issues with the wrong number of template arguments
// up front, to avoid mis-invoking constructors, but we don't // up front, to avoid misinvoking constructors, but we don't
// report these until later because if the template names a // report these until later because if the template names a
// bad operation, it's better to report that as the core problem. // bad operation, it's better to report that as the core problem.
const char* args_mismatch = nullptr; const char* args_mismatch = nullptr;

View file

@ -1,4 +1,4 @@
// See the file "COPYING" in the toplevel directory for copyright. // See the file "COPYING" in the main distribution directory for copyright.
// Gen-ZAM is a standalone program that takes as input a file specifying // Gen-ZAM is a standalone program that takes as input a file specifying
// ZAM operations and from them generates a (large) set of C++ include // ZAM operations and from them generates a (large) set of C++ include
@ -9,11 +9,9 @@
#pragma once #pragma once
#include <assert.h> #include <cassert>
#include <map>
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <set>
#include <string> #include <string>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
@ -442,15 +440,15 @@ protected:
// Generates the C++ case statement for evaluating the given flavor // Generates the C++ case statement for evaluating the given flavor
// of operation. // of operation.
void GenEval(EmitTarget et, const string& ot_str, const string& op_suffix, const string& eval, ZAM_InstClass zc); void GenEval(EmitTarget et, const string& oc_str, const string& op_suffix, const string& eval, ZAM_InstClass zc);
// Generates a description of the ZAM operation suitable for // Generates a description of the ZAM operation suitable for
// reflection. // reflection.
void GenDesc(const string& op_code, const string& ot_str, const string& eval); void GenDesc(const string& op_code, const string& oc_str, const string& eval);
// Generates the first part of a description, up to (but not including) // Generates the first part of a description, up to (but not including)
// the evaluation. // the evaluation.
void StartDesc(const string& op_code, const string& ot_str); void StartDesc(const string& op_code, const string& oc_str);
// Finishes a description, once the evaluation is done. // Finishes a description, once the evaluation is done.
void EndDesc(); void EndDesc();
@ -929,7 +927,7 @@ public:
// Generates a ZAM op-code for the given template, suffix, and // Generates a ZAM op-code for the given template, suffix, and
// instruction class. Also creates auxiliary information associated // instruction class. Also creates auxiliary information associated
// with the instruction. // with the instruction.
string GenOpCode(const ZAM_OpTemplate* ot, const string& suffix, ZAM_InstClass zc = ZIC_REGULAR); string GenOpCode(const ZAM_OpTemplate* op_templ, const string& suffix, ZAM_InstClass zc = ZIC_REGULAR);
// These methods provide low-level parsing (and error-reporting) // These methods provide low-level parsing (and error-reporting)
// access to ZAM_OpTemplate objects. // access to ZAM_OpTemplate objects.