Skip to content

Commit

Permalink
Improve typechecking, both compile-time and runtime
Browse files Browse the repository at this point in the history
Adds much stricter typechecking in the iASL compiler, and
also adds some additional checking in the interpreter.
  • Loading branch information
acpibob committed Sep 18, 2015
1 parent 205528b commit 8d0f96e
Show file tree
Hide file tree
Showing 15 changed files with 500 additions and 147 deletions.
48 changes: 31 additions & 17 deletions source/compiler/aslbtypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,10 @@ AnMapArgTypeToBtype (
case ARGI_DDBHANDLE:
/*
* DDBHandleObject := SuperName
* ACPI_BTYPE_REFERENCE: Index reference as parameter of Load/Unload
* ACPI_BTYPE_REFERENCE_OBJECT:
* Index reference as parameter of Load/Unload
*/
return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE);
return (ACPI_BTYPE_DDB_HANDLE | ACPI_BTYPE_REFERENCE_OBJECT);

/* Interchangeable types */
/*
Expand Down Expand Up @@ -205,9 +206,24 @@ AnMapArgTypeToBtype (

case ARGI_REFERENCE:

return (ACPI_BTYPE_REFERENCE);
return (ACPI_BTYPE_NAMED_REFERENCE); /* Name or Namestring */

case ARGI_TARGETREF:

/*
* Target operand for most math and logic operators.
* Package objects not allowed as target.
*/
return (ACPI_BTYPE_COMPUTE_DATA | ACPI_BTYPE_DEBUG_OBJECT |
ACPI_BTYPE_REFERENCE_OBJECT);

case ARGI_STORE_TARGET:

/* Special target for Store(), includes packages */

return (ACPI_BTYPE_DATA | ACPI_BTYPE_DEBUG_OBJECT |
ACPI_BTYPE_REFERENCE_OBJECT);

case ARGI_FIXED_TARGET:
case ARGI_SIMPLE_TARGET:

Expand All @@ -221,28 +237,33 @@ AnMapArgTypeToBtype (
* Used only by SizeOf operator
*/
return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE);
ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE_OBJECT);

case ARGI_COMPLEXOBJ:

/* Buffer, String, or package */

return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER | ACPI_BTYPE_PACKAGE);
return (ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
ACPI_BTYPE_PACKAGE);

case ARGI_REF_OR_STRING:

return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE);
/* Used by DeRefOf operator only */

return (ACPI_BTYPE_STRING | ACPI_BTYPE_REFERENCE_OBJECT);

case ARGI_REGION_OR_BUFFER:

/* Used by Load() only. Allow buffers in addition to regions/fields */

return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER | ACPI_BTYPE_FIELD_UNIT);
return (ACPI_BTYPE_REGION | ACPI_BTYPE_BUFFER |
ACPI_BTYPE_FIELD_UNIT);

case ARGI_DATAREFOBJ:

return (ACPI_BTYPE_INTEGER |ACPI_BTYPE_STRING | ACPI_BTYPE_BUFFER |
ACPI_BTYPE_PACKAGE | ACPI_BTYPE_REFERENCE | ACPI_BTYPE_DDB_HANDLE);
/* Used by Store() only, as the source operand */

return (ACPI_BTYPE_DATA_REFERENCE | ACPI_BTYPE_REFERENCE_OBJECT);

default:

Expand Down Expand Up @@ -346,7 +367,7 @@ AnMapEtypeToBtype (
case ACPI_TYPE_LOCAL_RESOURCE:
case ACPI_TYPE_LOCAL_RESOURCE_FIELD:

return (ACPI_BTYPE_REFERENCE);
return (ACPI_BTYPE_REFERENCE_OBJECT);

default:

Expand Down Expand Up @@ -473,12 +494,6 @@ AnGetBtype (
"could not map type");
}

/*
* Since it was a named reference, enable the
* reference bit also
*/
ThisNodeBtype |= ACPI_BTYPE_REFERENCE;

if (Op->Asl.ParseOpcode == PARSEOP_METHODCALL)
{
ReferencedNode = Node->Op;
Expand Down Expand Up @@ -514,7 +529,6 @@ AnGetBtype (
return (ThisNodeBtype);
}


/*******************************************************************************
*
* FUNCTION: AnMapObjTypeToBtype
Expand Down
5 changes: 3 additions & 2 deletions source/compiler/aslmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ const ASL_MAPPING_ENTRY AslKeywordMapping [] =
{
/*! [Begin] no source code translation (keep the table structure) */

/* AML Opcode Value Flags Btype */

/* ACCESSAS */ OP_TABLE_ENTRY (AML_INT_ACCESSFIELD_OP, 0, 0, 0),
/* ACCESSATTRIB_BLOCK */ OP_TABLE_ENTRY (AML_BYTE_OP, AML_FIELD_ATTRIB_BLOCK, 0, 0),
Expand Down Expand Up @@ -313,7 +314,7 @@ const ASL_MAPPING_ENTRY AslKeywordMapping [] =
/* INCLUDE */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0),
/* INCLUDE_END */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0),
/* INCREMENT */ OP_TABLE_ENTRY (AML_INCREMENT_OP, 0, 0, ACPI_BTYPE_INTEGER),
/* INDEX */ OP_TABLE_ENTRY (AML_INDEX_OP, 0, 0, ACPI_BTYPE_REFERENCE),
/* INDEX */ OP_TABLE_ENTRY (AML_INDEX_OP, 0, 0, ACPI_BTYPE_REFERENCE_OBJECT),
/* INDEXFIELD */ OP_TABLE_ENTRY (AML_INDEX_FIELD_OP, 0, NODE_AML_PACKAGE, 0),
/* INTEGER */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, ACPI_BTYPE_INTEGER),
/* INTERRUPT */ OP_TABLE_ENTRY (AML_DEFAULT_ARG_OP, 0, 0, 0),
Expand Down Expand Up @@ -429,7 +430,7 @@ const ASL_MAPPING_ENTRY AslKeywordMapping [] =
/* RAW_DATA */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0),
/* READWRITETYPE_BOTH */ OP_TABLE_ENTRY (AML_BYTE_OP, 1, 0, 0),
/* READWRITETYPE_READONLY */ OP_TABLE_ENTRY (AML_BYTE_OP, 0, 0, 0),
/* REFOF */ OP_TABLE_ENTRY (AML_REF_OF_OP, 0, 0, ACPI_BTYPE_REFERENCE),
/* REFOF */ OP_TABLE_ENTRY (AML_REF_OF_OP, 0, 0, ACPI_BTYPE_REFERENCE_OBJECT),
/* REGIONSPACE_CMOS */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_CMOS, 0, 0),
/* REGIONSPACE_EC */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_EC, 0, 0),
/* REGIONSPACE_FFIXEDHW */ OP_TABLE_ENTRY (AML_RAW_DATA_BYTE, ACPI_ADR_SPACE_FIXED_HARDWARE, 0, 0),
Expand Down

0 comments on commit 8d0f96e

Please sign in to comment.