blob: 37f70e8eeace614f74a7706df9f883b049433c3a [file] [log] [blame] [edit]
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stdlib.h>
#include <stdio.h>
#include <springbok_intrinsics.h>
#include <springbok.h>
class ExampleStatic {
public:
ExampleStatic() {
springbok_simprint_error("Hello pre-main C++ world.", 0);
value = 1279;
}
~ExampleStatic() {
springbok_simprint_error("Goodbye pre-main C++ world.", 0);
}
unsigned int value;
};
ExampleStatic exampleStatic;
extern "C" __attribute__((constructor)) void boop(void) {
springbok_simprint_error("Hello pre-main C world.", 0);
}
extern "C" __attribute__((destructor)) void beep(void) {
springbok_simprint_error("Goodbye pre-main C world.", 0);
}
extern "C" void blerp(void) {
springbok_simprint_error("Fare thee well, atexit.", 0);
}
extern "C" int main(void) {
static char thingy[10] = {13, 14, 15, 16};
atexit(blerp);
printf("%s(%d): Hello printf!\n", __PRETTY_FUNCTION__, __LINE__);
const float sorta_pi = 3.141592653589f;
int chars_needed = float_to_str(0, NULL, sorta_pi);
char *buffer = new char[chars_needed];
float_to_str(chars_needed, buffer, sorta_pi);
printf("Pi is ~%s, %d characters printed\n", buffer, chars_needed);
delete[] buffer;
return thingy[0] + thingy[1] + thingy[2] + thingy[3] + exampleStatic.value;
}