forked from ppxf25tqu/nudt-compiler-cpp
parent
c7e8b28d29
commit
827558938b
Binary file not shown.
@ -1,42 +1,83 @@
|
||||
// SysY 运行库实现:
|
||||
// - 按实验/评测规范提供 I/O 等函数实现
|
||||
// - 与编译器生成的目标代码链接,支撑运行时行为
|
||||
|
||||
#include<stdio.h>
|
||||
#include<stdarg.h>
|
||||
#include<sys/time.h>
|
||||
#include"sylib.h"
|
||||
/* Input & output functions */
|
||||
int getint(){int t; scanf("%d",&t); return t; }
|
||||
int getch(){char c; scanf("%c",&c); return (int)c; }
|
||||
float getfloat(){
|
||||
float n;
|
||||
scanf("%a", &n);
|
||||
return n;
|
||||
}
|
||||
|
||||
int getarray(int a[]){
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
for(int i=0;i<n;i++)scanf("%d",&a[i]);
|
||||
return n;
|
||||
}
|
||||
|
||||
int getfarray(float a[]) {
|
||||
int n;
|
||||
scanf("%d",&n);
|
||||
for(int i=0;i<n;i++)scanf("%d",&a[i]);
|
||||
scanf("%d", &n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
scanf("%a", &a[i]);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
void putint(int a){ printf("%d",a);}
|
||||
void putch(int a){ printf("%c",a); }
|
||||
void putarray(int n,int a[]){
|
||||
printf("%d:",n);
|
||||
for(int i=0;i<n;i++)printf(" %d",a[i]);
|
||||
printf("\n");
|
||||
printf("%d:",n);
|
||||
for(int i=0;i<n;i++)printf(" %d",a[i]);
|
||||
printf("\n");
|
||||
}
|
||||
float getfloat(){ float f; scanf("%f",&f); return f; }
|
||||
void putfloat(float a){ printf("%a",a); }
|
||||
int getfarray(float a[]){
|
||||
int n; scanf("%d",&n);
|
||||
for(int i=0;i<n;i++) scanf("%a",&a[i]);
|
||||
return n;
|
||||
void putfloat(float a) {
|
||||
printf("%a", a);
|
||||
}
|
||||
void putfarray(int n,float a[]){
|
||||
printf("%d:",n);
|
||||
for(int i=0;i<n;i++) printf(" %a",a[i]);
|
||||
void putfarray(int n, float a[]) {
|
||||
printf("%d:", n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf(" %a", a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
static struct timeval _sysy_start, _sysy_end;
|
||||
void starttime(){ gettimeofday(&_sysy_start, NULL); }
|
||||
void stoptime(){
|
||||
gettimeofday(&_sysy_end, NULL);
|
||||
long us = (_sysy_end.tv_sec - _sysy_start.tv_sec) * 1000000L
|
||||
+ (_sysy_end.tv_usec - _sysy_start.tv_usec);
|
||||
fprintf(stderr, "Timer: %ldus\n", us);
|
||||
}
|
||||
|
||||
void putf(char a[], ...) {
|
||||
va_list args;
|
||||
va_start(args, a);
|
||||
vfprintf(stdout, a, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/* Timing function implementation */
|
||||
__attribute((constructor)) void before_main(){
|
||||
for(int i=0;i<_SYSY_N;i++)
|
||||
_sysy_h[i] = _sysy_m[i]= _sysy_s[i] = _sysy_us[i] =0;
|
||||
_sysy_idx=1;
|
||||
}
|
||||
__attribute((destructor)) void after_main(){
|
||||
for(int i=1;i<_sysy_idx;i++){
|
||||
fprintf(stderr,"Timer@%04d-%04d: %dH-%dM-%dS-%dus\n",\
|
||||
_sysy_l1[i],_sysy_l2[i],_sysy_h[i],_sysy_m[i],_sysy_s[i],_sysy_us[i]);
|
||||
_sysy_us[0]+= _sysy_us[i];
|
||||
_sysy_s[0] += _sysy_s[i]; _sysy_us[0] %= 1000000;
|
||||
_sysy_m[0] += _sysy_m[i]; _sysy_s[0] %= 60;
|
||||
_sysy_h[0] += _sysy_h[i]; _sysy_m[0] %= 60;
|
||||
}
|
||||
fprintf(stderr,"TOTAL: %dH-%dM-%dS-%dus\n",_sysy_h[0],_sysy_m[0],_sysy_s[0],_sysy_us[0]);
|
||||
}
|
||||
void _sysy_starttime(int lineno){
|
||||
_sysy_l1[_sysy_idx] = lineno;
|
||||
gettimeofday(&_sysy_start,NULL);
|
||||
}
|
||||
void _sysy_stoptime(int lineno){
|
||||
gettimeofday(&_sysy_end,NULL);
|
||||
_sysy_l2[_sysy_idx] = lineno;
|
||||
_sysy_us[_sysy_idx] += 1000000 * ( _sysy_end.tv_sec - _sysy_start.tv_sec ) + _sysy_end.tv_usec - _sysy_start.tv_usec;
|
||||
_sysy_s[_sysy_idx] += _sysy_us[_sysy_idx] / 1000000 ; _sysy_us[_sysy_idx] %= 1000000;
|
||||
_sysy_m[_sysy_idx] += _sysy_s[_sysy_idx] / 60 ; _sysy_s[_sysy_idx] %= 60;
|
||||
_sysy_h[_sysy_idx] += _sysy_m[_sysy_idx] / 60 ; _sysy_m[_sysy_idx] %= 60;
|
||||
_sysy_idx ++;
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue