forked from NUDT-compiler/nudt-compiler-cpp
parent
0ff62e9b35
commit
d1bb1836e1
@ -0,0 +1,98 @@
|
||||
// SysY 运行库实现:
|
||||
// - 按实验/评测规范提供 I/O 等函数实现
|
||||
// - 与编译器生成的目标代码链接,支撑运行时行为
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
// 输入函数
|
||||
int getint() {
|
||||
int value;
|
||||
scanf("%d", &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
int getch() {
|
||||
char ch;
|
||||
scanf("%c", &ch);
|
||||
return (int)ch;
|
||||
}
|
||||
|
||||
float getfloat() {
|
||||
float value;
|
||||
scanf("%f", &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
int getarray(int arr[]) {
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%d", &arr[i]);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int getfarray(float arr[]) {
|
||||
int n;
|
||||
scanf("%d", &n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%f", &arr[i]);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
// 输出函数
|
||||
void putint(int value) {
|
||||
printf("%d", value);
|
||||
}
|
||||
|
||||
void putch(int ch) {
|
||||
printf("%c", (char)ch);
|
||||
}
|
||||
|
||||
void putfloat(float value) {
|
||||
printf("%a", value);
|
||||
}
|
||||
|
||||
void putarray(int n, int arr[]) {
|
||||
printf("%d:", n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf(" %d", arr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void putfarray(int n, float arr[]) {
|
||||
printf("%d:", n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf(" %a", arr[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
// putstr 在测试用例中定义
|
||||
|
||||
// 计时函数
|
||||
static clock_t start_time = 0;
|
||||
|
||||
void starttime() {
|
||||
start_time = clock();
|
||||
}
|
||||
|
||||
void stoptime() {
|
||||
clock_t end_time = clock();
|
||||
double elapsed = (double)(end_time - start_time) / CLOCKS_PER_SEC;
|
||||
fprintf(stderr, "Total time: %.6f seconds\n", elapsed);
|
||||
}
|
||||
|
||||
// 内存管理函数(如果需要)
|
||||
void* _sysy_allocate(int size) {
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void _sysy_deallocate(void* ptr) {
|
||||
free(ptr);
|
||||
}
|
||||
@ -0,0 +1,4 @@
|
||||
// SysY 运行库头文件:
|
||||
// - 声明运行库函数原型(供编译器生成 call 或链接阶段引用)
|
||||
// - 与 sylib.c 配套,按规范逐步补齐声明
|
||||
|
||||
Loading…
Reference in new issue