Skip to content

Commit

Permalink
Changed the name of the function and related code for log output.
Browse files Browse the repository at this point in the history
  • Loading branch information
ax-6 committed Jul 25, 2024
1 parent 4b848a0 commit b683526
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 60 deletions.
9 changes: 4 additions & 5 deletions aq/aq.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@

int main(int argc, char *argv[]) {
// TODO(Aqvm): Finish this function after completing AQVM development.
AqvmRuntimeDebugger_OutputReport("\"INFO\"", "\"main_Start\"",
"\"Aq main program has been started.\"",
NULL);
AqvmRuntimeDebugger_OutputLog("\"INFO\"", "\"main_Start\"",
"\"Aq main program has been started.\"", NULL);
if (Aqvm_InitVm() != 0) {
AqvmRuntimeDebugger_OutputReport("\"ERROR\"", "\"main_InitVmError\"",
"\"Initializing Aqvm met error.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"", "\"main_InitVmError\"",
"\"Initializing Aqvm met error.\"", NULL);
return -1;
}
return 0;
Expand Down
79 changes: 39 additions & 40 deletions aqvm/memory/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
int AqvmMemory_CheckMemoryConditions() {
int warning_count = 0;
if (sizeof(aqbyte) != 1) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"WARNING\"", "\"AqvmMemory_CheckMemoryConditions_ByteLengthWarning\"",
"\"The length requirement for the byte type does not conform to the "
"type "
Expand All @@ -24,7 +24,7 @@ int AqvmMemory_CheckMemoryConditions() {
++warning_count;
}
if (sizeof(aqint) != 4) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"WARNING\"", "\"AqvmMemory_CheckMemoryConditions_IntLengthWarning\"",
"\"The length requirement for the int type does not conform to the "
"type "
Expand All @@ -33,7 +33,7 @@ int AqvmMemory_CheckMemoryConditions() {
++warning_count;
}
if (sizeof(aqlong) != 8) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"WARNING\"", "\"AqvmMemory_CheckMemoryConditions_LongLengthWarning\"",
"\"The length requirement for the long type does not conform to the "
"type "
Expand All @@ -42,7 +42,7 @@ int AqvmMemory_CheckMemoryConditions() {
++warning_count;
}
if (sizeof(aqfloat) != 4) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"WARNING\"",
"\"AqvmMemory_CheckMemoryConditions_FloatLengthWarning\"",
"\"The length requirement for the float type does not conform to the "
Expand All @@ -51,7 +51,7 @@ int AqvmMemory_CheckMemoryConditions() {
++warning_count;
}
if (sizeof(aqdouble) != 8) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"WARNING\"",
"\"AqvmMemory_CheckMemoryConditions_DoubleLengthWarning\"",
"\"The length requirement for the double type does not conform to the "
Expand All @@ -61,7 +61,7 @@ int AqvmMemory_CheckMemoryConditions() {
}

if (warning_count == 0) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"INFO\"", "\"AqvmMemory_CheckMemoryConditions_CheckNormal\"",
"\"No memory conditions warning.\"", NULL);
}
Expand All @@ -71,14 +71,14 @@ int AqvmMemory_CheckMemoryConditions() {

struct AqvmMemory_Memory* AqvmMemory_InitializeMemory(void* data, void* type,
size_t size) {
AqvmRuntimeDebugger_OutputReport("\"INFO\"",
"\"AqvmMemory_InitializeMemory_Start\"",
"\"Memory initialization started.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"INFO\"",
"\"AqvmMemory_InitializeMemory_Start\"",
"\"Memory initialization started.\"", NULL);

struct AqvmMemory_Memory* memory_ptr =
(struct AqvmMemory_Memory*)malloc(sizeof(struct AqvmMemory_Memory));
if (memory_ptr == NULL) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"ERROR\"", "\"AqvmMemory_CreateMemory_MemoryAllocationFailure\"",
"\"Failed to allocate memory.\"", NULL);
return NULL;
Expand All @@ -92,37 +92,36 @@ struct AqvmMemory_Memory* AqvmMemory_InitializeMemory(void* data, void* type,
}

void AqvmMemory_FreeMemory(struct AqvmMemory_Memory* memory_ptr) {
AqvmRuntimeDebugger_OutputReport("\"INFO\"",
"\"AqvmMemory_FreeMemory_Start\"",
"\"Memory deallocation started.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"INFO\"", "\"AqvmMemory_FreeMemory_Start\"",
"\"Memory deallocation started.\"", NULL);

free(memory_ptr);
}

int AqvmMemory_SetType(const struct AqvmMemory_Memory* memory, size_t index,
uint8_t type) {
if (memory == NULL) {
AqvmRuntimeDebugger_OutputReport("\"ERROR\"",
"\"AqvmMemory_SetType_NullMemoryPointer\"",
"\"The memory pointer is NULL.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"",
"\"AqvmMemory_SetType_NullMemoryPointer\"",
"\"The memory pointer is NULL.\"", NULL);
return -1;
}
if (memory->type == NULL) {
AqvmRuntimeDebugger_OutputReport("\"ERROR\"",
"\"AqvmMemory_SetType_NullTypePointer\"",
"\"The type pointer is NULL.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"",
"\"AqvmMemory_SetType_NullTypePointer\"",
"\"The type pointer is NULL.\"", NULL);
return -2;
}
if (index > memory->size) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"ERROR\"", "\"AqvmMemory_SetType_OutOfMemoryRange\"",
"\"The index is out of memory range.\"", NULL);
return -3;
}
if (type > 0x0F) {
AqvmRuntimeDebugger_OutputReport("\"ERROR\"",
"\"AqvmMemory_SetType_OutOfTypeRange\"",
"\"The type is out of range.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"",
"\"AqvmMemory_SetType_OutOfTypeRange\"",
"\"The type is out of range.\"", NULL);
return -4;
}

