amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth
range given to batch 22), each with at least one independent
contract-edge defect and plain public docs. Claude reviewed 100/100
USABLE against current digests; no ID or source overlap with main or
batch 22. Difficulty is unmeasured.

progress.md records the wrap-up: all Codex sessions and Qwen schedulers
stopped for the user's rollout, Qwen results so far (57 HARD of 373),
and what is left on each batch branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 17:52:13 +08:00

272 lines
7.0 KiB
C++

#include "model.hpp"
#include <array>
#include <iostream>
#include <limits>
#include <string>
#include <vector>
namespace {
using lineirq::Controller;
using lineirq::Counters;
using lineirq::Reply;
using lineirq::Snapshot;
using lineirq::View;
struct Command {
std::string verb;
std::vector<long long> numbers;
bool valid = false;
};
bool separator(char c)
{
return c == ' ' || c == '\t' || c == '\r';
}
std::vector<std::string> split(const std::string& input)
{
std::vector<std::string> words;
std::size_t cursor = 0;
while (cursor < input.size()) {
while (cursor < input.size() && separator(input[cursor])) {
++cursor;
}
if (cursor == input.size()) {
break;
}
const std::size_t start = cursor;
while (cursor < input.size() && !separator(input[cursor])) {
++cursor;
}
words.push_back(input.substr(start, cursor - start));
}
return words;
}
bool integer(const std::string& word, long long& output)
{
if (word.empty()) {
return false;
}
std::size_t cursor = 0;
bool negative = false;
if (word[cursor] == '+' || word[cursor] == '-') {
negative = word[cursor] == '-';
++cursor;
}
if (cursor == word.size()) {
return false;
}
const unsigned long long positive =
static_cast<unsigned long long>(std::numeric_limits<long long>::max());
const unsigned long long limit = negative ? positive + 1ULL : positive;
unsigned long long value = 0;
for (; cursor < word.size(); ++cursor) {
const unsigned char character = static_cast<unsigned char>(word[cursor]);
if (character < '0' || character > '9') {
return false;
}
const unsigned digit = character - '0';
if (value > (limit - digit) / 10ULL) {
return false;
}
value = value * 10ULL + digit;
}
if (negative && value == positive + 1ULL) {
output = std::numeric_limits<long long>::min();
} else if (negative) {
output = -static_cast<long long>(value);
} else {
output = static_cast<long long>(value);
}
return true;
}
int arguments(const std::string& verb)
{
if (verb == "reset") {
return 1;
}
if (verb == "install") {
return 4;
}
if (verb == "remove") {
return 2;
}
if (verb == "disable") {
return 2;
}
if (verb == "enable") {
return 2;
}
if (verb == "pulse") {
return 3;
}
if (verb == "level") {
return 3;
}
if (verb == "countset") {
return 3;
}
if (verb == "enter") {
return 1;
}
if (verb == "finish") {
return 2;
}
if (verb == "inspect") {
return 2;
}
if (verb == "count") {
return 2;
}
if (verb == "ready") {
return 2;
}
if (verb == "totals") {
return 1;
}
if (verb == "snapshot") {
return 1;
}
return -1;
}
Command parse(const std::string& input)
{
Command command;
const std::vector<std::string> words = split(input);
if (words.empty()) {
return command;
}
command.verb = words[0];
const int arity = arguments(command.verb);
if (arity < 0) {
return command;
}
if (words.size() != static_cast<std::size_t>(arity + 1)) {
return command;
}
for (std::size_t index = 1; index < words.size(); ++index) {
long long number = 0;
if (!integer(words[index], number)) {
return command;
}
command.numbers.push_back(number);
}
if (command.numbers[0] < 0 || command.numbers[0] > 1) {
return command;
}
command.valid = true;
return command;
}
void print_view(const View& line)
{
std::cout << ' ' << line.live;
std::cout << ' ' << line.mode;
std::cout << ' ' << line.priority;
std::cout << ' ' << line.depth;
std::cout << ' ' << line.pending;
std::cout << ' ' << line.active;
std::cout << ' ' << line.asserted;
std::cout << ' ' << line.received;
std::cout << ' ' << line.handled;
std::cout << ' ' << line.entries;
}
void print_counters(const Counters& counters)
{
for (std::uint64_t value : counters) {
std::cout << ' ' << value;
}
}
void print_snapshot(char tag, int bank, const Snapshot& snapshot)
{
std::cout << tag << ' ' << bank;
print_counters(snapshot.counters);
for (const View& line : snapshot.lines) {
print_view(line);
}
std::cout << '\n';
}
Reply apply(Controller& controller, const Command& command, View& view)
{
const std::string& verb = command.verb;
const std::vector<long long>& numbers = command.numbers;
if (verb == "reset") {
return controller.reset();
}
if (verb == "install") {
return controller.install(numbers[1], numbers[2], numbers[3]);
}
if (verb == "remove") {
return controller.remove(numbers[1]);
}
if (verb == "disable") {
return controller.disable(numbers[1]);
}
if (verb == "enable") {
return controller.enable(numbers[1]);
}
if (verb == "pulse") {
return controller.pulse(numbers[1], numbers[2]);
}
if (verb == "level") {
return controller.level(numbers[1], numbers[2]);
}
if (verb == "countset") {
return controller.countset(numbers[1], numbers[2]);
}
if (verb == "enter") {
return controller.enter();
}
if (verb == "finish") {
return controller.finish(numbers[1]);
}
if (verb == "inspect") {
return controller.inspect(numbers[1], view);
}
if (verb == "count") {
return controller.count(numbers[1]);
}
if (verb == "ready") {
return controller.ready(numbers[1]);
}
if (verb == "totals" || verb == "snapshot") {
return Reply{};
}
return Reply{-8, 0};
}
void query(Controller& controller, const Command& command, const View& view)
{
if (command.verb == "inspect") {
std::cout << 'V';
print_view(view);
std::cout << '\n';
}
if (command.verb == "totals") {
std::cout << 'T';
print_counters(controller.totals());
std::cout << '\n';
}
if (command.verb == "snapshot") {
print_snapshot('Q', static_cast<int>(command.numbers[0]), controller.snapshot());
}
}
}
int main()
{
std::array<Controller, 2> controllers;
std::string input;
while (std::getline(std::cin, input)) {
const Command command = parse(input);
Reply reply{-8, 0};
View view;
if (command.valid) {
Controller& controller = controllers[command.numbers[0]];
reply = apply(controller, command, view);
}
std::cout << "R " << 0 << ' ' << reply.value << '\n';
if (command.valid) {
Controller& controller = controllers[command.numbers[0]];
query(controller, command, view);
}
for (int bank = 0; bank < 2; ++bank) {
print_snapshot('S', bank, controllers[bank].snapshot());
}
}
return 0;
}