-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support for basic structure type. Signed-off-by: vsoch <vsoch@users.noreply.github.com> Co-authored-by: vsoch <vsoch@users.noreply.github.com>
- Loading branch information
Showing
14 changed files
with
369 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
all: | ||
clang++ -fPIC -shared -O3 -g -o libfoo.so foo.c | ||
clang++ -O3 -o v main.c -L. -lfoo -Wl,-rpath,`pwd` | ||
clang++ -O3 -o foo-exec main.c -L. -lfoo -Wl,-rpath,`pwd` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cpp | ||
|
||
func GetFloatTypes() []string { | ||
return []string{"float", "double", "long double"} | ||
} | ||
|
||
// Integral Types | ||
type FloatFormalParam struct { | ||
Name string | ||
Type string | ||
IsComplex bool | ||
IsPointer bool | ||
Value string | ||
} | ||
|
||
// Declaration of a formal param | ||
func (p FloatFormalParam) DeclareFormalParam() string { | ||
return p.Type + " " + p.Reference() | ||
} | ||
|
||
// DeclareValues includes the value | ||
func (p FloatFormalParam) DeclareValue() string { | ||
return p.Prefix() + p.Type + " " + p.Name + " = " + p.Value | ||
} | ||
|
||
// Declaration of a float | ||
func (p FloatFormalParam) Declaration() string { | ||
// This is a declaration for formal params (we need the * for pointer) | ||
return p.Type + " " + p.Reference() | ||
} | ||
|
||
// TODO the above returns a & but for struct we don't want that? | ||
// also look up ow to define struct with pointer... | ||
|
||
// Reference of an integral formal param | ||
func (p FloatFormalParam) Reference() string { | ||
if p.IsPointer { | ||
return "&" + p.Name | ||
} | ||
return p.Name | ||
} | ||
|
||
// Prefix of an integral formal param | ||
func (p FloatFormalParam) Prefix() string { | ||
|
||
// TODO need to add complex back | ||
// if p.IsComplex { | ||
// return "_Complex " | ||
// } | ||
return "" | ||
} | ||
|
||
// Type of an integral formal param | ||
func (p FloatFormalParam) GetType() string { | ||
if p.IsPointer { | ||
return p.Type + " *" | ||
} | ||
return p.Type | ||
} | ||
|
||
// Raw type | ||
func (p FloatFormalParam) GetRawType() string { | ||
return p.Type | ||
} | ||
|
||
// Value returns the string representation of the value | ||
func (p FloatFormalParam) GetValue() string { | ||
return p.Value | ||
} | ||
|
||
// GetName returns the name | ||
func (p FloatFormalParam) GetName() string { | ||
if p.IsPointer { | ||
return "*" + p.Name | ||
} | ||
return p.Name | ||
} | ||
|
||
// GetFieldName returns the name without decoration | ||
func (p FloatFormalParam) GetFieldName() string { | ||
return p.Name | ||
} | ||
|
||
// Print prints an float formal param | ||
func (p FloatFormalParam) Print() string { | ||
// TODO we will want more custom formatting based on the type here | ||
return "std::cout << \"" + p.Name + " \" << " + p.Reference() + " << std::endl;" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package cpp | ||
|
||
// INTEGRAL Possible integral types | ||
func GetIntegralTypes(withinStruct bool) []string { | ||
if withinStruct { | ||
return []string{"char", "short", "int", "long", "long long"} | ||
} | ||
return []string{"char", "short", "int", "std::size_t", "long", "long long", "__int128"} | ||
} | ||
|
||
// Integral Types | ||
type IntegralFormalParam struct { | ||
Name string | ||
Type string | ||
IsSigned bool | ||
IsPointer bool | ||
Value string // since we are printing to a template, this can be a string | ||
} | ||
|
||
// Declaration of a formal param | ||
func (p IntegralFormalParam) DeclareFormalParam() string { | ||
if p.IsPointer { | ||
return p.Prefix() + " " + p.Type + " * " + p.Name | ||
} | ||
return p.Prefix() + " " + p.GetType() + " " + p.GetName() | ||
} | ||
|
||
// DeclareValues includes the value | ||
func (p IntegralFormalParam) DeclareValue() string { | ||
var result string | ||
if p.GetType() == "__int128" { | ||
result = p.Prefix() + p.GetType() + " " + p.Name + ";" | ||
result += p.GetValue() | ||
return result | ||
} | ||
return p.Prefix() + p.Type + " " + p.Name + " = " + p.Value | ||
} | ||
|
||
// Declaration of an integral formal param | ||
func (p IntegralFormalParam) Declaration() string { | ||
result := p.Prefix() + p.Type + " " + p.Name | ||
if p.GetRawType() == "__int128" { | ||
return p.Prefix() + p.GetType() + " " + p.Name | ||
} | ||
return result | ||
} | ||
|
||
// GetValue returns the string representation of the value | ||
func (p IntegralFormalParam) GetValue() string { | ||
return p.Value | ||
} | ||
|
||
// GetName returns the string representation of the value | ||
func (p IntegralFormalParam) GetName() string { | ||
if p.IsPointer { | ||
return "* " + p.Name | ||
} | ||
return p.Name | ||
} | ||
func (p IntegralFormalParam) GetFieldName() string { | ||
return p.Name | ||
} | ||
|
||
// Reference of an integral formal param | ||
func (p IntegralFormalParam) Reference() string { | ||
|
||
// TODO need help creating these types | ||
if p.Type == "double" { | ||
return p.Name | ||
} | ||
if p.IsPointer { | ||
return "&" + p.Name | ||
} | ||
return p.Name | ||
} | ||
|
||
// Prefix of an integral formal param | ||
func (p IntegralFormalParam) Prefix() string { | ||
|
||
// size T always unsigned | ||
if p.Type == "std::size_t" { | ||
return "" | ||
} | ||
if p.IsSigned { | ||
return "signed " | ||
} | ||
return "unsigned " | ||
} | ||
|
||
// GetType of an integral formal param | ||
func (p IntegralFormalParam) GetType() string { | ||
if p.IsPointer { | ||
return p.Type + " *" | ||
} | ||
return p.Type | ||
} | ||
|
||
func (p IntegralFormalParam) GetRawType() string { | ||
return p.Type | ||
} | ||
|
||
// Print prints an integral formal param | ||
func (p IntegralFormalParam) Print() string { | ||
// TODO not sure how to do this one | ||
if p.Type == "__int128" { | ||
return "" | ||
} | ||
// TODO we will want custom printing based on the type here | ||
return "std::cout << \"" + p.Name + " \" << " + p.Reference() + " << std::endl;" | ||
} |
Oops, something went wrong.