Revert "Rename programs to instruction_processors (#3789)" (#3824)

This reverts commit 34344982a9.
This commit is contained in:
Greg Fitzgerald
2019-04-17 15:05:49 -06:00
committed by GitHub
parent 083090817a
commit 51a2988bb2
93 changed files with 44 additions and 44 deletions

1
programs/bpf/c/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/out/

2
programs/bpf/c/makefile Normal file
View File

@ -0,0 +1,2 @@
BPF_SDK := ../../../sdk/bpf
include $(BPF_SDK)/bpf.mk

View File

@ -0,0 +1,30 @@
/**
* @brief Benchmark program that does work
*
* Counts Armstrong Numbers between 1 and x
*/
#include <solana_sdk.h>
extern bool entrypoint(const uint8_t *input) {
uint64_t x = *(uint64_t *) input;
uint64_t *result = (uint64_t *) input + 1;
uint64_t count = 0;
for (int i = 1; i <= x; i++) {
uint64_t temp = i;
uint64_t num = 0;
while (temp != 0) {
uint64_t rem = (temp % 10);
num += rem * rem * rem;
temp /= 10;
}
if (i == num) {
count++;
}
}
sol_log_64(x, count, 0, 0, 0);
*result = count;
return true;
}

View File

@ -0,0 +1,11 @@
#include <criterion/criterion.h>
#include "bench_alu.c"
Test(bench_alu, sanity) {
uint64_t input[] = {500, 0};
cr_assert(entrypoint((uint8_t *) input));
cr_assert_eq(input[0], 500);
cr_assert_eq(input[1], 5);
}

View File

@ -0,0 +1,14 @@
/**
* @brief Example C-based BPF program that prints out the parameters
* passed to it
*/
#include <solana_sdk.h>
#include "helper.h"
extern bool entrypoint(const uint8_t *input) {
sol_log(__FILE__);
helper_function();
sol_log(__FILE__);
return true;
}

View File

@ -0,0 +1,11 @@
/**
* @brief Example C-based BPF program that prints out the parameters
* passed to it
*/
#include <solana_sdk.h>
#include "helper.h"
void helper_function(void) {
sol_log(__FILE__);
}

View File

@ -0,0 +1,7 @@
/**
* @brief Example C-based BPF program that prints out the parameters
* passed to it
*/
#include <solana_sdk.h>
void helper_function(void);

View File

@ -0,0 +1,36 @@
/**
* @brief Example C-based BPF program that moves funds from one account to
* another
*/
#include <solana_sdk.h>
/**
* Number of SolKeyedAccount expected. The program should bail if an
* unexpected number of accounts are passed to the program's entrypoint
*/
#define NUM_KA 3
extern bool entrypoint(const uint8_t *input) {
SolKeyedAccount ka[NUM_KA];
SolParameters params = (SolParameters) { .ka = ka };
if (!sol_deserialize(input, &params, SOL_ARRAY_SIZE(ka))) {
return false;
}
if (!params.ka[0].is_signer) {
sol_log("Transaction not signed by key 0");
return false;
}
int64_t lamports = *(int64_t *)params.data;
if (*params.ka[0].lamports >= lamports) {
*params.ka[0].lamports -= lamports;
*params.ka[2].lamports += lamports;
// sol_log_64(0, 0, *ka[0].lamports, *ka[2].lamports, lamports);
} else {
// sol_log_64(0, 0, 0xFF, *ka[0].lamports, lamports);
}
return true;
}

View File

@ -0,0 +1,10 @@
#include <solana_sdk.h>
static const char msg[] = "This is a message";
static const char msg2[] = "This is a different message";
extern bool entrypoint(const uint8_t *input) {
sol_log((char*)msg);
sol_log((char*)msg2);
return true;
}

View File

@ -0,0 +1,22 @@
/**
* @brief Example C++-based BPF program that prints out the parameters
* passed to it
*/
#include <solana_sdk.h>
extern bool entrypoint(const uint8_t *input) {
SolKeyedAccount ka[1];
SolParameters params = (SolParameters) { .ka = ka };
sol_log(__FILE__);
if (!sol_deserialize(input, &params, SOL_ARRAY_SIZE(ka))) {
return false;
}
// Log the provided input parameters. In the case of the no-op
// program, no account keys or input data are expected but real
// programs will have specific requirements so they can do their work.
sol_log_params(&params);
return true;
}

View File

@ -0,0 +1,23 @@
/**
* @brief Example C-based BPF program that prints out the parameters
* passed to it
*/
#include <solana_sdk.h>
extern bool entrypoint(const uint8_t *input) {
SolKeyedAccount ka[1];
SolParameters params = (SolParameters) { .ka = ka };
sol_log(__FILE__);
if (!sol_deserialize(input, &params, SOL_ARRAY_SIZE(ka))) {
return false;
}
// Log the provided input parameters. In the case of the no-op
// program, no account keys or input data are expected but real
// programs will have specific requirements so they can do their work.
sol_log_params(&params);
return true;
}

View File

@ -0,0 +1,16 @@
/**
* @brief test program that generates BPF PC relative call instructions
*/
#include <solana_sdk.h>
void __attribute__ ((noinline)) helper() {
sol_log(__func__);
}
extern bool entrypoint(const uint8_t *input) {
sol_log(__func__);
helper();
return true;
}

View File

@ -0,0 +1,17 @@
#include <solana_sdk.h>
struct foo {const uint8_t *input;};
void foo(const uint8_t *input, struct foo foo) ;
extern bool entrypoint(const uint8_t *input) {
struct foo f;
f.input = input;
foo(input, f);
return true;
}
void foo(const uint8_t *input, struct foo foo) {
sol_log_64(0, 0, 0, (uint64_t)input, (uint64_t)foo.input);
sol_assert(input == foo.input);
}

View File

@ -0,0 +1,21 @@
#include <solana_sdk.h>
struct test_struct { uint64_t x; uint64_t y; uint64_t z;};
static struct test_struct __attribute__ ((noinline)) test_function(void) {
struct test_struct s;
s.x = 3;
s.y = 4;
s.z = 5;
return s;
}
extern bool entrypoint(const uint8_t* input) {
struct test_struct s = test_function();
sol_log("foobar");
if (s.x + s.y + s.z == 12 ) {
return true;
}
return false;
}