feat: complete Lab3 instruction selection and assembly generation
This commit is contained in:
@@ -1,4 +1,77 @@
|
||||
// SysY 运行库实现:
|
||||
// - 按实验/评测规范提供 I/O 等函数实现
|
||||
// - 与编译器生成的目标代码链接,支撑运行时行为
|
||||
#include <stdio.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
int getint() {
|
||||
int x;
|
||||
if (scanf("%d", &x) != 1) return 0;
|
||||
return x;
|
||||
}
|
||||
|
||||
int getch() {
|
||||
return getchar();
|
||||
}
|
||||
|
||||
float getfloat() {
|
||||
double x;
|
||||
if (scanf("%lf", &x) != 1) return 0.0f;
|
||||
return (float)x;
|
||||
}
|
||||
|
||||
int getarray(int a[]) {
|
||||
int n;
|
||||
if (scanf("%d", &n) != 1) return 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (scanf("%d", &a[i]) != 1) break;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int getfarray(float a[]) {
|
||||
int n;
|
||||
if (scanf("%d", &n) != 1) return 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
double val;
|
||||
if (scanf("%lf", &val) != 1) break;
|
||||
a[i] = (float)val;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
void putint(int x) {
|
||||
printf("%d", x);
|
||||
}
|
||||
|
||||
void putch(int x) {
|
||||
putchar(x);
|
||||
}
|
||||
|
||||
void putfloat(float x) {
|
||||
printf("%a", x);
|
||||
}
|
||||
|
||||
void putarray(int n, int a[]) {
|
||||
printf("%d:", n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf(" %d", a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void putfarray(int n, float a[]) {
|
||||
printf("%d:", n);
|
||||
for (int i = 0; i < n; i++) {
|
||||
printf(" %a", a[i]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
struct timeval start, stop;
|
||||
void starttime() {
|
||||
gettimeofday(&start, NULL);
|
||||
}
|
||||
|
||||
void stoptime() {
|
||||
gettimeofday(&stop, NULL);
|
||||
long long duration = (stop.tv_sec - start.tv_sec) * 1000000LL + (stop.tv_usec - start.tv_usec);
|
||||
printf("timer: %lld us\n", duration);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user