Skip to content

Instantly share code, notes, and snippets.

View ALSchwalm's full-sized avatar

Adam Schwalm ALSchwalm

View GitHub Profile
int main() {
Mammal *m;
if (rand() % 2) {
m = new Cat();
} else {
m = new Dog();
}
m->walk();
delete m;
#include <cstdlib>
#include <iostream>
struct Mammal {
Mammal() { std::cout << "Mammal::Mammal\n"; }
virtual ~Mammal() { std::cout << "Mammal::~Mammal\n"; };
virtual void run() = 0;
virtual void walk() = 0;
virtual void move() { walk(); }
};
@ALSchwalm
ALSchwalm / movc++
Last active February 2, 2024 01:39
Proof of concept that llvm bytecode can be used as an intermediary to compile many languages using movfuscator
# Compile c++ to llvm bytecode
clang++ -S -emit-llvm -o bytecode.ll $1
# Convert bytecode to C
llc -march=c -o code.c bytecode.ll
# 'fix' static inline. This is a workaround for a bug
# in one of the parsers, I think.
sed -i 's/static inline.*//' code.c
template<typename T>
class Foo {
public:
Foo() {
++c;
}
private:
thread_local static int c;
};
num test_enum
{
A,
B,
C
};
template<test_enum T>
int f(int x);