Revision | 91405797e5e196fc099684f5813141e98537b96d (tree) |
---|---|
Time | 2014-07-08 15:39:41 |
Author | hikarupsp <hikarupsp@user...> |
Commiter | hikarupsp |
エラー表示機能のリファクタリング。
@@ -62,11 +62,11 @@ int CHNCPU_BIOS_Op_putcReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_Op | ||
62 | 62 | opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader); |
63 | 63 | |
64 | 64 | if(opCache->r >= CHNCPU_NUMBER_OF_IREG){ |
65 | - env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
65 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
66 | 66 | return -1; |
67 | 67 | } |
68 | 68 | if(prefix != 0){ |
69 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
69 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
70 | 70 | return -1; |
71 | 71 | } |
72 | 72 | return 0; |
@@ -228,7 +228,7 @@ int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env) | ||
228 | 228 | printf("Prefix-%X\n", opcode); |
229 | 229 | #endif |
230 | 230 | if(opcode > CHNCPU_PREFIX_MAX){ |
231 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
231 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
232 | 232 | break; |
233 | 233 | } |
234 | 234 | prefix |= (0x01 << opcode); |
@@ -241,7 +241,7 @@ int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env) | ||
241 | 241 | if(opcode <= CHNCPU_OPECODE_MAX && opSet->bindFuncTable[opcode]){ |
242 | 242 | opSet->bindFuncTable[opcode](env, op, prefix); |
243 | 243 | } else{ |
244 | - env->errFlags |= CHNCPU_ERR_C_OPCODE; | |
244 | + env->errFlags |= CHNCPU_ERR_INVALID_OPCODE; | |
245 | 245 | } |
246 | 246 | #if DEBUG_PRINT_OP_BINDING |
247 | 247 | if(op->opCode <= CHNCPU_OPECODE_MAX && opSet->printFuncTable[op->opCode]){ |
@@ -254,42 +254,18 @@ int CHNCPU_PrepareBinaryForExecution(CHNCPU_RuntimeEnvironment *env) | ||
254 | 254 | break; |
255 | 255 | } |
256 | 256 | if(env->appbinReader->errorFlags){ |
257 | - env->errFlags |= CHNCPU_ERR_C_INVALID_BIN; | |
257 | + env->errFlags |= CHNCPU_ERR_INVALID_BINARY; | |
258 | 258 | } |
259 | 259 | if(env->errFlags){ |
260 | 260 | break; |
261 | 261 | } |
262 | 262 | } |
263 | 263 | if(env->currentIndex >= CHNCPU_LENGTH_OF_MAIN_MEMORY && !CH4Reader_IsEndOfBinary(env->appbinReader)){ |
264 | - env->errFlags |= CHNCPU_ERR_C_INTERNAL; | |
264 | + env->errFlags |= CHNCPU_ERR_INTERNAL; | |
265 | 265 | puts("INVALID-C: Internal error (low on memory)."); |
266 | 266 | } |
267 | 267 | if(env->errFlags){ |
268 | - printf(">>> Compile error in label:%d\n", env->currentLabel); | |
269 | - if(env->errFlags & CHNCPU_ERR_C_REGNUM){ | |
270 | - puts("INVALID-C: Invalid register number."); | |
271 | - } | |
272 | - if(env->errFlags & CHNCPU_ERR_C_BITS){ | |
273 | - puts("INVALID-C: Not supported bit width."); | |
274 | - } | |
275 | - if(env->errFlags & CHNCPU_ERR_C_OPCODE){ | |
276 | - printf("INVALID-C: Unknown opCode 0x%X\n", opcode); | |
277 | - } | |
278 | - if(env->errFlags & CHNCPU_ERR_C_EXPRESSION){ | |
279 | - puts("INVALID-C: Invalid expression."); | |
280 | - } | |
281 | - if(env->errFlags & CHNCPU_ERR_C_INVALID_BIN){ | |
282 | - puts("INVALID-C: Invalid binary."); | |
283 | - } | |
284 | - if(env->errFlags & CHNCPU_ERR_C_PREFIX){ | |
285 | - puts("INVALID-C: Invalid prefix."); | |
286 | - } | |
287 | - if(env->errFlags & CHNCPU_ERR_C_DUPLICATED_LB){ | |
288 | - puts("INVALID-C: Duplicated LabelID."); | |
289 | - } | |
290 | - if(env->errFlags & CHNCPU_ERR_C_UNAVAILABLE_PTYPE){ | |
291 | - puts("INVALID-C: Unavailable pointer type."); | |
292 | - } | |
268 | + CHNCPU_PrintErrorMessage(env); | |
293 | 269 | } |
294 | 270 | env->currentIndex = 0; |
295 | 271 | env->currentLabel = 0; |
@@ -329,29 +305,12 @@ int CHNCPU_Execute(CHNCPU_RuntimeEnvironment *env) | ||
329 | 305 | } |
330 | 306 | } else{ |
331 | 307 | // ロード時にチェックしたはずなのに不明な命令が来た |
332 | - env->errFlags |= CHNCPU_ERR_X_INTERNAL; | |
308 | + env->errFlags |= CHNCPU_ERR_INTERNAL; | |
333 | 309 | break; |
334 | 310 | } |
335 | 311 | } |
336 | 312 | if(env->errFlags){ |
337 | - if(env->errFlags & CHNCPU_ERR_X_INTERNAL){ | |
338 | - puts("INVALID-X: Internal error."); | |
339 | - } | |
340 | - if(env->errFlags & CHNCPU_ERR_X_TRUNCATED_VALUE){ | |
341 | - puts("INVALID-X: Truncated value without prefix 2F-0."); | |
342 | - } | |
343 | - if(env->errFlags & CHNCPU_ERR_X_LABEL_NOT_FOUND){ | |
344 | - puts("INVALID-X: Label not found."); | |
345 | - } | |
346 | - if(env->errFlags & CHNCPU_ERR_X_PTYPE_NOT_MATCHED){ | |
347 | - puts("INVALID-X: Pointer type not matched."); | |
348 | - } | |
349 | - if(env->errFlags & CHNCPU_ERR_X_BAD_ACCESS){ | |
350 | - puts("INVALID-X: Bad access."); | |
351 | - } | |
352 | - if(env->errFlags & CHNCPU_ERR_X_INVALID_PTYPE){ | |
353 | - puts("INVALID-X: Invalid pointer type."); | |
354 | - } | |
313 | + CHNCPU_PrintErrorMessage(env); | |
355 | 314 | } |
356 | 315 | |
357 | 316 | #if (DEBUG_PRINT_IREG_AFTER_EXECUTION || DEBUG_PRINT_PREG_AFTER_EXECUTION) |
@@ -371,7 +330,7 @@ int CHNCPU_Execute(CHNCPU_RuntimeEnvironment *env) | ||
371 | 330 | int CHNCPU_CHK_IsAvailableBits(CHNCPU_RuntimeEnvironment *env, ch4_uint bits) |
372 | 331 | { |
373 | 332 | if(bits > 32){ |
374 | - env->errFlags |= CHNCPU_ERR_C_BITS; | |
333 | + env->errFlags |= CHNCPU_ERR_INVALID_BITS; | |
375 | 334 | return 0; |
376 | 335 | } |
377 | 336 | return 1; |
@@ -390,7 +349,7 @@ int CHNCPU_AdjustValueForBit(CHNCPU_RuntimeEnvironment *env, int *value, ch4_uin | ||
390 | 349 | return 0; |
391 | 350 | } |
392 | 351 | if(!(prefix & CHNCPU_PREFIX_ALLOW_TRUNCATE)){ |
393 | - env->errFlags |= CHNCPU_ERR_X_TRUNCATED_VALUE; | |
352 | + env->errFlags |= CHNCPU_ERR_TRUNCATED_VALUE; | |
394 | 353 | return 1; |
395 | 354 | } |
396 | 355 |
@@ -39,24 +39,21 @@ | ||
39 | 39 | #define CHNCPU_MemoryIndex_INVALID (-1) |
40 | 40 | #define CHNCPU_PREFIX_MAX 31 |
41 | 41 | |
42 | -// ErrorCode at compile | |
43 | -#define CHNCPU_ERR_C_REGNUM 0x0001 | |
44 | -#define CHNCPU_ERR_C_BITS 0x0002 | |
45 | -#define CHNCPU_ERR_C_OPCODE 0x0004 | |
46 | -#define CHNCPU_ERR_C_EXPRESSION 0x0008 | |
47 | -#define CHNCPU_ERR_C_INTERNAL 0x0010 | |
48 | -#define CHNCPU_ERR_C_INVALID_BIN 0x0020 | |
49 | -#define CHNCPU_ERR_C_PREFIX 0x0040 | |
50 | -#define CHNCPU_ERR_C_DUPLICATED_LB 0x0080 | |
51 | -#define CHNCPU_ERR_C_UNAVAILABLE_PTYPE 0x0100 | |
52 | - | |
53 | -// ErrorCode in execution | |
54 | -#define CHNCPU_ERR_X_INTERNAL 0x01 | |
55 | -#define CHNCPU_ERR_X_TRUNCATED_VALUE 0x02 | |
56 | -#define CHNCPU_ERR_X_LABEL_NOT_FOUND 0x04 | |
57 | -#define CHNCPU_ERR_X_PTYPE_NOT_MATCHED 0x08 | |
58 | -#define CHNCPU_ERR_X_BAD_ACCESS 0x10 | |
59 | -#define CHNCPU_ERR_X_INVALID_PTYPE 0x20 | |
42 | +// Common ErrorCode | |
43 | +#define CHNCPU_ERR_INTERNAL 0x0001 | |
44 | +#define CHNCPU_ERR_INVALID_BITS 0x0002 | |
45 | +#define CHNCPU_ERR_INVALID_OPCODE 0x0004 | |
46 | +#define CHNCPU_ERR_INVALID_REGNUM 0x0008 | |
47 | +#define CHNCPU_ERR_INVALID_PTYPE 0x0010 | |
48 | +#define CHNCPU_ERR_INVALID_BINARY 0x0020 | |
49 | +#define CHNCPU_ERR_INVALID_PREFIX 0x0040 | |
50 | +#define CHNCPU_ERR_INVALID_EXPRESSION 0x0080 | |
51 | +#define CHNCPU_ERR_INVALID_BIOS_FUNC_ID 0x0100 | |
52 | +#define CHNCPU_ERR_DUPLICATED_LABEL_ID 0x0200 | |
53 | +#define CHNCPU_ERR_NOT_FOUND_LABEL 0x0400 | |
54 | +#define CHNCPU_ERR_NOT_MATCHED_PTYPE 0x0800 | |
55 | +#define CHNCPU_ERR_TRUNCATED_VALUE 0x1000 | |
56 | +#define CHNCPU_ERR_BAD_ACCESS 0x2000 | |
60 | 57 | |
61 | 58 | // (2F)Prefix |
62 | 59 | #define CHNCPU_PREFIX_ALLOW_TRUNCATE 0x01 |
@@ -224,7 +221,7 @@ int CHNCPU_Op_DATA_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
224 | 221 | int CHNCPU_Op_DATA_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op); |
225 | 222 | int CHNCPU_Op_DATA_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file); |
226 | 223 | CHNCPU_OpTag *CHNCPU_Op_DATA_CreateEmptyData(void); |
227 | -int CHNCPU_Op_DATA_AllocateRawDataMemory(CHNCPU_OpTag *op, ch4_sint dataType, ch4_uint dataCount); | |
224 | +int CHNCPU_Op_DATA_AllocateRawDataMemory(CHNCPU_OpTag *op, ch4_sint dataType, ch4_uint dataCount, unsigned int *errFlags); | |
228 | 225 | CHNCPU_OpTag *CHNCPU_Op_DATA_CreateDataFromFileAsPType(const char dataPath[], ch4_sint pType); |
229 | 226 | int CHNCPU_Op_DATA_AssignDataTagToPReg(CHNCPU_RuntimeEnvironment *env, ch4_uint p, CHNCPU_OpTag *op); |
230 | 227 | int CHNCPU_Op_DATA_WriteRawDataToFile(CHNCPU_OpTag *op, const char dataPath[], int dataCount, int dataType); |
@@ -252,5 +249,6 @@ CHNCPU_LabelTag *CHNCPU_Label_GetTagFromLabelID(CHNCPU_LabelSet *lbSet, int labe | ||
252 | 249 | void CHNCPU_DumpAppBin(CHNCPU_RuntimeEnvironment *env); |
253 | 250 | void CHNCPU_DumpIReg(CHNCPU_RuntimeEnvironment *env); |
254 | 251 | void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env); |
252 | +void CHNCPU_PrintErrorMessage(CHNCPU_RuntimeEnvironment *env); | |
255 | 253 | |
256 | 254 | #endif |
@@ -112,11 +112,11 @@ int CHNCPU_Op_LB_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, u | ||
112 | 112 | env->currentLabel = opCache->labelID; |
113 | 113 | |
114 | 114 | if(CHNCPU_Label_Add(env->labelSet, env->currentIndex, opCache->labelID, opCache->opt, CHNCPU_PType_Label)){ |
115 | - env->errFlags |= CHNCPU_ERR_C_DUPLICATED_LB; | |
115 | + env->errFlags |= CHNCPU_ERR_DUPLICATED_LABEL_ID; | |
116 | 116 | } |
117 | 117 | |
118 | 118 | if(prefix != 0){ |
119 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
119 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
120 | 120 | return -1; |
121 | 121 | } |
122 | 122 | return 0; |
@@ -157,18 +157,18 @@ int CHNCPU_Op_LIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
157 | 157 | opCache->bit = CH4Reader_ReadNextAsUINT(env->appbinReader); |
158 | 158 | |
159 | 159 | if(opCache->r >= CHNCPU_NUMBER_OF_IREG){ |
160 | - env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
160 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
161 | 161 | return -1; |
162 | 162 | } |
163 | 163 | if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bit)){ |
164 | 164 | return -1; |
165 | 165 | } |
166 | 166 | if(opCache->bit == 0 && opCache->imm != 0){ |
167 | - env->errFlags |= CHNCPU_ERR_C_EXPRESSION; | |
167 | + env->errFlags |= CHNCPU_ERR_INVALID_EXPRESSION; | |
168 | 168 | return -1; |
169 | 169 | } |
170 | 170 | if(prefix != 0){ |
171 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
171 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
172 | 172 | return -1; |
173 | 173 | } |
174 | 174 | CHNCPU_AdjustValueForBit(env, &opCache->imm, opCache->bit, CHNCPU_PREFIX_ALLOW_TRUNCATE); |
@@ -214,11 +214,11 @@ int CHNCPU_Op_PLIMM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op | ||
214 | 214 | opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader); |
215 | 215 | |
216 | 216 | if(opCache->r >= CHNCPU_NUMBER_OF_PREG){ |
217 | - env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
217 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
218 | 218 | return -1; |
219 | 219 | } |
220 | 220 | if(prefix != 0){ |
221 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
221 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
222 | 222 | return -1; |
223 | 223 | } |
224 | 224 | return 0; |
@@ -232,7 +232,7 @@ int CHNCPU_Op_PLIMM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | ||
232 | 232 | |
233 | 233 | label = CHNCPU_Label_GetTagFromLabelID(env->labelSet, opCache->labelID); |
234 | 234 | if(!label){ |
235 | - env->errFlags |= CHNCPU_ERR_X_LABEL_NOT_FOUND; | |
235 | + env->errFlags |= CHNCPU_ERR_NOT_FOUND_LABEL; | |
236 | 236 | return -1; |
237 | 237 | } |
238 | 238 |
@@ -276,11 +276,11 @@ int CHNCPU_Op_CND_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
276 | 276 | opCache->r = CH4Reader_ReadNextAsUINT(env->appbinReader); |
277 | 277 | |
278 | 278 | if(opCache->r >= CHNCPU_NUMBER_OF_PREG){ |
279 | - env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
279 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
280 | 280 | return -1; |
281 | 281 | } |
282 | 282 | if(prefix != 0){ |
283 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
283 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
284 | 284 | return -1; |
285 | 285 | } |
286 | 286 | return 0; |
@@ -326,7 +326,7 @@ int CHNCPU_Op_CALLBIOS_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag | ||
326 | 326 | if(fid <= CHNCPU_BIOS_OP_MAX && env->bios->bindFuncTable[fid]){ |
327 | 327 | env->bios->bindFuncTable[fid](env, opCache, prefix); |
328 | 328 | } else{ |
329 | - env->errFlags |= CHNCPU_ERR_C_OPCODE; | |
329 | + env->errFlags |= CHNCPU_ERR_INVALID_BIOS_FUNC_ID; | |
330 | 330 | } |
331 | 331 | |
332 | 332 | if(env->errFlags){ |
@@ -346,7 +346,7 @@ int CHNCPU_Op_CALLBIOS_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | ||
346 | 346 | env->bios->execFuncTable[fid](env, opCache); |
347 | 347 | } else{ |
348 | 348 | // ロード時にチェックしたはずなのに不明な命令が来た |
349 | - env->errFlags |= CHNCPU_ERR_X_INTERNAL; | |
349 | + env->errFlags |= CHNCPU_ERR_INTERNAL; | |
350 | 350 | } |
351 | 351 | |
352 | 352 | return 0; |
@@ -387,14 +387,14 @@ int CHNCPU_Op_LMEM_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
387 | 387 | |
388 | 388 | if(opCache->r >= CHNCPU_NUMBER_OF_IREG || |
389 | 389 | opCache->p >= CHNCPU_NUMBER_OF_PREG){ |
390 | - env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
390 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
391 | 391 | return -1; |
392 | 392 | } |
393 | 393 | if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bitDst)){ |
394 | 394 | return -1; |
395 | 395 | } |
396 | 396 | if(prefix != 0){ |
397 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
397 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
398 | 398 | return -1; |
399 | 399 | } |
400 | 400 | return 0; |
@@ -409,7 +409,7 @@ int CHNCPU_Op_LMEM_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | ||
409 | 409 | p = &env->pReg[opCache->p]; |
410 | 410 | |
411 | 411 | if(p->type != opCache->pType){ |
412 | - env->errFlags |= CHNCPU_ERR_X_PTYPE_NOT_MATCHED; | |
412 | + env->errFlags |= CHNCPU_ERR_NOT_MATCHED_PTYPE; | |
413 | 413 | return -1; |
414 | 414 | } |
415 | 415 |
@@ -458,14 +458,14 @@ int CHNCPU_Op_TernaryReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTa | ||
458 | 458 | if(opCache->r0 >= CHNCPU_NUMBER_OF_IREG || |
459 | 459 | opCache->r1 >= CHNCPU_NUMBER_OF_IREG || |
460 | 460 | opCache->r2 >= CHNCPU_NUMBER_OF_IREG){ |
461 | - env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
461 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
462 | 462 | return -1; |
463 | 463 | } |
464 | 464 | if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bit)){ |
465 | 465 | return -1; |
466 | 466 | } |
467 | 467 | if((prefix | CHNCPU_PREFIX_MASK_Op_TernaryReg) != CHNCPU_PREFIX_MASK_Op_TernaryReg){ |
468 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
468 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
469 | 469 | return -1; |
470 | 470 | } |
471 | 471 | return 0; |
@@ -494,13 +494,13 @@ int CHNCPU_Op_TernaryRegBitwise_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_O | ||
494 | 494 | // AND |
495 | 495 | result = env->iReg[opCache->r1] & env->iReg[opCache->r2]; |
496 | 496 | } else{ |
497 | - env->errFlags |= CHNCPU_ERR_X_INTERNAL; | |
497 | + env->errFlags |= CHNCPU_ERR_INTERNAL; | |
498 | 498 | return -1; |
499 | 499 | } |
500 | 500 | // check |
501 | 501 | checked = result & (0xFFFFFFFF >> (32 - opCache->bit)); |
502 | 502 | if(!(opCache->prefix & CHNCPU_PREFIX_ALLOW_TRUNCATE) && checked != result){ |
503 | - env->errFlags |= CHNCPU_ERR_X_TRUNCATED_VALUE; | |
503 | + env->errFlags |= CHNCPU_ERR_TRUNCATED_VALUE; | |
504 | 504 | return -1; |
505 | 505 | } |
506 | 506 | // store |
@@ -534,7 +534,7 @@ int CHNCPU_Op_TernaryRegArithmetic_Execute(CHNCPU_RuntimeEnvironment *env, CHNCP | ||
534 | 534 | } else if(opCode == 0x1B){ // MOD |
535 | 535 | result = env->iReg[opCache->r1] % env->iReg[opCache->r2]; |
536 | 536 | } else{ |
537 | - env->errFlags |= CHNCPU_ERR_X_INTERNAL; | |
537 | + env->errFlags |= CHNCPU_ERR_INTERNAL; | |
538 | 538 | return -1; |
539 | 539 | } |
540 | 540 | // check |
@@ -606,7 +606,7 @@ int CHNCPU_Op_CompareIReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpT | ||
606 | 606 | if(opCache->rSrc1 >= CHNCPU_NUMBER_OF_IREG || |
607 | 607 | opCache->rSrc2 >= CHNCPU_NUMBER_OF_IREG || |
608 | 608 | opCache->rDst >= CHNCPU_NUMBER_OF_IREG){ |
609 | - env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
609 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
610 | 610 | return -1; |
611 | 611 | } |
612 | 612 | if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bitDiff) || |
@@ -614,7 +614,7 @@ int CHNCPU_Op_CompareIReg_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpT | ||
614 | 614 | return -1; |
615 | 615 | } |
616 | 616 | if((prefix | CHNCPU_PREFIX_MASK_Op_CompareIReg) != CHNCPU_PREFIX_MASK_Op_CompareIReg){ |
617 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
617 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
618 | 618 | return -1; |
619 | 619 | } |
620 | 620 | return 0; |
@@ -660,12 +660,12 @@ int CHNCPU_Op_CompareIReg_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag * | ||
660 | 660 | } else if(opCode == 0x27){ |
661 | 661 | result = ((r1 & r2) != 0) ? -1 : 0; |
662 | 662 | } else{ |
663 | - env->errFlags |= CHNCPU_ERR_X_INTERNAL; | |
663 | + env->errFlags |= CHNCPU_ERR_INTERNAL; | |
664 | 664 | return -1; |
665 | 665 | } |
666 | 666 | // check with bitDst |
667 | 667 | if(opCache->bitDst == 0){ |
668 | - env->errFlags |= CHNCPU_ERR_X_TRUNCATED_VALUE; | |
668 | + env->errFlags |= CHNCPU_ERR_TRUNCATED_VALUE; | |
669 | 669 | return -1; |
670 | 670 | } |
671 | 671 | // store |
@@ -725,12 +725,7 @@ int CHNCPU_Op_DATA_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
725 | 725 | opCache->filePath = NULL; |
726 | 726 | |
727 | 727 | // Check ptype & Calculate rawDataByteSize |
728 | - if(CHNCPU_Op_DATA_AllocateRawDataMemory(op, opCache->dataType, opCache->dataCount)){ | |
729 | - if(CHNCPU_Op_DATA_CalculateByteSizeOfRawData(opCache->dataType, opCache->dataCount) <= 0){ | |
730 | - env->errFlags |= CHNCPU_ERR_C_UNAVAILABLE_PTYPE; | |
731 | - } else{ | |
732 | - env->errFlags |= CHNCPU_ERR_C_INTERNAL; | |
733 | - } | |
728 | + if(CHNCPU_Op_DATA_AllocateRawDataMemory(op, opCache->dataType, opCache->dataCount, &env->errFlags)){ | |
734 | 729 | return -1; |
735 | 730 | } |
736 | 731 |
@@ -742,11 +737,11 @@ int CHNCPU_Op_DATA_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
742 | 737 | } |
743 | 738 | |
744 | 739 | if(CHNCPU_Label_Add(env->labelSet, env->currentIndex, opCache->labelID, opCache->labelOpt, opCache->dataType)){ |
745 | - env->errFlags |= CHNCPU_ERR_C_DUPLICATED_LB; | |
740 | + env->errFlags |= CHNCPU_ERR_DUPLICATED_LABEL_ID; | |
746 | 741 | } |
747 | 742 | |
748 | 743 | if(prefix != 0){ |
749 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
744 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
750 | 745 | return -1; |
751 | 746 | } |
752 | 747 | return 0; |
@@ -811,18 +806,24 @@ CHNCPU_OpTag *CHNCPU_Op_DATA_CreateEmptyData(void) | ||
811 | 806 | |
812 | 807 | return op; |
813 | 808 | } |
814 | -int CHNCPU_Op_DATA_AllocateRawDataMemory(CHNCPU_OpTag *op, ch4_sint dataType, ch4_uint dataCount) | |
809 | +int CHNCPU_Op_DATA_AllocateRawDataMemory(CHNCPU_OpTag *op, ch4_sint dataType, ch4_uint dataCount, unsigned int *errFlags) | |
815 | 810 | { |
816 | 811 | // 生データのメモリを割り当てる。 |
817 | 812 | CHNCPU_OpCache_DATA *opCache; |
818 | 813 | |
819 | 814 | if(!op || op->opCode != CHNCPU_OP_DATA || !op->opCache){ |
815 | + if(errFlags){ | |
816 | + *errFlags |= CHNCPU_ERR_INTERNAL; | |
817 | + } | |
820 | 818 | return -1; |
821 | 819 | } |
822 | 820 | opCache = op->opCache; |
823 | 821 | |
824 | 822 | opCache->rawDataByteSize = CHNCPU_Op_DATA_CalculateByteSizeOfRawData(dataType, dataCount); |
825 | 823 | if(opCache->rawDataByteSize <= 0){ |
824 | + if(errFlags){ | |
825 | + *errFlags |= CHNCPU_ERR_INVALID_PTYPE; | |
826 | + } | |
826 | 827 | return -1; |
827 | 828 | } |
828 | 829 | if(opCache->rawData){ |
@@ -865,7 +866,7 @@ CHNCPU_OpTag *CHNCPU_Op_DATA_CreateDataFromFileAsPType(const char dataPath[], ch | ||
865 | 866 | fseek(fp, 0, SEEK_SET); |
866 | 867 | |
867 | 868 | // 現状はUINT8前提なのでopCache->rawDataByteSize==dataCount |
868 | - if(CHNCPU_Op_DATA_AllocateRawDataMemory(op, pType, opCache->rawDataByteSize)){ | |
869 | + if(CHNCPU_Op_DATA_AllocateRawDataMemory(op, pType, opCache->rawDataByteSize, NULL)){ | |
869 | 870 | fclose(fp); |
870 | 871 | free(opCache); |
871 | 872 | free(op); |
@@ -950,7 +951,7 @@ int CHNCPU_Op_DATA_ReadAtIndex(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
950 | 951 | |
951 | 952 | |
952 | 953 | if(!op || op->opCode != CHNCPU_OP_DATA || index < 0 || index >= ((CHNCPU_OpCache_DATA *)op->opCache)->dataCount){ |
953 | - env->errFlags |= CHNCPU_ERR_X_BAD_ACCESS; | |
954 | + env->errFlags |= CHNCPU_ERR_BAD_ACCESS; | |
954 | 955 | return 0; |
955 | 956 | } |
956 | 957 | opCache = op->opCache; |
@@ -958,7 +959,7 @@ int CHNCPU_Op_DATA_ReadAtIndex(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
958 | 959 | if(opCache->dataType == CHNCPU_PType_UINT8){ |
959 | 960 | retv = ((unsigned char *)opCache->rawData)[index]; |
960 | 961 | } else{ |
961 | - env->errFlags |= CHNCPU_ERR_X_INVALID_PTYPE; | |
962 | + env->errFlags |= CHNCPU_ERR_INVALID_PTYPE; | |
962 | 963 | return 0; |
963 | 964 | } |
964 | 965 |
@@ -999,7 +1000,7 @@ const char *CHNCPU_Op_DATA_GetFilePath(CHNCPU_OpTag *op) | ||
999 | 1000 | // |
1000 | 1001 | // 32 MALLOC |
1001 | 1002 | // |
1002 | -/* | |
1003 | + | |
1003 | 1004 | int CHNCPU_Op_MALLOC_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, unsigned int prefix) |
1004 | 1005 | { |
1005 | 1006 | CHNCPU_OpCache_MALLOC *opCache; |
@@ -1016,7 +1017,7 @@ int CHNCPU_Op_MALLOC_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *o | ||
1016 | 1017 | if(opCache->rType >= CHNCPU_NUMBER_OF_IREG || |
1017 | 1018 | opCache->rCount >= CHNCPU_NUMBER_OF_IREG || |
1018 | 1019 | opCache->p >= CHNCPU_NUMBER_OF_PREG){ |
1019 | - env->errFlags |= CHNCPU_ERR_C_REGNUM; | |
1020 | + env->errFlags |= CHNCPU_ERR_INVALID_REGNUM; | |
1020 | 1021 | return -1; |
1021 | 1022 | } |
1022 | 1023 | if(!CHNCPU_CHK_IsAvailableBits(env, opCache->bitType) || |
@@ -1024,7 +1025,7 @@ int CHNCPU_Op_MALLOC_BindOperand(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *o | ||
1024 | 1025 | return -1; |
1025 | 1026 | } |
1026 | 1027 | if(prefix != 0){ |
1027 | - env->errFlags |= CHNCPU_ERR_C_PREFIX; | |
1028 | + env->errFlags |= CHNCPU_ERR_INVALID_PREFIX; | |
1028 | 1029 | return -1; |
1029 | 1030 | } |
1030 | 1031 | return 0; |
@@ -1034,7 +1035,6 @@ int CHNCPU_Op_MALLOC_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | ||
1034 | 1035 | { |
1035 | 1036 | CHNCPU_OpTag *dataOpTag; |
1036 | 1037 | CHNCPU_OpCache_MALLOC *opCache; |
1037 | - int value; | |
1038 | 1038 | ch4_sint type; |
1039 | 1039 | ch4_uint count; |
1040 | 1040 |
@@ -1044,26 +1044,11 @@ int CHNCPU_Op_MALLOC_Execute(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op) | ||
1044 | 1044 | count = env->iReg[opCache->rCount]; |
1045 | 1045 | |
1046 | 1046 | dataOpTag = CHNCPU_Op_DATA_CreateEmptyData(); |
1047 | - if(CHNCPU_Op_DATA_AllocateRawDataMemory(dataOpTag, type, count)){ | |
1048 | - | |
1049 | - } | |
1050 | - | |
1051 | - | |
1052 | - value = CHNCPU_Op_DATA_ReadAtIndex(env, p->opTag, p->pindex); | |
1053 | - if(env->errFlags){ | |
1047 | + if(CHNCPU_Op_DATA_AllocateRawDataMemory(dataOpTag, type, count, &env->errFlags)){ | |
1054 | 1048 | return -1; |
1055 | 1049 | } |
1056 | 1050 | |
1057 | - CHNCPU_AdjustValueForBit(env, &value, opCache->bitDst, CHNCPU_PREFIX_ALLOW_TRUNCATE); | |
1058 | - if(env->errFlags){ | |
1059 | - return -1; | |
1060 | - } | |
1061 | - env->iReg[opCache->r] = value; | |
1062 | - env->iRegBits[opCache->r] = opCache->bitDst; | |
1063 | - | |
1064 | - p->pindex += opCache->pDiff; | |
1065 | - | |
1066 | - return 0; | |
1051 | + return 0; | |
1067 | 1052 | } |
1068 | 1053 | int CHNCPU_Op_MALLOC_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, FILE *file) |
1069 | 1054 | { |
@@ -1073,6 +1058,4 @@ int CHNCPU_Op_MALLOC_PrintCode(CHNCPU_RuntimeEnvironment *env, CHNCPU_OpTag *op, | ||
1073 | 1058 | fprintf(file, "LMEM(p:0x%02X, pType:0x%X, pDiff:%d, r:%02X, bitDst:%d);\n", opCache->p, opCache->pType, opCache->pDiff, opCache->r, opCache->bitDst); |
1074 | 1059 | |
1075 | 1060 | return 0; |
1076 | -} | |
1077 | - | |
1078 | -*/ | |
\ No newline at end of file | ||
1061 | +} | |
\ No newline at end of file |
@@ -62,3 +62,51 @@ void CHNCPU_DumpPReg(CHNCPU_RuntimeEnvironment *env) | ||
62 | 62 | putchar('\n'); |
63 | 63 | } |
64 | 64 | } |
65 | + | |
66 | +void CHNCPU_PrintErrorMessage(CHNCPU_RuntimeEnvironment *env) | |
67 | +{ | |
68 | + printf(">>> Error in label:%d\n\t", env->currentLabel); | |
69 | + if(env->errFlags & CHNCPU_ERR_INTERNAL){ | |
70 | + puts("Internal error."); | |
71 | + } | |
72 | + if(env->errFlags & CHNCPU_ERR_INVALID_BITS){ | |
73 | + puts("Invalid bits."); | |
74 | + } | |
75 | + if(env->errFlags & CHNCPU_ERR_INVALID_OPCODE){ | |
76 | + puts("Invalid opCode."); | |
77 | + } | |
78 | + if(env->errFlags & CHNCPU_ERR_INVALID_REGNUM){ | |
79 | + puts("Invalid regNum."); | |
80 | + } | |
81 | + if(env->errFlags & CHNCPU_ERR_INVALID_PTYPE){ | |
82 | + puts("Invalid pType."); | |
83 | + } | |
84 | + if(env->errFlags & CHNCPU_ERR_INVALID_BINARY){ | |
85 | + puts("Invalid Binary."); | |
86 | + } | |
87 | + if(env->errFlags & CHNCPU_ERR_INVALID_PREFIX){ | |
88 | + puts("Invalid prefix."); | |
89 | + } | |
90 | + if(env->errFlags & CHNCPU_ERR_INVALID_EXPRESSION){ | |
91 | + puts("Invalid expression."); | |
92 | + } | |
93 | + if(env->errFlags & CHNCPU_ERR_INVALID_EXPRESSION){ | |
94 | + puts("Invalid BIOSFuncID."); | |
95 | + } | |
96 | + if(env->errFlags & CHNCPU_ERR_DUPLICATED_LABEL_ID){ | |
97 | + puts("LabelID duplicated."); | |
98 | + } | |
99 | + if(env->errFlags & CHNCPU_ERR_NOT_FOUND_LABEL){ | |
100 | + puts("LabelID not found."); | |
101 | + } | |
102 | + if(env->errFlags & CHNCPU_ERR_NOT_MATCHED_PTYPE){ | |
103 | + puts("PType not matched."); | |
104 | + } | |
105 | + if(env->errFlags & CHNCPU_ERR_TRUNCATED_VALUE){ | |
106 | + puts("Value truncated without prefix 2F-0."); | |
107 | + } | |
108 | + if(env->errFlags & CHNCPU_ERR_BAD_ACCESS){ | |
109 | + puts("Bad access on memory."); | |
110 | + } | |
111 | + return; | |
112 | +} |