Expand All @@ -143,19 +142,19 @@ int AqvmMemory_SetType(const struct AqvmMemory_Memory* memory, size_t index,

uint8_t AqvmMemory_GetType(struct AqvmMemory_Memory* memory, size_t index) {
if (memory == NULL) {
AqvmRuntimeDebugger_OutputReport("\"ERROR\"",
"\"AqvmMemory_GetType_NullMemoryPointer\"",
"\"The memory pointer is NULL.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"",
"\"AqvmMemory_GetType_NullMemoryPointer\"",
"\"The memory pointer is NULL.\"", NULL);
return 0x11;
}
if (memory->type == NULL) {
AqvmRuntimeDebugger_OutputReport("\"ERROR\"",
"\"AqvmMemory_GetType_NullTypePointer\"",
"\"The type pointer is NULL.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"",
"\"AqvmMemory_GetType_NullTypePointer\"",
"\"The type pointer is NULL.\"", NULL);
return 0x12;
}
if (index > memory->size) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"ERROR\"", "\"AqvmMemory_GetType_OutOfMemoryRange\"",
"\"The index is out of memory range.\"", NULL);
return 0x13;
Expand All @@ -177,27 +176,27 @@ uint8_t AqvmMemory_GetType(struct AqvmMemory_Memory* memory, size_t index) {
int AqvmMemory_WriteData(struct AqvmMemory_Memory* memory, size_t index,
void* data_ptr, size_t size) {
if (memory == NULL) {
AqvmRuntimeDebugger_OutputReport(
"\"ERROR\"", "\"AqvmMemory_WriteData_NullMemoryPointer\"",
"\"The memory pointer is NULL.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"",
"\"AqvmMemory_WriteData_NullMemoryPointer\"",
"\"The memory pointer is NULL.\"", NULL);
return -1;
}
if (memory->type == NULL) {
AqvmRuntimeDebugger_OutputReport("\"ERROR\"",
"\"AqvmMemory_WriteData_NullTypePointer\"",
"\"The type pointer is NULL.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"",
"\"AqvmMemory_WriteData_NullTypePointer\"",
"\"The type pointer is NULL.\"", NULL);
return -2;
}
if (index > memory->size) {
AqvmRuntimeDebugger_OutputReport(
AqvmRuntimeDebugger_OutputLog(
"\"ERROR\"", "\"AqvmMemory_WriteData_OutOfMemoryRange\"",
"\"The index is out of memory range.\"", NULL);
return -3;
}
if (data_ptr == NULL) {
AqvmRuntimeDebugger_OutputReport("\"ERROR\"",
"\"AqvmMemory_WriteData_NullDataPointer\"",
"\"The data pointer is NULL.\"", NULL);
AqvmRuntimeDebugger_OutputLog("\"ERROR\"",
"\"AqvmMemory_WriteData_NullDataPointer\"",
"\"The data pointer is NULL.\"", NULL);
return -4;
}

Expand Down
8 changes: 4 additions & 4 deletions aqvm/runtime/debugger/debugger.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
#include <string.h>
#include <time.h>

void AqvmRuntimeDebugger_OutputReport(const char* type, const char* code,
const char* message,
const char* other_info) {
void AqvmRuntimeDebugger_OutputLog(const char* type, const char* code,
const char* message,
const char* other_info) {
if (type == NULL) {
type = "NULL";
}
Expand Down Expand Up @@ -41,7 +41,7 @@ void AqvmRuntimeDebugger_OutputReport(const char* type, const char* code,
stderr,
"{\"Time\":%s,\"Type\":%s,\"Code\":%s,\"Message\":%s,\"ErrnoInfo\":{"
"\"Errno\":%d,\"Message\":\"%s\"},\"OtherInfo\":%s}\n",
time_str, "ERROR", "AqvmRuntimeDebugger_OutputReport_OutputToFileError",
time_str, "ERROR", "AqvmRuntimeDebugger_OutputLog_OutputToFileError",
"Failed to open log file", errno, strerror(errno), "NULL");
return;
}
Expand Down
22 changes: 11 additions & 11 deletions aqvm/runtime/debugger/debugger.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@

#include <stdint.h>

// Outputs |report| with time, errno and so on to printing to the console or
// other devices and writing to a log file. No return.
// Outputs log with |type|, |code|, |message|, |other_info|, time, errno and so
// on to printing to the console or other devices and writing to a log file. No
// return.
// |type|, |code|, and |message| are necessary and shouldn't be set to NULL in
// common. But |other_info| can be set to NULL if it is not needed.
// In general, |type| should be "ERROR", "WARNING" or "INFO". |code| should be a
// full function name plus a concise description of the error, separated by
// underscores (e.g., AqvmRuntimeDebugger_OutputReport_TestInfo). |message|
// common. But |other_info| can be set to NULL if it is not needed. In general,
// |type| should be "ERROR", "WARNING" or "INFO". |code| should be a full
// function name plus a concise description of the error, separated by
// underscores (e.g., AqvmRuntimeDebugger_OutputLog_TestInfo). |message|
// should be a detailed and accurate description. |other_info| on the other hand
// should be an additional information to the current report (e.g. system
// should be an additional information to the current log (e.g. system
// information).
// NOTICE: If you need to use the function, please use json format. The output
// is json format. For example, AqvmRuntimeDebugger_OutputReport("\"type\"",
// is json format. For example, AqvmRuntimeDebugger_OutputLog("\"type\"",
// "\"code\"", "\"message\"", "\"other_info\"");
void AqvmRuntimeDebugger_OutputReport(const char* type, const char* code,
const char* message,
const char* other_info);
void AqvmRuntimeDebugger_OutputLog(const char* type, const char* code,
const char* message, const char* other_info);

#endif

0 comments on commit b683526

Please sign in to comment.