Skip to content

Instantly share code, notes, and snippets.

@crabtw
crabtw / ffunc.c
Created March 22, 2012 17:02
rust ffi
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h>
void ffunc(struct sockaddr_in s, struct sockaddr_in (*cb)(struct sockaddr_in)) {
printf("rust -> c\n");
printf(" family: %u\n", s.sin_family);
printf(" port: %u\n", s.sin_port);
printf(" addr: %u\n", s.sin_addr.s_addr);
s.sin_family = AF_UNIX;
@crabtw
crabtw / llvm-mips.patch
Last active June 6, 2023 06:05
cross compile address sanitizer
Index: lib/Target/Mips/MipsISelLowering.cpp
===================================================================
--- lib/Target/Mips/MipsISelLowering.cpp (revision 182727)
+++ lib/Target/Mips/MipsISelLowering.cpp (working copy)
@@ -1073,7 +1073,14 @@
BuildMI(BB, DL, TII->get(Mips::AND), AlignedAddr)
.addReg(Ptr).addReg(MaskLSB2);
BuildMI(BB, DL, TII->get(Mips::ANDi), PtrLSB2).addReg(Ptr).addImm(3);
- BuildMI(BB, DL, TII->get(Mips::SLL), ShiftAmt).addReg(PtrLSB2).addImm(3);
+ if (Subtarget->isLittle()) {
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp (revision 181993)
+++ lib/Driver/Tools.cpp (working copy)
@@ -6007,8 +6007,12 @@
CmdArgs.push_back("/lib/ld-linux.so.3");
}
else if (ToolChain.getArch() == llvm::Triple::mips ||
- ToolChain.getArch() == llvm::Triple::mipsel)
- CmdArgs.push_back("/lib/ld.so.1");
@crabtw
crabtw / anonymous.td
Created November 20, 2019 14:48
llvm tablegen bugs
class AAA {
AAA a = !cast<AAA>(NAME);
}
foreach _ = [1, 2] in
def : AAA;
multiclass BBB {
def : AAA;
}
diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp
index e5afa1264a..a5691e7c91 100644
--- a/lib/Format/UnwrappedLineParser.cpp
+++ b/lib/Format/UnwrappedLineParser.cpp
@@ -1883,6 +1883,7 @@ void UnwrappedLineParser::parseLabel() {
--Line->Level;
if (CommentsBeforeNextToken.empty() && FormatTok->Tok.is(tok::l_brace)) {
CompoundStatementIndenter Indenter(this, Style, Line->Level);
+ ++Line->Level;
parseBlock(/*MustBeDeclaration=*/false);
@crabtw
crabtw / glib2.supp
Last active January 8, 2018 15:59
valgrind suppression file for glib2
# gobject
{
constructor
Memcheck:Leak
...
fun:gobject_init_ctor
}
# glib
@crabtw
crabtw / err.cpp
Last active April 28, 2017 03:09
#include <cstdlib>
#include <iostream>
static void err() {
std::cerr << std::endl;
exit(1);
}
template <typename First, typename... Rest>
static void err(First&& first, Rest&&... rest) {
@crabtw
crabtw / fmt.cpp
Created February 17, 2017 23:48
format
#include <cstdio>
#include <string>
struct Fmt {
operator const char *() {
return fmt.c_str();
}
std::string fmt;
};
@crabtw
crabtw / lib.sh
Last active January 20, 2016 01:09
rust cross compile scripts
HOST=x86_64-unknown-linux-gnu
#TARGET=mips-unknown-linux-gnu
#CROSS_TOOL=$HOME/tmp/mips-2013.05/bin
#CXX=mips-linux-gnu-g++
#CXXFLAGS="-shared -fPIC -mips32r2 -msoft-float -mabi=32"
#LLCFLAGS="-march=mips -mcpu=mips32r2 -soft-float -mattr=+mips32r2,+o32 -relocation-model=pic -disable-fp-elim -segmented-stacks"
TARGET=arm-unknown-linux-gnueabihf
CROSS_TOOL=$HOME/tmp/rpi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
@crabtw
crabtw / fix-select-coin.patch
Created January 1, 2016 08:07
Fix COIN key of gngeo 0.8
--- src/event.c.orig 2016-01-01 15:55:03.995071650 +0800
+++ src/event.c 2016-01-01 15:56:36.584921148 +0800
@@ -385,6 +385,11 @@
if (joy_state[1][GN_START])
memory.intern_start &= 0xFB;
+ if (joy_state[0][GN_SELECT_COIN])
+ memory.intern_start &= 0xFD;
+ if (joy_state[1][GN_SELECT_COIN])
+ memory.intern_start &= 0xF7;