forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
2.2 KiB
163 lines
2.2 KiB
#include "sylib.h"
|
|
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
|
|
extern int scanf(const char* format, ...);
|
|
extern int printf(const char* format, ...);
|
|
extern int getchar(void);
|
|
extern int putchar(int c);
|
|
|
|
int getint(void) {
|
|
int x = 0;
|
|
scanf("%d", &x);
|
|
return x;
|
|
}
|
|
|
|
int getch(void) {
|
|
return getchar();
|
|
}
|
|
|
|
int getarray(int a[]) {
|
|
int n;
|
|
scanf("%d", &n);
|
|
int i = 0;
|
|
for (; i < n; ++i) {
|
|
scanf("%d", &a[i]);
|
|
}
|
|
return n;
|
|
}
|
|
|
|
float getfloat(void) {
|
|
float x = 0.0f;
|
|
scanf("%f", &x);
|
|
return x;
|
|
}
|
|
|
|
int getfarray(float a[]) {
|
|
int n = 0;
|
|
if (scanf("%d", &n) != 1) {
|
|
return 0;
|
|
}
|
|
int i = 0;
|
|
for (; i < n; ++i) {
|
|
if (scanf("%f", &a[i]) != 1) {
|
|
return i;
|
|
}
|
|
}
|
|
return n;
|
|
}
|
|
|
|
void putint(int x) {
|
|
printf("%d", x);
|
|
}
|
|
|
|
void putch(int x) {
|
|
putchar(x);
|
|
}
|
|
|
|
void putarray(int n, int a[]) {
|
|
int i = 0;
|
|
printf("%d:", n);
|
|
for (; i < n; ++i) {
|
|
printf(" %d", a[i]);
|
|
}
|
|
putchar('\n');
|
|
}
|
|
|
|
void putfloat(float x) {
|
|
printf("%a", x);
|
|
}
|
|
|
|
void putfarray(int n, float a[]) {
|
|
int i = 0;
|
|
printf("%d:", n);
|
|
for (; i < n; ++i) {
|
|
printf(" %a", a[i]);
|
|
}
|
|
putchar('\n');
|
|
}
|
|
|
|
void puts(int s[]) {
|
|
if (!s) return;
|
|
while (*s) {
|
|
putchar(*s);
|
|
++s;
|
|
}
|
|
}
|
|
|
|
void _sysy_starttime(int lineno) {
|
|
(void)lineno;
|
|
}
|
|
|
|
void _sysy_stoptime(int lineno) {
|
|
(void)lineno;
|
|
}
|
|
|
|
void starttime(void) {
|
|
_sysy_starttime(0);
|
|
}
|
|
|
|
void stoptime(void) {
|
|
_sysy_stoptime(0);
|
|
}
|
|
|
|
int* memset(int* ptr, int value, int count) {
|
|
unsigned char* p = (unsigned char*)ptr;
|
|
unsigned char byte = (unsigned char)(value & 0xFF);
|
|
int i = 0;
|
|
for (; i < count; ++i) {
|
|
p[i] = byte;
|
|
}
|
|
return ptr;
|
|
}
|
|
|
|
int* sysy_alloc_i32(int count) {
|
|
if (count <= 0) {
|
|
return 0;
|
|
}
|
|
return (int*)malloc((size_t)count * sizeof(int));
|
|
}
|
|
|
|
float* sysy_alloc_f32(int count) {
|
|
if (count <= 0) {
|
|
return 0;
|
|
}
|
|
return (float*)malloc((size_t)count * sizeof(float));
|
|
}
|
|
|
|
void sysy_free_i32(int* ptr) {
|
|
if (!ptr) {
|
|
return;
|
|
}
|
|
free(ptr);
|
|
}
|
|
|
|
void sysy_free_f32(float* ptr) {
|
|
if (!ptr) {
|
|
return;
|
|
}
|
|
free(ptr);
|
|
}
|
|
|
|
void sysy_zero_i32(int* ptr, int count) {
|
|
int i = 0;
|
|
if (!ptr || count <= 0) {
|
|
return;
|
|
}
|
|
for (; i < count; ++i) {
|
|
ptr[i] = 0;
|
|
}
|
|
}
|
|
|
|
void sysy_zero_f32(float* ptr, int count) {
|
|
int i = 0;
|
|
if (!ptr || count <= 0) {
|
|
return;
|
|
}
|
|
for (; i < count; ++i) {
|
|
ptr[i] = 0.0f;
|
|
}
|
|
}
|
|
|