Finish converting GSL to absl::Span
One less dependency.
Change-Id: Iaac25a3c1312a21a8a2b77b8cfee2463bdb51196
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/motors/core/BUILD b/motors/core/BUILD
index 9d9687f..6c9962a 100644
--- a/motors/core/BUILD
+++ b/motors/core/BUILD
@@ -39,7 +39,7 @@
],
visibility = ["//visibility:public"],
deps = [
- "//third_party/GSL",
+ "@com_google_absl//absl/types:span",
],
)
diff --git a/motors/core/semihosting.h b/motors/core/semihosting.h
index c8de1f6..af2fa4b 100644
--- a/motors/core/semihosting.h
+++ b/motors/core/semihosting.h
@@ -3,7 +3,7 @@
// This file defines interfaces to the ARM semihosting functions.
-#include "third_party/GSL/include/gsl/gsl"
+#include "absl/types/span.h"
namespace frc971 {
namespace motors {
@@ -56,7 +56,7 @@
uint32_t length;
GetCommandLine() = default;
- GetCommandLine(gsl::span<char> buffer_in) {
+ GetCommandLine(absl::Span<char> buffer_in) {
buffer = buffer_in.data();
length = buffer_in.size();
}
@@ -114,16 +114,16 @@
uint32_t size;
Read() = default;
- Read(uint32_t handle_in, gsl::span<char> buffer_in) {
+ Read(uint32_t handle_in, absl::Span<char> buffer_in) {
handle = handle_in;
buffer = buffer_in.data();
size = buffer_in.size();
}
// Returns the result. If this is empty, that means the file is at EOF.
- gsl::span<const char> Execute() {
+ absl::Span<const char> Execute() {
const uint32_t not_read = integer_operation(0x06, this);
- return gsl::span<const char>(buffer, size - not_read);
+ return absl::Span<const char>(buffer, size - not_read);
}
};
@@ -160,7 +160,7 @@
uint32_t length;
Write() = default;
- Write(uint32_t handle_in, gsl::span<const char> buffer_in) {
+ Write(uint32_t handle_in, absl::Span<const char> buffer_in) {
handle = handle_in;
buffer = buffer_in.data();
length = buffer_in.size();
diff --git a/motors/peripheral/BUILD b/motors/peripheral/BUILD
index a42d502..7765ce1 100644
--- a/motors/peripheral/BUILD
+++ b/motors/peripheral/BUILD
@@ -45,7 +45,7 @@
hdrs = ["uart_buffer.h"],
visibility = ["//visibility:public"],
deps = [
- "//third_party/GSL",
+ "@com_google_absl//absl/types:span",
],
)
@@ -72,7 +72,7 @@
"//aos/containers:sized_array",
"//motors:util",
"//motors/core",
- "//third_party/GSL",
+ "@com_google_absl//absl/types:span",
],
)
@@ -99,6 +99,6 @@
":uart_buffer",
"//motors:util",
"//motors/core",
- "//third_party/GSL",
+ "@com_google_absl//absl/types:span",
],
)
diff --git a/motors/peripheral/spi.cc b/motors/peripheral/spi.cc
index c0bb767..8c4ad11 100644
--- a/motors/peripheral/spi.cc
+++ b/motors/peripheral/spi.cc
@@ -57,7 +57,7 @@
spi_.FlushInterruptRequests();
}
-void InterruptBufferedSpi::Write(gsl::span<const char> data,
+void InterruptBufferedSpi::Write(absl::Span<const char> data,
DisableInterrupts *disable_interrupts) {
frames_to_receive_ += data.size();
// Until we get all of the data queued, we'll call WriteFrames from our
@@ -82,11 +82,11 @@
}
}
-gsl::span<char> InterruptBufferedSpi::Read(
- gsl::span<char> buffer, DisableInterrupts *disable_interrupts) {
+absl::Span<char> InterruptBufferedSpi::Read(
+ absl::Span<char> buffer, DisableInterrupts *disable_interrupts) {
size_t bytes_read = 0;
{
- const gsl::span<const char> read_data =
+ const absl::Span<const char> read_data =
receive_buffer_.PopSpan(buffer.size());
std::copy(read_data.begin(), read_data.end(), buffer.begin());
bytes_read += read_data.size();
@@ -95,7 +95,7 @@
ReenableInterrupts{disable_interrupts};
{
- const gsl::span<const char> read_data =
+ const absl::Span<const char> read_data =
receive_buffer_.PopSpan(buffer.size() - bytes_read);
std::copy(read_data.begin(), read_data.end(),
buffer.subspan(bytes_read).begin());
diff --git a/motors/peripheral/spi.h b/motors/peripheral/spi.h
index 1cfb385..5361f91 100644
--- a/motors/peripheral/spi.h
+++ b/motors/peripheral/spi.h
@@ -1,10 +1,10 @@
#ifndef MOTORS_PERIPHERAL_SPI_H_
#define MOTORS_PERIPHERAL_SPI_H_
+#include "absl/types/span.h"
#include "motors/core/kinetis.h"
#include "motors/peripheral/uart_buffer.h"
#include "motors/util.h"
-#include "third_party/GSL/include/gsl/gsl"
namespace frc971 {
namespace teensy {
@@ -41,21 +41,11 @@
}
// Calling code must synchronize all of these.
- void EnableTransmitInterrupt() {
- rser_value_ |= M_SPI_TFFF_RE;
- }
- void DisableTransmitInterrupt() {
- rser_value_ &= ~M_SPI_TFFF_RE;
- }
- void EnableReceiveInterrupt() {
- rser_value_ |= M_SPI_RFDF_RE;
- }
- void DisableReceiveInterrupt() {
- rser_value_ &= ~M_SPI_RFDF_RE;
- }
- void FlushInterruptRequests() {
- module_->RSER = rser_value_;
- }
+ void EnableTransmitInterrupt() { rser_value_ |= M_SPI_TFFF_RE; }
+ void DisableTransmitInterrupt() { rser_value_ &= ~M_SPI_TFFF_RE; }
+ void EnableReceiveInterrupt() { rser_value_ |= M_SPI_RFDF_RE; }
+ void DisableReceiveInterrupt() { rser_value_ &= ~M_SPI_RFDF_RE; }
+ void FlushInterruptRequests() { module_->RSER = rser_value_; }
private:
KINETISK_SPI_t *const module_;
@@ -88,18 +78,20 @@
// Queues up the given data for immediate writing. Blocks only if the queue
// fills up before all of data is enqueued.
- void Write(gsl::span<const char> data, DisableInterrupts *disable_interrupts);
+ void Write(absl::Span<const char> data,
+ DisableInterrupts *disable_interrupts);
// Reads currently available data.
// Returns all the data which is currently available (possibly none);
// buffer is where to store the result. The return value will be a subspan of
// this.
- gsl::span<char> Read(gsl::span<char> buffer,
- DisableInterrupts *disable_interrupts);
+ absl::Span<char> Read(absl::Span<char> buffer,
+ DisableInterrupts *disable_interrupts);
// Should be called as the body of the interrupt handler.
void HandleInterrupt(const DisableInterrupts &disable_interrupts) {
- while (ReadAndWriteFrame(true, disable_interrupts)) {}
+ while (ReadAndWriteFrame(true, disable_interrupts)) {
+ }
spi_.FlushInterruptRequests();
}
diff --git a/motors/peripheral/uart.cc b/motors/peripheral/uart.cc
index 9cd4014..6e48320 100644
--- a/motors/peripheral/uart.cc
+++ b/motors/peripheral/uart.cc
@@ -52,12 +52,12 @@
module_->RWFIFO = 1;
}
-void Uart::DoWrite(gsl::span<const char> data) {
+void Uart::DoWrite(absl::Span<const char> data) {
// In theory, we could be more efficient about this by writing the number of
// bytes we know there's space for and only calling SpaceAvailable() (or
// otherwise reading S1) before the final one. In practice, the FIFOs are so
// short on this part it probably won't help anything.
- for (int i = 0; i < data.size(); ++i) {
+ for (size_t i = 0; i < data.size(); ++i) {
while (!SpaceAvailable()) {
}
WriteCharacter(data[i]);
@@ -93,7 +93,7 @@
}
}
-void InterruptBufferedUart::Write(gsl::span<const char> data) {
+void InterruptBufferedUart::Write(absl::Span<const char> data) {
DisableInterrupts disable_interrupts;
uart_.EnableTransmitInterrupt(disable_interrupts);
while (!data.empty()) {
@@ -104,18 +104,18 @@
}
}
-gsl::span<char> InterruptBufferedUart::Read(gsl::span<char> buffer) {
+absl::Span<char> InterruptBufferedUart::Read(absl::Span<char> buffer) {
size_t bytes_read = 0;
{
DisableInterrupts disable_interrupts;
- const gsl::span<const char> read_data =
+ const absl::Span<const char> read_data =
receive_buffer_.PopSpan(buffer.size());
std::copy(read_data.begin(), read_data.end(), buffer.begin());
bytes_read += read_data.size();
}
{
DisableInterrupts disable_interrupts;
- const gsl::span<const char> read_data =
+ const absl::Span<const char> read_data =
receive_buffer_.PopSpan(buffer.size() - bytes_read);
std::copy(read_data.begin(), read_data.end(),
buffer.subspan(bytes_read).begin());
diff --git a/motors/peripheral/uart.h b/motors/peripheral/uart.h
index ffb1529..d51bcfe 100644
--- a/motors/peripheral/uart.h
+++ b/motors/peripheral/uart.h
@@ -1,11 +1,11 @@
#ifndef MOTORS_PERIPHERAL_UART_H_
#define MOTORS_PERIPHERAL_UART_H_
+#include "absl/types/span.h"
#include "aos/containers/sized_array.h"
#include "motors/core/kinetis.h"
#include "motors/peripheral/uart_buffer.h"
#include "motors/util.h"
-#include "third_party/GSL/include/gsl/gsl"
namespace frc971 {
namespace teensy {
@@ -22,7 +22,7 @@
void Initialize(int baud_rate);
// Blocks until all of the data is at least queued.
- void Write(gsl::span<const char> data, const DisableInterrupts &) {
+ void Write(absl::Span<const char> data, const DisableInterrupts &) {
DoWrite(data);
}
@@ -77,7 +77,7 @@
module_->C2 = c2_value_;
}
- void DoWrite(gsl::span<const char> data);
+ void DoWrite(absl::Span<const char> data);
aos::SizedArray<char, 4> DoRead();
KINETISK_UART_t *const module_;
@@ -100,13 +100,13 @@
// Queues up the given data for immediate writing. Blocks only if the queue
// fills up before all of data is enqueued.
- void Write(gsl::span<const char> data);
+ void Write(absl::Span<const char> data);
// Reads currently available data.
// Returns all the data which is currently available (possibly none);
// buffer is where to store the result. The return value will be a subspan of
// this.
- gsl::span<char> Read(gsl::span<char> buffer);
+ absl::Span<char> Read(absl::Span<char> buffer);
// Should be called as the body of the interrupt handler.
void HandleInterrupt(const DisableInterrupts &disable_interrupts) {
diff --git a/motors/peripheral/uart_buffer.h b/motors/peripheral/uart_buffer.h
index 19015bb..c324a2d 100644
--- a/motors/peripheral/uart_buffer.h
+++ b/motors/peripheral/uart_buffer.h
@@ -2,8 +2,9 @@
#define MOTORS_PERIPHERAL_UART_BUFFER_H_
#include <array>
+#include <cstring>
-#include "third_party/GSL/include/gsl/gsl"
+#include "absl/types/span.h"
namespace frc971 {
namespace teensy {
@@ -13,14 +14,14 @@
class UartBuffer {
public:
// Returns the number of characters added.
- __attribute__((warn_unused_result)) int PushSpan(gsl::span<const char> data);
+ __attribute__((warn_unused_result)) int PushSpan(absl::Span<const char> data);
// max is the maximum size the returned span should be.
// The data in the result is only valid until another method is called.
// Note that this may not return all available data when doing so would
// require wrapping around, but it will always return a non-empty span if any
// data is available.
- gsl::span<const char> PopSpan(int max);
+ absl::Span<const char> PopSpan(int max);
bool empty() const { return size_ == 0; }
bool full() const { return size_ == kSize; }
@@ -44,7 +45,7 @@
};
template <int kSize>
-int UartBuffer<kSize>::PushSpan(gsl::span<const char> data) {
+int UartBuffer<kSize>::PushSpan(absl::Span<const char> data) {
const int end_location = (start_ + size_) % kSize;
const int remaining_end = ::std::min(kSize - size_, kSize - end_location);
const int on_end = ::std::min<int>(data.size(), remaining_end);
@@ -65,9 +66,10 @@
}
template <int kSize>
-gsl::span<const char> UartBuffer<kSize>::PopSpan(int max) {
+absl::Span<const char> UartBuffer<kSize>::PopSpan(int max) {
const size_t result_size = std::min(max, std::min(kSize - start_, size_));
- const auto result = gsl::span<const char>(data_).subspan(start_, result_size);
+ const auto result =
+ absl::Span<const char>(data_).subspan(start_, result_size);
start_ = (start_ + result_size) % kSize;
size_ -= result_size;
return result;
diff --git a/motors/print/BUILD b/motors/print/BUILD
index df27ce2..93f54f9 100644
--- a/motors/print/BUILD
+++ b/motors/print/BUILD
@@ -8,7 +8,7 @@
deps = [
"//aos/containers:sized_array",
"//motors/core",
- "//third_party/GSL",
+ "@com_google_absl//absl/types:span",
],
)
diff --git a/motors/print/itm.cc b/motors/print/itm.cc
index 0e3c38c..6f9164e 100644
--- a/motors/print/itm.cc
+++ b/motors/print/itm.cc
@@ -1,12 +1,16 @@
#include "motors/print/itm.h"
+#include <cstring>
+
+#include "absl/types/span.h"
#include "motors/core/itm.h"
namespace frc971 {
namespace motors {
namespace {
-template<int kPort> void WriteToPort(gsl::span<const char> buffer) {
+template <int kPort>
+void WriteToPort(absl::Span<const char> buffer) {
// This ignores memory barriers etc, because it will be called by
// CreatePrinting which must be called before any interrupts are enabled. That
// means the only thing we need to worry about is actually getting it
@@ -70,7 +74,7 @@
}
extern "C" int _write(const int /*file*/, char *const ptr, const int len) {
- WriteToPort<0>(gsl::span<const char>(ptr, len));
+ WriteToPort<0>(absl::Span<const char>(ptr, len));
return len;
}
@@ -81,12 +85,12 @@
_write(0, nullptr, 0);
}
-int ItmPrinting::WriteStdout(gsl::span<const char> buffer) {
+int ItmPrinting::WriteStdout(absl::Span<const char> buffer) {
WriteToPort<0>(buffer);
return buffer.size();
}
-int ItmPrinting::WriteDebug(gsl::span<const char> buffer) {
+int ItmPrinting::WriteDebug(absl::Span<const char> buffer) {
WriteToPort<1>(buffer);
return buffer.size();
}
diff --git a/motors/print/itm.h b/motors/print/itm.h
index 1ff0bd1..edcb798 100644
--- a/motors/print/itm.h
+++ b/motors/print/itm.h
@@ -1,6 +1,7 @@
#ifndef MOTORS_PRINT_ITM_
#define MOTORS_PRINT_ITM_
+#include "absl/types/span.h"
#include "motors/print/print.h"
namespace frc971 {
@@ -21,9 +22,9 @@
void Initialize() override {}
// This goes to stimulus port 0.
- int WriteStdout(gsl::span<const char> buffer) override;
+ int WriteStdout(absl::Span<const char> buffer) override;
// This goes to stimulus port 1.
- int WriteDebug(gsl::span<const char> buffer) override;
+ int WriteDebug(absl::Span<const char> buffer) override;
};
} // namespace motors
diff --git a/motors/print/print.h b/motors/print/print.h
index 89da913..34ba983 100644
--- a/motors/print/print.h
+++ b/motors/print/print.h
@@ -3,9 +3,9 @@
#include <memory>
+#include "absl/types/span.h"
#include "aos/containers/sized_array.h"
#include "motors/core/kinetis.h"
-#include "third_party/GSL/include/gsl/gsl"
namespace frc971 {
namespace teensy {
@@ -26,10 +26,12 @@
virtual void Initialize() = 0;
// Writes something directly to stdout/stderr (they are treated as the same).
- virtual int WriteStdout(gsl::span<const char> buffer) = 0;
+ virtual int WriteStdout(absl::Span<const char> buffer) = 0;
// Writes something to a separate debug stream. Some implementations will
// always ignore this, and others will ignore it under some conditions.
- virtual int WriteDebug(gsl::span<const char> buffer) { return buffer.size(); }
+ virtual int WriteDebug(absl::Span<const char> buffer) {
+ return buffer.size();
+ }
// Reads any characters which are available (never blocks).
//
@@ -46,7 +48,7 @@
~NopPrinting() override = default;
void Initialize() override {}
- int WriteStdout(gsl::span<const char> buffer) override {
+ int WriteStdout(absl::Span<const char> buffer) override {
return buffer.size();
}
};
diff --git a/motors/print/semihosting.cc b/motors/print/semihosting.cc
index 799b928..13bd78b 100644
--- a/motors/print/semihosting.cc
+++ b/motors/print/semihosting.cc
@@ -1,5 +1,6 @@
#include "motors/print/semihosting.h"
+#include "absl/types/span.h"
#include "motors/core/semihosting.h"
namespace frc971 {
@@ -11,11 +12,12 @@
}
extern "C" int _write(const int /*file*/, char *const ptr, const int len) {
- semihosting::Write operation{2 /* stderr */, gsl::span<const char>(ptr, len)};
+ semihosting::Write operation{2 /* stderr */,
+ absl::Span<const char>(ptr, len)};
return len - operation.Execute();
}
-int SemihostingPrinting::WriteStdout(gsl::span<const char> buffer) {
+int SemihostingPrinting::WriteStdout(absl::Span<const char> buffer) {
semihosting::Write operation{2 /* stderr */, buffer};
return buffer.size() - operation.Execute();
}
diff --git a/motors/print/semihosting.h b/motors/print/semihosting.h
index 6ea6c3b..d323a7a 100644
--- a/motors/print/semihosting.h
+++ b/motors/print/semihosting.h
@@ -1,6 +1,7 @@
#ifndef MOTORS_PRINT_SEMIHOSTING_H_
#define MOTORS_PRINT_SEMIHOSTING_H_
+#include "absl/types/span.h"
#include "motors/print/print.h"
namespace frc971 {
@@ -23,7 +24,7 @@
void Initialize() override {}
- int WriteStdout(gsl::span<const char> buffer) override;
+ int WriteStdout(absl::Span<const char> buffer) override;
// Could easily implement an optional WriteDebug which goes to a separate
// file if the name is filled out in the parameters.
diff --git a/motors/print/uart.cc b/motors/print/uart.cc
index 84b33cd..b635d23 100644
--- a/motors/print/uart.cc
+++ b/motors/print/uart.cc
@@ -51,7 +51,7 @@
NVIC_ENABLE_IRQ(stdout_status_interrupt_);
}
-int UartPrinting::WriteStdout(gsl::span<const char> buffer) {
+int UartPrinting::WriteStdout(absl::Span<const char> buffer) {
stdout_uart_.Write(buffer);
return buffer.size();
}
@@ -60,7 +60,7 @@
teensy::InterruptBufferedUart *const tty =
global_stdout.load(::std::memory_order_acquire);
if (tty != nullptr) {
- tty->Write(gsl::make_span(ptr, len));
+ tty->Write(absl::MakeSpan(ptr, len));
}
return len;
}
diff --git a/motors/print/uart.h b/motors/print/uart.h
index f4a61c8..7d81577 100644
--- a/motors/print/uart.h
+++ b/motors/print/uart.h
@@ -18,7 +18,7 @@
void Initialize() override;
- int WriteStdout(gsl::span<const char> buffer) override;
+ int WriteStdout(absl::Span<const char> buffer) override;
private:
teensy::InterruptBufferedUart stdout_uart_;
diff --git a/motors/print/usb.h b/motors/print/usb.h
index 981c5d3..1ed1bee 100644
--- a/motors/print/usb.h
+++ b/motors/print/usb.h
@@ -17,11 +17,11 @@
void Initialize() override;
- int WriteStdout(gsl::span<const char> buffer) override {
+ int WriteStdout(absl::Span<const char> buffer) override {
return stdout_tty_->Write(buffer.data(), buffer.size());
}
- int WriteDebug(gsl::span<const char> buffer) override {
+ int WriteDebug(absl::Span<const char> buffer) override {
if (debug_tty_ == nullptr) {
return buffer.size();
}
@@ -48,11 +48,11 @@
void Initialize() override;
- int WriteStdout(gsl::span<const char> buffer) override {
+ int WriteStdout(absl::Span<const char> buffer) override {
return stdout_tty_.Write(buffer.data(), buffer.size());
}
- int WriteDebug(gsl::span<const char> buffer) override {
+ int WriteDebug(absl::Span<const char> buffer) override {
return debug_tty_.Write(buffer.data(), buffer.size());
}